I am in the process of writing code for DSP effects and I've run into a snag for the tremolo effect. The code applies the tremolo to an existing (mono or stereo) file at a specified frequency (LFO of course) and depth. However, when the frequency and depth of the oscillator get higher, I start to hear subtle distortion in the result. Have a listen:
http://www.christianfloisand.com/tremsample.wav
Here is the code from the loop that's processing the effect (I've expanded the code here just for clarity.. many of these operations are optimized in the actual code and the LFO is implemented as a class):
Code: Select all
chanMode = 2; // for stereo
readCount = num. items read from input file into buffer (1024)
DEPTH = modulation depth, between 0 and 1
RATE = frequency of LFO
for (i = 0; i < chanMode; i++) {
for (j = i; j < readCount; j+=chanMode) {
tremSignal = (1 - DEPTH) + DEPTH * sin(phase);
buffer[j] *= tremSignal;
phase += TWOPI / SR * RATE;
if (phase >= TWOPI) phase -= TWOPI;
if (phase < 0.0) phase += TWOPI;
}
}
Any thoughts? At first I thought aliasing, but I've examined the frequency spectrum plot (in Audacity) many times and it shows no frequencies above Nyquist. The distortion starts to become noticeable around a frequency of 4 Hz+ and depth that exceeds 70%.
Any help.. words of advice.. would be greatly appreciated. Thanks!
Chris
