playback: do not hardcode pcm sink in audio_set_playback_frequency

make audio_set_playback_frequency() can be used for non-builtin pcm
sinks.

Change-Id: I9d1110f28753e912b84515594a1361cd17fa5e74
This commit is contained in:
mojyack 2026-02-12 19:52:32 +09:00
parent ea570c5728
commit 76d63246c5

View file

@ -27,6 +27,7 @@
#include "panic.h"
#include "core_alloc.h"
#include "sound.h"
#include "pcm_sink.h"
#include "codecs.h"
#include "codec_thread.h"
#include "voice_thread.h"
@ -4282,27 +4283,16 @@ static bool audio_auto_change_frequency(struct mp3entry *id3, bool play)
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 int play_sampr[] = {SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, SAMPR_176, SAMPR_192, 0 };
#elif HAVE_PLAY_FREQ >= 96
static const unsigned int play_sampr[] = {SAMPR_44, SAMPR_48, SAMPR_88, SAMPR_96, 0 };
#elif HAVE_PLAY_FREQ >= 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;
while (*p_sampr != 0)
const struct pcm_sink_caps* caps = pcm_sink_caps(pcm_current_sink());
for (size_t i = 0; i < caps->num_samprs; i += 1)
{
if (*p_sampr == sample_rate_hz)
if (caps->samprs[i] == sample_rate_hz)
{
sampr = *p_sampr;
sampr = caps->samprs[i];
break;
}
p_sampr++;
}
if (sampr == 0)