Compare commits

..

2 commits

Author SHA1 Message Date
mojyack
a6a1be6e30 plugins: remove hw_freq_sampr from plugin api
replaced by pcm_current_sink_caps

Change-Id: Ib17a1f5bb8ae479278ef467dfcc99fead6f1499e
2026-04-11 14:20:44 -04:00
mojyack
012c61eadf plugins: mikmod: remove hw_freq_sampr usage
TODO:

 * Dynamically hide the sample rates that aren't supported
   by the current sink
 * Better "default" selection based on hardware type/speed

Change-Id: I261544fc3ba78429eaaa81c89aebd2e68106caa3
2026-04-11 14:18:36 -04:00
5 changed files with 72 additions and 63 deletions

View file

@ -642,7 +642,6 @@ static const struct plugin_api rockbox_api = {
sound_get_pitch, sound_get_pitch,
sound_set_pitch, sound_set_pitch,
#endif #endif
&hw_freq_sampr[0],
pcm_play_lock, pcm_play_lock,
pcm_play_unlock, pcm_play_unlock,
pcm_current_sink_caps, pcm_current_sink_caps,

View file

@ -741,7 +741,6 @@ struct plugin_api {
int32_t (*sound_get_pitch)(void); int32_t (*sound_get_pitch)(void);
void (*sound_set_pitch)(int32_t pitch); void (*sound_set_pitch)(int32_t pitch);
#endif #endif
const unsigned long *hw_freq_sampr;
void (*pcm_play_lock)(void); void (*pcm_play_lock)(void);
void (*pcm_play_unlock)(void); void (*pcm_play_unlock)(void);
const struct pcm_sink_caps* (*pcm_current_sink_caps)(void); const struct pcm_sink_caps* (*pcm_current_sink_caps)(void);

View file

@ -502,12 +502,59 @@ static const struct configdata config[] =
{ TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL},
{ TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL},
{ TYPE_BOOL, 0, 1, { .bool_p = &settings.hqmixer }, "HQ Mixer", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.hqmixer }, "HQ Mixer", NULL},
{ TYPE_INT, 0, HW_NUM_FREQ-1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL}, { TYPE_INT, 0, SAMPR_NUM_FREQ - 1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL},
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
{ TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL},
#endif #endif
}; };
// XXX dynamically generate this list at runtime.
static const struct opt_items sr_names[SAMPR_NUM_FREQ] = {
[FREQ_192] = { "192kHz", TALK_ID(192, UNIT_KHZ) },
[FREQ_176] = { "176.4kHz", TALK_ID(176, UNIT_KHZ) },
[FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },
[FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },
[FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },
[FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },
[FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },
[FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },
[FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },
[FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },
[FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },
[FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },
[FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },
[FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },
};
static const unsigned long sr_nums[SAMPR_NUM_FREQ] =
{
[FREQ_192] = SAMPR_192,
[FREQ_176] = SAMPR_176,
[FREQ_96] = SAMPR_96,
[FREQ_88] = SAMPR_88,
[FREQ_64] = SAMPR_64,
[FREQ_48] = SAMPR_48,
[FREQ_44] = SAMPR_44,
[FREQ_32] = SAMPR_32,
[FREQ_24] = SAMPR_24,
[FREQ_22] = SAMPR_22,
[FREQ_16] = SAMPR_16,
[FREQ_12] = SAMPR_12,
[FREQ_11] = SAMPR_11,
[FREQ_8 ] = SAMPR_8,
};
static int sampr_to_setting_index(unsigned long sampr)
{
for(unsigned int i = 0; i < ARRAYLEN(sr_nums); i += 1)
{
if(sr_nums[i] == sampr)
return i;
}
/* no way... */
return ARRAYLEN(sr_nums) - 1;
}
static void applysettings(void) static void applysettings(void)
{ {
md_pansep = settings.pansep; md_pansep = settings.pansep;
@ -533,9 +580,27 @@ static void applysettings(void)
} }
#endif #endif
if (inited && (md_mixfreq != rb->hw_freq_sampr[settings.sample_rate])) { if (inited && (md_mixfreq != sr_nums[settings.sample_rate])) {
md_mixfreq = rb->hw_freq_sampr[settings.sample_rate]; /* validate configured samplerate and set md_mixfreq */
// MikMod_Reset(""); BROKEN! md_mixfreq = 0;
const struct pcm_sink_caps* caps = rb->pcm_current_sink_caps();
for(unsigned int i = 0; i < caps->num_samprs; i += 1)
{
if(caps->samprs[i] == sr_nums[settings.sample_rate])
{
md_mixfreq = sr_nums[settings.sample_rate];
break;
}
}
if(md_mixfreq == 0)
{
/* unsupported samplerate, use the default */
md_mixfreq = caps->samprs[caps->default_freq];
settings.sample_rate = sampr_to_setting_index(md_mixfreq);
}
// MikMod_Reset(""); BROKEN!
rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK);
rb->mixer_set_frequency(md_mixfreq); rb->mixer_set_frequency(md_mixfreq);
rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0);
@ -549,23 +614,6 @@ static void applysettings(void)
#endif #endif
} }
static const struct opt_items sr_names[HW_NUM_FREQ] = {
HW_HAVE_192_([HW_FREQ_192] = { "192kHz", TALK_ID(192, UNIT_KHZ) },)
HW_HAVE_176_([HW_FREQ_176] = { "176.4kHz", TALK_ID(176, UNIT_KHZ) },)
HW_HAVE_96_([HW_FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },)
HW_HAVE_88_([HW_FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },)
HW_HAVE_64_([HW_FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },)
HW_HAVE_48_([HW_FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },)
HW_HAVE_44_([HW_FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },)
HW_HAVE_32_([HW_FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },)
HW_HAVE_24_([HW_FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },)
HW_HAVE_22_([HW_FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },)
HW_HAVE_16_([HW_FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },)
HW_HAVE_12_([HW_FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },)
HW_HAVE_11_([HW_FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },)
HW_HAVE_8_( [HW_FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },)
};
/** /**
Shows the settings menu Shows the settings menu
*/ */
@ -626,7 +674,7 @@ static int settings_menu(void)
case 6: case 6:
rb->set_option("Sample Rate", &(settings.sample_rate), RB_INT, sr_names, rb->set_option("Sample Rate", &(settings.sample_rate), RB_INT, sr_names,
HW_NUM_FREQ, NULL); SAMPR_NUM_FREQ, NULL);
applysettings(); applysettings();
break; break;
@ -992,16 +1040,8 @@ enum plugin_status plugin_start(const void* parameter)
/* If there's no configured rate, use the default */ /* If there's no configured rate, use the default */
if (settings.sample_rate == -1) { if (settings.sample_rate == -1) {
int i; const struct pcm_sink_caps* caps = rb->pcm_current_sink_caps();
for (i = 0 ; i < HW_NUM_FREQ ; i++) { settings.sample_rate = sampr_to_setting_index(caps->samprs[caps->default_freq]);
if (rb->hw_freq_sampr[i] == SAMPLE_RATE) {
settings.sample_rate = i;
break;
}
}
if (settings.sample_rate == -1) {
settings.sample_rate = HW_NUM_FREQ -1;
}
} }
applysettings(); applysettings();

View file

@ -68,30 +68,6 @@ int mmsupp_sprintf(char *buf, const char *fmt, ... );
extern const struct plugin_api * rb; extern const struct plugin_api * rb;
#ifdef SIMULATOR
#define SAMPLE_RATE SAMPR_44 /* Required by Simulator */
#elif ((CONFIG_PLATFORM & PLATFORM_HOSTED) || defined(CPU_MIPS))
#define SAMPLE_RATE SAMPR_44 /* All MIPS and hosted targets are fast */
#elif defined(CPU_ARM)
/* Treat ARMv5+ as fast */
#if (ARM_ARCH >= 5)
#define SAMPLE_RATE SAMPR_44
#else
#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
#endif
#else /* !CPU_ARM */
/* Treat everyone else as slow */
#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
#endif /* !SIMULATOR */
#define BUF_SIZE 4096*8 #define BUF_SIZE 4096*8
#define NBUF 2 #define NBUF 2

View file

@ -1545,11 +1545,6 @@ void logf(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2)
\param fmt \param fmt
\description \description
const unsigned long *hw_freq_sampr
\group sound
\return
\description
const unsigned long *rec_freq_sampr const unsigned long *rec_freq_sampr
\group sound \group sound
\conditions (defined(HAVE_RECORDING)) \conditions (defined(HAVE_RECORDING))