xiph / opusfile

Stand-alone decoder library for .opus streams

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to save a WAV-file with original media info

SAV-master opened this issue · comments

Hello guys!
Now the output Wav-file is always saved as stereo and 48 Khz pcm.
How to save a WAV-file with original channel count and sample rate using your example opusfile_example.c?

How to fix the WAV header is clear.
What methods use to read data from opus file and what filters use to convert data?

Thank you in advance,
Andrey

To receive the encoded number of channels without downmixing, you should call op_read_float() instead of op_read_stereo(). Pass the output through a resampler to if you want to write data with the original same rate. There are many resampler implementations; if you're not sure which to use the one in the speexdsp library is a good choice. You can find the original sample rate in the OpusHead.input_sample_rate struct member.

Note however that opus files can contain multiple links, each with a different number of channels, original sample rate, and metadata tags. You'll need to decide what you want to do in such cases. This is the main reason the example uses the opus_read_stereo() call to downmix everything.

Thanks!