sound codec in java (adpcm)

Hi there!

I'm currently trying to decode (and later encode) IMA ADPCM. My program runs without any error.

The result is recognizable but it has some peaks in it and it's hissing.

Is there anyone with some hints where the flaw may be?

Or with useful links regarding sound-codecs?

I can also mail the sourcecode if it's necessary.

Thanks in advance!

Stefan

[406 byte] By [StefanowitschSa] at [2007-10-1 12:38:51]
# 1

Just happens that I have learnt about ADPCM when I was young, so I can probably give you an explanation.....

The fact is, I bet your code is perfect in terms of doing the job correctly. It is the compression algorithm that causes the distortion of the encoded signal.

In Adaptive Differential Pulse Code Modulation (hence ADPCM), a difference that can be varied is stored in place of the actual values of the samples in the audio stream. It is evident that if the values of the samples increase / decrease at a rate much higher than the difference than there is under-shooting / over-shooting - the latter is probably the cause for those peaks that you hear.

On the other hand, if the difference is much larger than the variation in the signal (e.g. period of quietness) than you will ended up with a rapidly alternating (i.e. high frequency) distortion - hence the hissing noise.

So I have good faith that your code is doing well.

Hope this helps~

Alex Lam S.L.

AlexLamSLa at 2007-7-10 15:00:42 > top of Java-index,Other Topics,Algorithms...
# 2

Thank you for your answer ;)

The problem is, if I open my generated file and the originally file in an wav editor (CoolEdit) there is a great difference in the look.

And CoolEdit has to decode it, too... So I think there must somewhere be a bug in my code...

I'm also not able to shift the generated samples 8 bit to the right(in order to get 8bit samples), because then I get only at the beginning some sound.

That's somewhat disturbing because in the blockheader (which is all wBlockAlign afaik) it should be repaired...

Maybe I missed something, but the specs I had so far didn't also mention loops or things like that.

Thanks so far!

Stefan Stefanowitsch

StefanowitschSa at 2007-7-10 15:00:42 > top of Java-index,Other Topics,Algorithms...
# 3

The difference in look is totally expected - and the fact that you have encoded it using ADPCM means that CoolEdit (or Adobe Audition, it is now called) needs to decode it first.

One thing that I would recommend you to try out is to use CoolEdit itself to convert the same wave file to ADPCM (with the same sampling rate and sample bits and all that) then open the resultant file back in CoolEdit - that would give you a good comparison of whether you program works.

But even given that, since there is a flexibility in the codec (the difference is adaptive), difference compression code can produce valid yet different compressed results - the worst yet still valid case being that difference is not changed all along, so it becomes effectively DPCM instead.

As for your Attempt to generate 8 bit samples - I think there could be some problem with the bit-shifting procedure alone. If you don't mind please post up the few lines of code (or wrapped in a method) the transformation you do to the 16-bit or 32-bit samples to narrow them down to 8-bit.

Btw, is the "some sound" you get at the beginning to expected ones or just random noise or what?

Hope this helps~

Alex Lam S.L.

AlexLamSLa at 2007-7-10 15:00:42 > top of Java-index,Other Topics,Algorithms...
# 4

>and the fact that you have encoded it using ADPCM

Oh, I only try to decode it ;)

The file is already encoded in ADPCM, encoding would be the next step...

>If you don't mind please post up the few lines of code

I can also send you a mail with the full sourcecode... it's just a test implementation and the sound file itself

(which looks like an GSM 6.10 IMA ADPCM afaik the only difference is that the data starts at byte 60 (header) and the first ADPCM value is in 64

>Btw, is the "some sound" you get at the beginning to expected ones or just

>random noise or what?

The soundfile is recognizable, relativly good, but it doesn't fade out if i don't shift

if i shift only the first short part is audible...

If you have some time I'd greatly welcome it if you take a look on it ;)

Its not big a programm, and with lots of comments so it should be easy to read it.

Thank you so far for your help ;)

StefanowitschSa at 2007-7-10 15:00:42 > top of Java-index,Other Topics,Algorithms...