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.
This commit is contained in:
Ken Thomases 2006-05-24 05:38:16 -05:00 committed by Alexandre Julliard
parent 6a6aec72d3
commit 178f9fecd9
1 changed files with 56 additions and 41 deletions

View File

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