Mercurial > mplayer.hg
annotate libaf/af_sub.c @ 26907:f0d0b666ee35
Fix compilation with internal dvdnav
author | rtogni |
---|---|
date | Sat, 31 May 2008 13:42:09 +0000 |
parents | b2402b4f0afa |
children | 72d0b1444141 |
rev | line source |
---|---|
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
1 /*============================================================================= |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
2 // |
13602
14090f7300a8
The full name of the GPL is GNU General Public License.
diego
parents:
8832
diff
changeset
|
3 // This software has been released under the terms of the GNU General Public |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
4 // license. See http://www.gnu.org/copyleft/gpl.html for details. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
5 // |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
6 // Copyright 2002 Anders Johansson ajh@watri.uwa.edu.au |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
7 // |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
8 //============================================================================= |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
9 */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
10 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
11 /* This filter adds a sub-woofer channels to the audio stream by |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
12 averaging the left and right channel and low-pass filter them. The |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
13 low-pass filter is implemented as a 4th order IIR Butterworth |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
14 filter, with a variable cutoff frequency between 10 and 300 Hz. The |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
15 filter gives 24dB/octave attenuation. There are two runtime |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
16 controls one for setting which channel to insert the sub-audio into |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
17 called AF_CONTROL_SUB_CH and one for setting the cutoff frequency |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
18 called AF_CONTROL_SUB_FC. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
19 */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
20 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
21 #include <stdio.h> |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
22 #include <stdlib.h> |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
23 #include <string.h> |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
24 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
25 #include "af.h" |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
26 #include "dsp.h" |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
27 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
28 // Q value for low-pass filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
29 #define Q 1.0 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
30 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
31 // Analog domain biquad section |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
32 typedef struct{ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
33 float a[3]; // Numerator coefficients |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
34 float b[3]; // Denominator coefficients |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
35 } biquad_t; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
36 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
37 // S-parameters for designing 4th order Butterworth filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
38 static biquad_t sp[2] = {{{1.0,0.0,0.0},{1.0,0.765367,1.0}}, |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
39 {{1.0,0.0,0.0},{1.0,1.847759,1.0}}}; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
40 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
41 // Data for specific instances of this filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
42 typedef struct af_sub_s |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
43 { |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
44 float w[2][4]; // Filter taps for low-pass filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
45 float q[2][2]; // Circular queues |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
46 float fc; // Cutoff frequency [Hz] for low-pass filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
47 float k; // Filter gain; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
48 int ch; // Channel number which to insert the filtered data |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
49 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
50 }af_sub_t; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
51 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
52 // Initialization and runtime control |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
53 static int control(struct af_instance_s* af, int cmd, void* arg) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
54 { |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
55 af_sub_t* s = af->setup; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
56 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
57 switch(cmd){ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
58 case AF_CONTROL_REINIT:{ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
59 // Sanity check |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
60 if(!arg) return AF_ERROR; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
61 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
62 af->data->rate = ((af_data_t*)arg)->rate; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
63 af->data->nch = max(s->ch+1,((af_data_t*)arg)->nch); |
14245 | 64 af->data->format = AF_FORMAT_FLOAT_NE; |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
65 af->data->bps = 4; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
66 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
67 // Design low-pass filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
68 s->k = 1.0; |
14275
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14245
diff
changeset
|
69 if((-1 == af_filter_szxform(sp[0].a, sp[0].b, Q, s->fc, |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
70 (float)af->data->rate, &s->k, s->w[0])) || |
14275
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14245
diff
changeset
|
71 (-1 == af_filter_szxform(sp[1].a, sp[1].b, Q, s->fc, |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
72 (float)af->data->rate, &s->k, s->w[1]))) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
73 return AF_ERROR; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
74 return af_test_output(af,(af_data_t*)arg); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
75 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
76 case AF_CONTROL_COMMAND_LINE:{ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
77 int ch=5; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
78 float fc=60.0; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
79 sscanf(arg,"%f:%i", &fc , &ch); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
80 if(AF_OK != control(af,AF_CONTROL_SUB_CH | AF_CONTROL_SET, &ch)) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
81 return AF_ERROR; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
82 return control(af,AF_CONTROL_SUB_FC | AF_CONTROL_SET, &fc); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
83 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
84 case AF_CONTROL_SUB_CH | AF_CONTROL_SET: // Requires reinit |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
85 // Sanity check |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
86 if((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
87 af_msg(AF_MSG_ERROR,"[sub] Subwoofer channel number must be between " |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
88 " 0 and %i current value is %i\n", AF_NCH-1, *(int*)arg); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
89 return AF_ERROR; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
90 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
91 s->ch = *(int*)arg; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
92 return AF_OK; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
93 case AF_CONTROL_SUB_CH | AF_CONTROL_GET: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
94 *(int*)arg = s->ch; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
95 return AF_OK; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
96 case AF_CONTROL_SUB_FC | AF_CONTROL_SET: // Requires reinit |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
97 // Sanity check |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
98 if((*(float*)arg > 300) || (*(float*)arg < 20)){ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
99 af_msg(AF_MSG_ERROR,"[sub] Cutoff frequency must be between 20Hz and" |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
100 " 300Hz current value is %0.2f",*(float*)arg); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
101 return AF_ERROR; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
102 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
103 // Set cutoff frequency |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
104 s->fc = *(float*)arg; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
105 return AF_OK; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
106 case AF_CONTROL_SUB_FC | AF_CONTROL_GET: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
107 *(float*)arg = s->fc; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
108 return AF_OK; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
109 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
110 return AF_UNKNOWN; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
111 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
112 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
113 // Deallocate memory |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
114 static void uninit(struct af_instance_s* af) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
115 { |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
116 if(af->data) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
117 free(af->data); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
118 if(af->setup) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
119 free(af->setup); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
120 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
121 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
122 #ifndef IIR |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
123 #define IIR(in,w,q,out) { \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
124 float h0 = (q)[0]; \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
125 float h1 = (q)[1]; \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
126 float hn = (in) - h0 * (w)[0] - h1 * (w)[1]; \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
127 out = hn + h0 * (w)[2] + h1 * (w)[3]; \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
128 (q)[1] = h0; \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
129 (q)[0] = hn; \ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
130 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
131 #endif |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
132 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
133 // Filter data through filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
134 static af_data_t* play(struct af_instance_s* af, af_data_t* data) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
135 { |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
136 af_data_t* c = data; // Current working data |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
137 af_sub_t* s = af->setup; // Setup for this instance |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
138 float* a = c->audio; // Audio data |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
139 int len = c->len/4; // Number of samples in current audio block |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
140 int nch = c->nch; // Number of channels |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
141 int ch = s->ch; // Channel in which to insert the sub audio |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
142 register int i; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
143 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
144 // Run filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
145 for(i=0;i<len;i+=nch){ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
146 // Average left and right |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
147 register float x = 0.5 * (a[i] + a[i+1]); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
148 IIR(x * s->k, s->w[0], s->q[0], x); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
149 IIR(x , s->w[1], s->q[1], a[i+ch]); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
150 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
151 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
152 return c; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
153 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
154 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
155 // Allocate memory and set function pointers |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
14275
diff
changeset
|
156 static int af_open(af_instance_t* af){ |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
157 af_sub_t* s; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
158 af->control=control; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
159 af->uninit=uninit; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
160 af->play=play; |
24888 | 161 af->mul=1; |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
162 af->data=calloc(1,sizeof(af_data_t)); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
163 af->setup=s=calloc(1,sizeof(af_sub_t)); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
164 if(af->data == NULL || af->setup == NULL) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
165 return AF_ERROR; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
166 // Set default values |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
167 s->ch = 5; // Channel nr 6 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
168 s->fc = 60; // Cutoff frequency 60Hz |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
169 return AF_OK; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
170 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
171 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
172 // Description of this filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
173 af_info_t af_info_sub = { |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
174 "Audio filter for adding a sub-base channel", |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
175 "sub", |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
176 "Anders", |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
177 "", |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
178 AF_FLAGS_NOT_REENTRANT, |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
14275
diff
changeset
|
179 af_open |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff
changeset
|
180 }; |