playback: do not hardcode pcm sink in audio_set_playback_frequency

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 76d63246c5d922304d861ba9de0f29185a3bd864
Author: mojyack <[email protected]>
Date:   Thu Feb 12 19:52:32 2026 +0900

    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

diff --git a/apps/playback.c b/apps/playback.c
index 0e8871c96c..c8c33dcd83 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -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)
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.