Play sound sequences asynchronously (#122)

* buzzer sequences: first draft, does not work on hardware yet (but in simulator)

* buzzer sequences: add changes to movement.c

* buzzer sequences: add demo face to Makefile

* buzzer sequences: fix problem of interrupted sounds. Add logic for repeating sub sequences. Tidy up (move logic to watch_buzzer files, remove buzzer_demo_face)

* buzzer sequences: tidy up even more

* buzzer sequences: disable registering a 32 Hz tick callback for watch faces, so it will be used exclusively by the buzzer sequences functionality

* buzzer sequences: add callback slot functionality to watch_rtc and make watch_buzzer use it. Switch internal buzzer sequences tick frequency to 64 Hz. Revert changes to movement.c

* buzzer sequences: fix parameter sanity check in watch_rtc code

* buzzer sequences/watch_rtc: optimize calling tick callbacks in RTC_Handler

* buzzer sequences/watch_rtc: fix error in calling callback functions

* buzzer sequences: revert changes to watch_rtc logic. Instead, use TC3 as the source for timing the sound sequences.

* buzzer sequences: fix frequency of callback

* buzzer sequences: integrate changes from PR #162 (set both CCBUF and PERFBUF for correct buzzer tone)
This commit is contained in:
TheOnePerson
2023-01-11 21:26:33 +01:00
committed by GitHub
parent ca7e704429
commit 47812f462d
3 changed files with 220 additions and 1 deletions

View File

@@ -160,5 +160,28 @@ void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms);
/// @brief An array of periods for all the notes on a piano, corresponding to the names in BuzzerNote.
extern const uint16_t NotePeriods[108];
/** @brief Plays the given sequence of notes in a non-blocking way.
* @param note_sequence A pointer to the sequence of buzzer note & duration tuples, ending with a zero. A simple
* RLE logic is implemented: a negative number instead of a buzzer note means that the sequence
* is rewound by the given number of notes. The byte following a negative number determines the number
* of loops. I.e. if you want to repeat the last three notes of the sequence one time, you should provide
* the tuple -3, 1. The repeated notes must not contain any other repeat markers, or you will end up with
* an eternal loop.
* @param callback_on_end A pointer to a callback function to be invoked when the sequence has finished playing.
* @note This function plays the sequence asynchronously, so the UI will not be blocked.
* Hint: It is not possible to play the lowest note BUZZER_NOTE_A1 (55.00 Hz). The note is represented by a
* zero byte, which is used here as the end-of-sequence marker. But hey, a frequency that low cannot be
* played properly by the watch's buzzer, anyway.
*/
void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(void));
/** @brief Aborts a playing sequence.
*/
void watch_buzzer_abort_sequence(void);
#ifndef __EMSCRIPTEN__
void TC3_Handler(void);
#endif
/// @}
#endif