]> granicus.if.org Git - python/commitdiff
Issue #24326: Fixed audioop.ratecv() with non-default weightB argument.
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 29 May 2015 21:53:26 +0000 (00:53 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 29 May 2015 21:53:26 +0000 (00:53 +0300)
Original patch by David Moore.

Lib/test/test_audioop.py
Misc/NEWS
Modules/audioop.c

index 879adea2b8eb295a9992d5ed8873688207879453..01ed18d1c107a65b55c6b2c056c160b69872ab12 100644 (file)
@@ -363,6 +363,9 @@ class TestAudioop(unittest.TestCase):
                              (b'', (-2, ((0, 0),))))
             self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None)[0],
                              datas[w])
+            self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 1, 0)[0],
+                             datas[w])
+
         state = None
         d1, state = audioop.ratecv(b'\x00\x01\x02', 1, 1, 8000, 16000, state)
         d2, state = audioop.ratecv(b'\x00\x01\x02', 1, 1, 8000, 16000, state)
@@ -378,6 +381,20 @@ class TestAudioop(unittest.TestCase):
             self.assertEqual(d, d0)
             self.assertEqual(state, state0)
 
+        expected = {
+            1: packs[1](0, 0x0d, 0x37, -0x26, 0x55, -0x4b, -0x14),
+            2: packs[2](0, 0x0da7, 0x3777, -0x2630, 0x5673, -0x4a64, -0x129a),
+            3: packs[3](0, 0x0da740, 0x377776, -0x262fca,
+                        0x56740c, -0x4a62fd, -0x1298c0),
+            4: packs[4](0, 0x0da740da, 0x37777776, -0x262fc962,
+                        0x56740da6, -0x4a62fc96, -0x1298bf26),
+        }
+        for w in 1, 2, 3, 4:
+            self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 3, 1)[0],
+                             expected[w])
+            self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 30, 10)[0],
+                             expected[w])
+
     def test_reverse(self):
         for w in 1, 2, 3, 4:
             self.assertEqual(audioop.reverse(b'', w), b'')
index 76580093f3034c83e09eee22b72cb70af26a2ad3..e4e5064a4e665c4f88bc20d382b91eb064c1d031 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -56,6 +56,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #24326: Fixed audioop.ratecv() with non-default weightB argument.
+  Original patch by David Moore.
+
 - Issue #23840: tokenize.open() now closes the temporary binary file on error
   to fix a resource warning.
 
index 2d287f249b4afd4569899ba8a8483f0e310153e6..0358147f92a4c94bdd1814925d35e5b35a22e171 100644 (file)
@@ -1320,7 +1320,7 @@ audioop_ratecv_impl(PyModuleDef *module, Py_buffer *fragment, int width, int nch
     /* divide weightA and weightB by their greatest common divisor */
     d = gcd(weightA, weightB);
     weightA /= d;
-    weightA /= d;
+    weightB /= d;
 
     if ((size_t)nchannels > PY_SIZE_MAX/sizeof(int)) {
         PyErr_SetString(PyExc_MemoryError,