From a6340c9d706521ccbdbf75ecc868d350b9240db2 Mon Sep 17 00:00:00 2001
From: Cacodemon345 <wahil1976@outlook.com>
Date: Mon, 16 Dec 2024 13:37:27 +0600
Subject: [PATCH] Cleanup and volume silencing fix

---
 src/usb/usb_audio.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/usb/usb_audio.c b/src/usb/usb_audio.c
index 8644c01d15..d08ccfd67b 100644
--- a/src/usb/usb_audio.c
+++ b/src/usb/usb_audio.c
@@ -36,9 +36,6 @@ enum usb_audio_strings {
 };
 
 static const char* usb_audio_stringtable[] = {
-    [STRING_MANUFACTURER]       = "QEMU",
-    [STRING_PRODUCT]            = "QEMU USB Audio",
-    [STRING_SERIALNUMBER]       = "1",
     [STRING_CONFIG]             = "Audio Configuration",
     [STRING_USBAUDIO_CONTROL]   = "Audio Device",
     [STRING_INPUT_TERMINAL]     = "Audio Output Pipe",
@@ -263,13 +260,9 @@ usb_device_audio_handle_iface_change(usb_device_c* device, int iface)
         fifo8_reset(&usb_audio->audio_buf);
 }
 
-/*
- * Note: we arbitrarily map the volume control range onto -inf..+8 dB
- */
 #define ATTRIB_ID(cs, attrib, idif)     \
     (((cs) << 24) | ((attrib) << 16) | (idif))
 
-
 static int usb_device_audio_get_control(usb_device_audio *device, uint8_t attrib,
                                  uint16_t cscn, uint16_t idif,
                                  int length, uint8_t *data)
@@ -297,8 +290,8 @@ static int usb_device_audio_get_control(usb_device_audio *device, uint8_t attrib
         break;
     case ATTRIB_ID(VOLUME_CONTROL, CR_GET_MIN, 0x0200):
         if (cn < 2) {
-            data[0] = 0x01;
-            data[1] = 0x80;
+            data[0] = 0x00;
+            data[1] = 0xc2;
             ret = 2;
         }
         break;
@@ -486,8 +479,8 @@ usb_audio_get_buffer(int32_t *buffer, int len, void *priv)
         return; // Utter silence.
 
     for (int c = 0; c < len * 2; c++) {
-        double decibels = (usb_audio->vol[c & 1] / -32768.0) * 128.0;
-        double gain = (double)pow(10, (double)-decibels / 20.0);
+        double decibels = (usb_audio->vol[c & 1] / 32768.0) * 128.0;
+        double gain = (usb_audio->vol[c & 1] == ((int16_t)0x8000)) ? 0.0 : (double)pow(10, (double)decibels / 20.0);
         buffer[c] += usb_audio->buffer[c] * gain;
     }
 }