MeadowlarkDAW / creek

Realtime disk streaming IO for audio
Other
112 stars 12 forks source link

resampling #9

Closed Be-ing closed 2 years ago

Be-ing commented 2 years ago

It would be really convenient if creek could do automatic resampling to a specified sample rate. When JACK is running at 44100 Hz, I want to be able to play 48000 kHz files at the correct pitch. This could already be done by the user after getting audio data from creek. However, that is not trivial because resampling changes the rate at which creek needs to read from the file to get the desired number of frames at the desired sample rate. This could be done with rubato.

Be-ing commented 2 years ago

Implementing this could lay the groundwork for realtime timestreching which also requires changing the rate at which data is read from the filesystem. Unfortunately there are not any Rust libraries for timestretching (yet).

Be-ing commented 2 years ago

I was under the mistaken impression that variable speed playback required reading data from files at different speeds. I took a closer look at how it works in Mixxx and the code that reads audio from files only uses the playback rate to determine the direction. Mixxx uses a fixed block size which is assumed to be good enough for any settings of playback sample rate, audio file sample rate, and buffer size that a user may want. In practice this works. I cannot recall any bugs reported for Mixxx that were are result of that block size being too small. creek's default block size is already twice Mixxx's block size. If an application developer finds that is insufficient, they can already adjust the block size when initializing the ReadDiskStream.

So I don't think resampling should be within creek's scope. It is up to the code using creek to resample the audio from the file. For variable speed playback, the application can already request to read however many frames it needs from creek then resample those to the output buffer length.