classification
Title: sndhdr.whathdr returns -1 for WAV file frame count
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, n, python-dev, r.david.murray, rpyle
Priority: normal Keywords: patch

Created on 2009-01-21 17:19 by rpyle, last changed 2013-03-18 21:46 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
issue5024.diff n, 2013-03-18 18:22 review
Messages (6)
msg80333 - (view) Author: Robert Pyle (rpyle) Date: 2009-01-21 17:19
Seems like test_wav() could easily return the actual frame count by 
calling wave.py just as test_aifc() uses aifc.py.
msg109638 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-08 22:52
Robert, could you provide a patch for this?
msg109752 - (view) Author: Robert Pyle (rpyle) Date: 2010-07-09 15:27
On Jul 8, 2010, at 6:52 PM, Mark Lawrence wrote:

>
> Mark Lawrence <breamoreboy@yahoo.co.uk> added the comment:
>
> Robert, could you provide a patch for this?
>
> ----------
> nosy: +BreamoreBoy
> stage:  -> needs patch
> versions: +Python 3.2
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue5024>
> _______________________________________

Okay, I'm not sure exactly how I'm supposed to go about this.  Here's  
the output from diff <new file> <original file> for sndhdr.py

131d130
<     import wave
135,141c134,138
<     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())
---
 >     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
$

All I did was use test_aifc() as inspiration, so the patched sndhdr.py  
calls wave.py to get the file parameters.

Here's the new test_wav() in its entirety:

--------------------------------
def test_wav(h, f):
     import wave
     # 'RIFF' <len> 'WAVE' 'fmt ' <len>
     if h[:4] != 'RIFF' or h[8:12] != 'WAVE' or h[12:16] != 'fmt ':
         return None
     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())
--------------------------------

If you want anything else, please ask.

Bob Pyle
msg184484 - (view) Author: Ned Jackson Lovely (n) * Date: 2013-03-18 18:22
Added bytes literal 'b', made it a real patch, changed test to account for WAV files actually returning number of frames from this function.
msg184530 - (view) Author: Roundup Robot (python-dev) Date: 2013-03-18 21:43
New changeset f972488c6b39 by R David Murray in branch 'default':
#5024: whichhdr now returns the frame count for WAV files.
http://hg.python.org/cpython/rev/f972488c6b39
msg184531 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-03-18 21:46
Thanks, Ned.
History
Date User Action Args
2013-03-18 21:46:34r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg184531

resolution: fixed
stage: needs patch -> resolved
2013-03-18 21:43:04python-devsetnosy: + python-dev
messages: + msg184530
2013-03-18 18:22:23nsetfiles: + issue5024.diff
versions: + Python 3.4, - Python 3.2
nosy: + n

messages: + msg184484

keywords: + patch
2010-07-09 15:27:42rpylesetmessages: + msg109752
2010-07-08 22:52:02BreamoreBoysetversions: + Python 3.2
nosy: + BreamoreBoy

messages: + msg109638

stage: needs patch
2009-01-21 17:19:42rpylecreate