Index: /trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DevIchAc97.cpp	(revision 67928)
+++ /trunk/src/VBox/Devices/Audio/DevIchAc97.cpp	(revision 67929)
@@ -1733,7 +1733,4 @@
 static int ichac97MixerSetVolume(PAC97STATE pThis, int index, PDMAUDIOMIXERCTL enmMixerCtl, uint32_t uVal)
 {
-    bool    fCntlMuted;
-    uint8_t lCntlAtt, rCntlAtt;
-
     /*
      * From AC'97 SoundMax Codec AD1981A/AD1981B:
@@ -1746,12 +1743,12 @@
      */
     /// @todo Does this apply to anything other than the master volume control?
-    if (uVal & RT_BIT(5))
+    if (uVal & RT_BIT(5))  /* D5 bit set? */
         uVal |= RT_BIT(4) | RT_BIT(3) | RT_BIT(2) | RT_BIT(1) | RT_BIT(0);
-    if (uVal & RT_BIT(13))
+    if (uVal & RT_BIT(13)) /* D13 bit set? */
         uVal |= RT_BIT(12) | RT_BIT(11) | RT_BIT(10) | RT_BIT(9) | RT_BIT(8);
 
-    fCntlMuted = (uVal >> AC97_BARS_VOL_MUTE_SHIFT) & 1;
-    lCntlAtt   = (uVal >> 8) & AC97_BARS_VOL_MASK;
-    rCntlAtt   = uVal & AC97_BARS_VOL_MASK;
+    const bool    fCtlMuted    = (uVal >> AC97_BARS_VOL_MUTE_SHIFT) & 1;
+          uint8_t uCtlAttLeft  = (uVal >> 8) & AC97_BARS_VOL_MASK;
+          uint8_t uCtlAttRight = uVal & AC97_BARS_VOL_MASK;
 
     /* For the master and headphone volume, 0 corresponds to 0dB attenuation. For the other
@@ -1762,13 +1759,13 @@
 #ifndef VBOX_WITH_AC97_GAIN_SUPPORT
         /* NB: Currently there is no gain support, only attenuation. */
-        lCntlAtt = lCntlAtt < 8 ? 0 : lCntlAtt - 8;
-        rCntlAtt = rCntlAtt < 8 ? 0 : rCntlAtt - 8;
+        uCtlAttLeft  = uCtlAttLeft  < 8 ? 0 : uCtlAttLeft  - 8;
+        uCtlAttRight = uCtlAttRight < 8 ? 0 : uCtlAttRight - 8;
 #endif
     }
-    Assert(lCntlAtt <= 255 / AC97_DB_FACTOR);
-    Assert(rCntlAtt <= 255 / AC97_DB_FACTOR);
+    Assert(uCtlAttLeft  <= 255 / AC97_DB_FACTOR);
+    Assert(uCtlAttRight <= 255 / AC97_DB_FACTOR);
 
     LogFunc(("index=0x%x, uVal=%RU32, enmMixerCtl=%RU32\n", index, uVal, enmMixerCtl));
-    LogFunc(("lAtt=%RU8, rAtt=%RU8 ", lCntlAtt, rCntlAtt));
+    LogFunc(("uCtlAttLeft=%RU8, uCtlAttRight=%RU8 ", uCtlAttLeft, uCtlAttRight));
 
     /*
@@ -1777,8 +1774,8 @@
      * steps, each -0.375dB, where 0 corresponds to -96dB and 255 corresponds to 0dB.
      */
-    uint8_t lVol = PDMAUDIO_VOLUME_MAX - lCntlAtt * AC97_DB_FACTOR;
-    uint8_t rVol = PDMAUDIO_VOLUME_MAX - rCntlAtt * AC97_DB_FACTOR;
-
-    Log(("-> fMuted=%RTbool, lVol=%RU8, rVol=%RU8\n", fCntlMuted, lVol, rVol));
+    uint8_t lVol = PDMAUDIO_VOLUME_MAX - uCtlAttLeft  * AC97_DB_FACTOR;
+    uint8_t rVol = PDMAUDIO_VOLUME_MAX - uCtlAttRight * AC97_DB_FACTOR;
+
+    Log(("-> fMuted=%RTbool, lVol=%RU8, rVol=%RU8\n", fCtlMuted, lVol, rVol));
 
     int rc = VINF_SUCCESS;
@@ -1786,5 +1783,5 @@
     if (pThis->pMixer) /* Device can be in reset state, so no mixer available. */
     {
-        PDMAUDIOVOLUME Vol   = { fCntlMuted, lVol, rVol };
+        PDMAUDIOVOLUME Vol   = { fCtlMuted, lVol, rVol };
         PAUDMIXSINK    pSink = NULL;
 
@@ -1970,5 +1967,8 @@
     ichac97MixerRecordSelect(pThis, 0);
 
+    /* The default value is 8000h, which corresponds to 0 dB attenuation with mute on. */
     ichac97MixerSetVolume(pThis, AC97_Master_Volume_Mute,  PDMAUDIOMIXERCTL_VOLUME_MASTER, 0x8000);
+
+    /* The default value for stereo registers is 8808h, which corresponds to 0 dB gain with mute on.*/
     ichac97MixerSetVolume(pThis, AC97_PCM_Out_Volume_Mute, PDMAUDIOMIXERCTL_FRONT,         0x8808);
     ichac97MixerSetVolume(pThis, AC97_Line_In_Volume_Mute, PDMAUDIOMIXERCTL_LINE_IN,       0x8808);
@@ -2665,5 +2665,5 @@
 
                 default:
-                    LogFunc(("Unimplemented: %#x <- %#x (Byte)\n", uPort, u32Val));
+                    LogRel2(("AC97: Warning: Unimplemented NABMWrite (%u byte) portIdx=%#x <- %#x\n", cbVal, uPortIdx, u32Val));
                     break;
             }
@@ -2684,5 +2684,5 @@
                     break;
                 default:
-                    LogFunc(("Unimplemented: %#x <- %#x (Word)\n", uPort, u32Val));
+                    LogRel2(("AC97: Warning: Unimplemented NABMWrite (%u byte) portIdx=%#x <- %#x\n", cbVal, uPortIdx, u32Val));
                     break;
             }
@@ -2718,5 +2718,5 @@
                     break;
                 default:
-                    LogFunc(("Unimplemented: %#x <- %#x (DWord)\n", uPort, u32Val));
+                    LogRel2(("AC97: Warning: Unimplemented NABMWrite (%u byte) portIdx=%#x <- %#x\n", cbVal, uPortIdx, u32Val));
                     break;
             }
@@ -2725,5 +2725,5 @@
 
         default:
-            AssertMsgFailed(("Port=%#x cb=%d u32=%#x\n", uPort, cbVal, u32Val));
+            AssertLogRel(("AC97: Warning: Unimplemented NABMWrite (%u byte) portIdx=%#x <- %#x\n", cbVal, uPortIdx, u32Val));
             break;
     }
@@ -2753,9 +2753,11 @@
     int rc = VINF_SUCCESS;
 
+    uint32_t index = uPort - pThis->IOPortBase[0];
+
     switch (cbVal)
     {
         case 1:
         {
-            Log3Func(("U nam readb %#x\n", uPort));
+            LogRel2(("AC97: Warning: Unimplemented read (%u byte) port=%#x, idx=%RU32\n", cbVal, uPort, index));
             pThis->cas = 0;
             *pu32Val = UINT32_MAX;
@@ -2765,12 +2767,11 @@
         case 2:
         {
-            uint32_t index = uPort - pThis->IOPortBase[0];
             *pu32Val = UINT32_MAX;
             pThis->cas = 0;
+
             switch (index)
             {
                 default:
                     *pu32Val = ichac97MixerGet(pThis, index);
-                    Log3Func(("nam readw %#x -> %#x\n", uPort, *pu32Val));
                     break;
             }
@@ -2780,5 +2781,5 @@
         case 4:
         {
-            Log3Func(("U nam readl %#x\n", uPort));
+            LogRel2(("AC97: Warning: Unimplemented read (%u byte) port=%#x, idx=%RU32\n", cbVal, uPort, index));
             pThis->cas = 0;
             *pu32Val = UINT32_MAX;
@@ -2814,9 +2815,11 @@
     PAC97STATE pThis = (PAC97STATE)pvUser;
 
+    uint32_t uPortIdx = uPort - pThis->IOPortBase[0];
+
     switch (cbVal)
     {
         case 1:
         {
-            Log3Func(("U nam writeb %#x <- %#x\n", uPort, u32Val));
+            LogRel2(("AC97: Warning: Unimplemented NAMWrite (%u byte) port=%#x, idx=0x%x <- %#x\n", cbVal, uPort, uPortIdx, u32Val));
             pThis->cas = 0;
             break;
@@ -2825,7 +2828,6 @@
         case 2:
         {
-            uint32_t index = uPort - pThis->IOPortBase[0];
             pThis->cas = 0;
-            switch (index)
+            switch (uPortIdx)
             {
                 case AC97_Reset:
@@ -2834,6 +2836,6 @@
                 case AC97_Powerdown_Ctrl_Stat:
                     u32Val &= ~0xf;
-                    u32Val |= ichac97MixerGet(pThis, index) & 0xf;
-                    ichac97MixerSet(pThis, index, u32Val);
+                    u32Val |= ichac97MixerGet(pThis, uPortIdx) & 0xf;
+                    ichac97MixerSet(pThis, uPortIdx, u32Val);
                     break;
                 case AC97_Master_Volume_Mute:
@@ -2843,5 +2845,5 @@
                             break; /* Register controls surround (rear), do nothing. */
                     }
-                    ichac97MixerSetVolume(pThis, index, PDMAUDIOMIXERCTL_VOLUME_MASTER, u32Val);
+                    ichac97MixerSetVolume(pThis, uPortIdx, PDMAUDIOMIXERCTL_VOLUME_MASTER, u32Val);
                     break;
                 case AC97_Headphone_Volume_Mute:
@@ -2851,13 +2853,13 @@
                         {
                             /* Register controls PCM (front) outputs. */
-                            ichac97MixerSetVolume(pThis, index, PDMAUDIOMIXERCTL_VOLUME_MASTER, u32Val);
+                            ichac97MixerSetVolume(pThis, uPortIdx, PDMAUDIOMIXERCTL_VOLUME_MASTER, u32Val);
                         }
                     }
                     break;
                 case AC97_PCM_Out_Volume_Mute:
-                    ichac97MixerSetVolume(pThis, index, PDMAUDIOMIXERCTL_FRONT, u32Val);
+                    ichac97MixerSetVolume(pThis, uPortIdx, PDMAUDIOMIXERCTL_FRONT, u32Val);
                     break;
                 case AC97_Line_In_Volume_Mute:
-                    ichac97MixerSetVolume(pThis, index, PDMAUDIOMIXERCTL_LINE_IN, u32Val);
+                    ichac97MixerSetVolume(pThis, uPortIdx, PDMAUDIOMIXERCTL_LINE_IN, u32Val);
                     break;
                 case AC97_Record_Select:
@@ -2867,9 +2869,9 @@
                     /* Newer Ubuntu guests rely on that when controlling gain and muting
                      * the recording (capturing) levels. */
-                    ichac97MixerSetVolume(pThis, index, PDMAUDIOMIXERCTL_LINE_IN, u32Val);
+                    ichac97MixerSetVolume(pThis, uPortIdx, PDMAUDIOMIXERCTL_LINE_IN, u32Val);
                     break;
                 case AC97_Record_Gain_Mic_Mute:
                     /* Ditto; see note above. */
-                    ichac97MixerSetVolume(pThis, index, PDMAUDIOMIXERCTL_MIC_IN,  u32Val);
+                    ichac97MixerSetVolume(pThis, uPortIdx, PDMAUDIOMIXERCTL_MIC_IN,  u32Val);
                     break;
                 case AC97_Vendor_ID1:
@@ -2906,5 +2908,5 @@
                     if (ichac97MixerGet(pThis, AC97_Extended_Audio_Ctrl_Stat) & AC97_EACS_VRA)
                     {
-                        ichac97MixerSet(pThis, index, u32Val);
+                        ichac97MixerSet(pThis, uPortIdx, u32Val);
                         LogFunc(("Set front DAC rate to %RU32\n", u32Val));
                         ichac97StreamReOpen(pThis, &pThis->StreamOut);
@@ -2916,5 +2918,5 @@
                     if (ichac97MixerGet(pThis, AC97_Extended_Audio_Ctrl_Stat) & AC97_EACS_VRM)
                     {
-                        ichac97MixerSet(pThis, index, u32Val);
+                        ichac97MixerSet(pThis, uPortIdx, u32Val);
                         LogFunc(("Set MIC ADC rate to %RU32\n", u32Val));
                         ichac97StreamReOpen(pThis, &pThis->StreamMicIn);
@@ -2926,5 +2928,5 @@
                     if (ichac97MixerGet(pThis, AC97_Extended_Audio_Ctrl_Stat) & AC97_EACS_VRA)
                     {
-                        ichac97MixerSet(pThis, index, u32Val);
+                        ichac97MixerSet(pThis, uPortIdx, u32Val);
                         LogFunc(("Set front LR ADC rate to %RU32\n", u32Val));
                         ichac97StreamReOpen(pThis, &pThis->StreamLineIn);
@@ -2934,6 +2936,6 @@
                     break;
                 default:
-                    LogFunc(("U nam writew %#x <- %#x\n", uPort, u32Val));
-                    ichac97MixerSet(pThis, index, u32Val);
+                    LogRel2(("AC97: Warning: Unimplemented NAMWrite (%u byte) port=%#x, idx=0x%x <- %#x\n", cbVal, uPort, uPortIdx, u32Val));
+                    ichac97MixerSet(pThis, uPortIdx, u32Val);
                     break;
             }
@@ -2943,5 +2945,5 @@
         case 4:
         {
-            Log3Func(("U nam writel %#x <- %#x\n", uPort, u32Val));
+            LogRel2(("AC97: Warning: Unimplemented NAMWrite (%u byte) port=%#x, idx=0x%x <- %#x\n", cbVal, uPort, uPortIdx, u32Val));
             pThis->cas = 0;
             break;
@@ -2949,5 +2951,5 @@
 
         default:
-            AssertMsgFailed(("Port=%#x cb=%d u32=%#x\n", uPort, cbVal, u32Val));
+            AssertMsgFailed(("Unhandled NAMWrite port=%#x, cbVal=%u u32Val=%#x\n", uPort, cbVal, u32Val));
             break;
     }
