Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Open Source ALAC Decoder (Read 85758 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Open Source ALAC Decoder

Hi, David Hammerton from the ffmpeg mailing list wrote a reverse engineered ALAC decoder.

Quote
Located here is a basic decoder for Apple Lossless Audio Codec files (ALAC). ALAC is a proprietary lossless audio compression scheme. Apple never released any documents on the format.
What I provide here is a C implementation of a decoder, written from reverse engineering the file format. It turns out that most of the algorithms in the codec are fairly well known. ALAC uses an adaptive FIR prediction algorithm and stores the error values using a modified rice or golumb algorithm. Further details are in alac.c.

Although an encoder is not provided, by using the decoder as a sort of specification it should be fairly trivial to write an encoder. By exploiting other lossless audio encoders, such as FLAC, the task will be much easier. Although one wouldn't be able to copy the compression algorithms verbatim, as adaptive compression is used in ALAC and not in FLAC. There are, however, a bunch of academic papers on the issue.

The program located here will not be able to handle all ALAC files, it can only handle mono or stereo files. ALAC allows up to 8 channels. It should be trivial to finish the implementation once I find files that I can test it with. Likewise the decoder only supports 16bit sample sizes. Again, it should be trivial to fix.

The decoder is fairly self explanatory, it can read an ALAC stream from either a file or from stdin, and write it as raw PCM data or as a WAV file to either stdout or a file. In theory one should be able to stream data to the decoder.


I uploaded a binary here.  Not sure about the legality of this, I will remove if necessary.

Open Source ALAC Decoder

Reply #1
very cool.  I was about half-way done reverse engineering it last year, but I stopped when it seemed unlikely that ALAC could be converted to FLAC without reencoding.  but they are very close.

apple would be crazy to go after this though, as this will help adoption of the format.

Josh

Open Source ALAC Decoder

Reply #2
Very nice new
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?

Open Source ALAC Decoder

Reply #3
I should say that the binary that I uploaded is just for testing purposes *only*.  I am not sure if the output is indeed lossless.  I really didn't test it much.

Open Source ALAC Decoder

Reply #4
Quote
I should say that the binary that I uploaded is just for testing purposes *only*.  I am not sure if the output is indeed lossless.  I really didn't test it much.
[a href="index.php?act=findpost&pid=279582"][{POST_SNAPBACK}][/a]


I've tested with one big file, encoded in m4a ALAC, and decoded with the 'hacked' decoder. Sound is great, but compared to iTunes decoder bass are not as powerfull, some details are slightly less precise and trebles are also a bit...  no, I'm joking of course

I did a bit-to-bit comparison, and foobar2000's conclusions are:
Code: [Select]
INFO (foo_bitcompare) : Comparing:
INFO (foo_bitcompare) : location: "file://C:\2005.02.12\Murail, Tristan (1947-)\Serendib - L'esprit des dunes - Désintégrations\02. L'esprit des dunes • 1993-1994 - pour ensemble et électronique.wv" (0)
INFO (foo_bitcompare) : location: "file://C:\cmd\dunes.wav" (0)
INFO (foo_bitcompare) : No differences in decoded data found.
INFO (foo_bitcompare) : Finished successfully.


Seems to work perfectly, at least on this full track.

Open Source ALAC Decoder

Reply #5
  Amazing shit.

/me goes to change the lossless comparision table.

Open Source ALAC Decoder

Reply #6
Quote
  Amazing shit.

/me goes to change the lossless comparision table.
[a href="index.php?act=findpost&pid=279600"][{POST_SNAPBACK}][/a]


Anybody have a MAC OS X binary of this yet for testing? I would but don't to know to make one.

Open Source ALAC Decoder

Reply #7
I think under MacOS you could just unzip it, browse to the folder from the command line and type 'make'.  Though my unix skills are subpar.

Open Source ALAC Decoder

Reply #8
It would be great to also extract the tags and then be able to convert a library of ALAC into FLAC, without having to type in all the album information again.

Sean

Open Source ALAC Decoder

Reply #9
Quote
I think under MacOS you could just unzip it, browse to the folder from the command line and type 'make'.  Though my unix skills are subpar.
[a href="index.php?act=findpost&pid=279613"][{POST_SNAPBACK}][/a]


I tried that and it couldn't find any program named 'make' in Mac OS X. Anybody else know how to compile this for Mac?

Open Source ALAC Decoder

Reply #10
Quote
Quote
I think under MacOS you could just unzip it, browse to the folder from the command line and type 'make'.  Though my unix skills are subpar.
[a href="index.php?act=findpost&pid=279613"][{POST_SNAPBACK}][/a]


I tried that and it couldn't find any program named 'make' in Mac OS X. Anybody else know how to compile this for Mac?
[a href="index.php?act=findpost&pid=279626"][{POST_SNAPBACK}][/a]


You need to have the development tools installed.  If you install XCode you'll get gcc, make, and all the other stuff necessary.

I just tried compiling this on OS X (just type "make" as said) and it at least compiles with no problem.  I haven't tried the program on any input files though.

Open Source ALAC Decoder

Reply #11
Quote
You need to have the development tools installed.  If you install XCode you'll get gcc, make, and all the other stuff necessary.

I just tried compiling this on OS X (just type "make" as said) and it at least compiles with no problem.  I haven't tried the program on any input files though.
[a href="index.php?act=findpost&pid=279633"][{POST_SNAPBACK}][/a]


Thanks for the info Dibrom. Would it be possible to post the Mac OS X binary on HA or else have it posted on Rarewares? Thanks.

Open Source ALAC Decoder

Reply #12
Quote
  Amazing shit.

/me goes to change the lossless comparision table.
[a href="index.php?act=findpost&pid=279600"][{POST_SNAPBACK}][/a]


Hi

When will this comparision table be ready?  Will you let us know when its been modifies. 

Thanks

Open Source ALAC Decoder

Reply #13
On my 1.25 gHz/ 768MB  eMac it seems significantly slower than iTunes:

    WAV -------- M4A ------ iTunes ---- alac

  59.1 MB --- 32.3 MB --- 10 sec --- 16 sec 
  73.3 MB --- 41.1 MB --- 14 sec --- 21 sec 
  67.9 MB --- 41.2 MB --- 15 sec --- 30 sec
146.0 MB --- 76.3 MB --- 23 sec --- 41 sec
244.2 MB --- 140.5 MB --- 46 sec --- 90 sec

Open Source ALAC Decoder

Reply #14
This hasn't been optimised in any way. So it isn't any kind of a surprise.

Open Source ALAC Decoder

Reply #15
Quote
When will this comparision table be ready?  Will you let us know when its been modifies.  [{POST_SNAPBACK}][/a]


It's been ready for months

[a href="http://www.hydrogenaudio.org/forums/index.php?showtopic=29655]http://www.hydrogenaudio.org/forums/index....showtopic=29655[/url]

And I post at that thread whenever there is a modification to the first post.


@Bonzi: can I host your compile at RareWares?

Open Source ALAC Decoder

Reply #16
Quote
Quote
When will this comparision table be ready?  Will you let us know when its been modifies.  [{POST_SNAPBACK}][/a]


It's been ready for months

[a href="http://www.hydrogenaudio.org/forums/index.php?showtopic=29655]http://www.hydrogenaudio.org/forums/index....showtopic=29655[/url]

And I post at that thread whenever there is a modification to the first post.


@Bonzi: can I host your compile at RareWares?
[a href="index.php?act=findpost&pid=279729"][{POST_SNAPBACK}][/a]


Oh, that means I've been overlooking it! 
Thanks for setting things straight.

Open Source ALAC Decoder

Reply #17
Quote
Anybody have a MAC OS X binary of this yet for testing? I would but don't to know to make one.

I've uploaded a binary here.

Open Source ALAC Decoder

Reply #18
Quote
I've uploaded a binary here.
[a href="index.php?act=findpost&pid=279755"][{POST_SNAPBACK}][/a]


Sweet. Can I host it a RareWares?

Open Source ALAC Decoder

Reply #19
Quote
Sweet. Can I host it a RareWares?
[a href="index.php?act=findpost&pid=279762"][{POST_SNAPBACK}][/a]
Off course! 

Open Source ALAC Decoder

Reply #20
just got finished looking over the decoder source... first, that is one fantastic feat of reverse engineering.

second, ALAC does not resemble MPEG4-ALS, at least not the MPEG4-ALS I have read about.  some differences:

- ALAC transmits FIR coeffs directly w/linear quantization, ALS transmits arcsin transform of reflection coeffs
- ALAC adapts the FIR coeffs while ALS appears not to
- ALAC has more complicated stereo decorrelation
- ALAC adapts the rice parameter while coding the residual, ALS uses 1 or 4 fixed parameters per block.  ALS also has a mode which mixes rice and block codes
- ALAC has only 8 channels vs ALS' 256.

the ALAC design is similar to FLAC:

- first stage: optional interchannel decorrelation
- second stage: FIR interchannel decorrelation
- - (both have optional verbatim coding)
- - (both have optional fixed low-order predictors)
- third stage: residue coding with rice codes
- also, before second stage, FLAC has a 'wasted-bits' step which might have an ALAC analogue, it is hard to tell from the source

some differences:

1. interchannel decorrelation can use a linear combination of mid and side channels whereas FLAC computes only mid and side channels
2. ALAC FIR decorrelation adapts based on the sign of some measurement (have to look into that more)
3. rice parameter adapts, where FLAC uses precomputed parameters that are also transmitted

from those differences we can infer some things.  first, the decode complexity is higher that FLAC: there is an extra multiply per sample because of 1), 2) causes a few extra adds per sample times predictor order at least, and 3) is also more complex by an amount I haven't really quantified yet.  it is now clear also that the high decode speed on apple hardware is due to significant PPC optimization.

so it looks like apple did not make ALAC because FLAC's decode complexity was too high.

also, even with all these "improvements" the compression ratio of ALAC is similar to (but seems to average slightly lower) than FLAC.  so it wasn't made to blow FLAC out of the water on compression.

what's left?  either they just wanted something proprietary (well that didn't last long) or it has some unknown advantage on hi-res audio that isn't supported by the encoder yet.

Josh

 

Open Source ALAC Decoder

Reply #21
Do you think we will see software implementation (ie: foobar2000) anytime soon?

Is there a brave a kind soul here that could take care of that?
I'm the one in the picture, sitting on a giant cabbage in Mexico, circa 1978.
Reseñas de Rock en Español: www.estadogeneral.com

Open Source ALAC Decoder

Reply #22
Quote
Very nice new
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?
[{POST_SNAPBACK}][/a]
From [a href="http://ffmpeg.sourceforge.net/index.php]FFmpeg[/url]
Quote
(Mar 6, 2005) FFmpeg now includes a native decoder for Apple's Lossless Audio Codec (a.k.a. 'alac'). As usual, check out CVS.
Given the fact that FFDShow uses libavcodec, I would be surprised if a version of FFDShow supporting it were not available soon. Perhaps in FFDShow - Daily builds.

tec

p.s. guru: hilarious about it sounding differently.

Open Source ALAC Decoder

Reply #23
Quote
Quote
Very nice new
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?
[{POST_SNAPBACK}][/a]
From [a href="http://ffmpeg.sourceforge.net/index.php]FFmpeg[/url]
Quote
(Mar 6, 2005) FFmpeg now includes a native decoder for Apple's Lossless Audio Codec (a.k.a. 'alac'). As usual, check out CVS.
Given the fact that FFDShow uses libavcodec, I would be surprised if a version of FFDShow supporting it were not available soon. Perhaps in FFDShow - Daily builds.

tec

p.s. guru: hilarious about it sounding differently.
[a href="index.php?act=findpost&pid=279924"][{POST_SNAPBACK}][/a]

It would be nice if ffdshow can support it, but you need a mp4 parser that can "recognize" the ALAC.

Open Source ALAC Decoder

Reply #24
Quote
just got finished looking over the decoder source... first, that is one fantastic feat of reverse engineering.

(...)

so it looks like apple did not make ALAC because FLAC's decode complexity was too high.

also, even with all these "improvements" the compression ratio of ALAC is similar to (but seems to average slightly lower) than FLAC.  so it wasn't made to blow FLAC out of the water on compression.

what's left?  either they just wanted something proprietary (well that didn't last long) or it has some unknown advantage on hi-res audio that isn't supported by the encoder yet.

Josh
[a href="index.php?act=findpost&pid=279843"][{POST_SNAPBACK}][/a]
Very interesting feedback josh thanks...
Anyway the "unmotived" proprietary choice didn't surprised me too much from Apple...