Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New method for handling custom alarms #961

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
23 changes: 22 additions & 1 deletion src/extended_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,28 @@ int AUDIO_AddQueue(u16 music) {
return 0;
}

audio_queue[num_audio++] = music;
int new_num_audio = -1;

#if USE_NEW_CUSTOM_ALARM_MODE
u32 t = CLOCK_getms();

// Replace the last custom alarm id, if there is already one
if (voice_map[music].id >= CUSTOM_ALARM_ID)
{
u32 id = voice_map[audio_queue[next_audio-1]].id;
if (id == MUSIC_STARTUP || id >= CUSTOM_ALARM_ID) // Only skip welcome message or custom alarms
audio_queue_time = t + CUSTOM_ALARM_IGNORE_MS; // Do not consume the audio right away (prevent triggering transitional sounds)

for (u8 i = next_audio; i < num_audio; i++)
if (voice_map[audio_queue[i]].id >= CUSTOM_ALARM_ID)
new_num_audio = i;
}
#endif

if (new_num_audio < 0)
audio_queue[num_audio++] = music; // Add to queue
else
audio_queue[new_num_audio] = music; // Replace queue item, do not enqueue custom sounds
return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/music.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum Music {
#endif
#define VOICE_UNIT_OFFSET 130
#define CUSTOM_ALARM_ID 200 // start of custom MP3 IDs
#define USE_NEW_CUSTOM_ALARM_MODE 1 // if this is 0, all the custom alarms are enqueued and never skipped
#define CUSTOM_ALARM_IGNORE_MS 200 // ignore custom alarms if the switch was faster than this value (requires USE_NEW_CUSTOM_ALARM_MODE)
#define VOICE_DEC_SEP 110 // MP3 ID of DECSEP = 110 + MUSIC_TOTAL
#define NUM_STICKS 4
#define NUM_AUX_KNOBS (INP_HAS_CALIBRATION - NUM_STICKS) // Exclude sticks
Expand Down