Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to find sample rate of a stream? #19

Closed
medakk opened this issue May 1, 2018 · 2 comments
Closed

How to find sample rate of a stream? #19

medakk opened this issue May 1, 2018 · 2 comments

Comments

@medakk
Copy link

medakk commented May 1, 2018

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?

@hraban
Copy link
Owner

hraban commented Jun 17, 2018

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.

@hraban hraban closed this as completed Jun 17, 2018
@hraban
Copy link
Owner

hraban commented Jun 17, 2018

..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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants