Tuesday, 23 August 2016

audio - Distorted output of delay VST effect in C


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?


enter image description here




No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...