Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the audio duration using libsndfile

Tags:

c++

libsndfile

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.

like image 678
IT World Avatar asked Oct 17 '25 21:10

IT World


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()
like image 91
Matthieu Brucher Avatar answered Oct 20 '25 11:10

Matthieu Brucher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!