[ python-Bugs-1512791 ] module wave does no rounding

SourceForge.net noreply at sourceforge.net
Mon Jun 26 17:16:36 CEST 2006


Bugs item #1512791, was opened at 2006-06-26 15:16
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1512791&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Kochanski (gpk)
Assigned to: Nobody/Anonymous (nobody)
Summary: module wave does no rounding

Initial Comment:
In wave.py, a floating point frame rate is truncated
(rather than rounded) in function _write_header().

Fractional frame rates are perfectly reasonable,
even if not normally seen in audio practice,
and the software ought to represent them as accurately
as possible.

Moreover, it's sometimes reasonable to store the
inverse of the frame rate, which is the time
interval between frames.   That's important
when you're doing signal processing, and some
data formats store 1.0/framerate rather than
framerate.

Anyhow, if you give setframerate() a float,
it truncates rather than rounding, so
dt = 1.0/44100
setframerate(1.0/dt)  can end up setting
the frame rate to 44099 Hz in the resulting
data file.

The fix is to change the last line of setframerate() to
self._framerate = int(round(framerate))
.
That also has the beneficial side-effect of giving
an earlier error report in case someone gives
the wrong type of object to setframerate()
(such as None, or "44100", or some class).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1512791&group_id=5470


More information about the Python-bugs-list mailing list