Shop OBEX P1 Docs P2 Docs Learn Events
ADPCM .wav player code? — Parallax Forums

ADPCM .wav player code?

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...

Comments

  • Wuerfel_21Wuerfel_21 Posts: 4,461
    edited 2020-09-18 17:12
    Note that "ADPCM" is just an umbrella term for many different codecs - just WAV files support some 14 different ADPCM codecs of varying quality and complexity.

    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.
  • RaymanRayman Posts: 13,860
    I'm hoping to find one that will play Windows .wav files with ADPCM encoding of some type.

    But, I'm not sure I can find that with MIT license...
  • RaymanRayman Posts: 13,860
    I found some MIT license stuff here:
    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...
  • Rayman wrote: »
    Also has a-law and mu-law. I don't know much about those though. Anybody know the compression ratio of these?

    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.
    Rayman wrote: »
    I think ADPCM is 4:1 compression ratio. Not the best, but better than nothing...
    Once again, depends on the particular codec. Most are 4 bit per sample with some extra data, so slightly less than 4:1.
  • Ahle2Ahle2 Posts: 1,178
    My question is why you are interested in a lossy compression (well, there are variants that are lossless but with very poor compression ratio) technique that usually doesn't even have a good compression ratio? It made sense in the past with slow CPU's and low bandwidth for non audiophile applications like telephones and stuff. I know that MP3 is very taxing, complex and needs a lot of code for a MCU application (even though it without doubt could be made on the P2 for real time playback of CD quality audio), but even that is not very neccessary to have on the P2 when we have GB's of memory for "free" on a SD card. From an engineering point of view I totally understand why you would go down that path though. A lot of cool algorithms and some head scratching. You will learn a lot about sound encoding/decoding in general. (I know, because I have been in that rabbit hole myself)

    I say go for it!
  • RaymanRayman Posts: 13,860
    I would love to find an mp3 decoder that worked with C on P2...
    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...
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-09-18 18:12
    The ITU (International Telecommunications Union) developed standards for several audio codecs that are used in telephony, such as G.711 (alaw & ulaw) and G.721 which is a 32 kbps ADPCM audio codec. I believe G.721 was superseded by G.726, which allows for more bit rates. It's been a few years since I worked with these algorithms, so I consulted with my younger self from 10 years ago for more information. Please look at the thread at https://forums.parallax.com/discussion/125759/audio-compression .

    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 .
  • Rayman wrote: »
    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...

    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
  • RaymanRayman Posts: 13,860
    @"Dave Hein" I downloaded but noticed has "ITU-T General Public License"... Don't like the look of that...

    But, I also got a G726 decoder from same place as ADPCM. Do you think that one would be better in some way?
  • G.726 is identical to G.721 at 32 kbps. G.726 just includes additional quantizers for 16, 24 and 40 kbps. G.721 was developed so that twice as many voice calls could be sent over the same lines that were sending 64 kbps G.711 A-law or u-law. They assumed a sample rate of 8,000 samples/second with an analog bandwidth of 3.3 KHz. Of course, you can use G.721/G.726 at a higher sample rate to achieve a higher analog bandwidth.

    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?
  • RaymanRayman Posts: 13,860
    edited 2020-09-18 22:09
    I started looking again and came across MusePack with BSD licensed decoder... Maybe I should try that...

    ADPCM is sounding like it is mostly for voice. Maybe not so good for music?
  • Maybe AM Solid Gold
  • RaymanRayman Posts: 13,860
    edited 2020-09-19 17:53
    Actually, I think I just found an old mp2 and an old mp3 code to try...

    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
  • potatoheadpotatohead Posts: 10,253
    edited 2020-09-19 18:33
    Many players were derived from this integer? optimized code:

    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... )
  • potatohead wrote: »
    Many players were derived from this integer? optimized code:

    https://tracker.debian.org/pkg/amp

    Hmmm, that points to # Amp: Atomistic Machine-learning Package #

    Where did you say the integer optimized MP3 code was?
  • Hold on... lol
  • Maybe the integer version of OPUS would be a good option? Very low latency (implies small buffers) and very pleasant sounding artifacts.
Sign In or Register to comment.