How to find sample rate of a stream?
medakk opened this issue · 2 comments
I'm using opus.NewStream
to read in a stream of opus data. How do I find out the sample rate of the stream, after some data has been read?
Hi Karthikk, Sorry that it took so long to get back to you about this. I looked around when you originally posted this, got lost, and promptly forgot about it. Just had another look and found the answer for you:
The channel count can also change between links. If your application is not prepared to deal with this, it can use the stereo API to ensure the audio from all links will always get decoded into a common format. Since libopusfile always decodes to 48 kHz, you do not have to worry about the sample rate changing between links (as was possible with Vorbis). This makes application support for chained files with libopusfile very easy.
⏤ https://www.opus-codec.org/docs/opusfile_api-0.7/index.html
Easy as π! :)
Hope this answers your question.
..Better quote:
The libopusfile API always decodes files to 48 kHz. The original sample rate is not preserved by the lossy compression, though it is stored in the header to allow you to resample to it after decoding (the libopusfile API does not currently provide a resampler, but the the Speex resampler is a good choice if you need one). In general, if you are playing back the audio, you should leave it at 48 kHz, provided your audio hardware supports it. When decoding to a file, it may be worth resampling back to the original sample rate, so as not to surprise users who might not expect the sample rate to change after encoding to Opus and decoding.