Skip to content

Commit

Permalink
wavpack: add bits_per_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
drizzt committed May 5, 2020
1 parent 9642ddf commit 4c15df2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mutagen/wavpack.py
Expand Up @@ -78,6 +78,7 @@ class WavPackInfo(StreamInfo):
channels (int): number of audio channels (1 or 2)
length (float): file length in seconds, as a float
sample_rate (int): audio sampling rate in Hz
bits_per_sample (int): audio sample size
version (int): WavPack stream version
"""

Expand All @@ -90,10 +91,12 @@ def __init__(self, fileobj):
self.version = header.version
self.channels = bool(header.flags & 4) or 2
self.sample_rate = RATES[(header.flags >> 23) & 0xF]
self.bits_per_sample = ((header.flags & 3) + 1) * 8

# most common multiplier (DSD64)
if (header.flags >> 31) & 1:
self.sample_rate *= 4
self.bits_per_sample = 1

if header.total_samples == -1 or header.block_index != 0:
# TODO: we could make this faster by using the tag size
Expand Down
9 changes: 9 additions & 0 deletions tests/test_wavpack.py
Expand Up @@ -20,6 +20,9 @@ def test_channels(self):
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(self.audio.info.length, 3.68, 2)

Expand Down Expand Up @@ -48,6 +51,9 @@ def test_channels(self):
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(self.audio.info.length, 3.705, 3)

Expand All @@ -72,6 +78,9 @@ def test_channels(self):
def test_sample_rate(self):
self.failUnlessEqual(self.audio.info.sample_rate, 352800)

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

def test_length(self):
self.failUnlessAlmostEqual(self.audio.info.length, 0.01, 3)

Expand Down

0 comments on commit 4c15df2

Please sign in to comment.