Another optimizations on AUDIO

This commit is contained in:
bsongis
2012-02-02 22:25:59 +00:00
parent acd523e699
commit 7f00d8c3dc
2 changed files with 156 additions and 229 deletions
+111 -172
View File
@@ -19,12 +19,8 @@ audioQueue::audioQueue()
aqinit();
}
// TODO should not be needed
void audioQueue::aqinit()
{
//make sure haptic off by default
HAPTIC_OFF;
toneTimeLeft = 0;
tonePause = 0;
@@ -32,16 +28,10 @@ void audioQueue::aqinit()
t_queueWidx = 0;
#ifdef HAPTIC
toneHaptic = 0;
hapticTick = 0;
#endif
}
bool audioQueue::busy()
{
return (toneTimeLeft > 0);
}
#if 0
bool audioQueue::freeslots(uint8_t slots)
{
@@ -78,18 +68,19 @@ void audioQueue::heartbeat()
SPEAKER_OFF;
HAPTIC_OFF;
if (tonePause-- <= 0) {
if (t_queueRidx != t_queueWidx) {
toneFreq = queueToneFreq[t_queueRidx];
toneTimeLeft = queueToneLength[t_queueRidx];
toneFreqIncr = queueToneFreqIncr[t_queueRidx];
tonePause = queueTonePause[t_queueRidx];
if (tonePause > 0) {
tonePause--;
}
else if (t_queueRidx != t_queueWidx) {
toneFreq = queueToneFreq[t_queueRidx];
toneTimeLeft = queueToneLength[t_queueRidx];
toneFreqIncr = queueToneFreqIncr[t_queueRidx];
tonePause = queueTonePause[t_queueRidx];
#if defined(HAPTIC)
toneHaptic = queueToneHaptic[t_queueRidx];
toneHaptic = queueToneHaptic[t_queueRidx];
#endif
if (!queueToneRepeat[t_queueRidx]--) {
t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH;
}
if (!queueToneRepeat[t_queueRidx]--) {
t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH;
}
}
}
@@ -153,12 +144,107 @@ void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
}
}
#ifdef FRSKY
void audioQueue::frskyevent(uint8_t e)
// TODO check
#define BEEP_NOKEYS 1
void audioQueue::event(uint8_t e, uint8_t f)
{
if (empty()) {
// example playASAP(tStart,tLen,tPause,tRepeat,tHaptic,tEnd);
switch(e) {
uint8_t beepVal = g_eeGeneral.beeperVal;
if (e < AU_FRSKY_FIRST || empty()) {
switch (e) {
// startup tune
case AU_TADA:
if (empty()) {
playASAP(50, 10, 5);
playASAP(90, 10, 5);
playASAP(110, 5, 4, 2);
}
break;
// warning one
case AU_WARNING1:
playNow(BEEP_DEFAULT_FREQ, 10, 1, 0, 1);
break;
// warning two
case AU_WARNING2:
playNow(BEEP_DEFAULT_FREQ, 20, 1, 0, 1);
break;
// warning three
case AU_WARNING3:
playNow(BEEP_DEFAULT_FREQ, 30, 1, 0, 1);
break;
// error
case AU_ERROR:
playNow(BEEP_DEFAULT_FREQ, 40, 1, 0, 1);
break;
// keypad up (seems to be used when going left/right through system menu options. 0-100 scales etc)
case AU_KEYPAD_UP:
if (beepVal != BEEP_NOKEYS) {
playNow(BEEP_KEY_UP_FREQ, 10, 1);
}
break;
// keypad down (seems to be used when going left/right through system menu options. 0-100 scales etc)
case AU_KEYPAD_DOWN:
if (beepVal != BEEP_NOKEYS) {
playNow(BEEP_KEY_DOWN_FREQ, 10, 1);
}
break;
// trim move
case AU_TRIM_MOVE:
playNow(f, 6, 1);
break;
// trim center
case AU_TRIM_MIDDLE:
playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1);
break;
// menu display (also used by a few generic beeps)
case AU_MENUS:
if (beepVal != BEEP_NOKEYS) {
playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 0);
}
break;
// pot/stick center
case AU_POT_STICK_MIDDLE:
playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 0, 0);
break;
// mix warning 1
case AU_MIX_WARNING_1:
playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 1, 1);
break;
// mix warning 2
case AU_MIX_WARNING_2:
playNow(BEEP_DEFAULT_FREQ + 52, 10, 1, 2, 1);
break;
// mix warning 3
case AU_MIX_WARNING_3:
playNow(BEEP_DEFAULT_FREQ + 54, 10, 1, 3, 1);
break;
// time 30 seconds left
case AU_TIMER_30:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 3, 1);
break;
// time 20 seconds left
case AU_TIMER_20:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 2, 1);
break;
// time 10 seconds left
case AU_TIMER_10:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 1, 1);
break;
// time <3 seconds left
case AU_TIMER_LT3:
playNow(BEEP_DEFAULT_FREQ, 20, 25, 1, 1);
break;
// inactivity timer alert
case AU_INACTIVITY:
playNow(70, 10, 2,2);
break;
// low battery in tx
case AU_TX_BATTERY_LOW:
if (empty()) {
playASAP(60, 20, 3, 2, 0, 1);
playASAP(80, 20, 3, 2, 1, -1);
}
break;
case AU_FRSKY_WARN1:
playASAP(BEEP_DEFAULT_FREQ+20,15,5,2,1);
break;
@@ -226,153 +312,6 @@ void audioQueue::frskyevent(uint8_t e)
}
}
}
#endif
void audioQueue::event(uint8_t e, uint8_t f)
{
uint8_t beepVal = g_eeGeneral.beeperVal;
switch (e) {
//startup tune
// case 0:
case AU_TADA:
if (empty()) {
playASAP(50, 10, 5);
playASAP(90, 10, 5);
playASAP(110, 5, 4, 2);
}
break;
//warning one
// case 1:
case AU_WARNING1:
playNow(BEEP_DEFAULT_FREQ, 10, 1, 0, 1);
break;
//warning two
//case 2:
case AU_WARNING2:
playNow(BEEP_DEFAULT_FREQ, 20, 1, 0, 1);
break;
//warning three
//case 3:
case AU_WARNING3:
playNow(BEEP_DEFAULT_FREQ, 30, 1, 0, 1);
break;
//error
//case 4:
case AU_ERROR:
playNow(BEEP_DEFAULT_FREQ, 40, 1, 0, 1);
break;
//keypad up (seems to be used when going left/right through system menu options. 0-100 scales etc)
//case 5:
case AU_KEYPAD_UP:
if (beepVal != BEEP_NOKEYS) {
playNow(BEEP_KEY_UP_FREQ, 10, 1);
}
break;
//keypad down (seems to be used when going left/right through system menu options. 0-100 scales etc)
//case 6:
case AU_KEYPAD_DOWN:
if (beepVal != BEEP_NOKEYS) {
playNow(BEEP_KEY_DOWN_FREQ, 10, 1);
}
break;
//trim sticks move
//case 7:
case AU_TRIM_MOVE:
//if(beepVal != BEEP_NOKEYS){
playNow(f, 6, 1);
//}
break;
//trim sticks center
//case 8:
case AU_TRIM_MIDDLE:
//if(beepVal != BEEP_NOKEYS){
playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1);
//}
break;
//menu display (also used by a few generic beeps)
//case 9:
case AU_MENUS:
if (beepVal != BEEP_NOKEYS) {
playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 0);
}
break;
//pot/stick center
//case 10:
case AU_POT_STICK_MIDDLE:
playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 0, 0);
break;
//mix warning 1
//case 11:
case AU_MIX_WARNING_1:
playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 1, 1);
break;
//mix warning 2
//case 12:
case AU_MIX_WARNING_2:
playNow(BEEP_DEFAULT_FREQ + 52, 10, 1, 2, 1);
break;
//mix warning 3
//case 13:
case AU_MIX_WARNING_3:
playNow(BEEP_DEFAULT_FREQ + 54, 10, 1, 3, 1);
break;
//time 30 seconds left
//case 14:
case AU_TIMER_30:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 3, 1);
break;
//time 20 seconds left
//case 15:
case AU_TIMER_20:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 2, 1);
break;
//time 10 seconds left
//case 16:
case AU_TIMER_10:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 1, 1);
break;
//time <3 seconds left
//case 17:
case AU_TIMER_LT3:
playNow(BEEP_DEFAULT_FREQ, 20, 25, 1, 1);
break;
//inactivity timer alert
//case 18:
case AU_INACTIVITY:
playNow(70, 10, 2,2);
break;
//low battery in tx
//case 19:
case AU_TX_BATTERY_LOW:
if (empty()) {
playASAP(60, 20, 3, 2, 0, 1);
playASAP(80, 20, 3, 2, 1, -1);
}
break;
default:
break;
}
}
void audioDefevent(uint8_t e)
{
+45 -57
View File
@@ -35,53 +35,45 @@
#define BEEP_KEY_DOWN_FREQ (BEEP_DEFAULT_FREQ-5)
/* make sure the defines below always go in numeric order */
#define AU_TADA (0)
#define AU_WARNING1 (1)
#define AU_WARNING2 (2)
#define AU_WARNING3 (3)
#define AU_ERROR (4)
#define AU_KEYPAD_UP (5)
#define AU_KEYPAD_DOWN (6)
#define AU_TRIM_MOVE (7)
#define AU_TRIM_MIDDLE (8)
#define AU_MENUS (9)
#define AU_POT_STICK_MIDDLE (10)
#define AU_MIX_WARNING_1 (11)
#define AU_MIX_WARNING_2 (12)
#define AU_MIX_WARNING_3 (13)
#define AU_TIMER_30 (14)
#define AU_TIMER_20 (15)
#define AU_TIMER_10 (16)
#define AU_TIMER_LT3 (17)
#define AU_INACTIVITY (18)
#define AU_TX_BATTERY_LOW (19)
#ifdef FRSKY
#define AU_FRSKY_WARN1 (0)
#define AU_FRSKY_WARN2 (1)
#define AU_FRSKY_CHEEP (2)
#define AU_FRSKY_RING (3)
#define AU_FRSKY_SCIFI (4)
#define AU_FRSKY_ROBOT (5)
#define AU_FRSKY_CHIRP (6)
#define AU_FRSKY_TADA (7)
#define AU_FRSKY_CRICKET (8)
#define AU_FRSKY_SIREN (9)
#define AU_FRSKY_ALARMC (10)
#define AU_FRSKY_RATATA (11)
#define AU_FRSKY_TICK (12)
#define AU_FRSKY_HAPTIC1 (13)
#define AU_FRSKY_HAPTIC2 (14)
#define AU_FRSKY_HAPTIC3 (15)
#endif
#define BEEP_QUIET (0)
#define BEEP_NOKEYS (1)
#define BEEP_XSHORT (2)
#define BEEP_SHORT (3)
#define BEEP_NORMAL (4)
#define BEEP_LONG (5)
#define BEEP_XLONG (6)
enum AUDIO_SOUNDS {
AU_TADA,
AU_WARNING1,
AU_WARNING2,
AU_WARNING3,
AU_ERROR,
AU_KEYPAD_UP,
AU_KEYPAD_DOWN,
AU_TRIM_MOVE,
AU_TRIM_MIDDLE,
AU_MENUS,
AU_POT_STICK_MIDDLE,
AU_MIX_WARNING_1,
AU_MIX_WARNING_2,
AU_MIX_WARNING_3,
AU_TIMER_30,
AU_TIMER_20,
AU_TIMER_10,
AU_TIMER_LT3,
AU_INACTIVITY,
AU_TX_BATTERY_LOW,
AU_FRSKY_FIRST,
AU_FRSKY_WARN1 = AU_FRSKY_FIRST,
AU_FRSKY_WARN2,
AU_FRSKY_CHEEP,
AU_FRSKY_RING,
AU_FRSKY_SCIFI,
AU_FRSKY_ROBOT,
AU_FRSKY_CHIRP,
AU_FRSKY_TADA,
AU_FRSKY_CRICKET,
AU_FRSKY_SIREN,
AU_FRSKY_ALARMC,
AU_FRSKY_RATATA,
AU_FRSKY_TICK,
AU_FRSKY_HAPTIC1,
AU_FRSKY_HAPTIC2,
AU_FRSKY_HAPTIC3
};
class audioQueue
{
@@ -95,13 +87,9 @@ class audioQueue
void playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0, uint8_t tHaptic=0, int8_t tFreqIncr=0);
bool busy();
inline bool busy() { return (toneTimeLeft > 0); }
void event(uint8_t e,uint8_t f=BEEP_DEFAULT_FREQ);
#if defined(FRSKY)
void frskyevent(uint8_t e);
#endif
void event(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ);
#if defined(ISER9X)
inline void driver() {
@@ -173,13 +161,13 @@ class audioQueue
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
#ifdef HAPTIC
uint8_t toneHaptic;
uint8_t hapticTick;
uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH];
uint8_t toneHaptic;
uint8_t hapticTick;
uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH];
#endif
#if defined(PCBSTD)
uint8_t toneCounter;
uint8_t toneCounter;
#endif
};