1 /* libSoX Bandpass effect file. July 5, 1991
2 * Copyright 1991 Lance Norskog And Sundry Contributors
4 * This source code is freely redistributable and may be used for
5 * any purpose. This copyright notice must be maintained.
6 * Lance Norskog And Sundry Contributors are not responsible for
7 * the consequences of using this software.
9 * Algorithm: 2nd order recursive filter.
10 * Formula stolen from MUSIC56K, a toolkit of 56000 assembler stuff.
12 * This is a 2nd order recursive band pass filter of the form.
13 * y(n)= a * x(n) - b * y(n-1) - c * y(n-2)
17 * c = EXP(-2*pi*cBW/S_RATE)
18 * b = -4*c/(1+c)*COS(2*pi*cCF/S_RATE)
19 * if cSCL=2 (i.e. noise input)
20 * a = SQT(((1+c)*(1+c)-b*b)*(1-c)/(1+c))
22 * a = SQT(1-b*b/(4*c))*(1-c)
24 * note : cCF is the center frequency in Hertz
25 * cBW is the band width in Hertz
26 * cSCL is a scale factor, use 1 for pitched sounds
30 * July 1, 1999 - Jan Paul Schmidt <jps@fundament.org>
32 * This looks like the resonator band pass in SPKit. It's a
33 * second order all-pole (IIR) band-pass filter described
34 * at the pages 186 - 189 in
35 * Dodge, Charles & Jerse, Thomas A. 1985:
36 * Computer Music -- Synthesis, Composition and Performance.
37 * New York: Schirmer Books.
38 * Reference from the SPKit manual.
41 p
->a2
= exp(-2 * M_PI
* bw_Hz
/ effp
->in_signal
.rate
);
42 p
->a1
= -4 * p
->a2
/ (1 + p
->a2
) * cos(2 * M_PI
* p
->fc
/ effp
->in_signal
.rate
);
43 p
->b0
= sqrt(1 - p
->a1
* p
->a1
/ (4 * p
->a2
)) * (1 - p
->a2
);
44 if (p
->filter_type
== filter_BPF_SPK_N
) {
45 mult
= sqrt(((1+p
->a2
) * (1+p
->a2
) - p
->a1
*p
->a1
) * (1-p
->a2
) / (1+p
->a2
)) / p
->b0
;