diff options
author | Chris Robinson <[email protected]> | 2010-09-22 17:19:35 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-09-22 17:19:35 -0700 |
commit | 8558bc1d412c0b9be5504fda3b82e3ff03989926 (patch) | |
tree | 40c27f0a533522aea14438c2689f5c318a48251b /Alc/mixer.c | |
parent | 03f56419d0d751ac3ac63bc7e3ee59bf544cb077 (diff) |
Allow accessing the buffer data as multiple data types in the mixer
Also reduces a bunch of indentation
Diffstat (limited to 'Alc/mixer.c')
-rw-r--r-- | Alc/mixer.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c index 1a89737a..6460e658 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -81,7 +81,7 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) #define DO_MIX_MONO(resampler) do { \ if(j == 0) \ { \ - value = (resampler)(Data[DataPosInt], Data[DataPosInt+1], \ + value = (resampler)(Data.f32[DataPosInt], Data.f32[DataPosInt+1], \ DataPosFrac); \ \ outsamp = lpFilter4PC(DryFilter, 0, value); \ @@ -103,7 +103,7 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) while(BufferSize--) \ { \ /* First order interpolator */ \ - value = (resampler)(Data[DataPosInt], Data[DataPosInt+1], \ + value = (resampler)(Data.f32[DataPosInt], Data.f32[DataPosInt+1], \ DataPosFrac); \ \ /* Direct path final mix buffer and panning */ \ @@ -134,7 +134,7 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) ALuint pos = ((DataPosInt < DataSize) ? DataPosInt : (DataPosInt-1)); \ ALuint frac = ((DataPosInt < DataSize) ? DataPosFrac : \ ((DataPosFrac-increment)&FRACTIONMASK)); \ - value = (resampler)(Data[pos], Data[pos+1], frac); \ + value = (resampler)(Data.f32[pos], Data.f32[pos+1], frac); \ \ outsamp = lpFilter4PC(DryFilter, 0, value); \ PendingClicks[FRONT_LEFT] += outsamp*DrySend[FRONT_LEFT]; \ @@ -160,8 +160,8 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) { \ for(i = 0;i < Channels;i++) \ { \ - value = (resampler)(Data[DataPosInt*Channels + i], \ - Data[(DataPosInt+1)*Channels + i], \ + value = (resampler)(Data.f32[DataPosInt*Channels + i], \ + Data.f32[(DataPosInt+1)*Channels + i], \ DataPosFrac); \ \ outsamp = lpFilter2PC(DryFilter, chans[i]*2, value); \ @@ -180,8 +180,8 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) { \ for(i = 0;i < Channels;i++) \ { \ - value = (resampler)(Data[DataPosInt*Channels + i], \ - Data[(DataPosInt+1)*Channels + i], \ + value = (resampler)(Data.f32[DataPosInt*Channels + i], \ + Data.f32[(DataPosInt+1)*Channels + i], \ DataPosFrac); \ \ outsamp = lpFilter2P(DryFilter, chans[i]*2, value); \ @@ -208,8 +208,8 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) ((DataPosFrac-increment)&FRACTIONMASK)); \ for(i = 0;i < Channels;i++) \ { \ - value = (resampler)(Data[pos*Channels + i], \ - Data[(pos+1)*Channels + i], \ + value = (resampler)(Data.f32[pos*Channels + i], \ + Data.f32[(pos+1)*Channels + i], \ frac); \ \ outsamp = lpFilter2PC(DryFilter, chans[i]*2, value); \ @@ -232,8 +232,8 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) { \ for(i = 0;i < Channels;i++) \ { \ - value = (resampler)(Data[DataPosInt*Channels + i], \ - Data[(DataPosInt+1)*Channels + i], \ + value = (resampler)(Data.f32[DataPosInt*Channels + i], \ + Data.f32[(DataPosInt+1)*Channels + i], \ DataPosFrac); \ \ outsamp = lpFilter2PC(DryFilter, chans[i]*2, value); \ @@ -250,8 +250,8 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) { \ for(i = 0;i < Channels;i++) \ { \ - value = (resampler)(Data[DataPosInt*Channels + i], \ - Data[(DataPosInt+1)*Channels + i], \ + value = (resampler)(Data.f32[DataPosInt*Channels + i], \ + Data.f32[(DataPosInt+1)*Channels + i], \ DataPosFrac); \ \ outsamp = lpFilter2P(DryFilter, chans[i]*2, value); \ @@ -276,8 +276,8 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) ((DataPosFrac-increment)&FRACTIONMASK)); \ for(i = 0;i < Channels;i++) \ { \ - value = (resampler)(Data[pos*Channels + i], \ - Data[(pos+1)*Channels + i], \ + value = (resampler)(Data.f32[pos*Channels + i], \ + Data.f32[(pos+1)*Channels + i], \ frac); \ \ outsamp = lpFilter2PC(DryFilter, chans[i]*2, value); \ @@ -364,7 +364,11 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, j = 0; do { const ALbuffer *ALBuffer; - ALfloat *Data = NULL; + union { + ALfloat *f32; + ALshort *s16; + ALubyte *u8; + } Data = { NULL }; ALuint DataSize = 0; ALuint LoopStart = 0; ALuint LoopEnd = 0; @@ -374,7 +378,7 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, /* Get buffer info */ if((ALBuffer=BufferListItem->buffer) != NULL) { - Data = ALBuffer->data; + Data.u8 = ALBuffer->data; DataSize = ALBuffer->size; DataSize /= aluFrameSizeFromFormat(ALBuffer->format); Channels = aluChannelsFromFormat(ALBuffer->format); @@ -405,7 +409,8 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, { ALint ulExtraSamples = BUFFER_PADDING*Channels*Bytes; ulExtraSamples = min(NextBuf->size, ulExtraSamples); - memcpy(&Data[DataSize*Channels], NextBuf->data, ulExtraSamples); + memcpy(&Data.u8[DataSize*Channels*Bytes], + NextBuf->data, ulExtraSamples); } } else if(Looping) @@ -415,11 +420,13 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, { ALint ulExtraSamples = BUFFER_PADDING*Channels*Bytes; ulExtraSamples = min(NextBuf->size, ulExtraSamples); - memcpy(&Data[DataSize*Channels], &NextBuf->data[LoopStart*Channels], ulExtraSamples); + memcpy(&Data.u8[DataSize*Channels*Bytes], + &((ALubyte*)NextBuf->data)[LoopStart*Channels*Bytes], + ulExtraSamples); } } else - memset(&Data[DataSize*Channels], 0, (BUFFER_PADDING*Channels*Bytes)); + memset(&Data.u8[DataSize*Channels*Bytes], 0, (BUFFER_PADDING*Channels*Bytes)); /* Figure out how many samples we can mix. */ DataSize64 = LoopEnd; |