Apple Lossless Audio Coding: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
No edit summary
(link to recently open sourced codec)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
* FOURCCS: alac
* FOURCCS: alac
* Company: [[Apple]]
* Company: [[Apple]]
* Technical Description: [http://craz.net/programs/itunes/alac.html http://craz.net/programs/itunes/alac.html]
* Technical Description: http://craz.net/programs/itunes/alac.html
* Samples: http://samples.mplayerhq.hu/A-codecs/lossless/ (luckynight.m4a)


Lossless audio coding using linear prediction with Golomb-Rice coding of the difference.  Similar to FLAC, although the bitstreams are not compatible.  Usually stored in an [[Apple QuickTime|MP4]] container, as a private extension since it is not part of the MPEG-4 standard.
Apple Lossless Audio Coding using linear prediction with [[Golomb|Golomb-Rice]] coding of the difference.  Similar to FLAC, although the bitstreams are not compatible.  Usually stored in an [[MP4]] container, as a private extension since it is not part of the MPEG-4 standard.
 
On October 27, 2011, ALAC was open sourced under the Apache License 2.0. The source can be found at [http://alac.macosforge.org/ http://alac.macosforge.org/].
 
=== Extradata ===
 
{| border="1"
! Syntax !! Number of bits !! Semantics
|-
|atom size || 32 || (0x24), big-endian
|-
|tag || 32 || 'alac'
|-
|??? || 32 || zero ?
|-
|max sample per frame || 32 ||
|-
|??? || 8 || zero ?
|-
|sample size || 8 ||
|-
|rice history mult || 8 ||
|-
|rice initial history || 8 ||
|-
|rice kmodifier || 8 ||
|-
|channels || 8 || ?
|-
|??? || 16 ||
|-
|max coded frame size || 32 ||
|-
|bitrate || 32 || ?
|-
|samplerate || 32 ||
|}


=== Frame Header ===
=== Frame Header ===
Line 11: Line 48:
| channels || 3 || Number of channel -1 (Should be the same than in extradata ???)
| channels || 3 || Number of channel -1 (Should be the same than in extradata ???)
|-
|-
| ??? || 4 || ???
| ??? || 4 || ??? (seem to be always 0)
|-
|-
| ??? || 12 || ???
| ??? || 12 || ??? (seem to be always 0)
|-
|-
| hasoutputsamples || 1 || the number of samples is stored in the header
| hasoutputsamples || 1 || the number of samples is stored in the header
Line 21: Line 58:
| isverbatim || 1 || if 1, the data is not compressed
| isverbatim || 1 || if 1, the data is not compressed
|-
|-
| if (hassize) { || ||
| if (hasoutputsamples) { || ||
|-
|-
| outputsamples || 32 || number of samples
| outputsamples || 32 || number of samples (sometimes the value is wrong [1])
|-
|-
| } || ||
| } || ||
|}
|}
[1]  http://www1.mplayerhq.hu/MPlayer/samples/A-codecs/lossless/luckynight.m4a need + 32 and http://www1.mplayerhq.hu/MPlayer/samples/A-codecs/lossless/ALAC/old_midi_stuff.m4a + 112


=== Verbatim frame ===
=== Verbatim frame ===
Line 39: Line 79:
! Syntax !! Number of bits !! Semantics
! Syntax !! Number of bits !! Semantics
|-
|-
| interlacing_shift || 8 || 0 if no channel interlacing.  
| interlacing_shift || 8 || should be 0 if no channel interlacing.  
|-
|-
| interlacing_leftweight || 8 ||
| interlacing_leftweight || 8 ||
Line 55: Line 95:
| predictor_coef_table || 16 * predictor_coef_num ||
| predictor_coef_table || 16 * predictor_coef_num ||
|-
|-
| bastardized_rice_decompressed data || ||
| }
|-
| for each channel {
|-
| compressed data || || modfied Rice coding and Adaptive FIR filter
|-
|-
| }
| }
Line 67: Line 111:
:''right = mid - ((difference * interlacing_leftweight) >> interlacing_shift)''
:''right = mid - ((difference * interlacing_leftweight) >> interlacing_shift)''
:''left = right + difference''
:''left = right + difference''
It seems we have interlacing_leftweight == interlacing_shift in most of the samples
=== Frame Footer ===
{| border="1"
! Syntax !! Number of bits !! Semantics
|-
| EOF || 3 || should be always 7
|}


[[Category:Lossless Audio Codecs]]
[[Category:Lossless Audio Codecs]]
[[Category:Audio Codecs]]
[[Category:Audio Codecs]]

Latest revision as of 18:08, 27 October 2011

Apple Lossless Audio Coding using linear prediction with Golomb-Rice coding of the difference. Similar to FLAC, although the bitstreams are not compatible. Usually stored in an MP4 container, as a private extension since it is not part of the MPEG-4 standard.

On October 27, 2011, ALAC was open sourced under the Apache License 2.0. The source can be found at http://alac.macosforge.org/.

Extradata

Syntax Number of bits Semantics
atom size 32 (0x24), big-endian
tag 32 'alac'
??? 32 zero ?
max sample per frame 32
??? 8 zero ?
sample size 8
rice history mult 8
rice initial history 8
rice kmodifier 8
channels 8 ?
??? 16
max coded frame size 32
bitrate 32 ?
samplerate 32

Frame Header

Syntax Number of bits Semantics
channels 3 Number of channel -1 (Should be the same than in extradata ???)
??? 4 ??? (seem to be always 0)
??? 12 ??? (seem to be always 0)
hasoutputsamples 1 the number of samples is stored in the header
wasted_bytes 2 unknow (same as flac ???)
isverbatim 1 if 1, the data is not compressed
if (hasoutputsamples) {
outputsamples 32 number of samples (sometimes the value is wrong [1])
}


[1] http://www1.mplayerhq.hu/MPlayer/samples/A-codecs/lossless/luckynight.m4a need + 32 and http://www1.mplayerhq.hu/MPlayer/samples/A-codecs/lossless/ALAC/old_midi_stuff.m4a + 112

Verbatim frame

Syntax Number of bits Semantics
data sample_size * outputsamples * channels Unencoded subblock

Compressed frame

Syntax Number of bits Semantics
interlacing_shift 8 should be 0 if no channel interlacing.
interlacing_leftweight 8
for each channel {
prediction_type 4 should be 0
prediction_quantitization 4
ricemodifier 3
predictor_coef_num 5
predictor_coef_table 16 * predictor_coef_num
}
for each channel {
compressed data modfied Rice coding and Adaptive FIR filter
}

Channel Interlacing

It is a mid/side stereo with weight. channel 0 is the mid(average) channel, channel 1 is the side(difference) channel.

right = mid - ((difference * interlacing_leftweight) >> interlacing_shift)
left = right + difference

It seems we have interlacing_leftweight == interlacing_shift in most of the samples

Frame Footer

Syntax Number of bits Semantics
EOF 3 should be always 7