Help - Search - Members - Calendar
Full Version: Open Source ALAC Decoder
Hydrogenaudio Forums > Hydrogenaudio Forum > Validated News
Bonzi
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.
jcoalson
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
guruboolez
Very nice new smile.gif
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?
Bonzi
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.
guruboolez
QUOTE(Bonzi @ Mar 5 2005, 10:50 PM)
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.
*



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

I did a bit-to-bit comparison, and foobar2000's conclusions are:
CODE
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.
rjamorim
ohmy.gif Amazing shit.

/me goes to change the lossless comparision table.
guest0101
QUOTE(rjamorim @ Mar 5 2005, 04:27 PM)
ohmy.gif  Amazing shit.

/me goes to change the lossless comparision table.
*



Anybody have a MAC OS X binary of this yet for testing? I would but don't to know to make one.
Mike Giacomelli
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.
svkelley
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
guest0101
QUOTE(Mike Giacomelli @ Mar 5 2005, 06:37 PM)
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.
*



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?
Dibrom
QUOTE(guest0101 @ Mar 5 2005, 06:42 PM)
QUOTE(Mike Giacomelli @ Mar 5 2005, 06:37 PM)
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.
*



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?
*



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.
guest0101
QUOTE(Dibrom @ Mar 5 2005, 08:00 PM)

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



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.
JEN
QUOTE(rjamorim @ Mar 6 2005, 12:27 AM)
ohmy.gif  Amazing shit.

/me goes to change the lossless comparision table.
*



Hi

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

Thanks
ffooky
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
Latexxx
This hasn't been optimised in any way. So it isn't any kind of a surprise.
rjamorim
QUOTE(JEN @ Mar 6 2005, 05:55 AM)
When will this comparision table be ready?  Will you let us know when its been modifies. 
*



It's been ready for months smile.gif

http://www.hydrogenaudio.org/forums/index....showtopic=29655

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


@Bonzi: can I host your compile at RareWares? smile.gif
JEN
QUOTE(rjamorim @ Mar 6 2005, 04:09 PM)
QUOTE(JEN @ Mar 6 2005, 05:55 AM)
When will this comparision table be ready?  Will you let us know when its been modifies. 
*



It's been ready for months smile.gif

http://www.hydrogenaudio.org/forums/index....showtopic=29655

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


@Bonzi: can I host your compile at RareWares? smile.gif
*



Oh, that means I've been overlooking it! blush.gif
Thanks for setting things straight. biggrin.gif
krmathis
QUOTE(guest0101 @ Mar 6 2005, 12:35 AM)
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.
rjamorim
QUOTE(solaris @ Mar 6 2005, 01:28 PM)
I've uploaded a binary here.
*



Sweet. Can I host it a RareWares? smile.gif
krmathis
QUOTE(rjamorim @ Mar 6 2005, 05:34 PM)
Sweet. Can I host it a RareWares? smile.gif
*

Off course! smile.gif
jcoalson
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
AtaqueEG
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?
Tec9SD
QUOTE(guruboolez @ Mar 5 2005, 04:34 PM)
Very nice new smile.gif
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?
*
From FFmpeg
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.
yong
QUOTE(Tec9SD @ Mar 7 2005, 09:34 AM)
QUOTE(guruboolez @ Mar 5 2005, 04:34 PM)
Very nice new smile.gif
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?
*
From FFmpeg
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.
*


It would be nice if ffdshow can support it, but you need a mp4 parser that can "recognize" the ALAC. smile.gif
Tang
QUOTE(jcoalson @ Mar 6 2005, 12:24 PM)
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
*

Very interesting feedback josh thanks...
Anyway the "unmotived" proprietary choice didn't surprised me too much from Apple... wink.gif
Busemann
QUOTE(jcoalson @ Mar 6 2005, 12:24 PM)
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.


Well, we already know that it will support 24bit multichannel encoding in QT 7..
guest0101
Well it appears that news sources are quoting/metioning this particular thread here on HA and the Slashdot article about this new open source ALAC decoder. Very interesting to see this getting picked up in the computer news sites:

MacObserver.com article:
http://www.macobserver.com/article/2005/03/07.2.shtml
jcoalson
QUOTE(Busemann @ Mar 7 2005, 06:43 AM)
Well, we already know that it will support 24bit multichannel encoding in QT 7..
*

FLAC has 24bit multichannel too, but the question is whether ALAC's compression will be significantly better. have to wait and see.

Josh
guest0101
Uh, oh, now the news outlets just released a story portraying this Apple Lossless decoder as "Cracking iTunes". I can't believe it. You'd think he was breaking .m4p DRM or something.

Article: Developer cracks iTunes encoding format

http://www.pcpro.co.uk/news/70103/develope...ing-format.html

also

a story on MacDailyNews.com:
http://macdailynews.com/index.php/weblog/comments/5171/
xmixahlx
this wasn't not mentioned here, and i thought it should be...

the developer does amazing work, also writing libopendaap + tunesbrowser:
http://craz.net/programs/itunes/


later
yong
Did someone know?
Mplayer(Daily CVS version) now is able to playback ALAC, smile.gif
but still have bug(audio distorsion) haven't fix yet tongue.gif

EDIT:Sorry, the mplayer i used is outdated...(20050322),
May be this bug already fixed at new daily cvs version.shifty.gif
keytotime
Could somebody please compile the latest version found at http://craz.net/programs/itunes/alac.html.
kurtnoise
For windows I guess ?

http://kurtnoise.free.fr/index.php?dir=mp4...coder-0.1.3.zip or here.
john33
Updated Win32 compiles at Rarewares Lossless page now. smile.gif
keytotime
Wow That was Fast. Thank You.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.