diff --git a/apps/filetree.c b/apps/filetree.c index fc5e4d3934..03a4d7ca36 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -509,6 +509,9 @@ int ft_enter(struct tree_context* c) MAX_FILENAME); talk_init(); /* use voice of same language */ splash(HZ, ID2P(LANG_LANGUAGE_LOADED)); +#if CONFIG_CODEC == SWCODEC && !defined(HAVE_HARDWARE_BEEP) + audio_buffer_reset(); +#endif } break; diff --git a/apps/playback.c b/apps/playback.c index d2d9bb6a34..1a638eb7c8 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -136,6 +136,7 @@ enum { Q_AUDIO_POSTINIT, Q_AUDIO_FILL_BUFFER, Q_AUDIO_FINISH_LOAD, + Q_AUDIO_RESTORE_BUFFER, Q_CODEC_REQUEST_COMPLETE, Q_CODEC_REQUEST_FAILED, @@ -490,6 +491,12 @@ int audio_buffer_state(void) return buffer_state; } +void audio_buffer_reset(void) +{ + LOGFQUEUE("audio_queue >| Q_AUDIO_RESTORE_BUFFER"); + queue_send(&audio_queue, Q_AUDIO_RESTORE_BUFFER, 0); +} + #ifdef HAVE_RECORDING unsigned char *audio_get_recording_buffer(size_t *buffer_size) { @@ -2389,6 +2396,12 @@ static void audio_thread(void) audio_finish_load_track(); break; + case Q_AUDIO_RESTORE_BUFFER: + LOGFQUEUE("audio < Q_AUDIO_RESTORE_BUFFER"); + if (buffer_state != AUDIOBUF_STATE_INITIALIZED) + audio_reset_buffer(); + break; + case Q_AUDIO_PLAY: LOGFQUEUE("audio < Q_AUDIO_PLAY"); if (playing && ev.data <= 0) diff --git a/apps/plugin.c b/apps/plugin.c index e55ecd46a7..cf015e2503 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -784,6 +784,13 @@ int plugin_load(const char* plugin, const void* parameter) splash(HZ*2, str(LANG_PLUGIN_ERROR)); break; } + +#if CONFIG_CODEC == SWCODEC && !defined (HAVE_HARDWARE_BEEP) + /* Did the plugin trash the buffer? Restore it. */ + if (audio_buffer_state() == AUDIOBUF_STATE_TRASHED) + audio_buffer_reset(); +#endif + return PLUGIN_OK; } diff --git a/apps/recorder/pcm_record.c b/apps/recorder/pcm_record.c index 8642150b18..bc6a532f2f 100644 --- a/apps/recorder/pcm_record.c +++ b/apps/recorder/pcm_record.c @@ -1167,6 +1167,10 @@ static void pcmrec_close(void) pcm_close_recording(); reset_hardware(); audio_remove_encoder(); +#ifndef HAVE_HARDWARE_BEEP + /* Restore keyclicks */ + audio_buffer_reset(); +#endif } /* pcmrec_close */ /* PCMREC_OPTIONS */ diff --git a/apps/settings.c b/apps/settings.c index 4babe33cdb..cc50b93869 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -885,6 +885,9 @@ void settings_apply(bool read_disk) global_settings.lang_file); lang_load(buf); talk_init(); /* use voice of same language */ +#if CONFIG_CODEC == SWCODEC && !defined(HAVE_HARDWARE_BEEP) + audio_buffer_reset(); +#endif } /* load the icon set */ icons_init(); diff --git a/firmware/export/audio.h b/firmware/export/audio.h index b4a2c82200..8320642947 100644 --- a/firmware/export/audio.h +++ b/firmware/export/audio.h @@ -112,6 +112,7 @@ enum audio_buffer_state AUDIOBUF_STATE_VOICED_ONLY = 1, /* voice-only */ }; int audio_buffer_state(void); +void audio_buffer_reset(void); #endif /* channel modes */ diff --git a/firmware/usb.c b/firmware/usb.c index 95c33ad8e9..eb040a60a0 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -125,6 +125,17 @@ static void usb_slave_mode(bool on) if (rc <= 0) /* no partition */ panicf("mount: %d",rc); +#ifndef BOOTLOADER +#if CONFIG_CPU == IMX31L || CONFIG_USBOTG == USBOTG_ISP1583 || \ + defined(CPU_TCC77X) || defined(CPU_TCC780X) + /* These use a static transfer buffer */ +#elif defined(USB_STORAGE) && !defined (HAVE_HARDWARE_BEEP) + /* Storage can use the audio buffer, restore it if it did to get + * keyclicks back. */ + if (audio_buffer_state() == BUFFER_STATE_TRASHED) + audio_buffer_reset(); +#endif /* USB_STORAGE */ +#endif /* BOOTLOADER */ } } #endif