annotate audacious/iir_cfs.c @ 1853:1c19a0dca33d trunk

[svn] - resize fixes
author nenolod
date Mon, 09 Oct 2006 03:56:32 -0700
parents 0a73d1faeb4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
1 /*
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
2 * Copyright (C) 2002-2005 Felipe Rivera <liebremx at users.sourceforge.net>
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
3 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
7 * (at your option) any later version.
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
8 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
12 * GNU General Public License for more details.
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
13 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
17 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
18 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
19 * Coefficient stuff
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
20 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
21 * $Id: iir_cfs.c,v 1.1 2005/10/17 01:57:59 liebremx Exp $
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
22 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
23
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
24 #include "iir_cfs.h"
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
25 #include <stdio.h>
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
26 #include <math.h>
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
27
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
28 /***************************
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
29 * IIR filter coefficients *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
30 ***************************/
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
31 static sIIRCoefficients iir_cf10_11k_11025[10] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
32 static sIIRCoefficients iir_cf10_22k_22050[10] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
33 static sIIRCoefficients iir_cforiginal10_44100[10] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
34 static sIIRCoefficients iir_cforiginal10_48000[10] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
35 static sIIRCoefficients iir_cf10_44100[10] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
36 static sIIRCoefficients iir_cf10_48000[10] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
37 static sIIRCoefficients iir_cf15_44100[15] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
38 static sIIRCoefficients iir_cf15_48000[15] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
39 static sIIRCoefficients iir_cf25_44100[25] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
40 static sIIRCoefficients iir_cf25_48000[25] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
41 static sIIRCoefficients iir_cf31_44100[31] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
42 static sIIRCoefficients iir_cf31_48000[31] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
43
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
44 /******************************************************************
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
45 * Definitions and data structures to calculate the coefficients
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
46 ******************************************************************/
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
47 static const double band_f011k[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
48 { 31, 62, 125, 250, 500, 1000, 2000, 3000, 4000, 5500
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
49 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
50 static const double band_f022k[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
51 { 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 11000
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
52 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
53 static const double band_f010[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
54 { 31, 62, 125, 250, 500, 1000, 2000, 4000, 8000, 16000
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
55 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
56 static const double band_original_f010[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
57 { 60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
58 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
59 static const double band_f015[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
60 { 25,40,63,100,160,250,400,630,1000,1600,2500,4000,6300,10000,16000
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
61 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
62 static const double band_f025[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
63 { 20,31.5,40,50,80,100,125,160,250,315,400,500,800,
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
64 1000,1250,1600,2500,3150,4000,5000,8000,10000,12500,16000,20000
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
65 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
66 static const double band_f031[] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
67 { 20,25,31.5,40,50,63,80,100,125,160,200,250,315,400,500,630,800,
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
68 1000,1250,1600,2000,2500,3150,4000,5000,6300,8000,10000,12500,16000,20000
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
69 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
70
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
71 #define GAIN_F0 1.0
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
72 #define GAIN_F1 GAIN_F0 / M_SQRT2
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
73
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
74 #define SAMPLING_FREQ 44100.0
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
75 #define TETA(f) (2*M_PI*(double)f/bands[n].sfreq)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
76 #define TWOPOWER(value) (value * value)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
77
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
78 #define BETA2(tf0, tf) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
79 (TWOPOWER(GAIN_F1)*TWOPOWER(cos(tf0)) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
80 - 2.0 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
81 + TWOPOWER(GAIN_F1) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
82 - TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
83 #define BETA1(tf0, tf) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
84 (2.0 * TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf)) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
85 + TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf0)) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
86 - 2.0 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
87 - TWOPOWER(GAIN_F1) + TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
88 #define BETA0(tf0, tf) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
89 (0.25 * TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf0)) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
90 - 0.5 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
91 + 0.25 * TWOPOWER(GAIN_F1) \
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
92 - 0.25 * TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
93
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
94 #define GAMMA(beta, tf0) ((0.5 + beta) * cos(tf0))
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
95 #define ALPHA(beta) ((0.5 - beta)/2.0)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
96
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
97 struct {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
98 sIIRCoefficients *coeffs;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
99 const double *cfs;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
100 double octave;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
101 int band_count;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
102 double sfreq;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
103 } bands[] = {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
104 { iir_cf10_11k_11025, band_f011k, 1.0, 10, 11025.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
105 { iir_cf10_22k_22050, band_f022k, 1.0, 10, 22050.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
106 { iir_cforiginal10_44100, band_original_f010, 1.0, 10, 44100.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
107 { iir_cforiginal10_48000, band_original_f010, 1.0, 10, 48000.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
108 { iir_cf10_44100, band_f010, 1.0, 10, 44100.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
109 { iir_cf10_48000, band_f010, 1.0, 10, 48000.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
110 { iir_cf15_44100, band_f015, 2.0/3.0, 15, 44100.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
111 { iir_cf15_48000, band_f015, 2.0/3.0, 15, 48000.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
112 { iir_cf25_44100, band_f025, 1.0/3.0, 25, 44100.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
113 { iir_cf25_48000, band_f025, 1.0/3.0, 25, 48000.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
114 { iir_cf31_44100, band_f031, 1.0/3.0, 31, 44100.0 },
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
115 { iir_cf31_48000, band_f031, 1.0/3.0, 31, 48000.0 },
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 430
diff changeset
116 { 0, 0, 0, 0, 0 }
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
117 };
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
118
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
119 /*************
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
120 * Functions *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
121 *************/
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
122
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
123 /* Get the coeffs for a given number of bands and sampling frequency */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
124 sIIRCoefficients* get_coeffs(gint *bands, gint sfreq, gboolean use_xmms_original_freqs)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
125 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
126 sIIRCoefficients *iir_cf = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
127 switch(sfreq)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
128 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
129 case 11025: iir_cf = iir_cf10_11k_11025;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
130 *bands = 10;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
131 break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
132 case 22050: iir_cf = iir_cf10_22k_22050;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
133 *bands = 10;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
134 break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
135 case 48000:
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
136 switch(*bands)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
137 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
138 case 31: iir_cf = iir_cf31_48000; break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
139 case 25: iir_cf = iir_cf25_48000; break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
140 case 15: iir_cf = iir_cf15_48000; break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
141 default:
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
142 iir_cf = use_xmms_original_freqs ?
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
143 iir_cforiginal10_48000 :
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
144 iir_cf10_48000;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
145 break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
146 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
147 break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
148 default:
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
149 switch(*bands)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
150 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
151 case 31: iir_cf = iir_cf31_44100; break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
152 case 25: iir_cf = iir_cf25_44100; break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
153 case 15: iir_cf = iir_cf15_44100; break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
154 default:
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
155 iir_cf = use_xmms_original_freqs ?
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
156 iir_cforiginal10_44100 :
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
157 iir_cf10_44100;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
158 break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
159 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
160 break;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
161 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
162 return iir_cf;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
163 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
164
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
165 /* Get the freqs at both sides of F0. These will be cut at -3dB */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
166 static void find_f1_and_f2(double f0, double octave_percent, double *f1, double *f2)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
167 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
168 double octave_factor = pow(2.0, octave_percent/2.0);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
169 *f1 = f0/octave_factor;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
170 *f2 = f0*octave_factor;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
171 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
172
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
173 /* Find the quadratic root
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
174 * Always return the smallest root */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
175 static int find_root(double a, double b, double c, double *x0) {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
176 double k = c-((b*b)/(4.*a));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
177 double h = -(b/(2.*a));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
178 double x1 = 0.;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
179 if (-(k/a) < 0.)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
180 return -1;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
181 *x0 = h - sqrt(-(k/a));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
182 x1 = h + sqrt(-(k/a));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
183 if (x1 < *x0)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
184 *x0 = x1;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
185 return 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
186 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
187
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
188 /* Calculate all the coefficients as specified in the bands[] array */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
189 void calc_coeffs()
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
190 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
191 int i, n;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
192 double f1, f2;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
193 double x0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
194
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
195 n = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
196 for (; bands[n].cfs; n++) {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
197 double *freqs = (double *)bands[n].cfs;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
198 for (i=0; i<bands[n].band_count; i++)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
199 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
200
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
201 /* Find -3dB frequencies for the center freq */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
202 find_f1_and_f2(freqs[i], bands[n].octave, &f1, &f2);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
203 /* Find Beta */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
204 if ( find_root(
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
205 BETA2(TETA(freqs[i]), TETA(f1)),
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
206 BETA1(TETA(freqs[i]), TETA(f1)),
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
207 BETA0(TETA(freqs[i]), TETA(f1)),
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
208 &x0) == 0)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
209 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
210 /* Got a solution, now calculate the rest of the factors */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
211 /* Take the smallest root always (find_root returns the smallest one)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
212 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
213 * NOTE: The IIR equation is
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
214 * y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2])
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
215 * Now the 2 factor has been distributed in the coefficients
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
216 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
217 /* Now store the coefficients */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
218 bands[n].coeffs[i].beta = 2.0 * x0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
219 bands[n].coeffs[i].alpha = 2.0 * ALPHA(x0);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
220 bands[n].coeffs[i].gamma = 2.0 * GAMMA(x0, TETA(freqs[i]));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
221 #ifdef DEBUG
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
222 printf("Freq[%d]: %f. Beta: %.10e Alpha: %.10e Gamma %.10e\n",
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
223 i, freqs[i], bands[n].coeffs[i].beta,
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
224 bands[n].coeffs[i].alpha, bands[n].coeffs[i].gamma);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
225 #endif
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
226 } else {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
227 /* Shouldn't happen */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
228 bands[n].coeffs[i].beta = 0.;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
229 bands[n].coeffs[i].alpha = 0.;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
230 bands[n].coeffs[i].gamma = 0.;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
231 printf(" **** Where are the roots?\n");
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
232 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
233 }// for i
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
234 }//for n
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
235 }