Index: trunk/src/VBox/Devices/Audio/audio.c
===================================================================
--- trunk/src/VBox/Devices/Audio/audio.c	(revision 7504)
+++ trunk/src/VBox/Devices/Audio/audio.c	(revision 7525)
@@ -1870,4 +1870,5 @@
         case AUD_MIXER_PCM:
             name = "PCM_OUT";
+            vol  = &pcm_out_volume;
             break;
         case AUD_MIXER_LINE_IN:
Index: trunk/src/VBox/Devices/Audio/solaudio.c
===================================================================
--- trunk/src/VBox/Devices/Audio/solaudio.c	(revision 7504)
+++ trunk/src/VBox/Devices/Audio/solaudio.c	(revision 7525)
@@ -59,5 +59,5 @@
 } conf =
 {
-    INIT_FIELD (cbBuffer =) 8912,
+    INIT_FIELD (cbBuffer =) 4352,
 };
 
@@ -123,10 +123,10 @@
 
 
-static char *solaudio_getdevice ()
+static char *solaudio_getdevice (void)
 {
     /* This is for multiple audio devices where env. var determines current one,
      * otherwise else we fallback to default.
      */
-    char *pszAudioDev = RTEnvGet("AUDIODEV");
+    const char *pszAudioDev = RTEnvGet("AUDIODEV");
     if (pszAudioDev)
         return RTStrDup(pszAudioDev);
@@ -141,6 +141,6 @@
     int AudioCtl;
     struct stat FileStat;
-    const char *pszAudioDev = NULL;
-    const char *pszAudioCtl = "/dev/audioctl";
+    char *pszAudioDev = NULL;
+    char *pszAudioCtl = NULL;
     audio_info_t AudioInfo;
 
@@ -149,5 +149,5 @@
     {
         LogRel(("solaudio: solaudio_getdevice() failed to return a valid device.\n"));
-        goto err;
+        return -1;
     }
 
@@ -155,5 +155,5 @@
     {
         LogRel(("solaudio: failed to stat %s\n", pszAudioDev));
-        goto err;
+        goto err2;
     }
 
@@ -161,5 +161,5 @@
     {
         LogRel(("solaudio: invalid mode for %s\n", pszAudioDev));
-        goto err;
+        goto err2;
     }
 
@@ -168,7 +168,8 @@
     {
         LogRel(("solaudio: failed to open %s\n", pszAudioDev));
-        goto err;
-    }
-
+        goto err2;
+    }
+
+    RTStrAPrintf(&pszAudioCtl, "%sctl", pszAudioDev);
     AudioCtl = open(pszAudioCtl, O_WRONLY | O_NONBLOCK);
     if (AudioCtl < 0)
@@ -193,5 +194,4 @@
     AudioInfo.play.buffer_size = info->play.buffer_size;
     AudioInfo.play.gain = AUDIO_MAX_GAIN;
-    AudioInfo.play.balance = AUDIO_MID_BALANCE;
     if (ioctl(AudioDev, AUDIO_SETINFO, &AudioInfo) < 0)
     {
@@ -204,7 +204,11 @@
     *pfd = AudioDev;
     *pctl_fd = AudioCtl;
+    RTStrFree(pszAudioDev);
+    RTStrFree(pszAudioCtl);
     return 0;
 
 err:
+    RTStrFree(pszAudioCtl);
+err2:
     RTStrFree(pszAudioDev);
     return -1;
@@ -224,5 +228,12 @@
     AudioInfo.play.channels = as->nchannels;
     AudioInfo.play.precision = aud_to_solfmt(as->fmt);
+#if 0
+    /* Not really needed. */
+    int cbPerSample = (AudioInfo.play.channels * AudioInfo.play.precision) / 8;
+    int cbPerSecond = cbPerSample * AudioInfo.play.sample_rate;
+    AudioInfo.play.buffer_size = cbPerSecond > 131072 ? conf.cbBuffer : conf.cbBuffer / 2;
+#endif
     AudioInfo.play.buffer_size = conf.cbBuffer;
+
     if (as->fmt == AUD_FMT_U8)
         AudioInfo.play.encoding = AUDIO_ENCODING_LINEAR8;
@@ -260,4 +271,5 @@
 static void solaudio_stop (solaudioVoiceOut *sol)
 {
+    audio_info_t AudioInfo;
     LogFlow(("solaudio: stop\n"));
     if (sol->AudioDev < 0 || sol->AudioCtl < 0)
@@ -269,5 +281,5 @@
     if (ioctl(sol->AudioCtl, I_SETSIG, 0) < 0)
     {
-        LogRel(("solaudio: failed to stop signalling\n"));
+        Log(("solaudio: failed to stop signalling\n"));
         return;
     }
@@ -275,7 +287,26 @@
     if (ioctl(sol->AudioDev, I_FLUSH, FLUSHW) < 0)
     {
-        Log(("solaudio: failed to drop unplayed buffers\n"));
+        LogRel(("solaudio: failed to drop unplayed buffers\n"));
         return;
     }
+
+    AUDIO_INITINFO(&AudioInfo);
+    AudioInfo.play.samples = 0;
+    AudioInfo.play.pause = 0;
+    AudioInfo.play.eof = 0;
+    AudioInfo.play.error = 0;
+    sol->cBuffersPlayed = 0;
+    if (ioctl(sol->AudioDev, AUDIO_SETINFO, &AudioInfo) < 0)
+    {
+        LogRel(("solaudio: AUDIO_SETINFO failed during stop.\n"));
+        return;
+    }
+}
+
+
+static void solaudio_fini_out (HWVoiceOut *hw)
+{
+    solaudioVoiceOut *sol = (solaudioVoiceOut *) hw;
+    solaudio_stop (sol);
 
     close(sol->AudioDev);
@@ -283,5 +314,4 @@
     close(sol->AudioCtl);
     sol->AudioCtl = -1;
-    sol->cBuffersPlayed = 0;
     if (sol->pPCMBuf)
     {
@@ -289,11 +319,5 @@
         sol->pPCMBuf = NULL;
     }
-}
-
-
-static void solaudio_fini_out (HWVoiceOut *hw)
-{
-    solaudioVoiceOut *sol = (solaudioVoiceOut *) hw;
-    solaudio_stop (sol);
+
     LogFlow(("solaudio: fini_out done\n"));
 }
@@ -312,5 +336,6 @@
     }
 
-    cbBuffer = AudioInfo.play.buffer_size * (2 + AudioInfo.play.eof - sol->cBuffersPlayed);
+    if (sol->cBuffersPlayed - AudioInfo.play.eof <= 2)
+        cbBuffer = AudioInfo.play.buffer_size;
 
     LogFlow(("avail: eof=%d samples=%d bufsize=%d bufplayed=%d avail=%d\n", AudioInfo.play.eof, AudioInfo.play.samples,
@@ -328,7 +353,7 @@
 
     WaitTimeSpec.tv_sec = 0;
-    WaitTimeSpec.tv_nsec = 1000000;
-
-    while (AudioInfo.play.eof < pSol->cBuffersPlayed - 2)
+    WaitTimeSpec.tv_nsec = 100000000;
+
+    while (AudioInfo.play.eof + 10 < pSol->cBuffersPlayed)
     {
         nanosleep(&WaitTimeSpec, NULL);
@@ -373,10 +398,11 @@
             break;
 
+        /* Increment eof marker for synchronous buffer processed */
+        write (pSol->AudioDev, NULL, 0);
+        pSol->cBuffersPlayed++;
+
         hw->rpos   = (hw->rpos + csToWrite) % hw->samples;
         csSamples -= csToWrite;
     }
-    /* Increment eof marker for synchronous buffer processed */
-    write (pSol->AudioDev, NULL, 0);
-    pSol->cBuffersPlayed++;
     return csDecr;
 }
@@ -392,4 +418,5 @@
             /* reset the eof marker and samples markers */
             audio_info_t AudioInfo;
+            LogFlow(("solaudio: voice_enable\n"));
             AUDIO_INITINFO(&AudioInfo);
             ioctl(pSol->AudioDev, AUDIO_GETINFO, &AudioInfo);
@@ -400,5 +427,4 @@
 
             audio_pcm_info_clear_buf(&hw->info, pSol->pPCMBuf, hw->samples);
-            LogFlow(("solaudio: voice_enable\n"));
             break;
         }
@@ -429,9 +455,10 @@
 static void solaudio_audio_fini (void *opaque)
 {
-    (void) opaque;
-}
-
-
-static struct audio_pcm_ops solaudio_pcm_ops = {
+    NOREF(opaque);
+}
+
+
+static struct audio_pcm_ops solaudio_pcm_ops =
+{
     solaudio_init_out,
     solaudio_fini_out,
@@ -447,5 +474,6 @@
 };
 
-static struct audio_option solaudio_options[] = {
+static struct audio_option solaudio_options[] =
+{
     {"BUFFER_SIZE", AUD_OPT_INT, &conf.cbBuffer,
      "Size of the buffer in bytes", NULL, 0},
@@ -453,5 +481,6 @@
 };
 
-struct audio_driver solaudio_audio_driver = {
+struct audio_driver solaudio_audio_driver =
+{
     INIT_FIELD (name           = ) "solaudio",
     INIT_FIELD (descr          = ) "SolarisAudio http://sun.com",
