Opus codec? #10756
Replies: 6 comments 1 reply
-
See also parallel discussion at https://discordapp.com/channels/574275045187125269/1012726713291128862/1075251278009073724 |
Beta Was this translation helpful? Give feedback.
-
I was able to get this to compile and have called my first opus function, on the Unix port. To avoid undefined-QSTR errors, I had to avoid compiling the existing cexample and cppexample, and change my sources to |
Beta Was this translation helpful? Give feedback.
-
I was able to decode opus in micropython running on Unix.
(Even though they recommend a big buffer, the file I tried pulls 960-samples or 3840-bytes per call maximum) |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, libopusfile is a little less friendly to cross-compiled cmake compared to ogg/opus, or arduino-libopus... |
Beta Was this translation helpful? Give feedback.
-
I was able to get this to work under CircuitPython after addressing some minor extension module differences, tweaking arduino-libopus and writing a makefile. Still pretty rough, and doesn't use the C-only smooth audio playback API for circuitpython. Need to keep at it until we can feed it data from a network; micropython/circuitpython doesn't think "a Python class with a read() method" is a file. |
Beta Was this translation helpful? Give feedback.
-
I was able to get Opus decoding to work under MicroPython as an external module, in https://github.com/dholth/arduino-libopus/blob/main/micropython/opusdec_i2s.py. I can easily fit 2 1/2 minutes of 48kbps stereo audio as a 1MB file on the RP2040's built-in flash. It compiles something like this Unlike CircuitPython, when compiled under micropython we don't have to hack in the following symbols:
I'm playing the audio through a MAX98357A DAC which should expect right-justified samples, which I understand is what machine.I2S spits out.
Playback quality is pretty good with minor gitches, as long as I use the blocking API and set ibuf=BUFFER_LENGTH_IN_BYTES to the same 20ms chunks that the Opus codec produces. Although it sounds like it is clipping, and I haven't gotten the I2S.shift() function working yet to reduce the volume. The IRQ API is extremely glitchy, at least how I'm using it. I tried single and double buffering the decoded samples, either decoding it right away or decoding the next callback's samples after writing the current ones. The IRQ callback is passed an undocumented parameter which from the C code appears to be the I2S object. I have not tried the async API. |
Beta Was this translation helpful? Give feedback.
-
I thought it would be interesting to get the Opus codec into micropython. Some people run it on the ESP32 for example. This handy distribution is easy to compile with cmake, but maybe not for the Unix port. Branch at https://github.com/dholth/micropython/tree/opus/examples/usercmodule/opus. It looks like I need to edit the
micropython.mk
to match themicropython.cmake
if I want the other build to work; read through all of the included C modules to figure out what the API is; ...Beta Was this translation helpful? Give feedback.
All reactions