| 1 | #ifndef _Resonator_h_ |
| 2 | #define _Resonator_h_ |
| 3 | /* Resonator.h |
| 4 | * |
| 5 | * Copyright (C) 2008-2019 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | * See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * djmw 20081029 |
| 23 | * djmw 20110306 Latest modification |
| 24 | */ |
| 25 | |
| 26 | #include "Sound.h" |
| 27 | |
| 28 | Thing_define (Filter, Daata) { |
| 29 | double samplingPeriod; |
| 30 | double a, b, c; |
| 31 | double p1, p2; |
| 32 | |
| 33 | virtual double v_getOutput (double input); |
| 34 | virtual void v_setCoefficients (double frequency, double bandwidth); |
| 35 | virtual void v_resetMemory (); |
| 36 | }; |
| 37 | |
| 38 | Thing_define (Resonator, Filter) { |
| 39 | bool normaliseAtDC; |
| 40 | |
| 41 | void v_setCoefficients (double frequency, double bandwidth) |
| 42 | override; |
| 43 | }; |
| 44 | |
| 45 | Thing_define (AntiResonator, Resonator) { |
| 46 | double v_getOutput (double input) |
| 47 | override; |
| 48 | void v_setCoefficients (double frequency, double bandwidth) |
| 49 | override; |
| 50 | }; |
| 51 | |
| 52 | Thing_define (ConstantGainResonator, Filter) { |
| 53 | double d; |
| 54 | double p3, p4; |
| 55 | |
| 56 | double v_getOutput (double input) |
| 57 | override; |
| 58 | void v_setCoefficients (double frequency, double bandwidth) |
| 59 | override; |
| 60 | void v_resetMemory () |
| 61 | override; |
| 62 | }; |
| 63 | |
| 64 | autoResonator Resonator_create (double samplingPeriod, bool normaliseAtDC); |
| 65 | |
| 66 | autoConstantGainResonator ConstantGainResonator_create (double samplingPeriod); |
| 67 | |
| 68 | autoAntiResonator AntiResonator_create (double samplingPeriod); |
| 69 | |
| 70 | /* |
| 71 | Set a,b,c |
| 72 | normaliseAtDC == true: H(0) = 1 -> a = 1 - b - c |
| 73 | normaliseAtDC == false: H(Fmax) = 1 -> a = (1 + c)sin(2*pi*F*T) |
| 74 | */ |
| 75 | void Filter_setCoefficients (Filter me, double frequency, double bandwidth); |
| 76 | |
| 77 | double Filter_getOutput (Filter me, double input); |
| 78 | |
| 79 | void Filter_resetMemory (Filter me); |
| 80 | |
| 81 | #endif /* _Resonator_h_ */ |
| 82 |