Ken Thomases : winecoreaudio: Keep processing wavehdrs to satisfy AudioUnit data request.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jun 1 06:49:01 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 178f9fecd95692e55c9b433bda1b7795f81dab3f
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=178f9fecd95692e55c9b433bda1b7795f81dab3f

Author: Ken Thomases <ken at codeweavers.com>
Date:   Wed May 24 05:38:16 2006 -0500

winecoreaudio: Keep processing wavehdrs to satisfy AudioUnit data request.

When fulfilling the output AudioUnit's request for audio data, don't
stop when the current wavehdr is exhausted; advance to the next.  This
addresses the buzzy quality of the sound.

---

 dlls/winmm/winecoreaudio/audio.c |   79 +++++++++++++++++++++++---------------
 1 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/dlls/winmm/winecoreaudio/audio.c b/dlls/winmm/winecoreaudio/audio.c
index 771bdb6..e27e0d6 100644
--- a/dlls/winmm/winecoreaudio/audio.c
+++ b/dlls/winmm/winecoreaudio/audio.c
@@ -1376,51 +1376,66 @@ OSStatus CoreAudio_woAudioUnitIOProc(voi
                                      UInt32 inNumberFrames, 
                                      AudioBufferList *ioData)
 {
-    UInt32 channel;
+    UInt32 buffer;
     WINE_WAVEOUT *wwo = (WINE_WAVEOUT *) inRefCon;
     int nextPtr = 0;
     int needNotify = 0;
-    
-    pthread_mutex_lock(&wwo->lock);
-    if(wwo->state == WINE_WS_PLAYING)
+
+    unsigned int dataNeeded = ioData->mBuffers[0].mDataByteSize;
+    unsigned int dataProvided = 0;
+
+    while (dataNeeded > 0)
     {
-        unsigned int available;
-        unsigned int count = ioData->mBuffers[0].mDataByteSize;
-        
-        available = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
-        
-        for (channel = 0; channel < ioData->mNumberBuffers; channel++)
+        pthread_mutex_lock(&wwo->lock);
+
+        if (wwo->state == WINE_WS_PLAYING && wwo->lpPlayPtr)
         {
-            if ( available >= count)
-            { 
-                memcpy(ioData->mBuffers[channel].mData, wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, count);
-                wwo->dwPartialOffset += count;
-                wwo->dwPlayedTotal += count;
-            }
+            unsigned int available = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
+            unsigned int toCopy;
+
+            if (available >= dataNeeded)
+                toCopy = dataNeeded;
             else
+                toCopy = available;
+
+            if (toCopy > 0)
             {
-                int s;
-                memcpy(ioData->mBuffers[channel].mData, wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, available);
-                wwo->dwPartialOffset += available;
-                wwo->dwPlayedTotal += available;
-                
-                /* Fill with silence */
-                for (s = available; s < count; s++)
-                    ((int *)ioData->mBuffers[channel].mData)[s] = 0;
-                
-                nextPtr = 1;
+                memcpy((char*)ioData->mBuffers[0].mData + dataProvided,
+                    wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, toCopy);
+                wwo->dwPartialOffset += toCopy;
+                wwo->dwPlayedTotal += toCopy;
+                dataProvided += toCopy;
+                dataNeeded -= toCopy;
+                available -= toCopy;
             }
+
+            if (available == 0)
+                nextPtr = 1;
+
+            needNotify = 1;
+        }
+        else
+        {
+            memset((char*)ioData->mBuffers[0].mData + dataProvided, 0, dataNeeded);
+            dataProvided += dataNeeded;
+            dataNeeded = 0;
+        }
+
+        pthread_mutex_unlock(&wwo->lock);
+
+        if (nextPtr)
+        {
+            wodHelper_PlayPtrNext(wwo);
+            nextPtr = 0;
         }
-        needNotify = 1;
     }
-    else
+
+    /* We only fill buffer 0.  Set any others that might be requested to 0. */
+    for (buffer = 1; buffer < ioData->mNumberBuffers; buffer++)
     {
-        for (channel = 0; channel < ioData->mNumberBuffers; channel++)
-            memset(ioData->mBuffers[channel].mData, 0, ioData->mBuffers[channel].mDataByteSize);
+        memset(ioData->mBuffers[buffer].mData, 0, ioData->mBuffers[buffer].mDataByteSize);
     }
-    pthread_mutex_unlock(&wwo->lock);
 
-    if (nextPtr) wodHelper_PlayPtrNext(wwo); 
     if (needNotify) wodHelper_NotifyCompletions(wwo, FALSE);
     return noErr;
 }




More information about the wine-cvs mailing list