On Wed, May 4, 2016 at 7:18 AM, Vittalprasad <vittalprasad.br at
gmail.com> wrote:> Hi all,
>
> i am trying convert pcm (16bit pcm) stereo file to mono pcm file using
> opus_encode and opus_decode, i am able do this but i have doubt about
> TOC byte after opus encode.
> below is how encoder and decoder structures are used to do encode and
> decode file
> opus_encoder_create(8000, 2, OPUS_APPLICATION_AUDIO, &err);
> opus_decoder_create(8000, 1, &err);
>
> after opus encode bits looks like this
> 00 00 00 12 31 69 52 10 08
It looks like you are probably using the opus_demo program (with the
-e option) to produce this. The opus_demo program is used to test the
encoder and decoder. With the -e option it will output each Opus
packet with an 8-byte header, consisting of a 4-byte length and 4
bytes for the final state of the range encoder. The purpose of this
format is pass it as input to opus_demo -d.
> doubts are
> 1)i know 12(hexa) is size of encoded frame and 08 is TOC byte, here i
> have doubt i am using stereo input and 20ms frame then TOC should be
> 0C, and
The Opus encoder will try to make the best use of whatever bitrate is
available. At the lowest rates it will allocate all bits to a
downmixed encoding of only the narrowband frequencies (TOC = 08). As
the bitrate is increased it will allocate bits to the higher
frequencies and to stereo. A good demonstration of this is the
"Bitrate scalability" demo at: https://opus-codec.org/examples/
The coded audio bandwidth and whether stereo information has been
coded can change on each packet, and is indicated by the TOC byte at
the beginning of the packet. However any stream can be decoded as
either mono or stereo so there is no need for a client to check this.
If the stream is decoded as stereo but no packets have stereo
information coded (for example, because the bitrate was very low for
the entire duration of the stream) then the output will simply be
identical on both channels.
> 2)also about the 4 bytes after 12
This is the final range encoder state, used by opus_demo -d to verify
that the decoded symbols match those that were encoded.
- Mark
>
> --
> Thanks & Regards
> Vittalprasad B R
> 8722397247