Compilation problem. Optimizations. Sounds should not collide any more

This commit is contained in:
bsongis
2012-02-01 13:54:14 +00:00
parent 8d0265cd3e
commit 1ef48ee323
2 changed files with 97 additions and 114 deletions
+15 -36
View File
@@ -12,9 +12,7 @@
* *
*/ */
#include "er9x.h" #include "open9x.h"
#if defined(PCBV4) #if defined(PCBV4)
#define SPEAKER_OFF TCCR0A &= ~(1<<COM0A0) // tone off #define SPEAKER_OFF TCCR0A &= ~(1<<COM0A0) // tone off
@@ -48,16 +46,6 @@ void audioQueue::aqinit()
#ifdef FRSKY #ifdef FRSKY
frskySample = 0; frskySample = 0;
#endif #endif
//flush queue on init!
for(uint8_t x = 0; x < AUDIO_QUEUE_LENGTH; x++){
queueToneFreq[x] = 0;
queueToneFreqIncr[x] = 0;
queueToneLength[x] = 0;
queueTonePause[x] = 0;
queueToneRepeat[x] = 0;
}
} }
bool audioQueue::busy() bool audioQueue::busy()
@@ -65,12 +53,12 @@ bool audioQueue::busy()
return (toneTimeLeft > 0); return (toneTimeLeft > 0);
} }
/* TODO to be added when needed #if 0
bool audioQueue::freeslots(uint8_t slots) bool audioQueue::freeslots(uint8_t slots)
{ {
return AUDIO_QUEUE_LENGTH - ((t_queueWidx + AUDIO_QUEUE_LENGTH - t_queueRidx) % AUDIO_QUEUE_LENGTH) >= slots; return AUDIO_QUEUE_LENGTH - ((t_queueWidx + AUDIO_QUEUE_LENGTH - t_queueRidx) % AUDIO_QUEUE_LENGTH) >= slots;
} }
*/ #endif
// heartbeat is responsibile for issueing the audio tones and general square waves // heartbeat is responsibile for issueing the audio tones and general square waves
// it is essentially the life of the class. // it is essentially the life of the class.
@@ -143,14 +131,6 @@ void audioQueue::playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr)
{ {
if (g_eeGeneral.beeperVal) { if (g_eeGeneral.beeperVal) {
//required or you cannot do haptic only events
if(tFreq == 0){
toneFreq = 0;
} else {
toneFreq = tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator
}
toneFreq = (tFreq ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator toneFreq = (tFreq ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator
toneTimeLeft = getToneLength(tLen); toneTimeLeft = getToneLength(tLen);
tonePause = tPause; tonePause = tPause;
@@ -171,14 +151,8 @@ void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr)
{ {
if (g_eeGeneral.beeperVal) { if (g_eeGeneral.beeperVal) {
uint8_t next_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH;
//required or you cannot do haptic only events if (next_queueWidx != t_queueRidx) {
if(tFreq == 0){
queueToneFreq[t_queueWidx] = 0;
} else {
queueToneFreq[t_queueWidx] = tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator
}
queueToneFreq[t_queueWidx] = (tFreq ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator queueToneFreq[t_queueWidx] = (tFreq ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator
queueToneLength[t_queueWidx] = getToneLength(tLen); queueToneLength[t_queueWidx] = getToneLength(tLen);
queueTonePause[t_queueWidx] = tPause; queueTonePause[t_queueWidx] = tPause;
@@ -187,8 +161,8 @@ void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
#endif #endif
queueToneRepeat[t_queueWidx] = tRepeat; queueToneRepeat[t_queueWidx] = tRepeat;
queueToneFreqIncr[t_queueWidx] = tFreqIncr; queueToneFreqIncr[t_queueWidx] = tFreqIncr;
t_queueWidx = next_queueWidx;
t_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH; }
} }
} }
@@ -206,6 +180,7 @@ void audioQueue::frskyeventSample(uint8_t e)
void audioQueue::frskyevent(uint8_t e) void audioQueue::frskyevent(uint8_t e)
{ {
if (empty()) {
// example playASAP(tStart,tLen,tPause,tRepeat,tHaptic,tEnd); // example playASAP(tStart,tLen,tPause,tRepeat,tHaptic,tEnd);
switch(e) { switch(e) {
case AU_FRSKY_WARN1: case AU_FRSKY_WARN1:
@@ -233,7 +208,6 @@ void audioQueue::frskyevent(uint8_t e)
playASAP(80,15,2,1,1); playASAP(80,15,2,1,1);
break; break;
case AU_FRSKY_CHIRP: case AU_FRSKY_CHIRP:
playASAP(BEEP_DEFAULT_FREQ+40,5,1,2,1); playASAP(BEEP_DEFAULT_FREQ+40,5,1,2,1);
playASAP(BEEP_DEFAULT_FREQ+54,5,1,3,1); playASAP(BEEP_DEFAULT_FREQ+54,5,1,3,1);
break; break;
@@ -274,7 +248,7 @@ void audioQueue::frskyevent(uint8_t e)
default: default:
break; break;
} }
}
} }
#endif #endif
@@ -286,9 +260,11 @@ void audioQueue::event(uint8_t e, uint8_t f) {
//startup tune //startup tune
// case 0: // case 0:
case AU_TADA: case AU_TADA:
if (empty()) {
playASAP(50, 10, 5); playASAP(50, 10, 5);
playASAP(90, 10, 5); playASAP(90, 10, 5);
playASAP(110, 5, 4, 2); playASAP(110, 5, 4, 2);
}
break; break;
//warning one //warning one
@@ -411,8 +387,10 @@ void audioQueue::event(uint8_t e, uint8_t f) {
//low battery in tx //low battery in tx
//case 19: //case 19:
case AU_TX_BATTERY_LOW: case AU_TX_BATTERY_LOW:
if (empty()) {
playASAP(60, 20, 3, 2, 0, 1); playASAP(60, 20, 3, 2, 0, 1);
playASAP(80, 20, 3, 2, 1, -1); playASAP(80, 20, 3, 2, 1, -1);
}
break; break;
default: default:
@@ -420,6 +398,7 @@ void audioQueue::event(uint8_t e, uint8_t f) {
} }
} }
void audioDefevent(uint8_t e) { void audioDefevent(uint8_t e)
{
audio.event(e, BEEP_DEFAULT_FREQ); audio.event(e, BEEP_DEFAULT_FREQ);
} }
+5 -1
View File
@@ -159,7 +159,11 @@ inline void driver() {
// it is essentially the life of the class. // it is essentially the life of the class.
void heartbeat(); void heartbeat();
// TODO bool freeslots(uint8_t slots); // bool freeslots(uint8_t slots);
inline bool empty() {
return (t_queueRidx == t_queueWidx);
}
protected: protected:
void aqinit(); // To stop constructor being compiled twice void aqinit(); // To stop constructor being compiled twice