Page 1 of 1

Delay - shorter than one sample ?

PostPosted: Tue Feb 21, 2017 5:09 pm
by Rocko
Hi,

Playing around with very short delays and came up with an intrguing question.
At 48KHz sample rate, a single sample time span is (1/48,000 sec) = 20.833 uSec [micro seconds].

So, using the stock DELAY module, I can add a single delay of 20.833 uSec and next step would be 41.667 (2x20.833).
But, what if I needed a delay of 30 uSec, just between these two values. Is this possible? Can I delay a signal by 1.5 samples or does it have to be an integer?

Is there some kind of technique to achieve such a thing?

Thanks,
Rocko

Re: Delay - shorter than one sample ?

PostPosted: Tue Feb 21, 2017 7:25 pm
by martinvicanek
There is a thing called fractional delay which does what you describe. It uses some sort of interpolation to produce intersample values. The simplest interpolation would be linear, but there are more sophisticated ones. It depends on your application which one is appropriate.

Re: Delay - shorter than one sample ?

PostPosted: Wed Feb 22, 2017 9:09 am
by Spogg
martinvicanek wrote:There is a thing called fractional delay which does what you describe. It uses some sort of interpolation to produce intersample values. The simplest interpolation would be linear, but there are more sophisticated ones. It depends on your application which one is appropriate.


Since Flowstone processes the stream elements just once per sample period how could the fractional thing work?

I expect some sort of Martinmagic to follow...

Cheers

Spogg

Re: Delay - shorter than one sample ?

PostPosted: Wed Feb 22, 2017 10:19 am
by tulamide
Wouldn't it be easier to use latency to be ahead of time and then do your work on fractions after they have happened?

Re: Delay - shorter than one sample ?

PostPosted: Wed Feb 22, 2017 11:09 am
by martinvicanek
Tulamide, you are right, of course processing can only be on samples in the past, including the current sample. (Maybe we should put a time travel prim on the wishlist :lol:)

No magic, seek for "Interpolated Delay" in your toolbox and you shall find:
Code: Select all
streamin in;
streamout out;
streamin delay;

float index;
float intdelay,frac;
float temp1,temp2;
float out1;

float mem[44100];
float MAXDELAY=44100;

stage(2)
{
   mem[index]=in;
   
   intdelay = delay - 0.499999;
   intdelay = rndint(intdelay);
   frac = delay - intdelay;

   temp1 = index - intdelay;
   temp2 = temp1 - 1;
   
   temp1 = temp1 + (temp1 < 0)&MAXDELAY;
   temp1 = mem[temp1];

   temp2 = temp2 + (temp2 < 0)&MAXDELAY;
   temp2 = mem[temp2];

   out =  temp1 + frac * (temp2 - temp1);
   out1 = out;
   
   index=index+1;
   index=(index<MAXDELAY)&index;
}


Basically you take a weighted average as the value between two samples (linear interpolation).

Re: Delay - shorter than one sample ?

PostPosted: Wed Feb 22, 2017 4:01 pm
by mHz
Eventually in the spectrum the comb filter effect is similar to just a low- or highpass filter.
So interpolating it really helps.

Re: Delay - shorter than one sample ?

PostPosted: Sun Mar 05, 2017 11:21 am
by Rocko
Hi,

Thanks.

any idea why I couldn't find the 'interpolated delay' prim in my toolbox?
Using FlowStone 3.0.8.1 ...

Thanks,
Rocko

Re: Delay - shorter than one sample ?

PostPosted: Sun Mar 05, 2017 11:58 am
by nix
Have you got the audio pack and the dsp pack?
Here is the delay->
interpolated delay.fsm
(2.07 KiB) Downloaded 1246 times