Mercurial > mplayer.hg
annotate libaf/af_pan.c @ 20987:ee1c45139b46
Xvid3 support is no more: Remove Xvid3-specific options
author | gpoirier |
---|---|
date | Sat, 18 Nov 2006 09:57:52 +0000 |
parents | 851d10933f27 |
children | 105f32787336 |
rev | line source |
---|---|
8607 | 1 /*============================================================================= |
2 // | |
13602
14090f7300a8
The full name of the GPL is GNU General Public License.
diego
parents:
12008
diff
changeset
|
3 // This software has been released under the terms of the GNU General Public |
8607 | 4 // license. See http://www.gnu.org/copyleft/gpl.html for details. |
5 // | |
6 // Copyright 2002 Anders Johansson ajh@atri.curtin.edu.au | |
7 // | |
8 //============================================================================= | |
9 */ | |
10 | |
11 /* */ | |
12 | |
13 #include <stdio.h> | |
14 #include <stdlib.h> | |
15 | |
16 #include <unistd.h> | |
17 #include <inttypes.h> | |
18 #include <math.h> | |
19 #include <limits.h> | |
20 | |
21 #include "af.h" | |
22 | |
23 // Data for specific instances of this filter | |
24 typedef struct af_pan_s | |
25 { | |
26 float level[AF_NCH][AF_NCH]; // Gain level for each channel | |
27 }af_pan_t; | |
28 | |
29 // Initialization and runtime control | |
30 static int control(struct af_instance_s* af, int cmd, void* arg) | |
31 { | |
32 af_pan_t* s = af->setup; | |
33 | |
34 switch(cmd){ | |
35 case AF_CONTROL_REINIT: | |
36 // Sanity check | |
37 if(!arg) return AF_ERROR; | |
38 | |
39 af->data->rate = ((af_data_t*)arg)->rate; | |
14245 | 40 af->data->format = AF_FORMAT_FLOAT_NE; |
8607 | 41 af->data->bps = 4; |
42 af->mul.n = af->data->nch; | |
43 af->mul.d = ((af_data_t*)arg)->nch; | |
14433
95bb94a930a3
always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents:
14245
diff
changeset
|
44 af_frac_cancel(&af->mul); |
8607 | 45 |
46 if((af->data->format != ((af_data_t*)arg)->format) || | |
47 (af->data->bps != ((af_data_t*)arg)->bps)){ | |
48 ((af_data_t*)arg)->format = af->data->format; | |
49 ((af_data_t*)arg)->bps = af->data->bps; | |
50 return AF_FALSE; | |
51 } | |
52 return control(af,AF_CONTROL_PAN_NOUT | AF_CONTROL_SET, &af->data->nch); | |
53 case AF_CONTROL_COMMAND_LINE:{ | |
54 int nch = 0; | |
55 int n = 0; | |
56 char* cp = NULL; | |
57 int j,k; | |
58 // Read number of outputs | |
59 sscanf((char*)arg,"%i%n", &nch,&n); | |
60 if(AF_OK != control(af,AF_CONTROL_PAN_NOUT | AF_CONTROL_SET, &nch)) | |
61 return AF_ERROR; | |
62 | |
63 // Read pan values | |
64 cp = &((char*)arg)[n]; | |
65 j = 0; k = 0; | |
66 while((*cp == ':') && (k < AF_NCH)){ | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
67 sscanf(cp, ":%f%n" , &s->level[j][k], &n); |
8607 | 68 af_msg(AF_MSG_VERBOSE,"[pan] Pan level from channel %i to" |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
69 " channel %i = %f\n",k,j,s->level[j][k]); |
8607 | 70 cp =&cp[n]; |
71 j++; | |
72 if(j>=nch){ | |
73 j = 0; | |
74 k++; | |
75 } | |
76 } | |
77 return AF_OK; | |
78 } | |
79 case AF_CONTROL_PAN_LEVEL | AF_CONTROL_SET:{ | |
80 int i; | |
81 int ch = ((af_control_ext_t*)arg)->ch; | |
82 float* level = ((af_control_ext_t*)arg)->arg; | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
83 if (ch >= AF_NCH) |
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
84 return AF_FALSE; |
8607 | 85 for(i=0;i<AF_NCH;i++) |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
86 s->level[ch][i] = level[i]; |
8607 | 87 return AF_OK; |
88 } | |
89 case AF_CONTROL_PAN_LEVEL | AF_CONTROL_GET:{ | |
90 int i; | |
91 int ch = ((af_control_ext_t*)arg)->ch; | |
92 float* level = ((af_control_ext_t*)arg)->arg; | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
93 if (ch >= AF_NCH) |
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
94 return AF_FALSE; |
8607 | 95 for(i=0;i<AF_NCH;i++) |
96 level[i] = s->level[ch][i]; | |
97 return AF_OK; | |
98 } | |
99 case AF_CONTROL_PAN_NOUT | AF_CONTROL_SET: | |
100 // Reinit must be called after this function has been called | |
101 | |
102 // Sanity check | |
12008 | 103 if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > AF_NCH){ |
8607 | 104 af_msg(AF_MSG_ERROR,"[pan] The number of output channels must be" |
105 " between 1 and %i. Current value is %i\n",AF_NCH,((int*)arg)[0]); | |
106 return AF_ERROR; | |
107 } | |
108 af->data->nch=((int*)arg)[0]; | |
109 return AF_OK; | |
110 case AF_CONTROL_PAN_NOUT | AF_CONTROL_GET: | |
111 *(int*)arg = af->data->nch; | |
112 return AF_OK; | |
113 } | |
114 return AF_UNKNOWN; | |
115 } | |
116 | |
117 // Deallocate memory | |
118 static void uninit(struct af_instance_s* af) | |
119 { | |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8607
diff
changeset
|
120 if(af->data->audio) |
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8607
diff
changeset
|
121 free(af->data->audio); |
8607 | 122 if(af->data) |
123 free(af->data); | |
124 if(af->setup) | |
125 free(af->setup); | |
126 } | |
127 | |
128 // Filter data through filter | |
129 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
130 { | |
131 af_data_t* c = data; // Current working data | |
132 af_data_t* l = af->data; // Local data | |
133 af_pan_t* s = af->setup; // Setup for this instance | |
134 float* in = c->audio; // Input audio data | |
135 float* out = NULL; // Output audio data | |
136 float* end = in+c->len/4; // End of loop | |
137 int nchi = c->nch; // Number of input channels | |
138 int ncho = l->nch; // Number of output channels | |
139 register int j,k; | |
140 | |
141 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
142 return NULL; | |
143 | |
144 out = l->audio; | |
145 // Execute panning | |
146 // FIXME: Too slow | |
147 while(in < end){ | |
148 for(j=0;j<ncho;j++){ | |
149 register float x = 0.0; | |
150 register float* tin = in; | |
151 for(k=0;k<nchi;k++) | |
152 x += tin[k] * s->level[j][k]; | |
153 out[j] = x; | |
154 } | |
155 out+= ncho; | |
156 in+= nchi; | |
157 } | |
158 | |
159 // Set output data | |
160 c->audio = l->audio; | |
161 c->len = (c->len*af->mul.n)/af->mul.d; | |
162 c->nch = l->nch; | |
163 | |
164 return c; | |
165 } | |
166 | |
167 // Allocate memory and set function pointers | |
168 static int open(af_instance_t* af){ | |
169 af->control=control; | |
170 af->uninit=uninit; | |
171 af->play=play; | |
172 af->mul.n=1; | |
173 af->mul.d=1; | |
174 af->data=calloc(1,sizeof(af_data_t)); | |
175 af->setup=calloc(1,sizeof(af_pan_t)); | |
176 if(af->data == NULL || af->setup == NULL) | |
177 return AF_ERROR; | |
178 // Set initial pan to pass-through. | |
179 return AF_OK; | |
180 } | |
181 | |
182 // Description of this filter | |
183 af_info_t af_info_pan = { | |
184 "Panning audio filter", | |
185 "pan", | |
186 "Anders", | |
187 "", | |
188 AF_FLAGS_NOT_REENTRANT, | |
189 open | |
190 }; |