DSPRelated.com
Forums

streaming resampled buffers seamlessly

Started by sammy davis jr. February 25, 2004
Hi guys,

this problem is driving me nuts over here.

I'm working on a streaming resampling method that resamples buffers in 
sequence, when i reach the end of an input buffer i zeropad it (enough 
for the anti-alisaing filter), generate the output buffer, and i'm done.

the problem is that those last zero-samples at the end of my input 
buffer skew the last two samples of my output buffer (resampled)

so if i'm pumping buffers of sinewaves @ 440Hz ...there is a click on 
the buffer boundaries where the last sample is interpolated with the 
zeropadded samples instead of the next buffer coming in (that I have no 
knowledge of yet)

i know there must be a way to smooth out these boundary clicks ...
does anyone have any ideas on how to go about this ??

thanks!!!
sdj

As you realize, you really want to use data from the next buffer, rather
than zeros.  One simple way is to store 2 buffers of data before starting
your work.  Then you will know what is in the next buffer.  Of course, this
also introduces an additional processing latency based on the buffer length.

If that is not acceptable, then how about this.  Conceptually, zero pad the
beginning of the first buffer with enough zeros for your filter.  Then save
off an equal number of samples from the end of the first buffer for later
use.  Now process the block up to but not including the samples from the end
you saved off.  When the next buffer arrives, insert the saved samples from
the previous buffer at the beginning, save off an equal number from the end,
and run your filter.  Repeat.

With this method, the extra latency will only be based on the size of your
filter rather than the whole block, so it should be better.  I don't think
there is any way to do better than this in a real-time casual system.

"sammy davis jr." <sdj@ratpackproductions.com> wrote in message
news:Tm9%b.15137$253.956348@news20.bellglobal.com...
> Hi guys, > > this problem is driving me nuts over here. > > I'm working on a streaming resampling method that resamples buffers in > sequence, when i reach the end of an input buffer i zeropad it (enough > for the anti-alisaing filter), generate the output buffer, and i'm done. > > the problem is that those last zero-samples at the end of my input > buffer skew the last two samples of my output buffer (resampled) > > so if i'm pumping buffers of sinewaves @ 440Hz ...there is a click on > the buffer boundaries where the last sample is interpolated with the > zeropadded samples instead of the next buffer coming in (that I have no > knowledge of yet) > > i know there must be a way to smooth out these boundary clicks ... > does anyone have any ideas on how to go about this ?? > > thanks!!! > sdj >
Also, check that no state information within the filter is being lost when
you set up to filter the next block (pointers, prev states etc.).

Jim Adamthwaite
In article <Tm9%b.15137$253.956348@news20.bellglobal.com>,
sammy davis jr. <sdj@ratpackproductions.com> wrote:
>I'm working on a streaming resampling method that resamples buffers in >sequence, when i reach the end of an input buffer i zeropad it (enough >for the anti-alisaing filter), generate the output buffer, and i'm done. > >the problem is that those last zero-samples at the end of my input >buffer skew the last two samples of my output buffer (resampled) > >so if i'm pumping buffers of sinewaves @ 440Hz ...there is a click on >the buffer boundaries where the last sample is interpolated with the >zeropadded samples instead of the next buffer coming in (that I have no >knowledge of yet) > >i know there must be a way to smooth out these boundary clicks ... >does anyone have any ideas on how to go about this ??
The usual answer is to use data from the previous and following buffers, instead of zero padding. But if that isn't possible, wouldn't the interpolations errors at the ends of each buffer be reduced by using something better than zeros for the padding? Repeating the end-point value, or mirroring the data around the boundry are a couple methods I've heard of. But if the waveform is polynomial smooth, perhaps filling past the ends of the actual data using extrapolation by the method of finite differences instead of zero padding, and before the resampling interpolation, would produce even less transition boundry errors. Perhaps essentially zero error if the signal was "close enough" (say a difference beneath the system noise level) to a sufficiently bounded degree of polynomial. IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include <canonical.disclaimer> // only my own opinions, etc.