summaryrefslogtreecommitdiffstats
path: root/Modules/audioop.c
diff options
context:
space:
mode:
authorSjoerd Mullender <sjoerd@acm.org>1994-09-06 16:19:33 (GMT)
committerSjoerd Mullender <sjoerd@acm.org>1994-09-06 16:19:33 (GMT)
commita1426136786711bae9a5a576a0e4fbf27979cac9 (patch)
tree7e4e4376376136db8b919b22aebeb82a30fc43e2 /Modules/audioop.c
parente202c38d76d2d3946fc16baa9f6e536871779802 (diff)
downloadcpython-a1426136786711bae9a5a576a0e4fbf27979cac9.zip
cpython-a1426136786711bae9a5a576a0e4fbf27979cac9.tar.gz
cpython-a1426136786711bae9a5a576a0e4fbf27979cac9.tar.bz2
Added minmax function.
Diffstat (limited to 'Modules/audioop.c')
-rw-r--r--Modules/audioop.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index d4e020b..e3297a3 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -217,6 +217,32 @@ audioop_max(self, args)
}
static object *
+audioop_minmax(self, args)
+ object *self;
+ object *args;
+{
+ signed char *cp;
+ int len, size, val;
+ int i;
+ int min = 0x7fffffff, max = -0x7fffffff;
+
+ if (!getargs(args, "(s#i)", &cp, &len, &size))
+ return NULL;
+ if (size != 1 && size != 2 && size != 4) {
+ err_setstr(AudioopError, "Size should be 1, 2 or 4");
+ return NULL;
+ }
+ for (i = 0; i < len; i += size) {
+ if (size == 1) val = (int) *CHARP(cp, i);
+ else if (size == 2) val = (int) *SHORTP(cp, i);
+ else if (size == 4) val = (int) *LONGP(cp, i);
+ if (val > max) max = val;
+ if (val < min) min = val;
+ }
+ return mkvalue("(ii)", min, max);
+}
+
+static object *
audioop_avg(self, args)
object *self;
object *args;
@@ -1178,6 +1204,7 @@ audioop_adpcm2lin(self, args)
static struct methodlist audioop_methods[] = {
{ "max", audioop_max },
+ { "minmax", audioop_minmax },
{ "avg", audioop_avg },
{ "maxpp", audioop_maxpp },
{ "avgpp", audioop_avgpp },