summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-20 15:59:35 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-20 15:59:35 (GMT)
commitb24c9ea51491e620f99b813cec1b015c968415bf (patch)
tree1dd620fe54b603b0b8a5e9e3353a0cb259d01408 /Modules
parent511f16357c7d206304d6f4a0864ecb3c947a8bf6 (diff)
downloadcpython-b24c9ea51491e620f99b813cec1b015c968415bf.zip
cpython-b24c9ea51491e620f99b813cec1b015c968415bf.tar.gz
cpython-b24c9ea51491e620f99b813cec1b015c968415bf.tar.bz2
fixed ratecv to continue working if product of rates is bigger than 32 bits
(Sjoerd)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/audioop.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 003f8af..471f851 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -945,6 +945,18 @@ audioop_lin2lin(self, args)
return rv;
}
+static int
+gcd(a, b)
+ int a, b;
+{
+ while (b > 0) {
+ int tmp = a % b;
+ a = b;
+ b = tmp;
+ }
+ return a;
+}
+
static PyObject *
audioop_ratecv(self, args)
PyObject *self;
@@ -977,6 +989,15 @@ audioop_ratecv(self, args)
PyErr_SetString(AudioopError, "not a whole number of frames");
return NULL;
}
+ if (inrate <= 0 || outrate <= 0) {
+ PyErr_SetString(AudioopError, "sampling rate not > 0");
+ return NULL;
+ }
+ /* divide inrate and outrate by their greatest common divisor */
+ d = gcd(inrate, outrate);
+ inrate /= d;
+ outrate /= d;
+
prev_i = malloc(nchannels * sizeof(int));
cur_i = malloc(nchannels * sizeof(int));
len /= size * nchannels; /* # of frames */