diff options
author | Chris Robinson <[email protected]> | 2010-09-22 18:49:46 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-09-22 18:49:46 -0700 |
commit | 4e3c94509340071307d3422011cee7b11f870851 (patch) | |
tree | c02da34b5d2f3f42547c8888395e3db2c8532868 /Alc | |
parent | 8558bc1d412c0b9be5504fda3b82e3ff03989926 (diff) |
Compact some reused code
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/mixer.c | 184 |
1 files changed, 69 insertions, 115 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c index 6460e658..a4b82c98 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -293,6 +293,60 @@ static __inline ALfloat cos_lerp(ALfloat val1, ALfloat val2, ALint frac) } while(0) +#define MIX_MONO() do { \ + switch(Resampler) \ + { \ + case POINT_RESAMPLER: \ + DO_MIX_MONO(point); break; \ + case LINEAR_RESAMPLER: \ + DO_MIX_MONO(lerp); break; \ + case COSINE_RESAMPLER: \ + DO_MIX_MONO(cos_lerp); break; \ + case RESAMPLER_MIN: \ + case RESAMPLER_MAX: \ + break; \ + } \ +} while(0) + +#define MIX_STEREO() do { \ + const int chans[] = { \ + FRONT_LEFT, FRONT_RIGHT, \ + SIDE_LEFT, SIDE_RIGHT, \ + BACK_LEFT, BACK_RIGHT \ + }; \ + \ + switch(Resampler) \ + { \ + case POINT_RESAMPLER: \ + DO_MIX_STEREO(point); break; \ + case LINEAR_RESAMPLER: \ + DO_MIX_STEREO(lerp); break; \ + case COSINE_RESAMPLER: \ + DO_MIX_STEREO(cos_lerp); break; \ + case RESAMPLER_MIN: \ + case RESAMPLER_MAX: \ + break; \ + } \ +} while(0) + +#define MIX_MC(...) do { \ + const int chans[] = { __VA_ARGS__ }; \ + \ + switch(Resampler) \ + { \ + case POINT_RESAMPLER: \ + DO_MIX_MC(point); break; \ + case LINEAR_RESAMPLER: \ + DO_MIX_MC(lerp); break; \ + case COSINE_RESAMPLER: \ + DO_MIX_MC(cos_lerp); break; \ + case RESAMPLER_MIN: \ + case RESAMPLER_MAX: \ + break; \ + } \ +} while(0) + + static void MixSource(ALsource *ALSource, ALCcontext *ALContext, float (*DryBuffer)[OUTPUTCHANNELS], ALuint SamplesToDo, ALfloat *ClickRemoval, ALfloat *PendingClicks) @@ -440,126 +494,26 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, /* Actual sample mixing loops */ if(Channels == 1) /* Mono */ - { - switch(Resampler) - { - case POINT_RESAMPLER: - DO_MIX_MONO(point); break; - case LINEAR_RESAMPLER: - DO_MIX_MONO(lerp); break; - case COSINE_RESAMPLER: - DO_MIX_MONO(cos_lerp); break; - case RESAMPLER_MIN: - case RESAMPLER_MAX: - break; - } - } + MIX_MONO(); else if(Channels == 2) /* Stereo */ - { - const int chans[] = { - FRONT_LEFT, FRONT_RIGHT, - SIDE_LEFT, SIDE_RIGHT, - BACK_LEFT, BACK_RIGHT - }; - - switch(Resampler) - { - case POINT_RESAMPLER: - DO_MIX_STEREO(point); break; - case LINEAR_RESAMPLER: - DO_MIX_STEREO(lerp); break; - case COSINE_RESAMPLER: - DO_MIX_STEREO(cos_lerp); break; - case RESAMPLER_MIN: - case RESAMPLER_MAX: - break; - } - } + MIX_STEREO(); else if(Channels == 4) /* Quad */ - { - const int chans[] = { - FRONT_LEFT, FRONT_RIGHT, - BACK_LEFT, BACK_RIGHT - }; - - switch(Resampler) - { - case POINT_RESAMPLER: - DO_MIX_MC(point); break; - case LINEAR_RESAMPLER: - DO_MIX_MC(lerp); break; - case COSINE_RESAMPLER: - DO_MIX_MC(cos_lerp); break; - case RESAMPLER_MIN: - case RESAMPLER_MAX: - break; - } - } + MIX_MC(FRONT_LEFT, FRONT_RIGHT, + BACK_LEFT, BACK_RIGHT); else if(Channels == 6) /* 5.1 */ - { - const int chans[] = { - FRONT_LEFT, FRONT_RIGHT, - FRONT_CENTER, LFE, - BACK_LEFT, BACK_RIGHT - }; - - switch(Resampler) - { - case POINT_RESAMPLER: - DO_MIX_MC(point); break; - case LINEAR_RESAMPLER: - DO_MIX_MC(lerp); break; - case COSINE_RESAMPLER: - DO_MIX_MC(cos_lerp); break; - case RESAMPLER_MIN: - case RESAMPLER_MAX: - break; - } - } + MIX_MC(FRONT_LEFT, FRONT_RIGHT, + FRONT_CENTER, LFE, + BACK_LEFT, BACK_RIGHT); else if(Channels == 7) /* 6.1 */ - { - const int chans[] = { - FRONT_LEFT, FRONT_RIGHT, - FRONT_CENTER, LFE, - BACK_CENTER, - SIDE_LEFT, SIDE_RIGHT - }; - - switch(Resampler) - { - case POINT_RESAMPLER: - DO_MIX_MC(point); break; - case LINEAR_RESAMPLER: - DO_MIX_MC(lerp); break; - case COSINE_RESAMPLER: - DO_MIX_MC(cos_lerp); break; - case RESAMPLER_MIN: - case RESAMPLER_MAX: - break; - } - } + MIX_MC(FRONT_LEFT, FRONT_RIGHT, + FRONT_CENTER, LFE, + BACK_CENTER, + SIDE_LEFT, SIDE_RIGHT); else if(Channels == 8) /* 7.1 */ - { - const int chans[] = { - FRONT_LEFT, FRONT_RIGHT, - FRONT_CENTER, LFE, - BACK_LEFT, BACK_RIGHT, - SIDE_LEFT, SIDE_RIGHT - }; - - switch(Resampler) - { - case POINT_RESAMPLER: - DO_MIX_MC(point); break; - case LINEAR_RESAMPLER: - DO_MIX_MC(lerp); break; - case COSINE_RESAMPLER: - DO_MIX_MC(cos_lerp); break; - case RESAMPLER_MIN: - case RESAMPLER_MAX: - break; - } - } + MIX_MC(FRONT_LEFT, FRONT_RIGHT, + FRONT_CENTER, LFE, + BACK_LEFT, BACK_RIGHT, + SIDE_LEFT, SIDE_RIGHT); else /* Unknown? */ { while(BufferSize--) |