[Python-checkins] cpython: #5024: whichhdr now returns the frame count for WAV files.

r.david.murray python-checkins at python.org
Mon Mar 18 22:43:05 CET 2013


http://hg.python.org/cpython/rev/f972488c6b39
changeset: 82736:f972488c6b39
user: R David Murray <rdmurray at bitdance.com>
date: Mon Mar 18 17:42:42 2013 -0400
summary:
 #5024: whichhdr now returns the frame count for WAV files.
Patch by Ned Jackson Lovely based on a suggestion by Robert Pyle.
files:
 Lib/sndhdr.py | 13 ++++++++-----
 Lib/test/test_sndhdr.py | 2 +-
 Misc/ACKS | 1 +
 Misc/NEWS | 3 +++
 4 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/Lib/sndhdr.py b/Lib/sndhdr.py
--- a/Lib/sndhdr.py
+++ b/Lib/sndhdr.py
@@ -137,14 +137,17 @@
 
 
 def test_wav(h, f):
+ import wave
 # 'RIFF' <len> 'WAVE' 'fmt ' <len>
 if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ':
 return None
- style = get_short_le(h[20:22])
- nchannels = get_short_le(h[22:24])
- rate = get_long_le(h[24:28])
- sample_bits = get_short_le(h[34:36])
- return 'wav', rate, nchannels, -1, sample_bits
+ f.seek(0)
+ try:
+ w = wave.openfp(f, 'r')
+ except (EOFError, wave.Error):
+ return None
+ return ('wav', w.getframerate(), w.getnchannels(),
+ w.getnframes(), 8*w.getsampwidth())
 
 tests.append(test_wav)
 
diff --git a/Lib/test/test_sndhdr.py b/Lib/test/test_sndhdr.py
--- a/Lib/test/test_sndhdr.py
+++ b/Lib/test/test_sndhdr.py
@@ -12,7 +12,7 @@
 ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)),
 ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)),
 ('sndhdr.voc', ('voc', 0, 1, -1, 8)),
- ('sndhdr.wav', ('wav', 44100, 2, -1, 16)),
+ ('sndhdr.wav', ('wav', 44100, 2, 5, 16)),
 ):
 filename = findfile(filename, subdir="sndhdrdata")
 what = sndhdr.what(filename)
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -746,6 +746,7 @@
 Anne Lord
 Tom Loredo
 Justin Love
+Ned Jackson Lovely
 Jason Lowe
 Tony Lownds
 Ray Loyzaga
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -287,6 +287,9 @@
 Library
 -------
 
+- Issue #5024: sndhdr.whichhdr now returns the frame count for WAV files
+ rather than -1.
+
 - Issue #17460: Remove the strict argument of HTTPConnection and removing the
 DeprecationWarning being issued from 3.2 onwards.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /