[opus] Sample code for encoding / decoding a RAW file

Edwin van den Oetelaar edwin at oetelaar.com
Wed May 15 10:05:02 PDT 2013


Hello Hermann,

Can you explain what you are looking for, or what your problem is?
General API or something else?

You know the API is documented here :
http://www.opus-codec.org/docs/html_api-1.0.2/group__opus__encoder.html

What you need to do is
1) create a encoder context
OpusEncoder *enc = opus_encoder_create(sampling_rate, channels,
application, &err);
2) set the parameters up right
eg.
opus_int32 signal_type = OPUS_SIGNAL_MUSIC;
opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type));

3) call opus_encode() with the raw input sample buffer and length as
parameters and you get back bytes in a buffer with a length as encoded
data
uint32_t len = opus_encode(sCelt->enc_state, //
                                   inputBuffer, //
                                   framesPerBuffer,
                                   outpacket, //
                                   PACKETSIZE);

With this data you do your file stuff.

Later you can read it back from a file and put it into opus_decode()
1) create a decoder context like
2) no parameters
3) read some stuff from file
4) decode it
uint32_t use_fec = 0;
int rv = opus_decode(sCelt->dec_state, (const uint8_t *) packet.data,
                             packet.len, outputBuffer,
framesPerBuffer, use_fec);

5) use the frames you got back from the decoder...

Hope this helps somebody,
Greetings
Edwin van den Oetelaar



On Wed, May 15, 2013 at 5:59 PM, Hermann Weber <hermie.weber at gmx.de> wrote:
> Hello,
>
> my last try:
>
> Isn't it possible that somebody writes a simple sample code on how to
> encode / decode a RAW file?
> The opus_demo.exe is not suitable (neither for encoding nor for
> decoding, but of course it is a good testing suite for somebody who
> knows what he is doing).
>
> For Speex there was such a great example for encoding / decoding a RAW
> file, but not for Opus.
>
> I also posted this work on some freelancer platforms, but nobody could /
> want to do it.
> So it is surely not as simple as it sounds.
> On one freelancer platform I even found a request for just the same work.
>
> I know the Opus devs are busy, but just having a demo for such a
> seemingly simple operation would be nice.
>
> Greetings,
> Hermann
> _______________________________________________
> opus mailing list
> opus at xiph.org
> http://lists.xiph.org/mailman/listinfo/opus


More information about the opus mailing list