Skip to content

Commit

Permalink
fixed ratecv to continue working if product of rates is bigger than 3…
Browse files Browse the repository at this point in the history
…2 bits

(Sjoerd)
  • Loading branch information
gvanrossum committed May 20, 1997
1 parent 511f163 commit b24c9ea
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Modules/audioop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit b24c9ea

Please sign in to comment.