Can someone please tell me what is wrong here. delay has a buffer (del) with a pointer *p, but is outputting zero (0) every sample.
(Fixed Delay with 3 secs)
float delay(float *sig, float dtime, float *del, int *p, int vecsize, float sr) {
int dt;
float out;
dt = (int) (dtime*sr);// dtime = 3secs, sr=44100.0
for(int i=0; i<vecsize; i++){
out = del[*p];
del[*p] = sig[i];
sig[i] = out;
*p = (*p != dt-1 ? *p+1 : 0);
}
return *sig;
}
Your
delay()function appears to work fine, so the error must be in how you called it. See the following example program:The output produced is as expected:
Note that you should really be passing
dtdirectly to thedelay()function, rather than calculating it fromsranddtime– as far as thedelay()function is concerned, it’s the delay in number of samples (and hence the assumed size of thedel[]delay line array) that matters. You’d have to have calculated that value in the caller anyway, to appropriately size thedel[]array.