Distortion in IMA ADPCM, suspect block header issue

Audio software developers forum.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by DennisChau » Mon Nov 30, 2015 10:10 am

Hi guys,

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
--
Dennis
Attachments
Voice3011152932_PCM2bytes.wav
ADPCM data from my code
(39.56 KiB) Downloaded 44 times
Sine-1KHz-16x16-5s_SWgenerated (modified).wav
PCM data
(156.29 KiB) Downloaded 48 times
Sine-1KHz-16x16-5s (IMA ADPCM).wav
ADPCM data from Audacity
(39.56 KiB) Downloaded 51 times
++PIC on ADPCM.rar
ADPCM algo from Microchip
(149.54 KiB) Downloaded 47 times
DennisChau
 
Posts: 4
Joined: Mon Nov 30, 2015 9:52 am
Operating System: Please select

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by Gale Andrews » Mon Nov 30, 2015 10:43 am

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.

If you want an IMA ADPCM specification, have you tried http://www.cs.columbia.edu/~hgs/audio/dvi/?


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26093
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by DennisChau » Mon Nov 30, 2015 12:33 pm

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
--
Dennis
DennisChau
 
Posts: 4
Joined: Mon Nov 30, 2015 9:52 am
Operating System: Please select

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by DennisChau » Mon Nov 30, 2015 3:16 pm

Hi Gale,
I've take a look at libsndfile, in particulare ima_adpcm.c
Code: Select all
static int
wav_w64_ima_encode_block (SF_PRIVATE *psf, IMA_ADPCM_PRIVATE *pima)
{
   /* Encode the block header. */
   for (chan = 0 ; chan < pima->channels ; chan++)
   {   pima->block [chan*4]   = pima->samples [chan] & 0xFF ;
      pima->block [chan*4+1]   = (pima->samples [chan] >> 8) & 0xFF ;

      pima->block [chan*4+2] = pima->stepindx [chan] ;
      pima->block [chan*4+3] = 0 ;

      pima->previous [chan] = pima->samples [chan] ;
      } ;
..
}


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 ..
--
Dennis
DennisChau
 
Posts: 4
Joined: Mon Nov 30, 2015 9:52 am
Operating System: Please select

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by Gale Andrews » Tue Dec 01, 2015 1:13 pm

DennisChau wrote: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.

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.


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26093
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by DennisChau » Tue Dec 01, 2015 1:33 pm

Hi Gale,

Perhaps I did not explain very clear..

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

Thank you
--
Dennis
DennisChau
 
Posts: 4
Joined: Mon Nov 30, 2015 9:52 am
Operating System: Please select

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by steve » Tue Dec 01, 2015 2:33 pm

DennisChau wrote:I'm just trying to understand more on how IMA ADPCM is packaged into WAV format in Audacity.

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).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 44630
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Distortion in IMA ADPCM, suspect block header issue

Permanent link to this post Posted by Gale Andrews » Tue Dec 01, 2015 2:58 pm

DennisChau wrote:- "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

You did not attach a file of that name.

DennisChau wrote:
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.

No developers hang out here. For expert opinion I suggest you ask on libsndfile-devel.

That said, I don't see why you expect your Microchip algorithm should give the same result as IMA ADPCM. Does this help: http://www.microchip.com/forums/m698891.aspx?


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual
Gale Andrews
Quality Assurance
 
Posts: 26093
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10


Return to General Audio Programming



Who is online

Users browsing this forum: No registered users and 3 guests