Mercurial > mplayer.hg
annotate libaf/af_pan.c @ 22864:e15beff67d91
Move pci.db out of its single-file subdirectory.
author | diego |
---|---|
date | Sun, 01 Apr 2007 12:31:15 +0000 |
parents | 904e3f3f8bee |
children | bd9e74cd4d3d |
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 <inttypes.h> | |
17 #include <math.h> | |
18 #include <limits.h> | |
19 | |
20 #include "af.h" | |
21 | |
22 // Data for specific instances of this filter | |
23 typedef struct af_pan_s | |
24 { | |
25 float level[AF_NCH][AF_NCH]; // Gain level for each channel | |
26 }af_pan_t; | |
27 | |
28 // Initialization and runtime control | |
29 static int control(struct af_instance_s* af, int cmd, void* arg) | |
30 { | |
31 af_pan_t* s = af->setup; | |
32 | |
33 switch(cmd){ | |
34 case AF_CONTROL_REINIT: | |
35 // Sanity check | |
36 if(!arg) return AF_ERROR; | |
37 | |
38 af->data->rate = ((af_data_t*)arg)->rate; | |
14245 | 39 af->data->format = AF_FORMAT_FLOAT_NE; |
8607 | 40 af->data->bps = 4; |
41 af->mul.n = af->data->nch; | |
42 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
|
43 af_frac_cancel(&af->mul); |
8607 | 44 |
45 if((af->data->format != ((af_data_t*)arg)->format) || | |
46 (af->data->bps != ((af_data_t*)arg)->bps)){ | |
47 ((af_data_t*)arg)->format = af->data->format; | |
48 ((af_data_t*)arg)->bps = af->data->bps; | |
49 return AF_FALSE; | |
50 } | |
51 return control(af,AF_CONTROL_PAN_NOUT | AF_CONTROL_SET, &af->data->nch); | |
52 case AF_CONTROL_COMMAND_LINE:{ | |
53 int nch = 0; | |
54 int n = 0; | |
55 char* cp = NULL; | |
56 int j,k; | |
57 // Read number of outputs | |
58 sscanf((char*)arg,"%i%n", &nch,&n); | |
59 if(AF_OK != control(af,AF_CONTROL_PAN_NOUT | AF_CONTROL_SET, &nch)) | |
60 return AF_ERROR; | |
61 | |
62 // Read pan values | |
63 cp = &((char*)arg)[n]; | |
64 j = 0; k = 0; | |
65 while((*cp == ':') && (k < AF_NCH)){ | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
66 sscanf(cp, ":%f%n" , &s->level[j][k], &n); |
8607 | 67 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
|
68 " channel %i = %f\n",k,j,s->level[j][k]); |
8607 | 69 cp =&cp[n]; |
70 j++; | |
71 if(j>=nch){ | |
72 j = 0; | |
73 k++; | |
74 } | |
75 } | |
76 return AF_OK; | |
77 } | |
78 case AF_CONTROL_PAN_LEVEL | AF_CONTROL_SET:{ | |
79 int i; | |
80 int ch = ((af_control_ext_t*)arg)->ch; | |
81 float* level = ((af_control_ext_t*)arg)->arg; | |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
82 if (ch >= AF_NCH) |
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
83 return AF_FALSE; |
8607 | 84 for(i=0;i<AF_NCH;i++) |
16493
851d10933f27
Fix af_pan commandline mess and (hopefully) improve description.
reimar
parents:
14433
diff
changeset
|
85 s->level[ch][i] = level[i]; |
8607 | 86 return AF_OK; |
87 } | |
88 case AF_CONTROL_PAN_LEVEL | AF_CONTROL_GET:{ | |
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++) |
95 level[i] = s->level[ch][i]; | |
96 return AF_OK; | |
97 } | |
98 case AF_CONTROL_PAN_NOUT | AF_CONTROL_SET: | |
99 // Reinit must be called after this function has been called | |
100 | |
101 // Sanity check | |
12008 | 102 if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > AF_NCH){ |
8607 | 103 af_msg(AF_MSG_ERROR,"[pan] The number of output channels must be" |
104 " between 1 and %i. Current value is %i\n",AF_NCH,((int*)arg)[0]); | |
105 return AF_ERROR; | |
106 } | |
107 af->data->nch=((int*)arg)[0]; | |
108 return AF_OK; | |
109 case AF_CONTROL_PAN_NOUT | AF_CONTROL_GET: | |
110 *(int*)arg = af->data->nch; | |
111 return AF_OK; | |
112 } | |
113 return AF_UNKNOWN; | |
114 } | |
115 | |
116 // Deallocate memory | |
117 static void uninit(struct af_instance_s* af) | |
118 { | |
22175
105f32787336
Fix nonsense tests ("if (af->data->audio)" before "if (af->data)").
uau
parents:
16493
diff
changeset
|
119 if(af->data) |
8674
93212da0032e
10l memory leak + bug fixes in ms to sample time conversion
anders
parents:
8607
diff
changeset
|
120 free(af->data->audio); |
22175
105f32787336
Fix nonsense tests ("if (af->data->audio)" before "if (af->data)").
uau
parents:
16493
diff
changeset
|
121 free(af->data); |
8607 | 122 if(af->setup) |
123 free(af->setup); | |
124 } | |
125 | |
126 // Filter data through filter | |
127 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
128 { | |
129 af_data_t* c = data; // Current working data | |
130 af_data_t* l = af->data; // Local data | |
131 af_pan_t* s = af->setup; // Setup for this instance | |
132 float* in = c->audio; // Input audio data | |
133 float* out = NULL; // Output audio data | |
134 float* end = in+c->len/4; // End of loop | |
135 int nchi = c->nch; // Number of input channels | |
136 int ncho = l->nch; // Number of output channels | |
137 register int j,k; | |
138 | |
139 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
140 return NULL; | |
141 | |
142 out = l->audio; | |
143 // Execute panning | |
144 // FIXME: Too slow | |
145 while(in < end){ | |
146 for(j=0;j<ncho;j++){ | |
147 register float x = 0.0; | |
148 register float* tin = in; | |
149 for(k=0;k<nchi;k++) | |
150 x += tin[k] * s->level[j][k]; | |
151 out[j] = x; | |
152 } | |
153 out+= ncho; | |
154 in+= nchi; | |
155 } | |
156 | |
157 // Set output data | |
158 c->audio = l->audio; | |
159 c->len = (c->len*af->mul.n)/af->mul.d; | |
160 c->nch = l->nch; | |
161 | |
162 return c; | |
163 } | |
164 | |
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:
22175
diff
changeset
|
166 static int af_open(af_instance_t* af){ |
8607 | 167 af->control=control; |
168 af->uninit=uninit; | |
169 af->play=play; | |
170 af->mul.n=1; | |
171 af->mul.d=1; | |
172 af->data=calloc(1,sizeof(af_data_t)); | |
173 af->setup=calloc(1,sizeof(af_pan_t)); | |
174 if(af->data == NULL || af->setup == NULL) | |
175 return AF_ERROR; | |
176 // Set initial pan to pass-through. | |
177 return AF_OK; | |
178 } | |
179 | |
180 // Description of this filter | |
181 af_info_t af_info_pan = { | |
182 "Panning audio filter", | |
183 "pan", | |
184 "Anders", | |
185 "", | |
186 AF_FLAGS_NOT_REENTRANT, | |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
22175
diff
changeset
|
187 af_open |
8607 | 188 }; |