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

Hermann Weber hermie.weber at gmx.de
Fri May 10 09:37:07 PDT 2013


Or is there anybody here who can help me for money?

Greetings,
Hermie

Am 10.05.2013 08:26, schrieb Hermann Weber:
> Hello!
>
> The API is really friendly, that is true.
> I just did not find sample code for decoding larger amounts of encoded data.
>
> I guess that this is "too easy" and will not work:
>
> 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);
> }
>
> The argument "encoded" might be larger amounts of data, so I think I
> have to split it into frames.
> For Speex I used the following:
>
> void CSpxCodec::Decode(unsigned char* inbuf, short* outbuf, unsigned int
> len)
> {
>
>        char cbits[MAX_FRAME_BYTES];
>        float output[MAX_FRAME_SIZE];
>
>        unsigned int i=0;
>        unsigned int j=0;
>
>        for (i=0; i<(len/62); i++)
>        {
>
>            for (j=0;j<62;j++)
>            {
>                cbits[j] = inbuf[(i*62)+j];
>            }
>
>            speex_bits_read_from(&bits, cbits, 62);
>            speex_decode(decstate, &bits, output);
>
>            for (j=0;j<160;j++)
>            {
>                outbuf[j+(i*160)] = output[j];
>            }
>        }
> }
>
> But for Opus I did not find any sample code that would reflect my situation.
> Can anybody help?
>
> Thank you.
> Hermie
>
>
>
>
>
> Am 09.05.2013 20:37, schrieb Jean-Marc Valin:
>> Look at the examples in the API doc. The Opus API is different from
>> Speex, bit it's still pretty simple (probably even simpler than Speex).
>>
>> 	Jean-Marc
>>
>> On 09/05/13 02:30 PM, Hermann Weber wrote:
>>> Hello!
>>>
>>> I was using Speex all the time, and I am now moving to Opus.
>>>
>>> I had encapsulated the decoder a bit, I had the following cpp file:
>>>
>>> #include "StdAfx.h"
>>> #include "spxcodec.h"
>>>
>>> #define MAX_FRAME_SIZE 2000
>>> #define MAX_FRAME_BYTES 2000
>>>
>>> CSpxCodec::CSpxCodec() : enh(1), rate(8000)
>>> {
>>> }
>>>
>>>
>>> CSpxCodec::~CSpxCodec()
>>> {
>>> }
>>>
>>> void CSpxCodec::Init()
>>> {
>>>        speex_bits_init(&bits);
>>>        decstate = speex_decoder_init(&speex_nb_mode);
>>>
>>>        speex_decoder_ctl(decstate, SPEEX_SET_SAMPLING_RATE, &rate);
>>>        speex_decoder_ctl(decstate, SPEEX_SET_ENH, &enh);
>>>
>>>        int iFrameSize=0;
>>>        speex_decoder_ctl(decstate, SPEEX_GET_FRAME_SIZE, &iFrameSize);
>>>
>>> }
>>>
>>> void CSpxCodec::Free()
>>> {
>>>        speex_bits_destroy(&bits);
>>>        speex_decoder_destroy(decstate);
>>> }
>>>
>>> void CSpxCodec::Decode(unsigned char* inbuf, short* outbuf, unsigned int
>>> len)
>>> {
>>>
>>>        char cbits[MAX_FRAME_BYTES];
>>>        float output[MAX_FRAME_SIZE];
>>>
>>>        unsigned int i=0;
>>>        unsigned int j=0;
>>>
>>>        for (i=0; i<(len/62); i++)
>>>        {
>>>
>>>            for (j=0;j<62;j++)
>>>            {
>>>                cbits[j] = inbuf[(i*62)+j];
>>>            }
>>>
>>>            speex_bits_read_from(&bits, cbits, 62);
>>>            speex_decode(decstate, &bits, output);
>>>
>>>            for (j=0;j<160;j++)
>>>            {
>>>                outbuf[j+(i*160)] = output[j];
>>>            }
>>>        }
>>> }
>>> -------------------
>>> I would like to ask if I can keep this "wrapper".
>>> Please anybody tell me that I can just replace the word "speex" with
>>> "opus", and it will work, hehehehehe!
>>> Can I keep the 62, 160 part, or will that be different in Opus?
>>> I am not asking because I am lazy, I am just scared because Opus look so
>>> much different than Speex, and there is no "encoding/decoding for
>>> dummies" example as there was in Speex.
>>> Could anybody perhaps give me another push in the right direction and
>>> tell me how a good starting point for Opus newbies?
>>>
>>> Thank you so much.
>>>
>>> Greetings,
>>> Hermie
>>> _______________________________________________
>>> opus mailing list
>>> opus at xiph.org
>>> http://lists.xiph.org/mailman/listinfo/opus
>>>
> _______________________________________________
> opus mailing list
> opus at xiph.org
> http://lists.xiph.org/mailman/listinfo/opus
>



More information about the opus mailing list