summaryrefslogtreecommitdiff
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-79b64a3fc7afbebcfc4dd0880b8c5d0195747b6f.tar.gz
rockbox-79b64a3fc7afbebcfc4dd0880b8c5d0195747b6f.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 @@
11795</phrase> 11795</phrase>
11796<phrase> 11796<phrase>
11797 id: LANG_AUTOMATIC 11797 id: LANG_AUTOMATIC
11798 desc: generic automatic 11798 desc: deprecated
11799 user: core 11799 user: core
11800 <source> 11800 <source>
11801 *: "Automatic" 11801 *: ""
11802 </source> 11802 </source>
11803 <dest> 11803 <dest>
11804 *: "Automatic" 11804 *: ""
11805 </dest> 11805 </dest>
11806 <voice> 11806 <voice>
11807 *: "Automatic" 11807 *: ""
11808 </voice> 11808 </voice>
11809</phrase> 11809</phrase>
11810<phrase> 11810<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,
60 60
61/***********************************/ 61/***********************************/
62/* PLAYBACK MENU */ 62/* PLAYBACK MENU */
63static int playback_callback(int action, 63MENUITEM_SETTING(shuffle_item, &global_settings.playlist_shuffle, NULL);
64 const struct menu_item_ex *this_item, 64MENUITEM_SETTING(repeat_mode, &global_settings.repeat_mode, NULL);
65 struct gui_synclist *this_list);
66
67MENUITEM_SETTING(shuffle_item, &global_settings.playlist_shuffle, playback_callback);
68MENUITEM_SETTING(repeat_mode, &global_settings.repeat_mode, playback_callback);
69MENUITEM_SETTING(play_selected, &global_settings.play_selected, NULL); 65MENUITEM_SETTING(play_selected, &global_settings.play_selected, NULL);
70 66
71MENUITEM_SETTING(ff_rewind_accel, &global_settings.ff_rewind_accel, NULL); 67MENUITEM_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
178MENUITEM_SETTING(resume_rewind, &global_settings.resume_rewind, NULL); 174MENUITEM_SETTING(resume_rewind, &global_settings.resume_rewind, NULL);
179MENUITEM_SETTING(pause_rewind, &global_settings.pause_rewind, NULL); 175MENUITEM_SETTING(pause_rewind, &global_settings.pause_rewind, NULL);
180#ifdef HAVE_PLAY_FREQ 176#ifdef HAVE_PLAY_FREQ
181MENUITEM_SETTING(play_frequency, &global_settings.play_frequency, 177MENUITEM_SETTING(play_frequency, &global_settings.play_frequency, NULL);
182 playback_callback);
183#endif 178#endif
184#ifdef HAVE_ALBUMART 179#ifdef HAVE_ALBUMART
185static int albumart_callback(int action, 180static int albumart_callback(int action,
@@ -239,29 +234,5 @@ MAKE_MENU(playback_settings,ID2P(LANG_PLAYBACK),0,
239#endif 234#endif
240 ); 235 );
241 236
242static int playback_callback(int action,
243 const struct menu_item_ex *this_item,
244 struct gui_synclist *this_list)
245{
246 (void)this_list;
247 switch (action)
248 {
249 case ACTION_ENTER_MENUITEM:
250 break;
251
252 case ACTION_EXIT_MENUITEM: /* on exit */
253 /* Playing or not */
254#ifdef HAVE_PLAY_FREQ
255 if (this_item == &play_frequency)
256 {
257 audio_set_playback_frequency(global_settings.play_frequency);
258 break;
259 }
260#endif /* HAVE_PLAY_FREQ */
261 break;
262 }
263 return action;
264 (void)this_item;
265}
266/* PLAYBACK MENU */ 237/* PLAYBACK MENU */
267/***********************************/ 238/***********************************/
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)
3981 } 3981 }
3982} 3982}
3983 3983
3984void audio_set_playback_frequency(int setting) 3984void audio_set_playback_frequency(unsigned int sample_rate_hz)
3985{ 3985{
3986 /* sample_rate_hz == 0 is "automatic", and also a sentinel */
3986#if HAVE_PLAY_FREQ >= 192 3987#if HAVE_PLAY_FREQ >= 192
3987 static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, SAMPR_176, SAMPR_192 }; 3988 static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, SAMPR_176, SAMPR_192, 0 };
3988#elif HAVE_PLAY_FREQ >= 96 3989#elif HAVE_PLAY_FREQ >= 96
3989 static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96 }; 3990 static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, 0 };
3990#elif HAVE_PLAY_FREQ >= 48 3991#elif HAVE_PLAY_FREQ >= 48
3991 static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48 }; 3992 static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, 0 };
3992#else 3993#else
3993 #error "HAVE_PLAY_FREQ < 48 ??" 3994 #error "HAVE_PLAY_FREQ < 48 ??"
3994#endif 3995#endif
3996 const unsigned int *p_sampr = play_sampr;
3997 unsigned int sampr = 0;
3995 3998
3996 if ((unsigned)setting > ARRAYLEN(play_sampr)) /* [0] is "automatic" */ 3999 while (*p_sampr != 0)
3997 setting = 0; 4000 {
4001 if (*p_sampr == sample_rate_hz)
4002 {
4003 sampr = *p_sampr;
4004 break;
4005 }
4006 p_sampr++;
4007 }
3998 4008
3999 unsigned long playback_sampr = mixer_get_frequency(); 4009 if (sampr == 0)
4000 unsigned long sampr = setting ? 4010 {
4001 play_sampr[setting - 1] : 4011 if (audio_status() == AUDIO_STATUS_PLAY)
4002 ((audio_status() == AUDIO_STATUS_PLAY) ? 4012 {
4003 audio_guess_frequency(audio_current_track()) : 4013 sampr = audio_guess_frequency(audio_current_track());
4004 playback_sampr); 4014 }
4015 else
4016 {
4017 logf("could not set sample rate to %u hz", sample_rate_hz);
4018 return; /* leave as is */
4019 }
4020 }
4005 4021
4006 if (sampr != playback_sampr) 4022 if (sampr != mixer_get_frequency())
4007 { 4023 {
4008 mixer_set_frequency(sampr); 4024 mixer_set_frequency(sampr);
4009 LOGFQUEUE("audio >| audio Q_AUDIO_REMAKE_AUDIO_BUFFER"); 4025 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);
83void audio_set_crossfade(int enable); 83void audio_set_crossfade(int enable);
84#endif 84#endif
85#ifdef HAVE_PLAY_FREQ 85#ifdef HAVE_PLAY_FREQ
86void audio_set_playback_frequency(int setting); 86void audio_set_playback_frequency(unsigned int sample_rate_hz);
87#endif 87#endif
88#ifdef HAVE_ALBUMART 88#ifdef HAVE_ALBUMART
89void set_albumart_mode(int setting); 89void 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 @@
41#include "kernel.h" 41#include "kernel.h"
42#include "open_plugin.h" 42#include "open_plugin.h"
43#include "misc.h" 43#include "misc.h"
44#include "playback.h"
44#ifdef HAVE_REMOTE_LCD 45#ifdef HAVE_REMOTE_LCD
45#include "lcd-remote.h" 46#include "lcd-remote.h"
46#endif 47#endif
@@ -387,7 +388,7 @@ static const char* list_pad_formatter(char *buffer, size_t buffer_size,
387{ 388{
388 switch (val) 389 switch (val)
389 { 390 {
390 case -1: return str(LANG_AUTOMATIC); 391 case -1: return str(LANG_AUTO);
391 case 0: return str(LANG_OFF); 392 case 0: return str(LANG_OFF);
392 default: break; 393 default: break;
393 } 394 }
@@ -399,7 +400,7 @@ static int32_t list_pad_getlang(int value, int unit)
399{ 400{
400 switch (value) 401 switch (value)
401 { 402 {
402 case -1: return LANG_AUTOMATIC; 403 case -1: return LANG_AUTO;
403 case 0: return LANG_OFF; 404 case 0: return LANG_OFF;
404 default: return TALK_ID(value, unit); 405 default: return TALK_ID(value, unit);
405 } 406 }
@@ -619,6 +620,30 @@ static void eq_set_default(void* setting, void* defaultval)
619 memcpy(setting, defaultval, sizeof(struct eq_band_setting)); 620 memcpy(setting, defaultval, sizeof(struct eq_band_setting));
620} 621}
621 622
623#ifdef HAVE_PLAY_FREQ
624static const char* formatter_freq_unit_0_is_auto(char *buffer, size_t buffer_size,
625 int value, const char *unit)
626{
627 if (value == 0)
628 return str(LANG_AUTO);
629 else
630 return db_format(buffer, buffer_size, value / 100, unit);
631}
632
633static int32_t getlang_freq_unit_0_is_auto(int value, int unit)
634{
635 if (value == 0)
636 return LANG_AUTO;
637 else
638 return talk_value_decimal(value, unit, 3, false);
639}
640
641static void playback_frequency_callback(int sample_rate_hz)
642{
643 audio_set_playback_frequency(sample_rate_hz);
644}
645#endif /* HAVE_PLAY_FREQ */
646
622/* perform shuffle/unshuffle of the current playlist based on the boolean provided */ 647/* perform shuffle/unshuffle of the current playlist based on the boolean provided */
623static void shuffle_playlist_callback(bool shuffle) 648static void shuffle_playlist_callback(bool shuffle)
624{ 649{
@@ -954,16 +979,17 @@ const struct settings_list settings[] = {
954#endif 979#endif
955 ), /* CHOICE_SETTING( repeat_mode ) */ 980 ), /* CHOICE_SETTING( repeat_mode ) */
956#ifdef HAVE_PLAY_FREQ 981#ifdef HAVE_PLAY_FREQ
957 STRINGCHOICE_SETTING(0, play_frequency, LANG_FREQUENCY, 0, 982 TABLE_SETTING(F_SOUNDSETTING|F_CB_ON_SELECT_ONLY|F_CB_ONLY_IF_CHANGED,
983 play_frequency, LANG_FREQUENCY, 0, "playback frequency", "auto",
984 UNIT_KHZ, formatter_freq_unit_0_is_auto,
985 getlang_freq_unit_0_is_auto,
986 playback_frequency_callback,
958#if HAVE_PLAY_FREQ >= 192 987#if HAVE_PLAY_FREQ >= 192
959 "playback frequency", "auto,44.1 kHz,48 kHz,88.2 kHz,96 kHz,176.4 kHz,192 kHz", NULL, 7, 988 7,0,SAMPR_44,SAMPR_48,SAMPR_88,SAMPR_96,SAMPR_176,SAMPR_192),
960 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)),
961#elif HAVE_PLAY_FREQ >= 96 989#elif HAVE_PLAY_FREQ >= 96
962 "playback frequency", "auto,44.1 kHz,48 kHz,88.2 kHz,96 kHz", NULL, 5, 990 5,0,SAMPR_44,SAMPR_48,SAMPR_88,SAMPR_96),
963 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)),
964#elif HAVE_PLAY_FREQ >= 48 991#elif HAVE_PLAY_FREQ >= 48
965 "playback frequency", "auto,44.1 kHz,48 kHz", NULL, 3, 992 3,0,SAMPR_44,SAMPR_48),
966 LANG_AUTOMATIC, TALK_ID_DECIMAL(441, 1, UNIT_KHZ), TALK_ID(48, UNIT_KHZ)),
967#else 993#else
968 #error "HAVE_PLAY_FREQ < 48???" 994 #error "HAVE_PLAY_FREQ < 48???"
969#endif 995#endif