diff options
author | Chris Robinson <[email protected]> | 2010-11-26 20:22:14 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-11-26 20:22:14 -0800 |
commit | 16c05d2c05dd92acccee807ea5124f3050118ca7 (patch) | |
tree | 9f670be0449638c72931b0a0c6db8a7bf84b851f | |
parent | 4d4d69978043c2939036ec1c464a351f1840d538 (diff) |
Avoid some more code duplication
-rw-r--r-- | Alc/mixer.c | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c index 18c93b84..eb5ede86 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -612,6 +612,41 @@ DECL_TEMPLATE(ALubyte, cubic8) #undef DECL_TEMPLATE +#define DECL_TEMPLATE(sampler) \ +static void Mix_##sampler(ALsource *Source, ALCdevice *Device, \ + ALuint Channels, ALuint Bytes, \ + const ALvoid *Data, ALuint *DataPosInt, ALuint *DataPosFrac, \ + ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize) \ +{ \ + switch(Bytes) \ + { \ + case 1: \ + Mix_ALubyte_##sampler##8(Source, Device, Channels, \ + Data, DataPosInt, DataPosFrac, \ + OutPos, SamplesToDo, BufferSize); \ + break; \ + \ + case 2: \ + Mix_ALshort_##sampler##16(Source, Device, Channels, \ + Data, DataPosInt, DataPosFrac, \ + OutPos, SamplesToDo, BufferSize); \ + break; \ + \ + case 4: \ + Mix_ALfloat_##sampler##32(Source, Device, Channels, \ + Data, DataPosInt, DataPosFrac, \ + OutPos, SamplesToDo, BufferSize); \ + break; \ + } \ +} + +DECL_TEMPLATE(point) +DECL_TEMPLATE(lerp) +DECL_TEMPLATE(cubic) + +#undef DECL_TEMPLATE + + ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo) { ALbufferlistitem *BufferListItem; @@ -858,46 +893,19 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo) switch(Resampler) { case POINT_RESAMPLER: - if(Bytes == 4) - Mix_ALfloat_point32(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); - else if(Bytes == 2) - Mix_ALshort_point16(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); - else if(Bytes == 1) - Mix_ALubyte_point8(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); + Mix_point(Source, Device, Channels, Bytes, + SrcData, &DataPosInt, &DataPosFrac, + OutPos, SamplesToDo, BufferSize); break; case LINEAR_RESAMPLER: - if(Bytes == 4) - Mix_ALfloat_lerp32(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); - else if(Bytes == 2) - Mix_ALshort_lerp16(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); - else if(Bytes == 1) - Mix_ALubyte_lerp8(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); + Mix_lerp(Source, Device, Channels, Bytes, + SrcData, &DataPosInt, &DataPosFrac, + OutPos, SamplesToDo, BufferSize); break; case CUBIC_RESAMPLER: - if(Bytes == 4) - Mix_ALfloat_cubic32(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); - else if(Bytes == 2) - Mix_ALshort_cubic16(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); - else if(Bytes == 1) - Mix_ALubyte_cubic8(Source, Device, Channels, - SrcData, &DataPosInt, &DataPosFrac, - OutPos, SamplesToDo, BufferSize); + Mix_cubic(Source, Device, Channels, Bytes, + SrcData, &DataPosInt, &DataPosFrac, + OutPos, SamplesToDo, BufferSize); break; case RESAMPLER_MIN: case RESAMPLER_MAX: |