Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wavpack: add bits_per_sample #467

Merged
merged 1 commit into from May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
lazka marked this conversation as resolved.
Show resolved Hide resolved

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