Possible issue with ResamplingAudioSource

Greetings! I am using a ResamplingAudioSource to resample small chunks of audio samples (that will later be assembled back together). I noticed that after I resample a chunk of audio (to a higher sample rate), the new waveform seems to always start and end with zero (or very close to zero). This is introducing pops and crackles into the samples when I reassemble them.

I have attached a PDF illustration of the waveforms, so you can see the “before” and “after”.

So, my question is, can the ResamplingAudioSource be used to resample small chunks of audio samples in this way, without changing the shape of the start and end of the waveform? Is this perhaps a bug, or am I just using it incorrectly? Any thoughts would be appreciated!

Thanks in advance!

Sorry, here is the attachment.

If you’re getting discontinuities then you’re using ResamplingAudioSource wrong.

I’m not sure ResamplingAudioSource is designed to deal with non-contiguous blocks of samples. Just speaking from memory, I think it uses a set of Biquad filters internally to avoid aliasing. If you’re resetting (calling prepareToPlay) or creating a new ResamplingAudioSource in-between processing of samples, the filter states will be reset to 0. Doesn’t this mean that the first few samples will be close to 0 as the the filters build up?

If you know your sample blocks will be re-assembled in a certain order, make sure you process them in that order, without interruption to the ResamplingAudioSource.

Yes, like dave said, resampling has internal state so will certainly behave differently depending on the data you give it.

Typically when you have stateful DSP operations and need to process the data in blocks, you have to use larger, overlapping blocks, and cross-fade between them when reassembling them.

Thanks for all the advice. As was mentioned, the ResamplingAudioSource needs to maintain it’s state between calls, to avoid having discontinuities between the chunks of audio samples. I refactored a bit, to only call prepareToPlay() once, and use the same ResamplingAudioSource object for all resampling calls, and everything is working great now. Thanks again!