Fix some sound issues

This commit is contained in:
RogueMaster
2022-12-19 20:19:03 -05:00
parent 37a0e5463f
commit 929aea6a91
5 changed files with 39 additions and 14 deletions

View File

@@ -40,12 +40,15 @@ void tracker_speaker_stop() {
} }
void tracker_speaker_init() { void tracker_speaker_init() {
furi_hal_speaker_start(200.0f, 0.01f); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(200.0f, 0.01f);
}
tracker_speaker_stop(); tracker_speaker_stop();
} }
void tracker_speaker_deinit() { void tracker_speaker_deinit() {
furi_hal_speaker_stop(); furi_hal_speaker_stop();
furi_hal_speaker_release();
} }
static FuriHalInterruptISR tracker_isr; static FuriHalInterruptISR tracker_isr;

View File

@@ -85,19 +85,29 @@ int32_t ocarina_app(void* p) {
if(event.type == InputTypePress) { if(event.type == InputTypePress) {
switch(event.key) { switch(event.key) {
case InputKeyUp: case InputKeyUp:
furi_hal_speaker_start(NOTE_UP, volume); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_UP, volume);
}
break; break;
case InputKeyDown: case InputKeyDown:
furi_hal_speaker_start(NOTE_DOWN, volume); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_DOWN, volume);
}
break; break;
case InputKeyLeft: case InputKeyLeft:
furi_hal_speaker_start(NOTE_LEFT, volume); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_LEFT, volume);
}
break; break;
case InputKeyRight: case InputKeyRight:
furi_hal_speaker_start(NOTE_RIGHT, volume); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_RIGHT, volume);
}
break; break;
case InputKeyOk: case InputKeyOk:
furi_hal_speaker_start(NOTE_OK, volume); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_OK, volume);
}
break; break;
case InputKeyBack: case InputKeyBack:
processing = false; processing = false;
@@ -107,6 +117,7 @@ int32_t ocarina_app(void* p) {
} }
} else if(event.type == InputTypeRelease) { } else if(event.type == InputTypeRelease) {
furi_hal_speaker_stop(); furi_hal_speaker_stop();
furi_hal_speaker_release();
} }
} }

View File

@@ -102,11 +102,16 @@ static void tama_p1_hal_set_lcd_icon(u8_t icon, bool_t val) {
} }
static void tama_p1_hal_play_frequency(bool_t en) { static void tama_p1_hal_play_frequency(bool_t en) {
if(en) if(en) {
furi_hal_speaker_start(g_ctx->frequency, 0.5f); if(furi_hal_speaker_acquire(30)) {
else furi_hal_speaker_start(g_ctx->frequency, 0.5f);
furi_hal_speaker_stop(); }
} else {
if(furi_hal_speaker_is_mine()) {
furi_hal_speaker_stop();
furi_hal_speaker_release();
}
}
g_ctx->buzzer_on = en; g_ctx->buzzer_on = en;
} }

View File

@@ -114,11 +114,14 @@ static void decrease_volume(TuningForkState* tuning_fork_state) {
} }
static void play(TuningForkState* tuning_fork_state) { static void play(TuningForkState* tuning_fork_state) {
furi_hal_speaker_start(current_tuning_note_freq(tuning_fork_state), tuning_fork_state->volume); if(furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(current_tuning_note_freq(tuning_fork_state), tuning_fork_state->volume);
}
} }
static void stop() { static void stop() {
furi_hal_speaker_stop(); furi_hal_speaker_stop();
furi_hal_speaker_release();
} }
static void replay(TuningForkState* tuning_fork_state) { static void replay(TuningForkState* tuning_fork_state) {

View File

@@ -57,12 +57,15 @@ int32_t usb_midi_app(void* p) {
if(event->type == NoteOn) { if(event->type == NoteOn) {
NoteOnEvent note_on = AsNoteOn(event); NoteOnEvent note_on = AsNoteOn(event);
current_note = note_on.note; current_note = note_on.note;
furi_hal_speaker_start( if(furi_hal_speaker_acquire(30)) {
note_to_frequency(note_on.note), note_on.velocity / 127.0f); furi_hal_speaker_start(
note_to_frequency(note_on.note), note_on.velocity / 127.0f);
}
} else if(event->type == NoteOff) { } else if(event->type == NoteOff) {
NoteOffEvent note_off = AsNoteOff(event); NoteOffEvent note_off = AsNoteOff(event);
if(note_off.note == current_note) { if(note_off.note == current_note) {
furi_hal_speaker_stop(); furi_hal_speaker_stop();
furi_hal_speaker_release();
} }
} }
} }