[opus] Custom mode

Peter Svensson petersvenss85 at gmail.com
Sun Feb 17 20:47:03 UTC 2019

Hi all !

If someone could give me a hint on how to proceed with the following i'd be
very happy:

I have a test setup on an nrf52832 (Cortex M4) in which I receive audio
from a PDM microphone (64 sample frame) and pass it directly to an I2S
device i.e. from ISR to ISR. With uncompressed audio this works just fine.

Now I try to insert OPUS1.3 in the path but cannot make it work. The audio
passes through but ends up “down pitched” and heavily distorted.

Due to the 32MHz base clock (+ prescalers) available it is not possible to
get the desired 16kHz sample rate. I am therefore forced to work with

As I understand it the opus encoder does not mind a strange sample rate as
it will re-sample it to 48kHz (Correct?). The decoder, however, will always
output 48kHz, 24kHz, 16kHz etc (Correct?) which is incompatible with my
15625Hz rate. (However; If my assumptions are correct there could be a
possibility to make my I2S device master and, thus, be able to pull the
data at 16kHz)

Consequently I have been looking at “opus custom” as a solution but even
with a (seemingly) low complexity it does not yield the desired result.

*Setup code:*

mode = opus_custom_mode_create(15625, 64, &err);

size = opus_custom_encoder_get_size(mode, 1);

enc = malloc(size);

err = opus_custom_encoder_init(enc, mode, 1);

err = opus_custom_encoder_ctl(enc, OPUS_SET_BITRATE(16000));

err = opus_custom_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0));

size = opus_custom_decoder_get_size(mode, 1);

dec = malloc(size);

err = opus_custom_decoder_init(dec, mode, 1);

*ISR code (called once every 4.096ms):*

    nbBytes = opus_custom_encode(

        enc, (opus_int16 *)lMicBuf, 64, codedMicBuf, 64);

    frame_size = opus_custom_decode(

        dec, codedMicBuf, 64, decodedMicBuf, 64);


C:\Program Files\SEGGER\SEGGER Embedded Studio for ARM
3.50\gcc\arm-none-eabi\bin\cc1" -fmessage-length=0
-fno-diagnostics-show-caret -mcpu=cortex-m4 -mlittle-endian
-mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mtp=soft -nostdinc "-isystem


Any ideas?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xiph.org/pipermail/opus/attachments/20190217/93dd8087/attachment.html>

More information about the opus mailing list