annotate audacious/iir.c @ 1756:dd78822cd1d8 trunk

[svn] Do not try write NULL into a gconf key, convert it to "" first.
author chainsaw
date Sat, 23 Sep 2006 13:50:17 -0700
parents 67cd014f35a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * PCM time-domain equalizer
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
4 * Copyright (C) 2002-2005 Felipe Rivera <liebremx at users sourceforge net>
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 *
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
20 * $Id: iir.c,v 1.15 2005/10/17 01:57:59 liebremx Exp $
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #include <math.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include "iir.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
26 /* Coefficients */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
27 sIIRCoefficients *iir_cf;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
29 /* Volume gain
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
30 * values should be between 0.0 and 1.0
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
31 * Use the preamp from XMMS for now
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
32 * */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
33 float preamp[EQ_CHANNELS];
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
35 #ifdef BENCHMARK
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
36 #include "benchmark.h"
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
37 double timex = 0.0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
38 int count = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
39 unsigned int blength = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
40 #endif
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
42 /*
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
43 * Global vars
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
44 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
45 gint rate;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
46 int band_count;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
48 void set_preamp(gint chn, float val)
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 {
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
50 preamp[chn] = val;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
53 /* Init the filters */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
54 void init_iir()
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 {
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
56 calc_coeffs();
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
57 #if 0
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
58 band_count = cfg.band_num;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
59 #endif
348
f74bdb82f0a0 [svn] a lot of EQ tweaks, but the preamp still does not work right
nenolod
parents: 0
diff changeset
60
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
61 band_count = 10;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
62
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
63 rate = 44100;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
65 iir_cf = get_coeffs(&band_count, rate, TRUE);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
66 clean_history();
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
67 }
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
69 #ifdef ARCH_X86
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
70 /* Round function provided by Frank Klemm which saves around 100K
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
71 * CPU cycles in my PIII for each call to the IIR function with 4K samples
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
72 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
73 __inline__ int round_trick(float floatvalue_to_round)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
74 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
75 float floattmp ;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
76 int rounded_value ;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
78 floattmp = (int) 0x00FD8000L + (floatvalue_to_round);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
79 rounded_value = *(int*)(&floattmp) - (int)0x4B7D8000L;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
81 if ( rounded_value != (short) rounded_value )
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
82 rounded_value = ( rounded_value >> 31 ) ^ 0x7FFF;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
83 return rounded_value;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 }
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents: 348
diff changeset
85 #endif