Ken Thomases : winecoreaudio: Correct the AudioBufferList allocated for input.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jul 13 08:30:35 CDT 2007


Module: wine
Branch: master
Commit: 2fc548ae65e075fb1ceb7fe7f8c77d49a0dc8666
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2fc548ae65e075fb1ceb7fe7f8c77d49a0dc8666

Author: Ken Thomases <ken at codeweavers.com>
Date:   Fri Jul 13 07:21:29 2007 -0500

winecoreaudio: Correct the AudioBufferList allocated for input.

---

 dlls/winecoreaudio.drv/audio.c |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/dlls/winecoreaudio.drv/audio.c b/dlls/winecoreaudio.drv/audio.c
index 26a8c8a..1c9c770 100644
--- a/dlls/winecoreaudio.drv/audio.c
+++ b/dlls/winecoreaudio.drv/audio.c
@@ -1732,21 +1732,40 @@ static void widHelper_DestroyAudioBufferList(AudioBufferList* list)
  *                    widHelper_AllocateAudioBufferList          [internal]
  * Convenience function to allocate our audio buffers
  */
-static AudioBufferList* widHelper_AllocateAudioBufferList(UInt32 numChannels, UInt32 size)
+static AudioBufferList* widHelper_AllocateAudioBufferList(UInt32 numChannels, UInt32 bitsPerChannel, UInt32 bufferFrames, BOOL interleaved)
 {
+    UInt32                      numBuffers;
+    UInt32                      channelsPerFrame;
+    UInt32                      bytesPerFrame;
+    UInt32                      bytesPerBuffer;
     AudioBufferList*            list;
     UInt32                      i;
 
-    list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioBufferList) + numChannels * sizeof(AudioBuffer));
+    if (interleaved)
+    {
+        /* For interleaved audio, we allocate one buffer for all channels. */
+        numBuffers = 1;
+        channelsPerFrame = numChannels;
+    }
+    else
+    {
+        numBuffers = numChannels;
+        channelsPerFrame = 1;
+    }
+
+    bytesPerFrame = bitsPerChannel * channelsPerFrame / 8;
+    bytesPerBuffer = bytesPerFrame * bufferFrames;
+
+    list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, offsetof(AudioBufferList, mBuffers) + numBuffers * sizeof(AudioBuffer));
     if (list == NULL)
         return NULL;
 
-    list->mNumberBuffers = numChannels;
-    for (i = 0; i < numChannels; ++i)
+    list->mNumberBuffers = numBuffers;
+    for (i = 0; i < numBuffers; ++i)
     {
-        list->mBuffers[i].mNumberChannels = 1;
-        list->mBuffers[i].mDataByteSize = size;
-        list->mBuffers[i].mData = HeapAlloc(GetProcessHeap(), 0, size);
+        list->mBuffers[i].mNumberChannels = channelsPerFrame;
+        list->mBuffers[i].mDataByteSize = bytesPerBuffer;
+        list->mBuffers[i].mData = HeapAlloc(GetProcessHeap(), 0, bytesPerBuffer);
         if (list->mBuffers[i].mData == NULL)
         {
             widHelper_DestroyAudioBufferList(list);
@@ -1764,7 +1783,6 @@ static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
 {
     WINE_WAVEIN*    wwi;
     UInt32          frameCount;
-    UInt32          bytesPerFrame;
 
     TRACE("(%u, %p, %08X);\n", wDevID, lpDesc, dwFlags);
     if (lpDesc == NULL)
@@ -1842,9 +1860,8 @@ static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
     }
 
     /* Allocate our audio buffers */
-    /* For interleaved audio, we allocate one buffer for all channels. */
-    bytesPerFrame = wwi->format.wBitsPerSample * wwi->format.wf.nChannels / 8;
-    wwi->bufferList = widHelper_AllocateAudioBufferList(1, wwi->format.wf.nChannels * frameCount * bytesPerFrame);
+    wwi->bufferList = widHelper_AllocateAudioBufferList(wwi->format.wf.nChannels,
+        wwi->format.wBitsPerSample, frameCount, TRUE);
     if (wwi->bufferList == NULL)
     {
         ERR("Failed to allocate buffer list\n");




More information about the wine-cvs mailing list