annotate libaf/af_sub.c @ 36886:590e9305f12c

configure: Fix unnecessary rebuilds.
author reimar
date Fri, 07 Mar 2014 18:29:27 +0000
parents 2b9bc3c2933d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28229
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
1 /*
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
2 * Copyright (C) 2002 Anders Johansson ajh@watri.uwa.edu.au
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
3 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
4 * This file is part of MPlayer.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
5 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
7 * it under the terms of the GNU General Public License as published by
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
9 * (at your option) any later version.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
10 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
14 * GNU General Public License for more details.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
15 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
16 * You should have received a copy of the GNU General Public License along
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
19 */
8832
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 /* 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
22 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
23 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
24 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
25 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
26 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
27 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
28 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
29 */
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 #include <stdio.h>
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
32 #include <stdlib.h>
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
33 #include <string.h>
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
34
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 34174
diff changeset
35 #include "libavutil/common.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 32537
diff changeset
36 #include "mp_msg.h"
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
37 #include "af.h"
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
38 #include "dsp.h"
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
39
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
40 // 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
41 #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
42
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
43 // Analog domain biquad section
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
44 typedef struct{
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
45 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
46 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
47 } biquad_t;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
48
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
49 // 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
50 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
51 {{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
52
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
53 // 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
54 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
55 {
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
56 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
57 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
58 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
59 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
60 int ch; // Channel number which to insert the filtered data
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
61
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
62 }af_sub_t;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
63
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
64 // 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
65 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
66 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
67 af_sub_t* s = af->setup;
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
68
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
69 switch(cmd){
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
70 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
71 // Sanity check
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
72 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
73
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
74 af->data->rate = ((af_data_t*)arg)->rate;
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 34174
diff changeset
75 af->data->nch = FFMAX(s->ch+1,((af_data_t*)arg)->nch);
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13602
diff changeset
76 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
77 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
78
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
79 // 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
80 s->k = 1.0;
14275
de13fd557440 less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents: 14245
diff changeset
81 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
82 (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
83 (-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
84 (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
85 return AF_ERROR;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
86 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
87 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
88 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
89 int ch=5;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
90 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
91 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
92 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
93 return AF_ERROR;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
94 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
95 }
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_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
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((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28229
diff changeset
99 mp_msg(MSGT_AFILTER, MSGL_ERR, "[sub] Subwoofer channel number must be between "
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
100 " 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
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 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
104 return AF_OK;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
105 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
106 *(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
107 return AF_OK;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
108 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
109 // Sanity check
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
110 if((*(float*)arg > 300) || (*(float*)arg < 20)){
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28229
diff changeset
111 mp_msg(MSGT_AFILTER, MSGL_ERR, "[sub] Cutoff frequency must be between 20Hz and"
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
112 " 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
113 return AF_ERROR;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
114 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
115 // Set cutoff frequency
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
116 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
117 return AF_OK;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
118 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
119 *(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
120 return AF_OK;
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 return AF_UNKNOWN;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
123 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
124
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
125 // Deallocate memory
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
126 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
127 {
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
128 free(af->data);
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
129 free(af->setup);
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
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
132 #ifndef IIR
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
133 #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
134 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
135 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
136 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
137 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
138 (q)[1] = h0; \
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
139 (q)[0] = hn; \
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
140 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
141 #endif
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
142
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
143 // 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
144 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
145 {
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
146 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
147 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
148 float* a = c->audio; // Audio data
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
149 int len = c->len/4; // Number of samples in current audio block
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
150 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
151 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
152 register int i;
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 // Run filter
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
155 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
156 // 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
157 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
158 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
159 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
160 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
161
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
162 return c;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
163 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
164
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
165 // 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
166 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
167 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
168 af->control=control;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
169 af->uninit=uninit;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
170 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22746
diff changeset
171 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
172 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
173 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
174 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
175 return AF_ERROR;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
176 // Set default values
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
177 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
178 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
179 return AF_OK;
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
180 }
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
181
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
182 // 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
183 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
184 "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
185 "sub",
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
186 "Anders",
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
187 "",
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
188 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
189 af_open
8832
a1578b329cc0 Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
diff changeset
190 };