I’m implementing IMA ADPCM compression based on algorithm from Microchip (also attached here). and package data into WAV format. However, there is distortion in compressed data
My testing method:
generate a 5s of PCM data : 16kHz x 16 bit. File name: “Sine-1KHz-16x16-5s_SWgenerated (modified)”. It’s generated by repeating a complete sine wave cycle multiple times.
This data will be fed into Audacity and my compression code; then compare the output
“Sine-1KHz-16x16-5s_SWgenerated (IMA ADPCM)”: from Audacity
“Voice3011152932_PCM2bytes”: from my code
Playing “Voice3011152932_PCM2bytes”, there is a very distinct distortion.
When compare the binary, this is what is found at the block header (for example, at offset 572):
Audacity: DE 39 4F 00
My Code : 09 CF 4F 00
According to my understanding,
Byte 0: LSB of PCM sample
Byte 1: MSB of PCM sample
Byte 2: current index
Byte 3: zero
Apparently, this doesn’t match with Audacity
I would greatly appreciate if anyone could advise me on this issue
Thank you so much in advance
What do you mean by “fed into Audacity”? Do you mean record or import?
Are you complaining about an IMA ADPCM file that Audacity exports?
If there is distortion in your generated sound, why is that an Audacity bug? Does it distort in other apps?
Have you contacted libsndfile-devel? If there is an Audacity bug, the bug probably lies in the libsndfile library. That list may be able to advise you more about headers of different ADPCM formats.
Hi Gale,
Thanks for your reply
First of all, I did not claim this is Audacity bug and I myself do not think so anyway. I was merely looking for advices from those who have experience in this field.
"What do you mean by “fed into Audacity”? Do you mean record or import? "
==> I used Audacity to open and then export to IMA ADPCM
Yes, I also did check on the specs you link to and also the specs itself and my understanding was what I have described in earlier post. Perhaps I miss out something ?
I will take a look at Libsndfile. Thanks for the advice
Byte 0 and Byte 1 are LSB and MSB of PCM sample
However, in Audacity block header: (DE 39 4F 00); DE and 39 are not belong to the PCM data that I use to generate ADPCM. That’s what make me quite puzzled …
If “Voice3011152932_PCM2bytes” is your file and “Sine-1KHz-16x16-5s_SWgenerated (IMA ADPCM)” is the Audacity exported file, the headers of those two files (before the data) are identical.
Offset 572 in the Audacity exported file and your file appears to be CD. There are no DE hex values anywhere in either file.
If you are you saying that “ima_adpcm.c” is incorrect in some way, please say why.
If you just want advice about how to code internals of your formats, this is the wrong forum, sorry.
“Sine-1KHz-16x16-5s_SWgenerated (modified)” is PCM data.
I use Audacity to open, and export into “Sine-1KHz-16x16-5s_SWgenerated (IMA ADPCM)”
data DE 39 4F 00 is at offset 572 of “Sine-1KHz-16x16-5s_SWgenerated (IMA ADPCM)” file
I’m not expert in this, thus far from qualified to say whether it’s right or wrong. I’m just trying to understand more on how IMA ADPCM is packaged into WAV format in Audacity.
I’m not here to find faults, but rather to learn things.
If I understand your question correctly, encoding the uncompressed audio data from Audacity to IMA_ADPCM is handled by libsndfile. For more information about how libsndfile handles the conversion, you really need to look at their documentation / ask their developers (http://www.mega-nerd.com/libsndfile/lists.html).