Skip to content
Permalink
Browse files

Read audio info from ALAC files (#199)

The same container metadata is present on ALAC files as is on AAC files. This
populates channels, sample_rate, bits_per_sample, and length. Like most
lossless formats in Mutagen, it does *not* populate bitrate.
  • Loading branch information
sampsyo committed Oct 26, 2014
1 parent 50d0fd1 commit 192cfcaf14a74d74c72a7edc4bee0c7ffddf7bd9
Showing with 23 additions and 1 deletion.
  1. +1 −1 mutagen/mp4.py
  2. BIN tests/data/alac.m4a
  3. +22 −0 tests/test_mp4.py
@@ -1007,7 +1007,7 @@ def __init__(self, atoms, fileobj):
atom = trak[b"mdia", b"minf", b"stbl", b"stsd"]
fileobj.seek(atom.offset)
data = fileobj.read(atom.length)
if data[20:24] == b"mp4a":
if data[20:24] in (b"mp4a", b"alac"):
length = cdata.uint_be(data[16:20])
(self.channels, self.bits_per_sample, _,
self.sample_rate) = struct.unpack(">3HI", data[40:50])
BIN +9.25 KB tests/data/alac.m4a
Binary file not shown.
@@ -868,6 +868,28 @@ def tearDown(self):

add(TMP4UpdateParents64Bit)


class TMP4ALAC(TestCase):
original = os.path.join("tests", "data", "alac.m4a")

def setUp(self):
self.audio = MP4(self.original)

def test_channels(self):
self.failUnlessEqual(self.audio.info.channels, 2)

def test_sample_rate(self):
self.failUnlessEqual(self.audio.info.sample_rate, 44100)

def test_bits_per_sample(self):
self.failUnlessEqual(self.audio.info.bits_per_sample, 16)

def test_length(self):
self.failUnlessAlmostEqual(3.7, self.audio.info.length, 1)

add(TMP4ALAC)


NOTFOUND = os.system("tools/notarealprogram 2> %s" % devnull)

have_faad = True

0 comments on commit 192cfca

Please sign in to comment.
You can’t perform that action at this time.