SDL: Simplify get_channel_name() so it's easier for people to read and understand

From 45584ad73e808bf5c2c6b2a33571c24f21360823 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 22 Oct 2024 18:19:30 -0700
Subject: [PATCH] Simplify get_channel_name() so it's easier for people to read
 and understand

---
 test/testsurround.c | 122 ++++++++++++++++++++++++++++++--------------
 1 file changed, 84 insertions(+), 38 deletions(-)

diff --git a/test/testsurround.c b/test/testsurround.c
index dc3a8d72ac303..9c1aaae7fe436 100644
--- a/test/testsurround.c
+++ b/test/testsurround.c
@@ -27,65 +27,111 @@ static int active_channel;
 #define LFE_SINE_FREQ_HZ 50
 
 /* The channel layout is defined in SDL_audio.h */
-static const char *
-get_channel_name(int channel_index, int channel_count)
+static const char *get_channel_name(int channel_index, int channel_count)
 {
-    switch (channel_index) {
-    case 0:
-        return "Front Left";
+    switch (channel_count) {
     case 1:
-        return "Front Right";
+        return "Mono";
     case 2:
-        switch (channel_count) {
-        case 3:
-        case 5:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        }
+        break;
+    case 3:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        case 2:
             return "Low Frequency Effects";
-        case 4:
+        }
+        break;
+    case 4:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        case 2:
             return "Back Left";
-        default:
-            return "Front Center";
+        case 3:
+            return "Back Right";
         }
-    case 3:
-        switch (channel_count) {
+        break;
+    case 5:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        case 2:
+            return "Low Frequency Effects";
+        case 3:
+            return "Back Left";
         case 4:
             return "Back Right";
-        case 5:
-            return "Back Left";
-        default:
-            return "Low Frequency Effects";
         }
-    case 4:
-        switch (channel_count) {
+        break;
+    case 6:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        case 2:
+            return "Front Center";
+        case 3:
+            return "Low Frequency Effects";
+        case 4:
+            return "Back Left";
         case 5:
             return "Back Right";
-        case 6:
-            return "Side Left";
-        case 7:
-            return "Back Center";
-        case 8:
-            return "Back Left";
         }
         break;
-    case 5:
-        switch (channel_count) {
+    case 7:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        case 2:
+            return "Front Center";
+        case 3:
+            return "Low Frequency Effects";
+        case 4:
+            return "Back Center";
+        case 5:
+            return "Side Left";
         case 6:
             return "Side Right";
-        case 7:
-            return "Side Left";
-        case 8:
-            return "Back Right";
         }
         break;
-    case 6:
-        switch (channel_count) {
+    case 8:
+        switch (channel_index) {
+        case 0:
+            return "Front Left";
+        case 1:
+            return "Front Right";
+        case 2:
+            return "Front Center";
+        case 3:
+            return "Low Frequency Effects";
+        case 4:
+            return "Back Left";
+        case 5:
+            return "Back Right";
+        case 6:
+            return "Side Left";
         case 7:
             return "Side Right";
-        case 8:
-            return "Side Left";
         }
         break;
-    case 7:
-        return "Side Right";
+    default:
+        break;
     }
     SDLTest_AssertCheck(false, "Invalid channel_index for channel_count:  channel_count=%d channel_index=%d", channel_count, channel_index);
     SDL_assert(0);