summaryrefslogtreecommitdiffstats
path: root/Modules/audioop.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/audioop.c')
-rw-r--r--Modules/audioop.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 1e131d2..3f31a2b 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -5,8 +5,6 @@
#include "Python.h"
-typedef short PyInt16;
-
#if defined(__CHAR_UNSIGNED__)
#if defined(signed)
/* This module currently does not work on systems where only unsigned
@@ -51,13 +49,15 @@ fbound(double val, double minval, double maxval)
#define SEG_SHIFT (4) /* Left shift for segment number. */
#define SEG_MASK (0x70) /* Segment field mask. */
-static PyInt16 seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF,
- 0x1FF, 0x3FF, 0x7FF, 0xFFF};
-static PyInt16 seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF,
- 0x3FF, 0x7FF, 0xFFF, 0x1FFF};
+static const int16_t seg_aend[8] = {
+ 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
+};
+static const int16_t seg_uend[8] = {
+ 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF
+};
-static PyInt16
-search(PyInt16 val, PyInt16 *table, int size)
+static int16_t
+search(int16_t val, const int16_t *table, int size)
{
int i;
@@ -70,7 +70,7 @@ search(PyInt16 val, PyInt16 *table, int size)
#define st_ulaw2linear16(uc) (_st_ulaw2linear16[uc])
#define st_alaw2linear16(uc) (_st_alaw2linear16[uc])
-static PyInt16 _st_ulaw2linear16[256] = {
+static const int16_t _st_ulaw2linear16[256] = {
-32124, -31100, -30076, -29052, -28028, -27004, -25980,
-24956, -23932, -22908, -21884, -20860, -19836, -18812,
-17788, -16764, -15996, -15484, -14972, -14460, -13948,
@@ -143,10 +143,10 @@ static PyInt16 _st_ulaw2linear16[256] = {
* John Wiley & Sons, pps 98-111 and 472-476.
*/
static unsigned char
-st_14linear2ulaw(PyInt16 pcm_val) /* 2's complement (14-bit range) */
+st_14linear2ulaw(int16_t pcm_val) /* 2's complement (14-bit range) */
{
- PyInt16 mask;
- PyInt16 seg;
+ int16_t mask;
+ int16_t seg;
unsigned char uval;
/* u-law inverts all bits */
@@ -176,7 +176,7 @@ st_14linear2ulaw(PyInt16 pcm_val) /* 2's complement (14-bit range) */
}
-static PyInt16 _st_alaw2linear16[256] = {
+static const int16_t _st_alaw2linear16[256] = {
-5504, -5248, -6016, -5760, -4480, -4224, -4992,
-4736, -7552, -7296, -8064, -7808, -6528, -6272,
-7040, -6784, -2752, -2624, -3008, -2880, -2240,
@@ -237,9 +237,9 @@ static PyInt16 _st_alaw2linear16[256] = {
* John Wiley & Sons, pps 98-111 and 472-476.
*/
static unsigned char
-st_linear2alaw(PyInt16 pcm_val) /* 2's complement (13-bit range) */
+st_linear2alaw(int16_t pcm_val) /* 2's complement (13-bit range) */
{
- PyInt16 mask;
+ int16_t mask;
short seg;
unsigned char aval;
@@ -270,12 +270,12 @@ st_linear2alaw(PyInt16 pcm_val) /* 2's complement (13-bit range) */
/* End of code taken from sox */
/* Intel ADPCM step variation table */
-static int indexTable[16] = {
+static const int indexTable[16] = {
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8,
};
-static int stepsizeTable[89] = {
+static const int stepsizeTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
@@ -295,7 +295,7 @@ static int stepsizeTable[89] = {
#define GETINT8(cp, i) GETINTX(signed char, (cp), (i))
#define GETINT16(cp, i) GETINTX(short, (cp), (i))
-#define GETINT32(cp, i) GETINTX(PY_INT32_T, (cp), (i))
+#define GETINT32(cp, i) GETINTX(int32_t, (cp), (i))
#if WORDS_BIGENDIAN
#define GETINT24(cp, i) ( \
@@ -312,7 +312,7 @@ static int stepsizeTable[89] = {
#define SETINT8(cp, i, val) SETINTX(signed char, (cp), (i), (val))
#define SETINT16(cp, i, val) SETINTX(short, (cp), (i), (val))
-#define SETINT32(cp, i, val) SETINTX(PY_INT32_T, (cp), (i), (val))
+#define SETINT32(cp, i, val) SETINTX(int32_t, (cp), (i), (val))
#if WORDS_BIGENDIAN
#define SETINT24(cp, i, val) do { \
@@ -444,7 +444,9 @@ audioop_max_impl(PyObject *module, Py_buffer *fragment, int width)
return NULL;
for (i = 0; i < fragment->len; i += width) {
int val = GETRAWSAMPLE(width, fragment->buf, i);
- if (val < 0) absval = (-val);
+ /* Cast to unsigned before negating. Unsigned overflow is well-
+ defined, but signed overflow is not. */
+ if (val < 0) absval = (unsigned int)-(int64_t)val;
else absval = val;
if (absval > max) max = absval;
}
@@ -1125,7 +1127,7 @@ audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias)
val = ((unsigned int)GETINT24(fragment->buf, i)) & 0xffffffu;
else {
assert(width == 4);
- val = GETINTX(PY_UINT32_T, fragment->buf, i);
+ val = GETINTX(uint32_t, fragment->buf, i);
}
val += (unsigned int)bias;
@@ -1140,7 +1142,7 @@ audioop_bias_impl(PyObject *module, Py_buffer *fragment, int width, int bias)
SETINT24(ncp, i, (int)val);
else {
assert(width == 4);
- SETINTX(PY_UINT32_T, ncp, i, val);
+ SETINTX(uint32_t, ncp, i, val);
}
}
return rv;
@@ -1332,7 +1334,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
weightA /= d;
weightB /= d;
- if ((size_t)nchannels > PY_SIZE_MAX/sizeof(int)) {
+ if ((size_t)nchannels > SIZE_MAX/sizeof(int)) {
PyErr_SetString(PyExc_MemoryError,
"not enough memory for output buffer");
return NULL;