i’m currently trying to build a module using Adam Stark’s AudioFile.h.
the test sample i’m loading has a sample rate of 44100, while Rack is running at 48000, making the playback of the sample happen faster than it should, causing the sound to be a slightly higher pitch and be over too quickly.
You can do that (it’s called Zero Order Hold resampling), but the results won’t sound great, and you’ll end up with a lot of aliasing. Linear interpolation (blending between two adjacent samples) will help, but for best results you’ll want to use a proper sample rate converter on the buffer first. The Fundamental plugin uses Secret Rabbit Code (aka libsamplerate) which I have also had good experiences with.
thanks, i’m looking into this libsamplerate now. which of the Fundamental modules uses this? i’d like to look at an example to get an idea of how to use it.
Depends if you only need to do it once, or if you have to do it in real time for playback. Some of those fancy ones take a lot of cpu. For real time I use cubic interpolation. Works fine I the real world.
The delay module uses it for pitch changes when modulating the delay time.
In your case, you can probably use the simple API to resample the entire sample on load (and when the sample rate changes); real-time processing shouldn’t be necessary.
thanks, i see it. what i’m curious about is where the library is stored for the delay module to include it? i see the include but don’t see samplerate.h anywhere in the repository. do i only need the samplerate.h file from libsamplerate or do i need all the other libsamplerate files as well?
thanks a bunch for this. turns out libsamplerate is included in Rack, so i managed to use it and now the sample is playing back perfectly. thanks for all the help/suggestions, everyone.