diff options
-rw-r--r-- | apps/audio_path.c | 13 | ||||
-rw-r--r-- | apps/menus/sound_menu.c | 4 | ||||
-rw-r--r-- | apps/misc.c | 5 | ||||
-rw-r--r-- | apps/plugin.h | 4 | ||||
-rw-r--r-- | apps/recorder/recording.c | 4 | ||||
-rw-r--r-- | apps/settings.c | 2 | ||||
-rw-r--r-- | apps/settings.h | 4 | ||||
-rw-r--r-- | apps/settings_list.c | 10 | ||||
-rw-r--r-- | firmware/export/audio.h | 9 |
9 files changed, 43 insertions, 12 deletions
diff --git a/apps/audio_path.c b/apps/audio_path.c index 6709d4421d..3f43badc25 100644 --- a/apps/audio_path.c +++ b/apps/audio_path.c @@ -164,3 +164,16 @@ int audio_get_spdif_sample_rate(void) #endif /* HAVE_SPDIF_IN */ #endif /* PLATFORM_NATIVE */ + +#ifdef HAVE_SPEAKER +void audio_enable_speaker(int mode) +{ +#ifdef HAVE_HEADPHONE_DETECTION + /* if needed, query jack state */ + if(mode == 2) + mode = !headphones_inserted(); +#endif + /* treat any nonzero value as enable */ + audiohw_enable_speaker(mode); +} +#endif diff --git a/apps/menus/sound_menu.c b/apps/menus/sound_menu.c index 7c04662233..69e8e3676a 100644 --- a/apps/menus/sound_menu.c +++ b/apps/menus/sound_menu.c @@ -225,7 +225,7 @@ static int timestretch_callback(int action,const struct menu_item_ex *this_item) #endif #ifdef HAVE_SPEAKER - MENUITEM_SETTING(speaker_enabled, &global_settings.speaker_enabled, NULL); + MENUITEM_SETTING(speaker_mode, &global_settings.speaker_mode, NULL); #endif #ifdef AUDIOHW_HAVE_EQ @@ -269,7 +269,7 @@ MAKE_MENU(sound_settings, ID2P(LANG_SOUND_SETTINGS), NULL, Icon_Audio, ,&mdb_harmonics,&mdb_center,&mdb_shape #endif #ifdef HAVE_SPEAKER - ,&speaker_enabled + ,&speaker_mode #endif ); diff --git a/apps/misc.c b/apps/misc.c index 15e1b6ecad..e460eb542c 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -522,6 +522,11 @@ static void unplug_change(bool inserted) } } } + +#ifdef HAVE_SPEAKER + /* update speaker status */ + audio_enable_speaker(global_settings.speaker_mode); +#endif } #endif diff --git a/apps/plugin.h b/apps/plugin.h index f781f60350..c96c4ac899 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -160,12 +160,12 @@ void* plugin_get_buffer(size_t *buffer_size); #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 233 +#define PLUGIN_API_VERSION 234 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 233 +#define PLUGIN_MIN_API_VERSION 234 /* plugin return codes */ /* internal returns start at 0x100 to make exit(1..255) work */ diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 1c53c8026f..4816b3bad4 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -1097,7 +1097,7 @@ bool recording_screen(bool no_source) #ifdef HAVE_SPEAKER /* Disable speaker to prevent feedback */ - audiohw_enable_speaker(false); + audio_enable_speaker(0); #endif audio_init_recording(); @@ -1959,7 +1959,7 @@ rec_abort: #ifdef HAVE_SPEAKER /* Re-enable speaker */ - audiohw_enable_speaker(global_settings.speaker_enabled); + audio_enable_speaker(global_settings.speaker_mode); #endif /* make sure the trigger is really turned off */ diff --git a/apps/settings.c b/apps/settings.c index 992cc1f391..aa51e051e9 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -927,7 +927,7 @@ void settings_apply(bool read_disk) #endif #ifdef HAVE_SPEAKER - audiohw_enable_speaker(global_settings.speaker_enabled); + audio_enable_speaker(global_settings.speaker_mode); #endif if (read_disk) diff --git a/apps/settings.h b/apps/settings.h index c79aeb37f4..5de65bb193 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -746,8 +746,8 @@ struct user_settings #endif #ifdef HAVE_SPEAKER - bool speaker_enabled; -#endif + int speaker_mode; /* 0: off, 1: on, 2: auto (only if headphone detection) */ +#endif /* HAVE_SPEAKER */ bool prevent_skip; #ifdef HAVE_TOUCHSCREEN diff --git a/apps/settings_list.c b/apps/settings_list.c index 58be3d2575..57763d345a 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -2118,9 +2118,13 @@ const struct settings_list settings[] = { false, "shortcuts instead of quickscreen", NULL), #endif #ifdef HAVE_SPEAKER - OFFON_SETTING(0, speaker_enabled, LANG_ENABLE_SPEAKER, false, "speaker", - audiohw_enable_speaker), -#endif + CHOICE_SETTING(0, speaker_mode, LANG_ENABLE_SPEAKER, 0, "speaker mode", +# ifdef HAVE_HEADPHONE_DETECTION + "on,off,auto", audio_enable_speaker, 3, ID2P(LANG_OFF), ID2P(LANG_ON), ID2P(LANG_AUTO)), +#else /* HAVE_HEADPHONE_DETECTION */ + "on,off", audio_enable_speaker, 2, ID2P(LANG_OFF), ID2P(LANG_ON)), +#endif /* HAVE_HEADPHONE_DETECTION */ +#endif /* HAVE_SPEAKER */ #ifdef HAVE_TOUCHSCREEN CHOICE_SETTING(0, touch_mode, LANG_TOUCHSCREEN_MODE, DEFAULT_TOUCHSCREEN_MODE, "touchscreen mode", "point,grid", NULL, 2, diff --git a/firmware/export/audio.h b/firmware/export/audio.h index 08a88d6325..5710f9f653 100644 --- a/firmware/export/audio.h +++ b/firmware/export/audio.h @@ -232,6 +232,15 @@ int audio_get_spdif_sample_rate(void); void audio_spdif_set_monitor(int monitor_spdif); #endif /* HAVE_SPDIF_IN */ +#ifdef HAVE_SPEAKER +/* enable/disable the speaker: 0=off, 1=on, 2=on if jack unpluged, off otherwise + * NOTE this is a one time thing, this function doesn't implement the logic to + * check for jack events, it merely changes the speaker state to the expected + * state based on the requested mode. + */ +void audio_enable_speaker(int mode); +#endif + /***********************************************************************/ /* audio event handling */ enum track_event_flags |