Update music_beeper_worker.c

This commit is contained in:
RogueMaster
2022-12-19 20:04:52 -05:00
parent 13c851356c
commit 37a0e5463f

View File

@@ -47,7 +47,7 @@ static int32_t music_beeper_worker_thread_callback(void* context) {
NoteBlockArray_it_t it;
NoteBlockArray_it(it, instance->notes);
if(furi_hal_speaker_acquire(1000)) {
while(instance->should_work) {
if(NoteBlockArray_end_p(it)) {
NoteBlockArray_it(it, instance->notes);
@@ -57,8 +57,8 @@ static int32_t music_beeper_worker_thread_callback(void* context) {
float note_from_a4 = (float)note_block->semitone - NOTE_C4_SEMITONE;
float frequency = NOTE_C4 * powf(TWO_POW_TWELTH_ROOT, note_from_a4);
float duration =
60.0 * furi_kernel_get_tick_frequency() * 4 / instance->bpm / note_block->duration;
float duration = 60.0 * furi_kernel_get_tick_frequency() * 4 / instance->bpm /
note_block->duration;
uint32_t dots = note_block->dots;
while(dots > 0) {
duration += duration / 2;
@@ -79,7 +79,7 @@ static int32_t music_beeper_worker_thread_callback(void* context) {
furi_hal_speaker_stop();
furi_hal_speaker_start(frequency, volume);
while(instance->should_work && furi_get_tick() < next_tick) {
volume *= 1;
volume *= 0.9945679;
furi_hal_speaker_set_volume(volume);
furi_delay_ms(2);
}
@@ -88,6 +88,10 @@ static int32_t music_beeper_worker_thread_callback(void* context) {
}
furi_hal_speaker_stop();
furi_hal_speaker_release();
} else {
FURI_LOG_E(TAG, "Speaker system is busy with another process.");
}
return 0;
}
@@ -97,11 +101,8 @@ MusicBeeperWorker* music_beeper_worker_alloc() {
NoteBlockArray_init(instance->notes);
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "MusicBeeperWorker");
furi_thread_set_stack_size(instance->thread, 1024);
furi_thread_set_context(instance->thread, instance);
furi_thread_set_callback(instance->thread, music_beeper_worker_thread_callback);
instance->thread = furi_thread_alloc_ex(
"MusicBeeperWorker", 1024, music_beeper_worker_thread_callback, instance);
instance->volume = 1.0f;