annotate libaf/af_channels.c @ 10753:524b34c82c90

10l found by albeu
author alex
date Sun, 31 Aug 2003 21:55:11 +0000
parents 906f7a2dc085
children 8631b43c9d82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
1 /* Audio filter that adds and removes channels, according to the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
2 command line parameter channels. It is stupid and can only add
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
3 silence or copy channels not mix or filter.
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
4 */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
5 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
6 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
7 #include <string.h>
7570
a0bba1b6c458 FreeBSD fix
nexus
parents: 7568
diff changeset
8 #include <unistd.h>
7975
6e03baea602f Adding compile problem fix from Gabucino
anders
parents: 7615
diff changeset
9 #include <inttypes.h>
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
10
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
11 #include "af.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
12
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
13 #define FR 0
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
14 #define TO 1
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
15
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
16 typedef struct af_channels_s{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
17 int route[AF_NCH][2];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
18 int nr;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
19 int router;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
20 }af_channels_t;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
21
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
22 // Local function for copying data
8711
906f7a2dc085 sig 11 fix in reinit and resample + spelling error fixes
anders
parents: 8607
diff changeset
23 static void copy(void* in, void* out, int ins, int inos,int outs, int outos, int len, int bps)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25 switch(bps){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
26 case 1:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27 int8_t* tin = (int8_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
28 int8_t* tout = (int8_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
29 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
31 len = len/ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
32 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
33 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
34 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
35 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
36 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
37 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
38 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
39 case 2:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
40 int16_t* tin = (int16_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
41 int16_t* tout = (int16_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
42 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
43 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
44 len = len/(2*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
45 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
47 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
49 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
50 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
51 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
52 case 4:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 int32_t* tin = (int32_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
54 int32_t* tout = (int32_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
55 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
56 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
57 len = len/(4*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
58 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
59 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
60 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
61 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
62 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
63 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 case 8:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
66 int64_t* tin = (int64_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
67 int64_t* tout = (int64_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
68 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
69 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
70 len = len/(8*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
71 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
72 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
73 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
74 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
75 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
76 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
77 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
78 default:
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
79 af_msg(AF_MSG_ERROR,"[channels] Unsupported number of bytes/sample: %i"
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
80 " please report this error on the MPlayer mailing list. \n",bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
81 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
82 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
83
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
84 // Make sure the routes are sane
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
85 static int check_routes(af_channels_t* s, int nin, int nout)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
86 {
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
87 int i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
88 if((s->nr < 1) || (s->nr > AF_NCH)){
8711
906f7a2dc085 sig 11 fix in reinit and resample + spelling error fixes
anders
parents: 8607
diff changeset
89 af_msg(AF_MSG_ERROR,"[channels] The number of routing pairs must be"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
90 " between 1 and %i. Current value is %i\n",AF_NCH,s->nr);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
91 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
92 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
93
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
94 for(i=0;i<s->nr;i++){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
95 if((s->route[i][FR] >= nin) || (s->route[i][TO] >= nout)){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
96 af_msg(AF_MSG_ERROR,"[channels] Invalid routing in pair nr. %i.\n", i);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
97 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
98 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
99 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
100 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
101 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
102
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
103 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
104 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
105 {
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
106 af_channels_t* s = af->setup;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
107 switch(cmd){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
108 case AF_CONTROL_REINIT:
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
109
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
110 // Set default channel assignment
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
111 if(!s->router){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
112 int i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
113 // Make sure this filter isn't redundant
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
114 if(af->data->nch == ((af_data_t*)arg)->nch)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
115 return AF_DETACH;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
116
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
117 // If mono: fake stereo
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
118 if(((af_data_t*)arg)->nch == 1){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
119 s->nr = min(af->data->nch,2);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
120 for(i=0;i<s->nr;i++){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
121 s->route[i][FR] = 0;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
122 s->route[i][TO] = i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
123 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
124 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
125 else{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
126 s->nr = min(af->data->nch, ((af_data_t*)arg)->nch);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
127 for(i=0;i<s->nr;i++){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
128 s->route[i][FR] = i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
129 s->route[i][TO] = i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
130 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
131 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
132 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
133
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
134 af->data->rate = ((af_data_t*)arg)->rate;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
135 af->data->format = ((af_data_t*)arg)->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
136 af->data->bps = ((af_data_t*)arg)->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
137 af->mul.n = af->data->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
138 af->mul.d = ((af_data_t*)arg)->nch;
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
139 return check_routes(s,((af_data_t*)arg)->nch,af->data->nch);
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
140 case AF_CONTROL_COMMAND_LINE:{
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
141 int nch = 0;
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
142 int n = 0;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
143 // Check number of channels and number of routing pairs
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
144 sscanf(arg, "%i:%i%n", &nch, &s->nr, &n);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
145
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
146 // If router scan commandline for routing pairs
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
147 if(s->nr){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
148 char* cp = &((char*)arg)[n];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
149 int ch = 0;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
150 // Sanity check
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
151 if((s->nr < 1) || (s->nr > AF_NCH)){
8711
906f7a2dc085 sig 11 fix in reinit and resample + spelling error fixes
anders
parents: 8607
diff changeset
152 af_msg(AF_MSG_ERROR,"[channels] The number of routing pairs must be"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
153 " between 1 and %i. Current value is %i\n",AF_NCH,s->nr);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
154 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
155 s->router = 1;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
156 // Scan for pairs on commandline
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
157 while((*cp == ':') && (ch < s->nr)){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
158 sscanf(cp, ":%i:%i%n" ,&s->route[ch][FR], &s->route[ch][TO], &n);
8711
906f7a2dc085 sig 11 fix in reinit and resample + spelling error fixes
anders
parents: 8607
diff changeset
159 af_msg(AF_MSG_VERBOSE,"[channels] Routing from channel %i to"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
160 " channel %i\n",s->route[ch][FR],s->route[ch][TO]);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
161 cp = &cp[n];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
162 ch++;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
163 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
164 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
165
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
166 if(AF_OK != af->control(af,AF_CONTROL_CHANNELS | AF_CONTROL_SET ,&nch))
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
167 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
168 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
169 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
170 case AF_CONTROL_CHANNELS | AF_CONTROL_SET:
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
171 // Reinit must be called after this function has been called
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
172
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
173 // Sanity check
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
174 if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > 6){
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
175 af_msg(AF_MSG_ERROR,"[channels] The number of output channels must be"
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
176 " between 1 and %i. Current value is %i\n",AF_NCH,((int*)arg)[0]);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
177 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
178 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
179
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
180 af->data->nch=((int*)arg)[0];
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
181 if(!s->router)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
182 af_msg(AF_MSG_VERBOSE,"[channels] Changing number of channels"
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
183 " to %i\n",af->data->nch);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
184 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
185 case AF_CONTROL_CHANNELS | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
186 *(int*)arg = af->data->nch;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
187 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
188 case AF_CONTROL_CHANNELS_ROUTING | AF_CONTROL_SET:{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
189 int ch = ((af_control_ext_t*)arg)->ch;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
190 int* route = ((af_control_ext_t*)arg)->arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
191 s->route[ch][FR] = route[FR];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
192 s->route[ch][TO] = route[TO];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
193 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
194 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
195 case AF_CONTROL_CHANNELS_ROUTING | AF_CONTROL_GET:{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
196 int ch = ((af_control_ext_t*)arg)->ch;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
197 int* route = ((af_control_ext_t*)arg)->arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
198 route[FR] = s->route[ch][FR];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
199 route[TO] = s->route[ch][TO];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
200 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
201 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
202 case AF_CONTROL_CHANNELS_NR | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
203 s->nr = *(int*)arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
204 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
205 case AF_CONTROL_CHANNELS_NR | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
206 *(int*)arg = s->nr;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
207 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
208 case AF_CONTROL_CHANNELS_ROUTER | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
209 s->router = *(int*)arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
210 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
211 case AF_CONTROL_CHANNELS_ROUTER | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
212 *(int*)arg = s->router;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
213 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
214 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
215 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
216 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
217
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
218 // Deallocate memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
219 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
220 {
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
221 if(af->setup)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
222 free(af->setup);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
223 if(af->data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
224 free(af->data);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
225 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
226
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
227 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
228 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
229 {
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
230 af_data_t* c = data; // Current working data
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
231 af_data_t* l = af->data; // Local data
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
232 af_channels_t* s = af->setup;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
233 int i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
234
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
235 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
236 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
237
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
238 // Reset unused channels
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
239 memset(l->audio,0,(c->len*af->mul.n)/af->mul.d);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
240
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
241 if(AF_OK == check_routes(s,c->nch,l->nch))
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
242 for(i=0;i<s->nr;i++)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
243 copy(c->audio,l->audio,c->nch,s->route[i][FR],
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
244 l->nch,s->route[i][TO],c->len,c->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
245
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
246 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
247 c->audio = l->audio;
7590
0cba73469341 Fixing the fix buffer overrun should work now
anders
parents: 7589
diff changeset
248 c->len = (c->len*af->mul.n)/af->mul.d;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
249 c->nch = l->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
250
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
251 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
252 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
253
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
254 // Allocate memory and set function pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
255 static int open(af_instance_t* af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
256 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
257 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
258 af->play=play;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
259 af->mul.n=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
260 af->mul.d=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
261 af->data=calloc(1,sizeof(af_data_t));
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
262 af->setup=calloc(1,sizeof(af_channels_t));
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
263 if((af->data == NULL) || (af->setup == NULL))
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
264 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
265 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
266 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
267
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
268 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
269 af_info_t af_info_channels = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
270 "Insert or remove channels",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
271 "channels",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
272 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
273 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7590
diff changeset
274 AF_FLAGS_REENTRANT,
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
275 open
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
276 };