diff options
author | Chris Robinson <[email protected]> | 2013-05-18 00:43:09 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-05-18 00:43:09 -0700 |
commit | a7ad6080f0d3fc783fd5e1811b961ab9efe79cde (patch) | |
tree | cf55c6a36fa94c1074dc2adbd664e08f86c0df34 /Alc | |
parent | 563f16dc2a52de3217c90313ca6bddbbc20f20a0 (diff) |
Modulator fixes
Modulator functions return 0..1 instead of -1..+1
Apply high-pass filter before modulation
Increase fractional precision to 24 bits from 16
Thanks to Mike Gorchak
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alcModulator.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Alc/alcModulator.c b/Alc/alcModulator.c index 05b2fb00..f1f8dadd 100644 --- a/Alc/alcModulator.c +++ b/Alc/alcModulator.c @@ -49,23 +49,23 @@ typedef struct ALmodulatorState { ALfloat history[1]; } ALmodulatorState; -#define WAVEFORM_FRACBITS 16 +#define WAVEFORM_FRACBITS 24 #define WAVEFORM_FRACONE (1<<WAVEFORM_FRACBITS) #define WAVEFORM_FRACMASK (WAVEFORM_FRACONE-1) static __inline ALfloat Sin(ALuint index) { - return sinf(index * (F_PI*2.0f / WAVEFORM_FRACONE)); + return sinf(index * (F_PI*2.0f / WAVEFORM_FRACONE) - F_PI)*0.5f + 0.5f; } static __inline ALfloat Saw(ALuint index) { - return index*(2.0f/WAVEFORM_FRACONE) - 1.0f; + return (ALfloat)index / WAVEFORM_FRACONE; } static __inline ALfloat Square(ALuint index) { - return ((index>>(WAVEFORM_FRACBITS-1))&1)*2.0f - 1.0f; + return (ALfloat)((index >> (WAVEFORM_FRACBITS - 1)) & 1); } @@ -95,13 +95,12 @@ static void Process##func(ALmodulatorState *state, ALuint SamplesToDo, \ for(i = 0;i < SamplesToDo;i++) \ { \ samp = SamplesIn[i]; \ + samp = hpFilter1P(&state->iirFilter, 0, samp); \ \ index += step; \ index &= WAVEFORM_FRACMASK; \ samp *= func(index); \ \ - samp = hpFilter1P(&state->iirFilter, 0, samp); \ - \ for(k = 0;k < MaxChannels;k++) \ SamplesOut[k][i] += state->Gain[k] * samp; \ } \ |