Get the audio duration using libsndfile

Viewed 377

I created an application using libsndfile and wasapi, it allows playing an audio file slowly and manually with the cursor using QSlider.

I see that libsndfile uses frames, I want to know how to get the duration of this audio file but I can not find it in the documentation of libsndfile and play parts of the audio file using ms.

I managed to make it work with the frames but I want to understand how to do it with the milliseconds.

1 Answers

The objects libsndfile creates have a frames() method that gives you this information. samplerate() gives you the sampling rate, so then the duration is:

static_cast<double>(frames())/samplerate()
Related