Handling playback of different sample rates (beginner)

Hi - I am very new to audio programming and have been working on a cross platform audio player gui app (akin to foobar2000). I was originally using Rodio, which got me very far, but it looks like I need to implement my own playback/processing for some of the features I want to add. Rodio seems like it is meant for playback in gaming / simple audio features and not necessarily a dedicated audio playback application. Additionally, I really enjoy learning/playing with cpal, which is helping my understanding of audio programming.

How do most audio applications handle playing a sound which has a different sample rate than the audio hardware? ex. On Windows, my output device is configured to 48kHz, but the source (mp3) is 44.1kHz. This results in the sound being played faster than it should. It looks like Rodio does a linear interpolation between frames to up-sample to 48kHz. Does this produce artifacts in the signal?

I can set my device manually (through OS audio settings) to 44.1kHz and playback is correct. Do some applications change the sample rate configuration dynamically?

What other strategies are used?

You need to resample. Take a look at Rubato.

1 Like

I was pretty much in the same boat as you recently - was using Rodio to make a music player app, but decided I wanted a lower-level interface for more control. I added resampling using Rubato as mentioned above. Here’s my code if you want to use it as an example. This file contains the resampling code. Probably worth noting that It’s still WIP and could be cleaner. I’m still learning how audio stuff works too, so my example may not be the best, but it seems to work okay.

1 Like