playback: do not try to switch to a sampr the current sink doesn't support

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Wed, 6 May 2026 08:22:31 -0400
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 1d5aa533218e1be8d6194ea55e972d7e99b029a9
Author: Skye <[email protected]>
Date:   Mon May 4 01:09:31 2026 +0900

    playback: do not try to switch to a sampr the current sink doesn't support
    
    Change-Id: I73c18365cb3010ca45c6d41ae390b8de095c7589

diff --git a/apps/playback.c b/apps/playback.c
index 6a7e764248..8102f8d917 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -4247,12 +4247,22 @@ void audio_set_crossfade(int enable)
 static unsigned long audio_guess_frequency(struct mp3entry *id3)
 {
     const struct pcm_sink_caps* caps = pcm_sink_caps(pcm_current_sink());
+    bool have_44 = false;
+    bool have_48 = false;
     for (size_t i = 0; i < caps->num_samprs; i += 1)
     {
+        if (caps->samprs[i] == SAMPR_44)
+            have_44 = true;
+        if (caps->samprs[i] == SAMPR_48)
+            have_48 = true;
         if (id3->frequency == caps->samprs[i])
             return id3->frequency;
     }
-    return (id3->frequency % 4000) ? SAMPR_44 : SAMPR_48;
+    unsigned long fallback = (id3->frequency % 4000) ? SAMPR_44 : SAMPR_48;
+    if ((fallback == SAMPR_44 && have_44) || (fallback == SAMPR_48 && have_48))
+        return fallback;
+    else
+        return caps->samprs[caps->default_freq];
 }
 
 static bool audio_auto_change_frequency(struct mp3entry *id3, bool play)
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs