Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Opus on Cortex-M3 (Read 9900 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Opus on Cortex-M3

First post on this forum. This is a great community, so hopefully you'll all be able to help me.

I'm working on a project where I want to get the Opus decoder running on an embedded ARM core. basically, I want to decode and playback an encoded stream from an SD card on a Cortex M3.

To test the Opus codec first, I'm setting up a pretty basic demo where I'm filling a buffer from a .WAV file on an SD card, encoding it, then immediately decoding the result, and comparing the input, and output buffers. I'm leaving all of the settings in the encoder and decoder instances as the defaults aside from the sampling frequency (pulled from the .WAV header), and the channel count (also pulled from the .WAV header), in this case 192 K and stereo.

The issue I'm encountering is that the decoder is actually outputting twice the amount of data I expect it to. The input buffer size is 1920 samples (5 ms of 16-bit interleaved stereo data; frame size hard coded to 960 samples to match this); the encoder processes the data just fine, and typically outputs ~85 samples into its output buffer. When I pass the encoded data to the decoder, the decoder processes this, and writes the decoded data to its output buffer, with the opus_decode function returning 1960 (number of bytes decoded - which is correct). However 3920 bytes of data are actually written to the decoders output buffer. Each sample is written to the buffer twice, so every 2*ith sample and 2*i + 1th sample are the same.

I'm pretty sure that endianness is not the issue in this case. I've set the codec's options appropriately, and I've disabled the float API, and set it to run in fixed point mode. There's no errors or warnings at compile time, and there are no run-time errors. Any thoughts on what may be causing this?

 

Opus on Cortex-M3

Reply #1
When I pass the encoded data to the decoder, the decoder processes this, and writes the decoded data to its output buffer, with the opus_decode function returning 1960 (number of bytes decoded - which is correct). However 3920 bytes of data are actually written to the decoders output buffer. Each sample is written to the buffer twice, so every 2*ith sample and 2*i + 1th sample are the same.


According to this documentation:

https://mf4.xiph.org/jenkins/view/opus/job/...cb81799df9b3fc9

opus_decode returns the number of decoded samples, not the number of bytes.  Is it possible you're getting int16 samples? 

Opus on Cortex-M3

Reply #2
I'm leaving all of the settings in the encoder and decoder instances as the defaults aside from the sampling frequency (pulled from the .WAV header), and the channel count (also pulled from the .WAV header), in this case 192 K and stereo.


opus_encoder_init() only supports sampling rates of 8 kHz, 12 kHz, 16 kHz, 24 kHz, or 48 kHz, so if you think you're feeding it 192 kHz data, you're definitely doing something wrong.

I suggest reading the API documentation carefully: https://mf4.xiph.org/jenkins/view/opus/job/...html/index.html.

Opus on Cortex-M3

Reply #3
I'm leaving all of the settings in the encoder and decoder instances as the defaults aside from the sampling frequency (pulled from the .WAV header), and the channel count (also pulled from the .WAV header), in this case 192 K and stereo.


opus_encoder_init() only supports sampling rates of 8 kHz, 12 kHz, 16 kHz, 24 kHz, or 48 kHz, so if you think you're feeding it 192 kHz data, you're definitely doing something wrong.

I suggest reading the API documentation carefully: https://mf4.xiph.org/jenkins/view/opus/job/...html/index.html.

Opus will happily accept 192kHz WAV input, but will still give you a 48kHz (or possibly lower) Opus stream (with a value in the header saying 192!).

Definitely look at your decode function API though.  The return value is in samples, not bytes, deliberate but confusing at first.

Opus on Cortex-M3

Reply #4
Opus will happily accept 192kHz WAV input, but will still give you a 48kHz (or possibly lower) Opus stream (with a value in the header saying 192!).


opusenc the command-line tool will. But libopus the library will not, and it seemed clear the OP was using the latter.

Opus on Cortex-M3

Reply #5
When I pass the encoded data to the decoder, the decoder processes this, and writes the decoded data to its output buffer, with the opus_decode function returning 1960 (number of bytes decoded - which is correct). However 3920 bytes of data are actually written to the decoders output buffer. Each sample is written to the buffer twice, so every 2*ith sample and 2*i + 1th sample are the same.


According to this documentation:

https://mf4.xiph.org/jenkins/view/opus/job/...cb81799df9b3fc9

opus_decode returns the number of decoded samples, not the number of bytes.  Is it possible you're getting int16 samples?


My original post should read 3920 samples not bytes; this is my mistake... I expect the decoder to return int16_t type data,

Quote
opus_encoder_init() only supports sampling rates of 8 kHz, 12 kHz, 16 kHz, 24 kHz, or 48 kHz, so if you think you're feeding it 192 kHz data, you're definitely doing something wrong.


This sounds like the most likely problem. I'll give this a try.

Opus on Cortex-M3

Reply #6
When I pass the encoded data to the decoder, the decoder processes this, and writes the decoded data to its output buffer, with the opus_decode function returning 1960 (number of bytes decoded - which is correct). However 3920 bytes of data are actually written to the decoders output buffer. Each sample is written to the buffer twice, so every 2*ith sample and 2*i + 1th sample are the same.


According to this documentation:

https://mf4.xiph.org/jenkins/view/opus/job/...cb81799df9b3fc9

opus_decode returns the number of decoded samples, not the number of bytes.  Is it possible you're getting int16 samples?


My original post should read 3920 samples not bytes; this is my mistake... I expect the decoder to return int16_t type data,

Quote
opus_encoder_init() only supports sampling rates of 8 kHz, 12 kHz, 16 kHz, 24 kHz, or 48 kHz, so if you think you're feeding it 192 kHz data, you're definitely doing something wrong.


This sounds like the most likely problem. I'll give this a try.


Hello Maximus,

Do you have good news?

Can you post the code?

Thanks.

Re: Opus on Cortex-M3

Reply #7
i am also trying to port opus codec for cortex m3. but i am stuck at the first phase (getting all the files from the source code over to the IDE project). i am using IAR.  have anyone successfully ported it?