Search code examples
c#algorithmaudiostretchingsoundtouch

Sound stretching for DJ like effect algorithm


I am working on a project including sound stretching using SoundTouch and C#.

As an effect when stopping the music playback, I want to implement a stretch algorithm like when the DJs turn the Vinyl off but it takes some seconds for the Vinyl to stop rotating and meanwhile the music is still being played and the sound stretches to lower tempos until it goes to zero.

My problem is that I don't really know where I should start from. I thought of using some sort of iterations with ease-out decreasing the tempo for chunks of music samples, but it seems a little complicated to me and I have problem figuring the algorithm out.

Any kind of suggestion, starting point, example or help is really appreciated.

Thanks.


Solution

  • The effect of a record player slowing down requires no time-stretching, because you're not changing the tempo and the pitch independently. You just need to slow down the playback rate by resampling the audio.

    In the illustration below, the green dots represent the input audio samples, the grid is the output sample clock, and the orange dots are the resulting output audio samples.

    resampling audio with linear interpolation

    In order to generate the output audio samples, you need to interpolate between the input sample values. In the graph I've used linear interpolation, which is the simplest way. To increase audio quality, you could use a mathematically more precise interpolation method, like differential interpolation (search for spline drawing techniques for more info), but for your particular case of a rapid slow-down effect, linear interpolation may be good enough.