dsp: add option to swap left and right channels

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Thu, 16 Apr 2026 21:08:58 -0400
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit cc7418dd8bc4caa16940dff9acf7e4e8bca5be31
Author: Christian Soffke <[email protected]>
Date:   Thu Apr 16 10:52:16 2026 +0200

    dsp: add option to swap left and right channels
    
    Change-Id: Id4b518638436576cfb5e747548f10ece6e58eba0

diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index d0afa75c43..685dffb133 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -17085,3 +17085,17 @@
     *: "Show in Files"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_CHANNEL_SWAP
+  desc: in sound_settings
+  user: core
+  <source>
+    *: "Swap Left & Right"
+  </source>
+  <dest>
+    *: "Swap Left & Right"
+  </dest>
+  <voice>
+    *: "Swap Left & Right"
+  </voice>
+</phrase>
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 826f85825d..59fd4537a0 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -1060,11 +1060,12 @@ const struct settings_list settings[] = {
 /* 3-d enhancement effect */
     CHOICE_SETTING(0, channel_config, LANG_CHANNEL_CONFIGURATION,
                    0,"channels",
-                   "stereo,mono,custom,mono left,mono right,karaoke",
-                   sound_set_channels, 6,
+                   "stereo,mono,custom,mono left,mono right,karaoke,swap",
+                   sound_set_channels, 7,
                    ID2P(LANG_CHANNEL_STEREO), ID2P(LANG_CHANNEL_MONO),
                    ID2P(LANG_CHANNEL_CUSTOM), ID2P(LANG_CHANNEL_LEFT),
-                   ID2P(LANG_CHANNEL_RIGHT), ID2P(LANG_CHANNEL_KARAOKE)),
+                   ID2P(LANG_CHANNEL_RIGHT), ID2P(LANG_CHANNEL_KARAOKE),
+                   ID2P(LANG_CHANNEL_SWAP)),
     SOUND_SETTING(0, stereo_width, LANG_STEREO_WIDTH,
                   "stereo_width", SOUND_STEREO_WIDTH),
 #ifdef AUDIOHW_HAVE_DEPTH_3D
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 65570abb5b..ec465ca7b7 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -674,6 +674,7 @@ enum AUDIOHW_CHANNEL_CONFIG
     SOUND_CHAN_MONO_LEFT,
     SOUND_CHAN_MONO_RIGHT,
     SOUND_CHAN_KARAOKE,
+    SOUND_CHAN_SWAP,
     SOUND_CHAN_NUM_MODES,
 };
 
diff --git a/lib/rbcodec/dsp/channel_mode.c b/lib/rbcodec/dsp/channel_mode.c
index 7a83236648..86dc02e3a4 100644
--- a/lib/rbcodec/dsp/channel_mode.c
+++ b/lib/rbcodec/dsp/channel_mode.c
@@ -43,6 +43,8 @@ void channel_mode_proc_custom(struct dsp_proc_entry *this,
                               struct dsp_buffer **buf_p);
 void channel_mode_proc_karaoke(struct dsp_proc_entry *this,
                                struct dsp_buffer **buf_p);
+void channel_mode_proc_swap(struct dsp_proc_entry *this,
+                            struct dsp_buffer **buf_p);
 
 static struct channel_mode_data
 {
@@ -131,6 +133,25 @@ void channel_mode_proc_karaoke(struct dsp_proc_entry *this,
 }
 #endif /* CPU */
 
+void channel_mode_proc_swap(struct dsp_proc_entry *this,
+                            struct dsp_buffer **buf_p)
+{
+    struct dsp_buffer *buf = *buf_p;
+    int32_t *sl = buf->p32[0];
+    int32_t *sr = buf->p32[1];
+    int count = buf->remcount;
+
+    do
+    {
+        int32_t l = *sl;
+        *sl++ = *sr;
+        *sr++ = l;
+    }
+    while (--count > 0);
+
+    (void)this;
+}
+
 void channel_mode_proc_mono_left(struct dsp_proc_entry *this,
                                  struct dsp_buffer **buf_p)
 {
@@ -194,6 +215,7 @@ static void update_process_fn(struct dsp_proc_entry *this)
         [SOUND_CHAN_MONO_LEFT]  = channel_mode_proc_mono_left,
         [SOUND_CHAN_MONO_RIGHT] = channel_mode_proc_mono_right,
         [SOUND_CHAN_KARAOKE]    = channel_mode_proc_karaoke,
+        [SOUND_CHAN_SWAP]       = channel_mode_proc_swap,
     };
 
     this->process = fns[((struct channel_mode_data *)this->data)->mode];
diff --git a/manual/configure_rockbox/sound_settings.tex b/manual/configure_rockbox/sound_settings.tex
index f9c85b6fbb..a8e94737b9 100644
--- a/manual/configure_rockbox/sound_settings.tex
+++ b/manual/configure_rockbox/sound_settings.tex
@@ -178,6 +178,9 @@ change to customise your listening experience.
           to make the singer sound centrally placed, this often (but not
           always) has the effect of removing the voice track from a song. This
           setting also very often has other undesirable effects on the sound.
+      \item[Swap Left \& Right.]
+          Plays the left channel in the right stereo channel, and the right
+          channel in the left stereo channel.
   \end{description}
 
 \section{Stereo Width}
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs