Mercurial > mplayer.hg
annotate libaf/af_pan.c @ 36962:6bb8d4f4a7b0
Add missing #include.
author | ib |
---|---|
date | Mon, 24 Mar 2014 11:09:39 +0000 |
parents | 2b9bc3c2933d |
children |
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@atri.curtin.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 */ |
8607 | 20 |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 | |
24 #include <inttypes.h> | |
25 #include <math.h> | |
26 #include <limits.h> | |
27 | |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
28 #include "libavutil/common.h" |
34174
a93891202051
Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents:
32537
diff
changeset
|
29 #include "mp_msg.h" |
8607 | 30 #include "af.h" |
31 | |
32 // Data for specific instances of this filter | |
33 typedef struct af_pan_s | |
34 { | |
23532
a1eb547cf52e
Avoid zero output for pan filter; zero output now means same # of channels
zuxy
parents:
23531
diff
changeset
|
35 int nch; // Number of output channels; zero means same as input |
8607 | 36 float level[AF_NCH][AF_NCH]; // Gain level for each channel |
37 }af_pan_t; | |
38 | |
39 // Initialization and runtime control | |
40 static int control(struct af_instance_s* af, int cmd, void* arg) | |
41 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
42 af_pan_t* s = af->setup; |
8607 | 43 |
44 switch(cmd){ | |
45 case AF_CONTROL_REINIT: | |
46 // Sanity check | |
47 if(!arg) return AF_ERROR; | |
48 | |
49 af->data->rate = ((af_data_t*)arg)->rate; | |
14245 | 50 af->data->format = AF_FORMAT_FLOAT_NE; |
8607 | 51 af->data->bps = 4; |
23532
a1eb547cf52e
Avoid zero output for pan filter; zero output now means same # of channels
zuxy
parents:
23531
diff
changeset
|
52 af->data->nch = s->nch ? s->nch: ((af_data_t*)arg)->nch; |
24888 | 53 af->mul = (double)af->data->nch / ((af_data_t*)arg)->nch; |
8607 | 54 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
55 if((af->data->format != ((af_data_t*)arg)->format) || |
8607 | 56 (af->data->bps != ((af_data_t*)arg)->bps)){ |
57 ((af_data_t*)arg)->format = af->data->format; | |
58 ((af_data_t*)arg)->bps = af->data->bps; | |
59 return AF_FALSE; | |
60 } | |
23532
a1eb547cf52e
Avoid zero output for pan filter; zero output now means same # of channels
zuxy
parents:
23531
diff
changeset
|
61 return AF_OK; |
8607 | 62 case AF_CONTROL_COMMAND_LINE:{ |
63 int nch = 0; | |
64 int n = 0; | |
65 char* cp = NULL; | |
66 int j,k; | |
67 // Read number of outputs | |
68 sscanf((char*)arg,"%i%n", &nch,&n); | |
69 if(AF_OK != control(af,AF_CONTROL_PAN_NOUT | AF_CONTROL_SET, &nch)) | |
70 return AF_ERROR; | |
71 | |
72 // Read pan values | |
73 cp = &((char*)arg)[n]; | |
74 j = 0; k = 0; | |
75 while((*cp == ':') && (k < AF_NCH)){ | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
76 sscanf(cp, ":%f%n" , &s->level[j][k], &n); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
77 mp_msg(MSGT_AFILTER, MSGL_V, "[pan] Pan level from channel %i to" |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
78 " channel %i = %f\n",k,j,s->level[j][k]); |
8607 | 79 cp =&cp[n]; |
80 j++; | |
81 if(j>=nch){ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
82 j = 0; |
8607 | 83 k++; |
84 } | |
85 } | |
86 return AF_OK; | |
87 } | |
88 case AF_CONTROL_PAN_LEVEL | AF_CONTROL_SET:{ | |
89 int i; | |
90 int ch = ((af_control_ext_t*)arg)->ch; | |
91 float* level = ((af_control_ext_t*)arg)->arg; | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
92 if (ch >= AF_NCH) |
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
93 return AF_FALSE; |
8607 | 94 for(i=0;i<AF_NCH;i++) |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
95 s->level[ch][i] = level[i]; |
8607 | 96 return AF_OK; |
97 } | |
98 case AF_CONTROL_PAN_LEVEL | AF_CONTROL_GET:{ | |
99 int i; | |
100 int ch = ((af_control_ext_t*)arg)->ch; | |
101 float* level = ((af_control_ext_t*)arg)->arg; | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
102 if (ch >= AF_NCH) |
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
103 return AF_FALSE; |
8607 | 104 for(i=0;i<AF_NCH;i++) |
105 level[i] = s->level[ch][i]; | |
106 return AF_OK; | |
107 } | |
108 case AF_CONTROL_PAN_NOUT | AF_CONTROL_SET: | |
109 // Reinit must be called after this function has been called | |
110 | |
111 // Sanity check | |
12008 | 112 if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > AF_NCH){ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
113 mp_msg(MSGT_AFILTER, MSGL_ERR, "[pan] The number of output channels must be" |
8607 | 114 " between 1 and %i. Current value is %i\n",AF_NCH,((int*)arg)[0]); |
115 return AF_ERROR; | |
116 } | |
23532
a1eb547cf52e
Avoid zero output for pan filter; zero output now means same # of channels
zuxy
parents:
23531
diff
changeset
|
117 s->nch=((int*)arg)[0]; |
8607 | 118 return AF_OK; |
119 case AF_CONTROL_PAN_NOUT | AF_CONTROL_GET: | |
120 *(int*)arg = af->data->nch; | |
121 return AF_OK; | |
23551 | 122 case AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET:{ |
123 float val = *(float*)arg; | |
124 if (s->nch) | |
125 return AF_ERROR; | |
126 if (af->data->nch >= 2) { | |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
127 s->level[0][0] = FFMIN(1.f, 1.f - val); |
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
128 s->level[0][1] = FFMAX(0.f, val); |
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
129 s->level[1][0] = FFMAX(0.f, -val); |
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
130 s->level[1][1] = FFMIN(1.f, 1.f + val); |
23551 | 131 } |
132 return AF_OK; | |
133 } | |
134 case AF_CONTROL_PAN_BALANCE | AF_CONTROL_GET: | |
135 if (s->nch) | |
136 return AF_ERROR; | |
137 *(float*)arg = s->level[0][1] - s->level[1][0]; | |
138 return AF_OK; | |
8607 | 139 } |
140 return AF_UNKNOWN; | |
141 } | |
142 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
143 // Deallocate memory |
8607 | 144 static void uninit(struct af_instance_s* af) |
145 { | |
22175
105f32787336
Fix nonsense tests ("if (af->data->audio)" before "if (af->data)").
uau
parents:
16493
diff
changeset
|
146 if(af->data) |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8607
diff
changeset
|
147 free(af->data->audio); |
22175
105f32787336
Fix nonsense tests ("if (af->data->audio)" before "if (af->data)").
uau
parents:
16493
diff
changeset
|
148 free(af->data); |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
29263
diff
changeset
|
149 free(af->setup); |
8607 | 150 } |
151 | |
152 // Filter data through filter | |
153 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
154 { | |
155 af_data_t* c = data; // Current working data | |
156 af_data_t* l = af->data; // Local data | |
157 af_pan_t* s = af->setup; // Setup for this instance | |
158 float* in = c->audio; // Input audio data | |
159 float* out = NULL; // Output audio data | |
160 float* end = in+c->len/4; // End of loop | |
161 int nchi = c->nch; // Number of input channels | |
162 int ncho = l->nch; // Number of output channels | |
163 register int j,k; | |
164 | |
165 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
166 return NULL; | |
167 | |
168 out = l->audio; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
169 // Execute panning |
8607 | 170 // FIXME: Too slow |
171 while(in < end){ | |
172 for(j=0;j<ncho;j++){ | |
173 register float x = 0.0; | |
174 register float* tin = in; | |
175 for(k=0;k<nchi;k++) | |
176 x += tin[k] * s->level[j][k]; | |
177 out[j] = x; | |
178 } | |
179 out+= ncho; | |
180 in+= nchi; | |
181 } | |
182 | |
183 // Set output data | |
184 c->audio = l->audio; | |
24888 | 185 c->len = c->len / c->nch * l->nch; |
8607 | 186 c->nch = l->nch; |
187 | |
188 return c; | |
189 } | |
190 | |
191 // 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:
22175
diff
changeset
|
192 static int af_open(af_instance_t* af){ |
8607 | 193 af->control=control; |
194 af->uninit=uninit; | |
195 af->play=play; | |
24888 | 196 af->mul=1; |
8607 | 197 af->data=calloc(1,sizeof(af_data_t)); |
198 af->setup=calloc(1,sizeof(af_pan_t)); | |
199 if(af->data == NULL || af->setup == NULL) | |
200 return AF_ERROR; | |
201 return AF_OK; | |
202 } | |
203 | |
204 // Description of this filter | |
205 af_info_t af_info_pan = { | |
206 "Panning audio filter", | |
207 "pan", | |
208 "Anders", | |
209 "", | |
23531
bd9e74cd4d3d
Make pan reentrant. Multiple pans in chain work fine.
zuxy
parents:
22748
diff
changeset
|
210 AF_FLAGS_REENTRANT, |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
22175
diff
changeset
|
211 af_open |
8607 | 212 }; |