ADPCM .wav player code?
Rayman
Posts: 14,646
in Propeller 2
Anybody seen code to play a .wav file encoded with ADPCM?
This looks to be the simplest audio compression to use...
Would like to do MP3, but that is complicated...
This looks to be the simplest audio compression to use...
Would like to do MP3, but that is complicated...
Comments
I've even created my own bespoke codec that I was meaning to write a PASM1 decoder for at one point. If you want I can see if I can dig up the code for that.
But, I'm not sure I can find that with MIT license...
http://my.fit.edu/~vkepuska/ece3551/Lecture Notes/Audio Codecs/
Also has a-law and mu-law. I don't know much about those though. Anybody know the compression ratio of these?
I think ADPCM is 4:1 compression ratio. Not the best, but better than nothing...
A-law and µ-law are basically 8 bit floating point values. Really simple to decode and much better quality than straight 8 bit PCM. There's a P1 ASM A-law decoder in tinySDDA if that's any use.
Once again, depends on the particular codec. Most are 4 bit per sample with some extra data, so slightly less than 4:1.
I say go for it!
But, there are a lot of issues... Most out there are GNU licensed (which I don't want to deal with). Or, have a license that says can only be used with a certain chip.
This one looks interesting: https://github.com/lieff/minimp3
But, I'm almost sure it won't compile on a P2...
Most of these codes seemed aimed at computers and not microcontrollers...
How bad does ADPCM sound?
4:1 ratio can be a big deal when trying to do video from a uSD card down a 1-bit SPI pipe...
You can download a 27 MB zip file that contains source code for a few audio codecs at http://www.itu.int/rec/T-REC-G.191/en .
Again, depending on codec, the quality can actually be pretty decent. Not transparent, but the quantization noise doesn't sound annoying like MP3 artifacts.
Anyways, I've found the code for the custom codec I spoke about and attached it. It's C++ but mostly plain C stuff. Very simple and unoptimized code. This one is really good for voice and such, because sections of centered deltas can be encoded at 8 bits per sample (the comments call it "joint mode")
Some notes
- Input files for encoding should be raw unsigned 16 bit stereo
- There's some stuff for mono encoding, but IDK if that actually works. Stereo works.
- The format and code are structured around 512 byte pages - useful when decoding from SD
- If you want to understand how it works, read the decoder first.
- The coefficients are chosen more or less randomly and are probably bad
But, I also got a G726 decoder from same place as ADPCM. Do you think that one would be better in some way?
I'm assuming the ADPCM code is referring to G.721. However, it may implement a non-standard form of ADPCM. Do you see any references to an ITU or CCITT standard in the source code?
ADPCM is sounding like it is mostly for voice. Maybe not so good for music?
Think the key is to search for "Public Domain" for these old codes... It's not really public domain, but I think the license is OK.
https://github.com/technosaurus/PDMP2
https://tracker.debian.org/pkg/amp
A long time ago, I compiled this on an SGI Indigo running at 30Mhz. It was able to play up to 256kbps files! 90 percent CPU utilization.
It is accurate and free of high end slurring artifacts and does well on even poorly encoded files. I am honestly tempted to compile it for use on my PC today. Sounds very good. The Fraunhofer codec does not even compare.
https://en.m.wikipedia.org/wiki/R4000
That CPU is no dog, but 30Mhz mp3 decode?
Maybe a P2 can do it. Trying this is on my list, but I am deep into a couple of projects for work right now. (Brutal, but pay well, so... )
Hmmm, that points to # Amp: Atomistic Machine-learning Package #
Where did you say the integer optimized MP3 code was?