annotate audacious/iir_fpu.c @ 443:aedd5dbc1a1c trunk

[svn] Be less spammy in the audacious trace log about not being able to find files.
author nenolod
date Mon, 16 Jan 2006 10:32:57 -0800
parents e01a4c8f616f
children 90a8a5e47d7f
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 * PCM time-domain equalizer
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 * 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
5 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * (at your option) any later version.
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
10 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
16 * 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
17 * 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
18 * 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
19 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
20 * $Id: iir_fpu.c,v 1.3 2005/11/13 20:02:58 lisanet Exp $
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
21 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
22
432
e01a4c8f616f [svn] Hello includes. Goodbye warnings.
chainsaw
parents: 430
diff changeset
23 #include <strings.h>
e01a4c8f616f [svn] Hello includes. Goodbye warnings.
chainsaw
parents: 430
diff changeset
24 #include <stdlib.h>
430
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
25 #include <glib.h>
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
26 #include "iir.h"
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
27 #include "iir_fpu.h"
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 static sXYData data_history[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
30 static sXYData data_history2[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
31 float gain[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
32 /* random noise */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
33 sample_t dither[256];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
34 gint di;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
35
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
36 void set_gain(gint index, gint chn, float val)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
37 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
38 gain[index][chn] = val;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
39 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
40
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
41 void clean_history()
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
42 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
43 gint n;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
44 /* Zero the history arrays */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
45 bzero(data_history, sizeof(sXYData) * EQ_MAX_BANDS * EQ_CHANNELS);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
46 bzero(data_history2, sizeof(sXYData) * EQ_MAX_BANDS * EQ_CHANNELS);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
47 /* this is only needed if we use fpu code and there's no other place for
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
48 the moment to init the dither array*/
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
49 for (n = 0; n < 256; n++) {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
50 dither[n] = (rand() % 4) - 2;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
51 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
52 di = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
53 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
54
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
55 __inline__ int iir(gpointer * d, gint length, gint nch)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
56 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
57 // FTZ_ON;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
58 gint16 *data = (gint16 *) * d;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
59 /* Indexes for the history arrays
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
60 * These have to be kept between calls to this function
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
61 * hence they are static */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
62 static gint i = 2, j = 1, k = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
63
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
64 gint index, band, channel;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
65 gint tempgint, halflength;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
66 sample_t out[EQ_CHANNELS], pcm[EQ_CHANNELS];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
67
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
68 #if 0
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
69 // Load the correct filter table according to the sampling rate if needed
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
70 if (srate != rate)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
71 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
72 band_count = eqcfg.band_num;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
73 rate = srate;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
74 iir_cf = get_coeffs(&band_count, rate, eqcfg.use_xmms_original_freqs);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
75 clean_history();
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
76 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
77 #endif
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
78
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
79 #ifdef BENCHMARK
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
80 start_counter();
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
81 #endif //BENCHMARK
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
82
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
83 /**
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
84 * IIR filter equation is
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
85 * 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
86 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
87 * NOTE: The 2 factor was introduced in the coefficients to save
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
88 * a multiplication
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
89 *
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
90 * This algorithm cascades two filters to get nice filtering
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
91 * at the expense of extra CPU cycles
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
92 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
93 /* 16bit, 2 bytes per sample, so divide by two the length of
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
94 * the buffer (length is in bytes)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
95 */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
96 halflength = (length >> 1);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
97 for (index = 0; index < halflength; index+=nch)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
98 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
99 /* For each channel */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
100 for (channel = 0; channel < nch; channel++)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
101 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
102 pcm[channel] = data[index+channel];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
103 /* Preamp gain */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
104 pcm[channel] *= preamp[channel];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
105
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
106 /* add random noise */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
107 pcm[channel] += dither[di];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
108
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
109 out[channel] = 0.;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
110 /* For each band */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
111 for (band = 0; band < band_count; band++)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
112 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
113 /* Store Xi(n) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
114 data_history[band][channel].x[i] = pcm[channel];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
115 /* Calculate and store Yi(n) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
116 data_history[band][channel].y[i] =
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 /* = alpha * [x(n)-x(n-2)] */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
119 iir_cf[band].alpha * ( data_history[band][channel].x[i]
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
120 - data_history[band][channel].x[k])
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
121 /* + gamma * y(n-1) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
122 + iir_cf[band].gamma * data_history[band][channel].y[j]
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
123 /* - beta * y(n-2) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
124 - iir_cf[band].beta * data_history[band][channel].y[k]
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 /*
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
127 * The multiplication by 2.0 was 'moved' into the coefficients to save
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
128 * CPU cycles here */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
129 /* Apply the gain */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
130 out[channel] += data_history[band][channel].y[i]*gain[band][channel]; // * 2.0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
131 } /* For each band */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
132
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
133 if (cfg.eq_extra_filtering)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
134 {
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
135 /* Filter the sample again */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
136 for (band = 0; band < band_count; band++)
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 /* Store Xi(n) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
139 data_history2[band][channel].x[i] = out[channel];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
140 /* Calculate and store Yi(n) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
141 data_history2[band][channel].y[i] =
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
142 (
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
143 /* y(n) = alpha * [x(n)-x(n-2)] */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
144 iir_cf[band].alpha * (data_history2[band][channel].x[i]
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
145 - data_history2[band][channel].x[k])
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
146 /* + gamma * y(n-1) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
147 + iir_cf[band].gamma * data_history2[band][channel].y[j]
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
148 /* - beta * y(n-2) */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
149 - iir_cf[band].beta * data_history2[band][channel].y[k]
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 /* Apply the gain */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
152 out[channel] += data_history2[band][channel].y[i]*gain[band][channel];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
153 } /* For each band */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
154 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
155
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
156 /* Volume stuff
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
157 Scale down original PCM sample and add it to the filters
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
158 output. This substitutes the multiplication by 0.25
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
159 Go back to use the floating point multiplication before the
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
160 conversion to give more dynamic range
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 out[channel] += pcm[channel]*0.25;
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 /* remove random noise */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
165 out[channel] -= dither[di]*0.25;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
166
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
167 /* Round and convert to integer */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
168 #ifdef ARCH_PPC
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
169 tempgint = round_ppc(out[channel]);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
170 #else
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
171 #ifdef ARCH_X86
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
172 tempgint = round_trick(out[channel]);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
173 #else
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
174 tempgint = (int)out[channel];
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
175 #endif
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
176 #endif
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
177
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
178 /* Limit the output */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
179 if (tempgint < -32768)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
180 data[index+channel] = -32768;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
181 else if (tempgint > 32767)
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
182 data[index+channel] = 32767;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
183 else
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
184 data[index+channel] = tempgint;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
185 } /* For each channel */
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 /* Wrap around the indexes */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
188 i = (i+1)%3;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
189 j = (j+1)%3;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
190 k = (k+1)%3;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
191 /* random noise index */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
192 di = (di + 1) % 256;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
193
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
194 }/* For each pair of samples */
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
195
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
196 #ifdef BENCHMARK
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
197 timex += get_counter();
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
198 blength += length;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
199 if (count++ == 1024)
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 printf("FLOATING POINT: %f %d\n",timex/1024.0, blength/1024);
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
202 blength = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
203 timex = 0.;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
204 count = 0;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
205 }
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
206 #endif // BENCHMARK
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
207
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
208 // FTZ_OFF;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
209 return length;
67cd014f35a2 [svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
diff changeset
210 }