Most simple static delay

Type : Static delay
References : Posted by antiprosynthesis[AT]hotmail[DOT]com
Notes :
This is the most simple static delay (just delays the input sound an amount of samples). Very useful for newbies also probably very easy to change in a feedback delay (for comb filters for example).

Note: fDlyTime is the delay time parameter (0 to 1)

i = input index
j = output index
Code :
if( i >= SampleRate )
    i = 0;

DlyBuffer[ i ] = Input;

j = i - (fDlyTime * SampleRate);

i++;

if( j < 0 )
    j = SampleRate + j;

Output = DlyBuffer[ j ];

Comments
from : antiprosynthesis[AT]hotmail[DOT]com
comment : Another note: The delay time will be 0 if fDlyTime is 0 or 1.

from : anonymous[AT]fake[DOT]org
comment : I think you should be careful with mixing floats and integers that way (error-prone, slow float-to-int conversions, etc). This should also work (haven't checked, not best way of doing it): ... (initializing) .. float numSecondsDelay = 0.3f; int numSamplesDelay_ = (int)(numSecondsDelay * sampleRate); // maybe want to round to an integer instead of truncating.. float *buffer_ = new float[2*numSamplesDelay]; for (int i = 0; i < numSamplesDelay_; ++i) { buffer_[i] = 0.f; } int readPtr_ = 0; int writePtr_ = numSamplesDelay_; ... (processing) ... for (i = each sample) { buffer_[writePtr_] = input[i]; output[i] = buffer_[readPtr_]; ++writePtr_; if (writePtr_ >= 2*numSamplesDelay_) writePtr_ = 0; ++readPtr_; if (readPtr_ >= 2*numSamplesDelay_) readPtr_ = 0; }

from : xeeton[at]gmail[dot]com
comment : I may be missing something, but I think it gets a little simpler than the previous two examples. The difference in result is that actual delay will be 1 if d is 0 or 1. i = input/output index d = delay (in samples) Code: out = buffer[i]; buffer[i] = in; i++; if(i >= delay) i = 0;

from : xeeton[at]gmail[dot]com
comment : or even in three lines... out = buffer[i]; buffer[i++] = in; if(i >= delay) i = 0;

from : gravitate[AT]dj-gravitate[DOT]co[DOT]uk
comment : The only problem with this implementation, is that it is not really an audio effect! all this will do is to delay the input signal by a given number of samples! ...why would you ever want to do that? ...this would only ever work if you had a DSP and speakers both connected to the audio source and run them at the same time, so the speakers would be playing the original sorce and the DSP containing the delayed source connected to another set of speakers! this is not really an audio efffect! ...Here is a pseudo code example of a delay effect that will mix both the original sound with the delayed sound: Pseudo Code implementation for simple delay: - This implementation will put the current audio signal to the left channel and the delayed audio signal to the right channel. this is suitable for any stereo codec! delay_function { left_channel // for stereo left right_channel // for stereo right mono // mono representation of stereo input delay_time // amount of time to delay input counter = 0 // counter //setup an array that is the same length as the maximum delay time: delay_array[max delay time] // array containing delayed data // convert stereo to mono: (left_channel + right_channel) / 2 // initalise time to delay signal - maybe input from user delay_time = x if (delay_time = 0){ left_out = mono right_out = mono } else { // put current input data to left channel: left_out = mono // put oldest delayed input data to right channel: right_out = delay_array[index] // overwrite with newest input: delay_array[index] = mono; // is index at end of delay buffer? if not increment, else set to zero if (index < delay_time) index++ else index = 0 } }

from : nobody[AT]nowhere[DOT]com
comment : I've need a delay before, many a time. 1) To compensate for a delay in another effect. 2) To manually build a high-pass delay. 3) In other ways for interesting effects in a modular host. 4) Building block for physical modeling or filtering. As long as you have multiple ins and/or outs, you want something like this.

from : kibibu[AT]gmail[DOT]com
comment : With (-1 < feedback < 1): out = buffer[i]; buffer[i++] = (out * feedback) + in; if(i >= delay) i = 0;

from : anon[AT]hell[DOT]org
comment : delays are the fundamental building blocks for almost any type of effects.

from : barbarawright[AT]mail15[DOT]com
comment : It is known that money makes us independent. But how to act if someone has no money? The one way is to try to get the personal loans and collateral loan.