ref: 1f2d58df2e13fcfc5cf5c75ed461fddbe39a0259
parent: f6b38c5d8016b695cfb21a11852542d0bf68f400
author: cbagwell <cbagwell>
date: Tue Oct 26 10:51:50 EDT 1999
*** empty log message ***
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -45,8 +45,9 @@
g723_24.c g723_40.c g72x.c gsm.c hcom.c maud.c raw.c \
sbdsp.c sf.c smp.c sndrtool.c tx16w.c voc.c wav.c wve.c
-ESRC = avg.c band.c chorus.c compand.c copy.c cut.c deemphas.c dyn.c echo.c \
- echos.c flanger.c highp.c lowp.c map.c mask.c phaser.c pick.c \
+ESRC = avg.c band.c bandpass.c breject.c btrworth.c chorus.c compand.c \
+ copy.c cut.c deemphas.c dyn.c echo.c echos.c flanger.c highp.c \
+ highpass.c lowp.c lowpass.c map.c mask.c phaser.c pick.c \
polyphas.c rate.c resample.c reverb.c reverse.c split.c \
stat.c swap.c vibro.c
@@ -66,8 +67,9 @@
g723_24.o g723_40.o g72x.o gsm.o hcom.o maud.o raw.o \
sbdsp.o sf.o smp.o sndrtool.o tx16w.o voc.o wav.o wve.o
-EOBJ = avg.o band.o chorus.o compand.o copy.o cut.o deemphas.o dyn.o echo.o \
- echos.o flanger.o highp.o lowp.o map.o mask.o phaser.o pick.o \
+EOBJ = avg.o band.o bandpass.o breject.o btrworth.o chorus.o compand.o \
+ copy.o cut.o deemphas.o dyn.o echo.o echos.c flanger.o highp.o \
+ highpass.o lowp.o lowpass.o map.o mask.o phaser.o pick.o \
polyphas.o rate.o resample.o reverb.o reverse.o split.o \
stat.o swap.o vibro.o
--- a/src/avr.c
+++ b/src/avr.c
@@ -1,6 +1,6 @@
/*
- AVR file format driver for SOX
+ AVR file format driver for SoX
Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
This source code is free software; you can redistribute it and/or modify
@@ -270,6 +270,8 @@
avr_t avr = (avr_t)ft->priv;
int size = avr->size / ft->info.channels;
+
+ rawstopwrite(ft);
/* Fix size */
fseek (ft->fp, 26L, SEEK_SET);
--- a/src/band.c
+++ b/src/band.c
@@ -30,6 +30,17 @@
* cBW is the band width in Hertz
* cSCL is a scale factor, use 1 for pitched sounds
* use 2 for noise.
+ *
+ *
+ * July 1, 1999 - Jan Paul Schmidt <jps@fundament.org>
+ *
+ * This looks like the resonator band pass in SPKit. It's a
+ * second order all-pole (IIR) band-pass filter described
+ * at the pages 186 - 189 in
+ * Dodge, Charles & Jerse, Thomas A. 1985:
+ * Computer Music -- Synthesis, Composition and Performance.
+ * New York: Schirmer Books.
+ * Reference from the SPKit manual.
*/
#include <math.h>
--- /dev/null
+++ b/src/bandpass.c
@@ -1,0 +1,84 @@
+/*
+
+ Band-pass effect file for SoX
+ Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+
+ This source code is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This source code is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Code based on the band-pass implementation in
+
+ Sound Processing Kit - A C++ Class Library for Audio Signal Processing
+ Copyright (C) 1995-1998 Kai Lassfolk
+
+ as described in
+
+ Computer music: synthesis, composition, and performance
+ Charles Dodge, Thomas A. Jerse
+ [2nd ed.]
+ Page 216
+
+ */
+
+#include <math.h>
+
+#include "st.h"
+#include "btrworth.h"
+
+
+
+void
+bandpass_getopts (effp, n, argv)
+eff_t effp;
+int n;
+char **argv;
+{
+ butterworth_t butterworth = (butterworth_t)effp->priv;
+
+ if (n != 2) {
+ fail("Usage: bandpass FREQUENCY BANDWIDTH");
+ }
+
+ butterworth_start (effp);
+
+ if (!(sscanf (argv [0], "%lf", &butterworth->frequency))) {
+ fail("bandpass: illegal frequency");
+ }
+
+ if (!(sscanf (argv [1], "%lf", &butterworth->bandwidth))) {
+ fail("bandpass: illegal bandwidth");
+ }
+}
+
+
+
+void
+bandpass_start (effp)
+eff_t effp;
+{
+ butterworth_t butterworth = (butterworth_t) effp->priv;
+ double c;
+ double d;
+
+ c = 1.0 / tan (M_PI * butterworth->bandwidth / effp->ininfo.rate);
+ d = 2 * cos (2 * M_PI * butterworth->frequency / effp->ininfo.rate);
+
+ butterworth->a [0] = 1.0 / (1.0 + c);
+ butterworth->a [1] = 0.0;
+ butterworth->a [2] = -butterworth->a [0];
+
+ butterworth->b [0] = -c * d * butterworth->a [0];
+ butterworth->b [1] = (c - 1.0) * butterworth->a[0];
+}
+
--- /dev/null
+++ b/src/breject.c
@@ -1,0 +1,84 @@
+/*
+
+ Band-reject effect file for SoX
+ Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+
+ This source code is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This source code is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Code based on the band-reject implementation in
+
+ Sound Processing Kit - A C++ Class Library for Audio Signal Processing
+ Copyright (C) 1995-1998 Kai Lassfolk
+
+ as described in
+
+ Computer music: synthesis, composition, and performance
+ Charles Dodge, Thomas A. Jerse
+ [2nd ed.]
+ Page 217
+
+ */
+
+#include <math.h>
+
+#include "st.h"
+#include "btrworth.h"
+
+
+
+void
+bandreject_getopts (effp, n, argv)
+eff_t effp;
+int n;
+char **argv;
+{
+ butterworth_t butterworth = (butterworth_t)effp->priv;
+
+ if (n != 2) {
+ fail("Usage: bandreject FREQUENCY BANDWIDTH");
+ }
+
+ butterworth_start (effp);
+
+ if (!(sscanf (argv [0], "%lf", &butterworth->frequency))) {
+ fail("bandreject: illegal frequency");
+ }
+
+ if (!(sscanf (argv [1], "%lf", &butterworth->bandwidth))) {
+ fail("bandreject: illegal bandwidth");
+ }
+}
+
+
+
+void
+bandreject_start (effp)
+eff_t effp;
+{
+ butterworth_t butterworth = (butterworth_t) effp->priv;
+ double c;
+ double d;
+
+ c = tan (M_PI * butterworth->bandwidth / effp->ininfo.rate);
+ d = 2 * cos (2 * M_PI * butterworth->frequency / effp->ininfo.rate);
+
+ butterworth->a [0] = 1.0 / (1.0 + c);
+ butterworth->a [1] = -d * butterworth->a[0];
+ butterworth->a [2] = butterworth->a[0];
+
+ butterworth->b [0] = butterworth->a[1];
+ butterworth->b [1] = (1.0 - c) * butterworth->a[0];
+}
+
--- /dev/null
+++ b/src/btrworth.c
@@ -1,0 +1,105 @@
+/*
+
+ Butterworth effect file for SoX
+ Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+
+ This source code is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This source code is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Code based on the butterworth implementation in
+
+ Sound Processing Kit - A C++ Class Library for Audio Signal Processing
+ Copyright (C) 1995-1998 Kai Lassfolk
+
+ as described in
+
+ Computer music: synthesis, composition, and performance
+ Charles Dodge, Thomas A. Jerse
+ [2nd ed.]
+ Page 214
+
+ */
+
+#include <math.h>
+
+#include "st.h"
+#include "btrworth.h"
+
+
+
+void
+butterworth_start (effp)
+eff_t effp;
+{
+ butterworth_t butterworth = (butterworth_t) effp->priv;
+
+ butterworth->x [0] = 0.0;
+ butterworth->x [1] = 0.0;
+ butterworth->y [0] = 0.0;
+ butterworth->y [1] = 0.0;
+}
+
+
+
+void
+butterworth_flow (effp, ibuf, obuf, isamp, osamp)
+eff_t effp;
+LONG *ibuf, *obuf;
+int *isamp, *osamp;
+{
+ butterworth_t butterworth = (butterworth_t) effp->priv;
+
+ double in;
+ double out;
+
+ int len;
+ int done;
+
+ len = ((*isamp > *osamp) ? *osamp : *isamp);
+
+ for (done = 0; done < len; done++) {
+ in = *ibuf++;
+
+ /*
+ * Substituting butterworth->a [x] and butterworth->b [x] with
+ * variables, which are set outside of the loop, did not increased
+ * speed on my AMD Box. GCC seems to do a good job :o)
+ */
+
+ out =
+ butterworth->a [0] * in +
+ butterworth->a [1] * butterworth->x [0] +
+ butterworth->a [2] * butterworth->x [1] -
+ butterworth->b [0] * butterworth->y [0] -
+ butterworth->b [1] * butterworth->y [1];
+
+ butterworth->x [1] = butterworth->x [0];
+ butterworth->x [0] = in;
+ butterworth->y [1] = butterworth->y [0];
+ butterworth->y [0] = out;
+
+ if (out < -2147483647.0) {
+ out = -2147483647.0;
+ }
+ else if (out > 2147483647.0) {
+ out = 2147483647.0;
+ }
+
+ *obuf++ = out;
+ }
+
+ *isamp = len;
+ *osamp = len;
+}
+
--- /dev/null
+++ b/src/btrworth.h
@@ -1,0 +1,52 @@
+/*
+
+ Butterworth effect file for SoX
+ Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+
+ This source code is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This source code is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Code based on the butterworth implementation in
+
+ Sound Processing Kit - A C++ Class Library for Audio Signal Processing
+ Copyright (C) 1995-1998 Kai Lassfolk
+
+ as described in
+
+ Computer music: synthesis, composition, and performance
+ Charles Dodge, Thomas A. Jerse
+ [2nd ed.]
+ Page 214
+
+ */
+
+void butterworth_start (P1 (eff_t effp));
+void butterworth_flow (P5 (eff_t effp, LONG *ibuf, LONG *obuf,
+ int *isamp, int *osamp));
+
+typedef struct butterworth {
+ double x [2];
+ double y [2];
+
+ double a [3];
+ double b [2];
+
+ /*
+ * Cut off frequency for low-pass and high-pass,
+ * center frequency for band-pass
+ */
+ double frequency;
+
+ double bandwidth;
+} *butterworth_t;
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -8,6 +8,7 @@
*/
#include "st.h"
+#include "btrworth.h"
/*
* Sound Tools file format and effect tables.
@@ -446,6 +447,12 @@
extern void band_flow();
extern void band_stop();
+extern void bandpass_getopts();
+extern void bandpass_start();
+
+extern void bandreject_getopts();
+extern void bandreject_start();
+
extern void chorus_getopts();
extern void chorus_start();
extern void chorus_flow();
@@ -501,11 +508,17 @@
extern void highp_flow();
extern void highp_stop();
+extern void highpass_getopts();
+extern void highpass_start();
+
extern void lowp_getopts();
extern void lowp_start();
extern void lowp_flow();
extern void lowp_stop();
+extern void lowpass_getopts();
+extern void lowpass_start();
+
extern void map_getopts();
extern void map_start();
extern void map_flow();
@@ -590,6 +603,10 @@
avg_getopts, avg_start, avg_flow, null_drain, avg_stop},
{"band", 0,
band_getopts, band_start, band_flow, null_drain, band_stop},
+ {"bandpass", 0,
+ bandpass_getopts, bandpass_start, butterworth_flow, null_drain, nothing},
+ {"bandreject", 0,
+ bandreject_getopts, bandreject_start, butterworth_flow, null_drain, nothing},
{"chorus", 0,
chorus_getopts, chorus_start, chorus_flow,
chorus_drain, chorus_stop},
@@ -617,8 +634,12 @@
flanger_drain, flanger_stop},
{"highp", 0,
highp_getopts, highp_start, highp_flow, null_drain,highp_stop},
+ {"highpass", 0,
+ highpass_getopts, highpass_start, butterworth_flow, null_drain,nothing},
{"lowp", 0,
lowp_getopts, lowp_start, lowp_flow, null_drain, lowp_stop},
+ {"lowpass", 0,
+ lowpass_getopts, lowpass_start, butterworth_flow, null_drain, nothing},
{"map", EFF_REPORT,
map_getopts, map_start, map_flow, null_drain, nothing},
{"mask", EFF_MCHAN,
--- /dev/null
+++ b/src/highpass.c
@@ -1,0 +1,78 @@
+/*
+
+ High-pass effect file for SoX
+ Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+
+ This source code is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This source code is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Code based on the high-pass implementation in
+
+ Sound Processing Kit - A C++ Class Library for Audio Signal Processing
+ Copyright (C) 1995-1998 Kai Lassfolk
+
+ as described in
+
+ Computer music: synthesis, composition, and performance
+ Charles Dodge, Thomas A. Jerse
+ [2nd ed.]
+ Page 215
+
+ */
+
+#include <math.h>
+
+#include "st.h"
+#include "btrworth.h"
+
+
+
+void
+highpass_getopts (effp, n, argv)
+eff_t effp;
+int n;
+char **argv;
+{
+ butterworth_t butterworth = (butterworth_t)effp->priv;
+
+ if (n != 1) {
+ fail("Usage: highpass FREQUENCY");
+ }
+
+ butterworth_start (effp);
+
+ if (!(sscanf (argv [0], "%lf", &butterworth->frequency))) {
+ fail("highpass: illegal frequency");
+ }
+}
+
+
+
+void
+highpass_start (effp)
+eff_t effp;
+{
+ butterworth_t butterworth = (butterworth_t) effp->priv;
+ double c;
+
+ c = tan (M_PI * butterworth->frequency / effp->ininfo.rate);
+
+ butterworth->a [0] = 1.0 / (1.0 + sqrt (2.0) * c + c * c);
+ butterworth->a [1] = -2.0 * butterworth->a [0];
+ butterworth->a [2] = butterworth->a [0];
+
+ butterworth->b [0] = 2 * (c * c - 1.0) * butterworth->a[0];
+ butterworth->b [1] = (1.0 - sqrt(2.0) * c + c * c) * butterworth->a [0];
+}
+
--- /dev/null
+++ b/src/lowpass.c
@@ -1,0 +1,66 @@
+/*
+
+ Low-pass effect file for SoX
+ Copyright (C) 1999 Jan Paul Schmidt <jps@fundament.org>
+
+ This source code is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This source code is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ */
+
+#include <math.h>
+
+#include "st.h"
+#include "btrworth.h"
+
+
+
+void
+lowpass_getopts (effp, n, argv)
+eff_t effp;
+int n;
+char **argv;
+{
+ butterworth_t butterworth = (butterworth_t)effp->priv;
+
+ if (n != 1) {
+ fail("Usage: lowpass FREQUENCY");
+ }
+
+ butterworth_start (effp);
+
+ if (!(sscanf (argv [0], "%lf", &butterworth->frequency))) {
+ fail("lowpass: illegal frequency");
+ }
+}
+
+
+
+void
+lowpass_start (effp)
+eff_t effp;
+{
+ butterworth_t butterworth = (butterworth_t) effp->priv;
+ double c;
+
+ c = 1.0 / tan (M_PI * butterworth->frequency / effp->ininfo.rate);
+
+ butterworth->a [0] = 1.0 / (1.0 + sqrt(2.0) * c + c * c);
+ butterworth->a [1] = 2.0 * butterworth->a [0];
+ butterworth->a [2] = butterworth->a [0];
+
+ butterworth->b [0] = 2 * (1.0 - c * c) * butterworth->a[0];
+ butterworth->b [1] = (1.0 - sqrt(2.0) * c + c * c) * butterworth->a [0];
+}
+