IPB

Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
Open Source ALAC Decoder
Bonzi
post Mar 5 2005, 20:28
Post #1


A/V Moderator


Group: Members
Posts: 278
Joined: 22-February 03
Member No.: 5132



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.
Go to the top of the page
+Quote Post
jcoalson
post Mar 5 2005, 21:26
Post #2


FLAC Developer


Group: Developer
Posts: 1526
Joined: 27-February 02
Member No.: 1408



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
Go to the top of the page
+Quote Post
guruboolez
post Mar 5 2005, 22:34
Post #3





Group: Members (Donating)
Posts: 3474
Joined: 7-November 01
From: Strasbourg (France)
Member No.: 420



Very nice new smile.gif
I suppose that foobar2000, winamp or DirectShow filters are now possible. Am I right?
Go to the top of the page
+Quote Post
Bonzi
post Mar 5 2005, 22:50
Post #4


A/V Moderator


Group: Members
Posts: 278
Joined: 22-February 03
Member No.: 5132



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.
Go to the top of the page
+Quote Post
guruboolez
post Mar 6 2005, 00:09
Post #5





Group: Members (Donating)
Posts: 3474
Joined: 7-November 01
From: Strasbourg (France)
Member No.: 420



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.
Go to the top of the page
+Quote Post
rjamorim
post Mar 6 2005, 00:27
Post #6


Rarewares admin


Group: Members
Posts: 7515
Joined: 30-September 01
From: Brazil
Member No.: 81



ohmy.gif Amazing shit.

/me goes to change the lossless comparision table.


--------------------
Get up-to-date binaries of Lame, AAC, Vorbis and much more at RareWares:
http://www.rarewares.org
Go to the top of the page
+Quote Post
guest0101
post Mar 6 2005, 00:35
Post #7





Group: Banned
Posts: 446
Joined: 15-July 03
Member No.: 7789



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.
Go to the top of the page
+Quote Post
saratoga
post Mar 6 2005, 02:37
Post #8





Group: Members
Posts: 5042
Joined: 2-September 02
Member No.: 3264



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.
Go to the top of the page
+Quote Post
svkelley
post Mar 6 2005, 03:26
Post #9





Group: Members
Posts: 35
Joined: 27-April 04
Member No.: 13747



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
Go to the top of the page
+Quote Post
guest0101
post Mar 6 2005, 03:42
Post #10





Group: Banned
Posts: 446
Joined: 15-July 03
Member No.: 7789



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?

This post has been edited by guest0101: Mar 6 2005, 03:42
Go to the top of the page
+Quote Post
Dibrom
post Mar 6 2005, 04:00
Post #11


Founder


Group: Admin
Posts: 2958
Joined: 26-August 02
From: Nottingham, UK
Member No.: 1



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.
Go to the top of the page
+Quote Post
guest0101
post Mar 6 2005, 05:28
Post #12





Group: Banned
Posts: 446
Joined: 15-July 03
Member No.: 7789



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.
Go to the top of the page
+Quote Post
JEN
post Mar 6 2005, 09:55
Post #13





Group: Banned
Posts: 1131
Joined: 19-September 02
Member No.: 3407



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
Go to the top of the page
+Quote Post
ffooky
post Mar 6 2005, 12:56
Post #14





Group: Members
Posts: 261
Joined: 8-July 04
Member No.: 15184



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

This post has been edited by ffooky: Mar 6 2005, 13:04
Go to the top of the page
+Quote Post
Latexxx
post Mar 6 2005, 13:01
Post #15


A/V Moderator


Group: Members
Posts: 858
Joined: 12-May 03
From: Finland
Member No.: 6557



This hasn't been optimised in any way. So it isn't any kind of a surprise.
Go to the top of the page
+Quote Post
rjamorim
post Mar 6 2005, 16:09
Post #16


Rarewares admin


Group: Members
Posts: 7515
Joined: 30-September 01
From: Brazil
Member No.: 81



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

This post has been edited by rjamorim: Mar 6 2005, 16:25


--------------------
Get up-to-date binaries of Lame, AAC, Vorbis and much more at RareWares:
http://www.rarewares.org
Go to the top of the page
+Quote Post
JEN
post Mar 6 2005, 16:35
Post #17





Group: Banned
Posts: 1131
Joined: 19-September 02
Member No.: 3407



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
Go to the top of the page
+Quote Post
krmathis
post Mar 6 2005, 17:28
Post #18





Group: Members
Posts: 742
Joined: 27-May 02
From: Oslo, Norway
Member No.: 2133



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.
Go to the top of the page
+Quote Post
rjamorim
post Mar 6 2005, 17:34
Post #19


Rarewares admin


Group: Members
Posts: 7515
Joined: 30-September 01
From: Brazil
Member No.: 81



QUOTE (solaris @ Mar 6 2005, 01:28 PM)
I've uploaded a binary here.
*


Sweet. Can I host it a RareWares? smile.gif


--------------------
Get up-to-date binaries of Lame, AAC, Vorbis and much more at RareWares:
http://www.rarewares.org
Go to the top of the page
+Quote Post
krmathis
post Mar 6 2005, 18:08
Post #20





Group: Members
Posts: 742
Joined: 27-May 02
From: Oslo, Norway
Member No.: 2133



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

This post has been edited by solaris: Mar 6 2005, 18:08
Go to the top of the page
+Quote Post
jcoalson
post Mar 6 2005, 21:24
Post #21


FLAC Developer


Group: Developer
Posts: 1526
Joined: 27-February 02
Member No.: 1408



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
Go to the top of the page
+Quote Post
AtaqueEG
post Mar 6 2005, 21:53
Post #22





Group: Members (Donating)
Posts: 1336
Joined: 18-November 01
From: Celaya, Guanajuato
Member No.: 478



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
Go to the top of the page
+Quote Post
Tec9SD
post Mar 7 2005, 02:34
Post #23





Group: Members
Posts: 188
Joined: 21-June 03
From: S. East, U.S.
Member No.: 7317



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.
Go to the top of the page
+Quote Post
yong
post Mar 7 2005, 11:42
Post #24





Group: Members
Posts: 202
Joined: 9-July 04
From: Malaysia
Member No.: 15210



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


--------------------
http://foobar2000.xrea.jp/
Go to the top of the page
+Quote Post
Tang
post Mar 7 2005, 11:50
Post #25





Group: Members (Donating)
Posts: 158
Joined: 27-January 04
Member No.: 11536



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

This post has been edited by Tang: Mar 7 2005, 11:54
Go to the top of the page
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd October 2014 - 03:01