[opus] Moving from Speex to Opus (question 2)

Hermann Weber hermie.weber at gmx.de
Fri May 10 10:05:11 PDT 2013

Hello Ralph,

do you think you can improve my old Speex code if it is a piece of cake 
for you?


Am 10.05.2013 18:51, schrieb Ralph Giles:
> On 13-05-09 11:26 PM, Hermann Weber wrote:
>> void COpusCodec::Decode(unsigned char* encoded, short* decoded, unsigned
>> int len)
>> {
>>       int max_size=960*6;
>>       int error;
>>       dec = opus_decoder_create(48000, 1, &error);//decode to 48kHz mono
>>       int frame_size=opus_decode(dec, encoded, len, decoded, max_size, 0);
>> }
> You need to loop, calling this for each encoded packet. It will return
> OPUS_BUFFER_TOO_SMALL if max_size isn't large enough to contain the
> output. You can find out how big the output will be by calling
> opus_packet_get_nb_frames() and opus_packet_get_samples_per_frame()
> ahead of time. Don't forget to multiply by the number of channels if you
> add support for more than mono.
> libopus will take care of unpacking any opus frames inside the packet,
> but you have to supply the packet length, and advance the encoded
> pointer, based on framing information from the container. For example,
> the RTP packet length minus headers, or the Ogg packet length if you're
> reading a .opus file.
> There are examples in opus/src/opus_demo.c, opus-tools/src/opusdec.c and
> opusfile/src/opusfile.c but they're somewhat dense as they're all
> handing many more options than your simple example.
>   -r

More information about the opus mailing list