From 9f037e89802a7b4fc6c287bab97b85050bbd6721 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 15 Sep 2009 19:30:27 -0700 Subject: [PATCH] Pass the device to aluMixData --- Alc/ALu.c | 14 ++++++++------ Alc/alsa.c | 14 ++++---------- Alc/dsound.c | 11 +++++++---- Alc/oss.c | 5 +---- Alc/portaudio.c | 5 +---- Alc/pulseaudio.c | 5 +---- Alc/solaris.c | 5 +---- Alc/wave.c | 5 +---- OpenAL32/Include/alu.h | 2 +- 9 files changed, 25 insertions(+), 41 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index 171758ba..712462ca 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -1200,15 +1200,16 @@ another_source: goto another_source; } -ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum format) +ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) { static float DryBuffer[BUFFERSIZE][OUTPUTCHANNELS]; ALuint SamplesToDo; ALeffectslot *ALEffectSlot; + ALCcontext *ALContext; int fpuState; ALuint i; - SuspendContext(ALContext); + SuspendContext(NULL); #if defined(HAVE_FESETROUND) fpuState = fegetround(); @@ -1228,6 +1229,7 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma /* Clear mixing buffer */ memset(DryBuffer, 0, SamplesToDo*OUTPUTCHANNELS*sizeof(ALfloat)); + ALContext = device->Context; if(ALContext) { MixSomeSources(ALContext, DryBuffer, SamplesToDo); @@ -1246,7 +1248,7 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma } //Post processing loop - switch(format) + switch(device->Format) { #define CHECK_WRITE_FORMAT(bits, type, func, isWin) \ case AL_FORMAT_MONO##bits: \ @@ -1258,14 +1260,14 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma } \ break; \ case AL_FORMAT_STEREO##bits: \ - if(ALContext && ALContext->Device->Bs2b) \ + if(device->Bs2b) \ { \ for(i = 0;i < SamplesToDo;i++) \ { \ float samples[2]; \ samples[0] = DryBuffer[i][FRONT_LEFT]; \ samples[1] = DryBuffer[i][FRONT_RIGHT]; \ - bs2b_cross_feed(ALContext->Device->Bs2b, samples); \ + bs2b_cross_feed(device->Bs2b, samples); \ ((type*)buffer)[0] = (func)(samples[0]); \ ((type*)buffer)[1] = (func)(samples[1]); \ buffer = ((type*)buffer) + 2; \ @@ -1374,7 +1376,7 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma _controlfp(fpuState, 0xfffff); #endif - ProcessContext(ALContext); + ProcessContext(NULL); } ALvoid aluHandleDisconnect(ALCdevice *device) diff --git a/Alc/alsa.c b/Alc/alsa.c index 5d7026e2..aad0835a 100644 --- a/Alc/alsa.c +++ b/Alc/alsa.c @@ -217,29 +217,25 @@ static ALuint ALSAProc(ALvoid *ptr) { frames = avail; - SuspendContext(NULL); err = psnd_pcm_mmap_begin(data->pcmHandle, &areas, &offset, &frames); if (err < 0) { err = xrun_recovery(data->pcmHandle, err); if (err < 0) AL_PRINT("mmap begin error: %s\n", psnd_strerror(err)); - ProcessContext(NULL); break; } WritePtr = (char*)areas->addr + (offset * areas->step / 8); - aluMixData(pDevice->Context, WritePtr, frames, pDevice->Format); + aluMixData(pDevice, WritePtr, frames); commitres = psnd_pcm_mmap_commit(data->pcmHandle, offset, frames); if (commitres < 0 || (commitres-frames) != 0) { AL_PRINT("mmap commit error: %s\n", psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); - ProcessContext(NULL); break; } - ProcessContext(NULL); avail -= frames; } @@ -265,12 +261,10 @@ static ALuint ALSANoMMapProc(ALvoid *ptr) break; } - avail = data->size / psnd_pcm_frames_to_bytes(data->pcmHandle, 1); - SuspendContext(NULL); - aluMixData(pDevice->Context, data->buffer, avail, pDevice->Format); - ProcessContext(NULL); - WritePtr = data->buffer; + avail = data->size / psnd_pcm_frames_to_bytes(data->pcmHandle, 1); + aluMixData(pDevice, WritePtr, avail); + while(avail > 0) { int ret = psnd_pcm_writei(data->pcmHandle, WritePtr, avail); diff --git a/Alc/dsound.c b/Alc/dsound.c index 16a8dbbe..8501623d 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -84,6 +84,7 @@ static ALuint DSoundProc(ALvoid *ptr) DWORD PlayCursor; VOID *WritePtr1, *WritePtr2; DWORD WriteCnt1, WriteCnt2; + DWORD FrameSize; DWORD FragSize; DWORD avail; HRESULT err; @@ -94,10 +95,14 @@ static ALuint DSoundProc(ALvoid *ptr) if(FAILED(err)) { AL_PRINT("Failed to get buffer caps: 0x%lx\n", err); + aluHandleDisconnect(pDevice); return 1; } FragSize = DSBCaps.dwBufferBytes / num_frags; + FrameSize = aluChannelsFromFormat(pDevice->Format) * + aluBytesFromFormat(pDevice->Format); + IDirectSoundBuffer_GetCurrentPosition(pData->DSsbuffer, &LastCursor, NULL); while(!pData->killNow) { @@ -131,10 +136,8 @@ static ALuint DSoundProc(ALvoid *ptr) if(SUCCEEDED(err)) { // If we have an active context, mix data directly into output buffer otherwise fill with silence - SuspendContext(NULL); - aluMixData(pDevice->Context, WritePtr1, WriteCnt1/DSBCaps.nBlockAlign, pDevice->Format); - aluMixData(pDevice->Context, WritePtr2, WriteCnt2/DSBCaps.nBlockAlign, pDevice->Format); - ProcessContext(NULL); + aluMixData(pDevice, WritePtr1, WriteCnt1/FrameSize); + aluMixData(pDevice, WritePtr2, WriteCnt2/FrameSize); // Unlock output buffer only when successfully locked IDirectSoundBuffer_Unlock(pData->DSsbuffer, WritePtr1, WriteCnt1, WritePtr2, WriteCnt2); diff --git a/Alc/oss.c b/Alc/oss.c index c7f5421e..bfad2237 100644 --- a/Alc/oss.c +++ b/Alc/oss.c @@ -90,10 +90,7 @@ static ALuint OSSProc(ALvoid *ptr) ALint len = data->data_size; ALubyte *WritePtr = data->mix_data; - SuspendContext(NULL); - aluMixData(pDevice->Context, WritePtr, len/frameSize, pDevice->Format); - ProcessContext(NULL); - + aluMixData(pDevice, WritePtr, len/frameSize); while(len > 0 && !data->killNow) { wrote = write(data->fd, WritePtr, len); diff --git a/Alc/portaudio.c b/Alc/portaudio.c index e9e15621..347306fe 100644 --- a/Alc/portaudio.c +++ b/Alc/portaudio.c @@ -61,10 +61,7 @@ static int pa_callback(const void *inputBuffer, void *outputBuffer, (void)timeInfo; (void)statusFlags; - SuspendContext(NULL); - aluMixData(device->Context, outputBuffer, framesPerBuffer, device->Format); - ProcessContext(NULL); - + aluMixData(device, outputBuffer, framesPerBuffer); return 0; } diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c index 80383250..76e0ef60 100644 --- a/Alc/pulseaudio.c +++ b/Alc/pulseaudio.c @@ -172,10 +172,7 @@ static void stream_write_callback(pa_stream *stream, size_t len, void *pdata) // pulse_data *data = Device->ExtraData; void *buf = ppa_xmalloc0(len); - SuspendContext(NULL); - aluMixData(Device->Context, buf, len/data->frame_size, Device->Format); - ProcessContext(NULL); - + aluMixData(Device, buf, len/data->frame_size); ppa_stream_write(stream, buf, len, ppa_xfree, 0, PA_SEEK_RELATIVE); } //}}} diff --git a/Alc/solaris.c b/Alc/solaris.c index 8ea190e6..b0c0adf4 100644 --- a/Alc/solaris.c +++ b/Alc/solaris.c @@ -65,10 +65,7 @@ static ALuint SolarisProc(ALvoid *ptr) ALint len = data->data_size; ALubyte *WritePtr = data->mix_data; - SuspendContext(NULL); - aluMixData(pDevice->Context, WritePtr, len/frameSize, pDevice->Format); - ProcessContext(NULL); - + aluMixData(pDevice, WritePtr, len/frameSize); while(len > 0 && !data->killNow) { wrote = write(data->fd, WritePtr, len); diff --git a/Alc/wave.c b/Alc/wave.c index bd6c408a..24b2faad 100644 --- a/Alc/wave.c +++ b/Alc/wave.c @@ -74,10 +74,7 @@ static ALuint WaveProc(ALvoid *ptr) while(avail >= pDevice->UpdateSize) { - SuspendContext(NULL); - aluMixData(pDevice->Context, data->buffer, pDevice->UpdateSize, - pDevice->Format); - ProcessContext(NULL); + aluMixData(pDevice, data->buffer, pDevice->UpdateSize); if(uSB.b[0] != 1 && aluBytesFromFormat(pDevice->Format) > 1) { diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 4641a698..62350c3f 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -146,7 +146,7 @@ static __inline ALuint aluChannelsFromFormat(ALenum format) } ALvoid aluInitPanning(ALCcontext *Context); -ALvoid aluMixData(ALCcontext *context,ALvoid *buffer,ALsizei size,ALenum format); +ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size); ALvoid aluHandleDisconnect(ALCdevice *device); #ifdef __cplusplus