Mercurial > mplayer.hg
annotate libaf/af_resample.c @ 18715:30d7ddf08889
Fix window position when changing videos while in fullscreen and for
window managers that modify position on Map. Oked by Alexander Strasser.
author | reimar |
---|---|
date | Thu, 15 Jun 2006 08:00:37 +0000 |
parents | 934380353fd6 |
children | 32d611b59079 |
rev | line source |
---|---|
7568 | 1 /*============================================================================= |
2 // | |
13602
14090f7300a8
The full name of the GPL is GNU General Public License.
diego
parents:
8905
diff
changeset
|
3 // This software has been released under the terms of the GNU General Public |
7568 | 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 /* This audio filter changes the sample rate. */ | |
12 #include <stdio.h> | |
13 #include <stdlib.h> | |
14 #include <unistd.h> | |
15 #include <inttypes.h> | |
16 | |
17 #include "af.h" | |
18 #include "dsp.h" | |
19 | |
20 /* Below definition selects the length of each poly phase component. | |
21 Valid definitions are L8 and L16, where the number denotes the | |
22 length of the filter. This definition affects the computational | |
23 complexity (see play()), the performance (see filter.h) and the | |
24 memory usage. The filterlenght is choosen to 8 if the machine is | |
25 slow and to 16 if the machine is fast and has MMX. | |
26 */ | |
27 | |
8607 | 28 #if !defined(HAVE_MMX) // This machine is slow |
29 #define L8 | |
30 #else | |
31 #define L16 | |
32 #endif | |
7568 | 33 |
8607 | 34 #include "af_resample.h" |
7568 | 35 |
8607 | 36 // Filtering types |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
37 #define RSMP_LIN (0<<0) // Linear interpolation |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
38 #define RSMP_INT (1<<0) // 16 bit integer |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
39 #define RSMP_FLOAT (2<<0) // 32 bit floating point |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
40 #define RSMP_MASK (3<<0) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
41 |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
42 // Defines for sloppy or exact resampling |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
43 #define FREQ_SLOPPY (0<<2) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
44 #define FREQ_EXACT (1<<2) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
45 #define FREQ_MASK (1<<2) |
7568 | 46 |
8607 | 47 // Accuracy for linear interpolation |
48 #define STEPACCURACY 32 | |
7568 | 49 |
50 // local data | |
51 typedef struct af_resample_s | |
52 { | |
8607 | 53 void* w; // Current filter weights |
54 void** xq; // Circular buffers | |
7580 | 55 uint32_t xi; // Index for circular buffers |
56 uint32_t wi; // Index for w | |
8607 | 57 uint32_t i; // Number of new samples to put in x queue |
7580 | 58 uint32_t dn; // Down sampling factor |
59 uint32_t up; // Up sampling factor | |
8607 | 60 uint64_t step; // Step size for linear interpolation |
61 uint64_t pt; // Pointer remainder for linear interpolation | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
62 int setup; // Setup parameters cmdline or through postcreate |
7568 | 63 } af_resample_t; |
64 | |
8607 | 65 // Fast linear interpolation resample with modest audio quality |
66 static int linint(af_data_t* c,af_data_t* l, af_resample_t* s) | |
7568 | 67 { |
8607 | 68 uint32_t len = 0; // Number of input samples |
69 uint32_t nch = l->nch; // Words pre transfer | |
70 uint64_t step = s->step; | |
71 int16_t* in16 = ((int16_t*)c->audio); | |
72 int16_t* out16 = ((int16_t*)l->audio); | |
73 int32_t* in32 = ((int32_t*)c->audio); | |
74 int32_t* out32 = ((int32_t*)l->audio); | |
75 uint64_t end = ((((uint64_t)c->len)/2LL)<<STEPACCURACY); | |
76 uint64_t pt = s->pt; | |
77 uint16_t tmp; | |
78 | |
79 switch (nch){ | |
80 case 1: | |
81 while(pt < end){ | |
82 out16[len++]=in16[pt>>STEPACCURACY]; | |
83 pt+=step; | |
7568 | 84 } |
8607 | 85 s->pt=pt & ((1LL<<STEPACCURACY)-1); |
86 break; | |
87 case 2: | |
88 end/=2; | |
89 while(pt < end){ | |
90 out32[len++]=in32[pt>>STEPACCURACY]; | |
91 pt+=step; | |
92 } | |
93 len=(len<<1); | |
94 s->pt=pt & ((1LL<<STEPACCURACY)-1); | |
95 break; | |
96 default: | |
97 end /=nch; | |
98 while(pt < end){ | |
99 tmp=nch; | |
100 do { | |
101 tmp--; | |
102 out16[len+tmp]=in16[tmp+(pt>>STEPACCURACY)*nch]; | |
103 } while (tmp); | |
104 len+=nch; | |
105 pt+=step; | |
106 } | |
107 s->pt=pt & ((1LL<<STEPACCURACY)-1); | |
7568 | 108 } |
109 return len; | |
110 } | |
111 | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
112 /* Determine resampling type and format */ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
113 static int set_types(struct af_instance_s* af, af_data_t* data) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
114 { |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
115 af_resample_t* s = af->setup; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
116 int rv = AF_OK; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
117 float rd = 0; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
118 |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
119 // Make sure this filter isn't redundant |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
120 if((af->data->rate == data->rate) || (af->data->rate == 0)) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
121 return AF_DETACH; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
122 /* If sloppy and small resampling difference (2%) */ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
123 rd = abs((float)af->data->rate - (float)data->rate)/(float)data->rate; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
124 if((((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (rd < 0.02) && |
14245 | 125 (data->format != (AF_FORMAT_FLOAT_NE))) || |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
126 ((s->setup & RSMP_MASK) == RSMP_LIN)){ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
127 s->setup = (s->setup & ~RSMP_MASK) | RSMP_LIN; |
14245 | 128 af->data->format = AF_FORMAT_S16_NE; |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
129 af->data->bps = 2; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
130 af_msg(AF_MSG_VERBOSE,"[resample] Using linear interpolation. \n"); |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
131 } |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
132 else{ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
133 /* If the input format is float or if float is explicitly selected |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
134 use float, otherwise use int */ |
14245 | 135 if((data->format == (AF_FORMAT_FLOAT_NE)) || |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
136 ((s->setup & RSMP_MASK) == RSMP_FLOAT)){ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
137 s->setup = (s->setup & ~RSMP_MASK) | RSMP_FLOAT; |
14245 | 138 af->data->format = AF_FORMAT_FLOAT_NE; |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
139 af->data->bps = 4; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
140 } |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
141 else{ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
142 s->setup = (s->setup & ~RSMP_MASK) | RSMP_INT; |
14245 | 143 af->data->format = AF_FORMAT_S16_NE; |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
144 af->data->bps = 2; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
145 } |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
146 af_msg(AF_MSG_VERBOSE,"[resample] Using %s processing and %s frequecy" |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
147 " conversion.\n", |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
148 ((s->setup & RSMP_MASK) == RSMP_FLOAT)?"floating point":"integer", |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
149 ((s->setup & FREQ_MASK) == FREQ_SLOPPY)?"inexact":"exact"); |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
150 } |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
151 |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
152 if(af->data->format != data->format || af->data->bps != data->bps) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
153 rv = AF_FALSE; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
154 data->format = af->data->format; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
155 data->bps = af->data->bps; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
156 af->data->nch = data->nch; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
157 return rv; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
158 } |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
159 |
7568 | 160 // Initialization and runtime control |
161 static int control(struct af_instance_s* af, int cmd, void* arg) | |
162 { | |
163 switch(cmd){ | |
164 case AF_CONTROL_REINIT:{ | |
165 af_resample_t* s = (af_resample_t*)af->setup; | |
166 af_data_t* n = (af_data_t*)arg; // New configureation | |
167 int i,d = 0; | |
168 int rv = AF_OK; | |
169 | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
170 // Free space for circular bufers |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
171 if(s->xq){ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
172 for(i=1;i<af->data->nch;i++) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
173 if(s->xq[i]) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
174 free(s->xq[i]); |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
175 free(s->xq); |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
176 } |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
177 |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
178 if(AF_DETACH == (rv = set_types(af,n))) |
7568 | 179 return AF_DETACH; |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
180 |
8607 | 181 // If linear interpolation |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
182 if((s->setup & RSMP_MASK) == RSMP_LIN){ |
8607 | 183 s->pt=0LL; |
184 s->step=((uint64_t)n->rate<<STEPACCURACY)/(uint64_t)af->data->rate+1LL; | |
17366 | 185 af_msg(AF_MSG_DEBUG0,"[resample] Linear interpolation step: 0x%016"PRIX64".\n", |
8607 | 186 s->step); |
187 af->mul.n = af->data->rate; | |
188 af->mul.d = n->rate; | |
14433
95bb94a930a3
always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents:
14275
diff
changeset
|
189 af_frac_cancel(&af->mul); |
8905 | 190 return rv; |
7568 | 191 } |
192 | |
193 // Calculate up and down sampling factors | |
14433
95bb94a930a3
always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents:
14275
diff
changeset
|
194 d=af_gcd(af->data->rate,n->rate); |
7568 | 195 |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
196 // If sloppy resampling is enabled limit the upsampling factor |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
197 if(((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (af->data->rate/d > 5000)){ |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
198 int up=af->data->rate/2; |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
199 int dn=n->rate/2; |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
200 int m=2; |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
201 while(af->data->rate/(d*m) > 5000){ |
14433
95bb94a930a3
always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents:
14275
diff
changeset
|
202 d=af_gcd(up,dn); |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
203 up/=2; dn/=2; m*=2; |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
204 } |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
205 d*=m; |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
206 } |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
207 |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
208 // Create space for circular bufers |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
209 s->xq = malloc(n->nch*sizeof(void*)); |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
210 for(i=0;i<n->nch;i++) |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
211 s->xq[i] = malloc(2*L*af->data->bps); |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
212 s->xi = 0; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
213 |
7568 | 214 // Check if the the design needs to be redone |
215 if(s->up != af->data->rate/d || s->dn != n->rate/d){ | |
216 float* w; | |
217 float* wt; | |
218 float fc; | |
219 int j; | |
220 s->up = af->data->rate/d; | |
221 s->dn = n->rate/d; | |
222 | |
223 // Calculate cuttof frequency for filter | |
224 fc = 1/(float)(max(s->up,s->dn)); | |
225 // Allocate space for polyphase filter bank and protptype filter | |
226 w = malloc(sizeof(float) * s->up *L); | |
227 if(NULL != s->w) | |
228 free(s->w); | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
229 s->w = malloc(L*s->up*af->data->bps); |
7568 | 230 |
231 // Design prototype filter type using Kaiser window with beta = 10 | |
232 if(NULL == w || NULL == s->w || | |
14275
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14245
diff
changeset
|
233 -1 == af_filter_design_fir(s->up*L, w, &fc, LP|KAISER , 10.0)){ |
8167 | 234 af_msg(AF_MSG_ERROR,"[resample] Unable to design prototype filter.\n"); |
7568 | 235 return AF_ERROR; |
236 } | |
237 // Copy data from prototype to polyphase filter | |
238 wt=w; | |
239 for(j=0;j<L;j++){//Columns | |
240 for(i=0;i<s->up;i++){//Rows | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
241 if((s->setup & RSMP_MASK) == RSMP_INT){ |
8607 | 242 float t=(float)s->up*32767.0*(*wt); |
243 ((int16_t*)s->w)[i*L+j] = (int16_t)((t>=0.0)?(t+0.5):(t-0.5)); | |
244 } | |
245 else | |
246 ((float*)s->w)[i*L+j] = (float)s->up*(*wt); | |
7568 | 247 wt++; |
248 } | |
249 } | |
250 free(w); | |
8607 | 251 af_msg(AF_MSG_VERBOSE,"[resample] New filter designed up: %i " |
252 "down: %i\n", s->up, s->dn); | |
7568 | 253 } |
254 | |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7616
diff
changeset
|
255 // Set multiplier and delay |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7616
diff
changeset
|
256 af->delay = (double)(1000*L/2)/((double)n->rate); |
7568 | 257 af->mul.n = s->up; |
258 af->mul.d = s->dn; | |
259 return rv; | |
260 } | |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
261 case AF_CONTROL_COMMAND_LINE:{ |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
262 af_resample_t* s = (af_resample_t*)af->setup; |
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
263 int rate=0; |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
264 int type=RSMP_INT; |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
265 int sloppy=1; |
8868
398e3fb7c103
10l bug for float conversion control + feature fix in volume control
anders
parents:
8867
diff
changeset
|
266 sscanf((char*)arg,"%i:%i:%i", &rate, &sloppy, &type); |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
267 s->setup = (sloppy?FREQ_SLOPPY:FREQ_EXACT) | |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
268 (clamp(type,RSMP_LIN,RSMP_FLOAT)); |
8607 | 269 return af->control(af,AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET, &rate); |
7998
d48a06d07afb
Adding commandline options for filters and fixing stupid bug in cfg
anders
parents:
7894
diff
changeset
|
270 } |
8607 | 271 case AF_CONTROL_POST_CREATE: |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
272 if((((af_cfg_t*)arg)->force & AF_INIT_FORMAT_MASK) == AF_INIT_FLOAT) |
8868
398e3fb7c103
10l bug for float conversion control + feature fix in volume control
anders
parents:
8867
diff
changeset
|
273 ((af_resample_t*)af->setup)->setup = RSMP_FLOAT; |
8607 | 274 return AF_OK; |
275 case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET: | |
7568 | 276 // Reinit must be called after this function has been called |
277 | |
278 // Sanity check | |
7616 | 279 if(((int*)arg)[0] < 8000 || ((int*)arg)[0] > 192000){ |
8607 | 280 af_msg(AF_MSG_ERROR,"[resample] The output sample frequency " |
281 "must be between 8kHz and 192kHz. Current value is %i \n", | |
282 ((int*)arg)[0]); | |
7568 | 283 return AF_ERROR; |
284 } | |
285 | |
286 af->data->rate=((int*)arg)[0]; | |
8607 | 287 af_msg(AF_MSG_VERBOSE,"[resample] Changing sample rate " |
288 "to %iHz\n",af->data->rate); | |
7568 | 289 return AF_OK; |
290 } | |
291 return AF_UNKNOWN; | |
292 } | |
293 | |
294 // Deallocate memory | |
295 static void uninit(struct af_instance_s* af) | |
296 { | |
297 if(af->data) | |
298 free(af->data); | |
299 } | |
300 | |
301 // Filter data through filter | |
302 static af_data_t* play(struct af_instance_s* af, af_data_t* data) | |
303 { | |
304 int len = 0; // Length of output data | |
305 af_data_t* c = data; // Current working data | |
306 af_data_t* l = af->data; // Local data | |
307 af_resample_t* s = (af_resample_t*)af->setup; | |
308 | |
309 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) | |
310 return NULL; | |
311 | |
312 // Run resampling | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
313 switch(s->setup & RSMP_MASK){ |
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
314 case(RSMP_INT): |
8607 | 315 # define FORMAT_I 1 |
316 if(s->up>s->dn){ | |
317 # define UP | |
318 # include "af_resample.h" | |
319 # undef UP | |
320 } | |
321 else{ | |
322 # define DN | |
323 # include "af_resample.h" | |
324 # undef DN | |
325 } | |
326 break; | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
327 case(RSMP_FLOAT): |
8607 | 328 # undef FORMAT_I |
329 # define FORMAT_F 1 | |
330 if(s->up>s->dn){ | |
331 # define UP | |
332 # include "af_resample.h" | |
333 # undef UP | |
334 } | |
335 else{ | |
336 # define DN | |
337 # include "af_resample.h" | |
338 # undef DN | |
339 } | |
340 break; | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
341 case(RSMP_LIN): |
8607 | 342 len = linint(c, l, s); |
343 break; | |
344 } | |
7568 | 345 |
346 // Set output data | |
347 c->audio = l->audio; | |
8607 | 348 c->len = len*l->bps; |
7568 | 349 c->rate = l->rate; |
350 | |
351 return c; | |
352 } | |
353 | |
354 // Allocate memory and set function pointers | |
355 static int open(af_instance_t* af){ | |
356 af->control=control; | |
357 af->uninit=uninit; | |
358 af->play=play; | |
359 af->mul.n=1; | |
360 af->mul.d=1; | |
361 af->data=calloc(1,sizeof(af_data_t)); | |
362 af->setup=calloc(1,sizeof(af_resample_t)); | |
363 if(af->data == NULL || af->setup == NULL) | |
364 return AF_ERROR; | |
8867
558f0b1f45ee
New auto config for volume and resample and added support for float flag in configuration
anders
parents:
8711
diff
changeset
|
365 ((af_resample_t*)af->setup)->setup = RSMP_INT | FREQ_SLOPPY; |
7568 | 366 return AF_OK; |
367 } | |
368 | |
369 // Description of this plugin | |
370 af_info_t af_info_resample = { | |
371 "Sample frequency conversion", | |
372 "resample", | |
373 "Anders", | |
374 "", | |
7615 | 375 AF_FLAGS_REENTRANT, |
7568 | 376 open |
377 }; | |
378 |