Need an audio codec?
Here’s DFPWM, a 1-bit-per-sample compressed audio codec. Reference implementation is aucmp.py, C version is aucmp.c and audecmp.c, all public domain. Look at aucmp.py for a (totally not peer-reviewed) mathematical definition of the base encoder, as well as some suggestions to get rid of the whining and make it not look so high-pass filtered.
https://github.com/asiekierka/pixmess/tree/master/scraps
Is this the right codec for me?
Well, let’s look at what it’s not for:
- If you can’t stream your own audio to the sound card, this is not for you.
- If you’re an audiophile, run away now. It’s a fairly comprehensible codec, but it definitely sounds compressed (it tends to add noise).
- There are definitely better-quality codecs. This is supposed to be simple to implement.
Now, some stuff itcould be good for:
- Low-power CPUs. Note, a hardware multiply would help.
- Low-latency encoding. This encodes sample-per-sample.
- Really, really small audio data. Encoding at 16kHz gives you 2KB/s.
- Avoiding having dependencies for libogg/libvorbis – though these DO have better audio quality than this codec.
…Well, I’m not all too sure what the hell this’d be useful for, considering that most people in Ludum Dare can’t code at any level other than “as far away from the hardware as possible”, but it’s a suprisingly decent codec.
So, if you’re implementing voice chat for whatever reason, or you are limited by memory (storage and/or RAM), this might be the codec for you.
This is really useful, thanks! As I want to stay away from dependencies this just comes right. A while ago I came up with my own ADPCM codec but it only has a 1:4 compression ratio (4 bits per sample). I couldn’t get a higher compression without introducing major noise.
OOPS. Forgot to mention: DFPWM = Dynamic Filter Pulse Width Modulation.