I'm getting some odd results with some code I'm working on. Help me with the implementation of this delay effect?
The code takes an input, adds delayed input to it and then passes it to the output whilst also copying it back to the delay line. Control of the delay level and feedback are provided to control respectively the amount of delayed signal added to the output and returning to the delay line.
Here's the process of my delay effect.
void delay::processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames)
{
float *in = inputs[0];
float *out = outputs[0];
float delayed_sample;
int delayed_sample_index;
for (int frame_idx=0;frame_idx< sampleFrames;frame_idx++)
{
delayed_sample_index = (((int)(cBuf.index-delay_samples) + CIRCULAR_BUFFER_LENGTH) % (int)CIRCULAR_BUFFER_LENGTH);
delayed_sample = (cBuf.buffer)[delayed_sample_index];
//write current sample to buffer
(cBuf.buffer)[cBuf.index] = in[frame_idx] + (delayed_sample*feedback);
//Calculate + write output sample
out[frame_idx] = in[frame_idx] + (delay_level*delayed_sample);
//Increment buffer index
cBuf.index = ((cBuf.index+1)) % CIRCULAR_BUFFER_LENGTH;
}
}
On the whole it works pretty well and functions as a delay effect should. However, the output I'm getting is slightly distorted. I'm not sure if this is an error in the arithmetic of sample times and values or something else. Any ideas?
No comments:
Post a Comment