Commit 58c1ac90 authored by Mark Dickinson's avatar Mark Dickinson

Issue #1512791: In setframerate method of Wave_write, round non-integral

inputs to the nearest integer.  Thanks Neil Tallim for the patch.
parent b03e4f8e
...@@ -157,6 +157,10 @@ Wave_write objects, as returned by :func:`.open`, have the following methods: ...@@ -157,6 +157,10 @@ Wave_write objects, as returned by :func:`.open`, have the following methods:
Set the frame rate to *n*. Set the frame rate to *n*.
.. versionchanged:: 3.2
A non-integral input to this method is rounded to the nearest
integer.
.. method:: Wave_write.setnframes(n) .. method:: Wave_write.setnframes(n)
......
...@@ -22,11 +22,14 @@ class TestWave(unittest.TestCase): ...@@ -22,11 +22,14 @@ class TestWave(unittest.TestCase):
except OSError: except OSError:
pass pass
def test_it(self): def test_it(self, test_rounding=False):
self.f = wave.open(TESTFN, 'wb') self.f = wave.open(TESTFN, 'wb')
self.f.setnchannels(nchannels) self.f.setnchannels(nchannels)
self.f.setsampwidth(sampwidth) self.f.setsampwidth(sampwidth)
self.f.setframerate(framerate) if test_rounding:
self.f.setframerate(framerate - 0.1)
else:
self.f.setframerate(framerate)
self.f.setnframes(nframes) self.f.setnframes(nframes)
output = b'\0' * nframes * nchannels * sampwidth output = b'\0' * nframes * nchannels * sampwidth
self.f.writeframes(output) self.f.writeframes(output)
...@@ -39,6 +42,13 @@ class TestWave(unittest.TestCase): ...@@ -39,6 +42,13 @@ class TestWave(unittest.TestCase):
self.assertEqual(nframes, self.f.getnframes()) self.assertEqual(nframes, self.f.getnframes())
self.assertEqual(self.f.readframes(nframes), output) self.assertEqual(self.f.readframes(nframes), output)
def test_fractional_framerate(self):
"""
Addresses [ 1512791 ] module wave does no rounding
Floating point framerates should be rounded, rather than truncated.
"""
self.test_it(test_rounding=True)
def test_issue7681(self): def test_issue7681(self):
self.f = wave.open(TESTFN, 'wb') self.f = wave.open(TESTFN, 'wb')
self.f.setnchannels(nchannels) self.f.setnchannels(nchannels)
......
...@@ -355,7 +355,7 @@ class Wave_write: ...@@ -355,7 +355,7 @@ class Wave_write:
raise Error('cannot change parameters after starting to write') raise Error('cannot change parameters after starting to write')
if framerate <= 0: if framerate <= 0:
raise Error('bad frame rate') raise Error('bad frame rate')
self._framerate = framerate self._framerate = int(round(framerate))
def getframerate(self): def getframerate(self):
if not self._framerate: if not self._framerate:
......
...@@ -792,6 +792,7 @@ Paul Swartz ...@@ -792,6 +792,7 @@ Paul Swartz
Thenault Sylvain Thenault Sylvain
Péter Szabó Péter Szabó
Arfrever Frehtes Taifersar Arahesis Arfrever Frehtes Taifersar Arahesis
Neil Tallim
Geoff Talvola Geoff Talvola
Musashi Tamura Musashi Tamura
William Tanksley William Tanksley
......
...@@ -132,6 +132,9 @@ Extensions ...@@ -132,6 +132,9 @@ Extensions
Library Library
------- -------
- Issue #1512791: In setframerate() in the wave module, non-integral
frame rates are rounded to the nearest integer.
- Issue #8797: urllib2 does a retry for Basic Authentication failure instead of - Issue #8797: urllib2 does a retry for Basic Authentication failure instead of
falling into recursion. falling into recursion.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment