summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2023-09-01 01:15:07 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2023-09-01 19:32:27 -0400
commit79b64a3fc7afbebcfc4dd0880b8c5d0195747b6f (patch)
tree4356483cb3ee638efb65ff594e3060c86f31633a
parent873f49b1f066f41ef0649647188708645e6c0663 (diff)
downloadrockbox-79b64a3fc7.tar.gz
rockbox-79b64a3fc7.zip
setting_list.c playback frequency cleanup
moves the callback to settings_list audio_set_playback_frequency now accepts an actual frequency 44100 192000 etc rather than an index Change-Id: Ieb3fc79a7fe3f1ff050465c8cd8061027e4572ff
-rw-r--r--apps/lang/english.lang8
-rw-r--r--apps/menus/playback_menu.c35
-rw-r--r--apps/playback.c42
-rw-r--r--apps/playback.h2
-rw-r--r--apps/settings_list.c44
5 files changed, 72 insertions, 59 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 695de3b232..922fa0340c 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -11795,16 +11795,16 @@
</phrase>
<phrase>
id: LANG_AUTOMATIC
- desc: generic automatic
+ desc: deprecated
user: core
<source>
- *: "Automatic"
+ *: ""
</source>
<dest>
- *: "Automatic"
+ *: ""
</dest>
<voice>
- *: "Automatic"
+ *: ""
</voice>
</phrase>
<phrase>
diff --git a/apps/menus/playback_menu.c b/apps/menus/playback_menu.c
index 61205b1a08..f28fffa8f6 100644
--- a/apps/menus/playback_menu.c
+++ b/apps/menus/playback_menu.c
@@ -60,12 +60,8 @@ static int setcrossfadeonexit_callback(int action,
/***********************************/
/* PLAYBACK MENU */
-static int playback_callback(int action,
- const struct menu_item_ex *this_item,
- struct gui_synclist *this_list);
-
-MENUITEM_SETTING(shuffle_item, &global_settings.playlist_shuffle, playback_callback);
-MENUITEM_SETTING(repeat_mode, &global_settings.repeat_mode, playback_callback);
+MENUITEM_SETTING(shuffle_item, &global_settings.playlist_shuffle, NULL);
+MENUITEM_SETTING(repeat_mode, &global_settings.repeat_mode, NULL);
MENUITEM_SETTING(play_selected, &global_settings.play_selected, NULL);
MENUITEM_SETTING(ff_rewind_accel, &global_settings.ff_rewind_accel, NULL);
@@ -178,8 +174,7 @@ MENUITEM_SETTING(rewind_across_tracks, &global_settings.rewind_across_tracks, NU
MENUITEM_SETTING(resume_rewind, &global_settings.resume_rewind, NULL);
MENUITEM_SETTING(pause_rewind, &global_settings.pause_rewind, NULL);
#ifdef HAVE_PLAY_FREQ
-MENUITEM_SETTING(play_frequency, &global_settings.play_frequency,
- playback_callback);
+MENUITEM_SETTING(play_frequency, &global_settings.play_frequency, NULL);
#endif
#ifdef HAVE_ALBUMART
static int albumart_callback(int action,
@@ -239,29 +234,5 @@ MAKE_MENU(playback_settings,ID2P(LANG_PLAYBACK),0,
#endif
);
-static int playback_callback(int action,
- const struct menu_item_ex *this_item,
- struct gui_synclist *this_list)
-{
- (void)this_list;
- switch (action)
- {
- case ACTION_ENTER_MENUITEM:
- break;
-
- case ACTION_EXIT_MENUITEM: /* on exit */
- /* Playing or not */
-#ifdef HAVE_PLAY_FREQ
- if (this_item == &play_frequency)
- {
- audio_set_playback_frequency(global_settings.play_frequency);
- break;
- }
-#endif /* HAVE_PLAY_FREQ */
- break;
- }
- return action;
- (void)this_item;
-}
/* PLAYBACK MENU */
/***********************************/
diff --git a/apps/playback.c b/apps/playback.c
index f298764a22..79f037029f 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -3981,29 +3981,45 @@ static void audio_change_frequency_callback(unsigned short id, void *data)
}
}
-void audio_set_playback_frequency(int setting)
+void audio_set_playback_frequency(unsigned int sample_rate_hz)
{
+ /* sample_rate_hz == 0 is "automatic", and also a sentinel */
#if HAVE_PLAY_FREQ >= 192
- static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, SAMPR_176, SAMPR_192 };
+ static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, SAMPR_176, SAMPR_192, 0 };
#elif HAVE_PLAY_FREQ >= 96
- static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96 };
+ static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, 0 };
#elif HAVE_PLAY_FREQ >= 48
- static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48 };
+ static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, 0 };
#else
#error "HAVE_PLAY_FREQ < 48 ??"
#endif
+ const unsigned int *p_sampr = play_sampr;
+ unsigned int sampr = 0;
- if ((unsigned)setting > ARRAYLEN(play_sampr)) /* [0] is "automatic" */
- setting = 0;
+ while (*p_sampr != 0)
+ {
+ if (*p_sampr == sample_rate_hz)
+ {
+ sampr = *p_sampr;
+ break;
+ }
+ p_sampr++;
+ }
- unsigned long playback_sampr = mixer_get_frequency();
- unsigned long sampr = setting ?
- play_sampr[setting - 1] :
- ((audio_status() == AUDIO_STATUS_PLAY) ?
- audio_guess_frequency(audio_current_track()) :
- playback_sampr);
+ if (sampr == 0)
+ {
+ if (audio_status() == AUDIO_STATUS_PLAY)
+ {
+ sampr = audio_guess_frequency(audio_current_track());
+ }
+ else
+ {
+ logf("could not set sample rate to %u hz", sample_rate_hz);
+ return; /* leave as is */
+ }
+ }
- if (sampr != playback_sampr)
+ if (sampr != mixer_get_frequency())
{
mixer_set_frequency(sampr);
LOGFQUEUE("audio >| audio Q_AUDIO_REMAKE_AUDIO_BUFFER");
diff --git a/apps/playback.h b/apps/playback.h
index b9aa413ef3..782f69fa38 100644
--- a/apps/playback.h
+++ b/apps/playback.h
@@ -83,7 +83,7 @@ void audio_set_cuesheet(bool enable);
void audio_set_crossfade(int enable);
#endif
#ifdef HAVE_PLAY_FREQ
-void audio_set_playback_frequency(int setting);
+void audio_set_playback_frequency(unsigned int sample_rate_hz);
#endif
#ifdef HAVE_ALBUMART
void set_albumart_mode(int setting);
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 32b1e38999..59719f2e08 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -41,6 +41,7 @@
#include "kernel.h"
#include "open_plugin.h"
#include "misc.h"
+#include "playback.h"
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
#endif
@@ -387,7 +388,7 @@ static const char* list_pad_formatter(char *buffer, size_t buffer_size,
{
switch (val)
{
- case -1: return str(LANG_AUTOMATIC);
+ case -1: return str(LANG_AUTO);
case 0: return str(LANG_OFF);
default: break;
}
@@ -399,7 +400,7 @@ static int32_t list_pad_getlang(int value, int unit)
{
switch (value)
{
- case -1: return LANG_AUTOMATIC;
+ case -1: return LANG_AUTO;
case 0: return LANG_OFF;
default: return TALK_ID(value, unit);
}
@@ -619,6 +620,30 @@ static void eq_set_default(void* setting, void* defaultval)
memcpy(setting, defaultval, sizeof(struct eq_band_setting));
}
+#ifdef HAVE_PLAY_FREQ
+static const char* formatter_freq_unit_0_is_auto(char *buffer, size_t buffer_size,
+ int value, const char *unit)
+{
+ if (value == 0)
+ return str(LANG_AUTO);
+ else
+ return db_format(buffer, buffer_size, value / 100, unit);
+}
+
+static int32_t getlang_freq_unit_0_is_auto(int value, int unit)
+{
+ if (value == 0)
+ return LANG_AUTO;
+ else
+ return talk_value_decimal(value, unit, 3, false);
+}
+
+static void playback_frequency_callback(int sample_rate_hz)
+{
+ audio_set_playback_frequency(sample_rate_hz);
+}
+#endif /* HAVE_PLAY_FREQ */
+
/* perform shuffle/unshuffle of the current playlist based on the boolean provided */
static void shuffle_playlist_callback(bool shuffle)
{
@@ -954,16 +979,17 @@ const struct settings_list settings[] = {
#endif
), /* CHOICE_SETTING( repeat_mode ) */
#ifdef HAVE_PLAY_FREQ
- STRINGCHOICE_SETTING(0, play_frequency, LANG_FREQUENCY, 0,
+ TABLE_SETTING(F_SOUNDSETTING|F_CB_ON_SELECT_ONLY|F_CB_ONLY_IF_CHANGED,
+ play_frequency, LANG_FREQUENCY, 0, "playback frequency", "auto",
+ UNIT_KHZ, formatter_freq_unit_0_is_auto,
+ getlang_freq_unit_0_is_auto,
+ playback_frequency_callback,
#if HAVE_PLAY_FREQ >= 192
- "playback frequency", "auto,44.1 kHz,48 kHz,88.2 kHz,96 kHz,176.4 kHz,192 kHz", NULL, 7,
- LANG_AUTOMATIC, TALK_ID_DECIMAL(441, 1, UNIT_KHZ), TALK_ID(48, UNIT_KHZ), TALK_ID_DECIMAL(882, 1, UNIT_KHZ), TALK_ID(96, UNIT_KHZ), TALK_ID_DECIMAL(1764, 1, UNIT_KHZ), TALK_ID(192, UNIT_KHZ)),
+ 7,0,SAMPR_44,SAMPR_48,SAMPR_88,SAMPR_96,SAMPR_176,SAMPR_192),
#elif HAVE_PLAY_FREQ >= 96
- "playback frequency", "auto,44.1 kHz,48 kHz,88.2 kHz,96 kHz", NULL, 5,
- LANG_AUTOMATIC, TALK_ID_DECIMAL(441, 1, UNIT_KHZ), TALK_ID(48, UNIT_KHZ), TALK_ID_DECIMAL(882, 1, UNIT_KHZ), TALK_ID(96, UNIT_KHZ)),
+ 5,0,SAMPR_44,SAMPR_48,SAMPR_88,SAMPR_96),
#elif HAVE_PLAY_FREQ >= 48
- "playback frequency", "auto,44.1 kHz,48 kHz", NULL, 3,
- LANG_AUTOMATIC, TALK_ID_DECIMAL(441, 1, UNIT_KHZ), TALK_ID(48, UNIT_KHZ)),
+ 3,0,SAMPR_44,SAMPR_48),
#else
#error "HAVE_PLAY_FREQ < 48???"
#endif