annotate libaf/af_resample.c @ 36843:1078b8dd7625

Cast appropriately.
author ib
date Tue, 25 Feb 2014 17:10:39 +0000
parents 2b9bc3c2933d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28229
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
1 /*
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
2 * This audio filter changes the sample rate.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
3 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
4 * Copyright (C) 2002 Anders Johansson ajh@atri.curtin.edu.au
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
5 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
6 * This file is part of MPlayer.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
7 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
9 * it under the terms of the GNU General Public License as published by
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
11 * (at your option) any later version.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
12 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
16 * GNU General Public License for more details.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
17 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
18 * You should have received a copy of the GNU General Public License along
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 28201
diff changeset
21 */
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
22
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
23 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25 #include <inttypes.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
26
24889
4055d43fc406 libaf: Remove rational number implementation
uau
parents: 24888
diff changeset
27 #include "libavutil/common.h"
28322
fa1f53d4d263 Add missing header for av_gcd, fixes the warning:
diego
parents: 28303
diff changeset
28 #include "libavutil/mathematics.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 32537
diff changeset
29 #include "mp_msg.h"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30 #include "af.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
31 #include "dsp.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
32
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
33 /* Below definition selects the length of each poly phase component.
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
34 Valid definitions are L8 and L16, where the number denotes the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
35 length of the filter. This definition affects the computational
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
36 complexity (see play()), the performance (see filter.h) and the
28809
5de88e6e2494 Comment typo fixes for af_resample
reimar
parents: 28322
diff changeset
37 memory usage. The filter length is chosen to 8 if the machine is
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
38 slow and to 16 if the machine is fast and has MMX.
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
39 */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
40
28292
d6001126678f More #ifdef HAVE_MMX etc. missed by earlier search.
reimar
parents: 28229
diff changeset
41 #if !HAVE_MMX // This machine is slow
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
42 #define L8
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
43 #else
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
44 #define L16
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
45 #endif
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46
28201
4ff973912251 Rename libaf/af_resample.h to libaf/af_resample_template.c, it is used as
diego
parents: 24900
diff changeset
47 #include "af_resample_template.c"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
49 // Filtering types
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
50 #define RSMP_LIN (0<<0) // Linear interpolation
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
51 #define RSMP_INT (1<<0) // 16 bit integer
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
52 #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
53 #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
54
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
55 // 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
56 #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
57 #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
58 #define FREQ_MASK (1<<2)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
59
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
60 // Accuracy for linear interpolation
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
61 #define STEPACCURACY 32
7568
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 // local data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 typedef struct af_resample_s
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 {
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
66 void* w; // Current filter weights
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
67 void** xq; // Circular buffers
7580
255039c14525 Changing to 32 bit aritmetics for counters
anders
parents: 7571
diff changeset
68 uint32_t xi; // Index for circular buffers
255039c14525 Changing to 32 bit aritmetics for counters
anders
parents: 7571
diff changeset
69 uint32_t wi; // Index for w
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
70 uint32_t i; // Number of new samples to put in x queue
7580
255039c14525 Changing to 32 bit aritmetics for counters
anders
parents: 7571
diff changeset
71 uint32_t dn; // Down sampling factor
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
72 uint32_t up; // Up sampling factor
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
73 uint64_t step; // Step size for linear interpolation
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
74 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
75 int setup; // Setup parameters cmdline or through postcreate
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
76 } af_resample_t;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
77
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
78 // Fast linear interpolation resample with modest audio quality
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
79 static int linint(af_data_t* c,af_data_t* l, af_resample_t* s)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
80 {
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
81 uint32_t len = 0; // Number of input samples
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
82 uint32_t nch = l->nch; // Words pre transfer
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
83 uint64_t step = s->step;
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
84 int16_t* in16 = ((int16_t*)c->audio);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
85 int16_t* out16 = ((int16_t*)l->audio);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
86 int32_t* in32 = ((int32_t*)c->audio);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
87 int32_t* out32 = ((int32_t*)l->audio);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
88 uint64_t end = ((((uint64_t)c->len)/2LL)<<STEPACCURACY);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
89 uint64_t pt = s->pt;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
90 uint16_t tmp;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
91
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
92 switch (nch){
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
93 case 1:
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
94 while(pt < end){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
95 out16[len++]=in16[pt>>STEPACCURACY];
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
96 pt+=step;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
97 }
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
98 s->pt=pt & ((1LL<<STEPACCURACY)-1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
99 break;
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
100 case 2:
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
101 end/=2;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
102 while(pt < end){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
103 out32[len++]=in32[pt>>STEPACCURACY];
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
104 pt+=step;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
105 }
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
106 len=(len<<1);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
107 s->pt=pt & ((1LL<<STEPACCURACY)-1);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
108 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
109 default:
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
110 end /=nch;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
111 while(pt < end){
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
112 tmp=nch;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
113 do {
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
114 tmp--;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
115 out16[len+tmp]=in16[tmp+(pt>>STEPACCURACY)*nch];
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
116 } while (tmp);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
117 len+=nch;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
118 pt+=step;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
119 }
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
120 s->pt=pt & ((1LL<<STEPACCURACY)-1);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
121 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
122 return len;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
123 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
124
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
125 /* 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
126 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
127 {
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
128 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
129 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
130 float rd = 0;
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
131
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
132 // Make sure this filter isn't redundant
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
133 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
134 return AF_DETACH;
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
135 /* 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
136 rd = abs((float)af->data->rate - (float)data->rate)/(float)data->rate;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
137 if((((s->setup & FREQ_MASK) == FREQ_SLOPPY) && (rd < 0.02) &&
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
138 (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 ((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
140 s->setup = (s->setup & ~RSMP_MASK) | RSMP_LIN;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13602
diff changeset
141 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
142 af->data->bps = 2;
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28813
diff changeset
143 mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Using linear interpolation. \n");
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
144 }
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
145 else{
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
146 /* 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
147 use float, otherwise use int */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
148 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
149 ((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
150 s->setup = (s->setup & ~RSMP_MASK) | RSMP_FLOAT;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13602
diff changeset
151 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
152 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
153 }
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
154 else{
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
155 s->setup = (s->setup & ~RSMP_MASK) | RSMP_INT;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13602
diff changeset
156 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
157 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
158 }
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28813
diff changeset
159 mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Using %s processing and %s frequecy"
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
160 " conversion.\n",
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
161 ((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
162 ((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
163 }
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
164
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
165 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
166 rv = AF_FALSE;
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
167 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
168 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
169 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
170 return rv;
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
171 }
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
172
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
173 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
174 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
175 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
176 switch(cmd){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
177 case AF_CONTROL_REINIT:{
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
178 af_resample_t* s = af->setup;
28813
113ae1bae806 Remove several useless casts from af_resample
reimar
parents: 28812
diff changeset
179 af_data_t* n = arg; // New configuration
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
180 int i,d = 0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
181 int rv = AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
182
28809
5de88e6e2494 Comment typo fixes for af_resample
reimar
parents: 28322
diff changeset
183 // Free space for circular buffers
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
184 if(s->xq){
28810
54230bed6a34 Use a single malloc to allocate space for the circular buffers.
reimar
parents: 28809
diff changeset
185 free(s->xq[0]);
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
186 free(s->xq);
21017
32d611b59079 Fix double free in af_resample when reinited with suitable parameters
uau
parents: 17366
diff changeset
187 s->xq = NULL;
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
188 }
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
189
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
190 if(AF_DETACH == (rv = set_types(af,n)))
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
191 return AF_DETACH;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
192
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
193 // 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
194 if((s->setup & RSMP_MASK) == RSMP_LIN){
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
195 s->pt=0LL;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
196 s->step=((uint64_t)n->rate<<STEPACCURACY)/(uint64_t)af->data->rate+1LL;
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28813
diff changeset
197 mp_msg(MSGT_AFILTER, MSGL_DBG2, "[resample] Linear interpolation step: 0x%016"PRIX64".\n",
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
198 s->step);
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 24595
diff changeset
199 af->mul = (double)af->data->rate / n->rate;
8905
295c20099f12 10l sig 11 bug reported by Fabian Franz
anders
parents: 8868
diff changeset
200 return rv;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
201 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
202
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
203 // Calculate up and down sampling factors
28303
44d67f7f8eb3 Fix compilation: s/ff_gcd/av_gcd.
cehoyos
parents: 28292
diff changeset
204 d=av_gcd(af->data->rate,n->rate);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
205
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
206 // 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
207 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
208 int up=af->data->rate/2;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
209 int dn=n->rate/2;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
210 int m=2;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
211 while(af->data->rate/(d*m) > 5000){
28303
44d67f7f8eb3 Fix compilation: s/ff_gcd/av_gcd.
cehoyos
parents: 28292
diff changeset
212 d=av_gcd(up,dn);
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
213 up/=2; dn/=2; m*=2;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
214 }
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
215 d*=m;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
216 }
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
217
28809
5de88e6e2494 Comment typo fixes for af_resample
reimar
parents: 28322
diff changeset
218 // Create space for circular buffers
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
219 s->xq = malloc(n->nch*sizeof(void*));
28811
7c0b23a811bd Use calloc to allocate the af_resample ring buffers, reportedly using
reimar
parents: 28810
diff changeset
220 s->xq[0] = calloc(n->nch, 2*L*af->data->bps);
28810
54230bed6a34 Use a single malloc to allocate space for the circular buffers.
reimar
parents: 28809
diff changeset
221 for(i=1;i<n->nch;i++)
54230bed6a34 Use a single malloc to allocate space for the circular buffers.
reimar
parents: 28809
diff changeset
222 s->xq[i] = (uint8_t *)s->xq[i-1] + 2*L*af->data->bps;
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
223 s->xi = 0;
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
224
28809
5de88e6e2494 Comment typo fixes for af_resample
reimar
parents: 28322
diff changeset
225 // Check if the design needs to be redone
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
226 if(s->up != af->data->rate/d || s->dn != n->rate/d){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
227 float* w;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
228 float* wt;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
229 float fc;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
230 int j;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
231 s->up = af->data->rate/d;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
232 s->dn = n->rate/d;
21058
1ed61a0494c4 Reinitialize some variables on af_resample reinit, fixes crash
uau
parents: 21017
diff changeset
233 s->wi = 0;
1ed61a0494c4 Reinitialize some variables on af_resample reinit, fixes crash
uau
parents: 21017
diff changeset
234 s->i = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
235
28809
5de88e6e2494 Comment typo fixes for af_resample
reimar
parents: 28322
diff changeset
236 // Calculate cutoff frequency for filter
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 35620
diff changeset
237 fc = 1/(float)(FFMAX(s->up,s->dn));
28809
5de88e6e2494 Comment typo fixes for af_resample
reimar
parents: 28322
diff changeset
238 // Allocate space for polyphase filter bank and prototype filter
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
239 w = malloc(sizeof(float) * s->up *L);
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30633
diff changeset
240 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
241 s->w = malloc(L*s->up*af->data->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
242
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
243 // Design prototype filter type using Kaiser window with beta = 10
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
244 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
245 -1 == af_filter_design_fir(s->up*L, w, &fc, LP|KAISER , 10.0)){
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28813
diff changeset
246 mp_msg(MSGT_AFILTER, MSGL_ERR, "[resample] Unable to design prototype filter.\n");
35620
6e78455a4b60 Fix a resource leak.
upsuper
parents: 34174
diff changeset
247 free(w);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
248 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
249 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
250 // Copy data from prototype to polyphase filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
251 wt=w;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
252 for(j=0;j<L;j++){//Columns
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
253 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
254 if((s->setup & RSMP_MASK) == RSMP_INT){
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
255 float t=(float)s->up*32767.0*(*wt);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
256 ((int16_t*)s->w)[i*L+j] = (int16_t)((t>=0.0)?(t+0.5):(t-0.5));
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
257 }
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
258 else
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
259 ((float*)s->w)[i*L+j] = (float)s->up*(*wt);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
260 wt++;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
261 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
262 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
263 free(w);
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28813
diff changeset
264 mp_msg(MSGT_AFILTER, MSGL_V, "[resample] New filter designed up: %i "
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
265 "down: %i\n", s->up, s->dn);
7568
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
7665
fbd5445cc853 Adding function for calculating the delay caused by the filters
anders
parents: 7616
diff changeset
268 // Set multiplier and delay
24900
9079c9745ff9 A/V sync: take audio filter buffers into account
uau
parents: 24889
diff changeset
269 af->delay = 0; // not set correctly, but shouldn't be too large anyway
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 24595
diff changeset
270 af->mul = (double)s->up / s->dn;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
271 return rv;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
272 }
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
273 case AF_CONTROL_COMMAND_LINE:{
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
274 af_resample_t* s = af->setup;
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7894
diff changeset
275 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
276 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
277 int sloppy=1;
8868
398e3fb7c103 10l bug for float conversion control + feature fix in volume control
anders
parents: 8867
diff changeset
278 sscanf((char*)arg,"%i:%i:%i", &rate, &sloppy, &type);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
279 s->setup = (sloppy?FREQ_SLOPPY:FREQ_EXACT) |
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 35620
diff changeset
280 (av_clip(type,RSMP_LIN,RSMP_FLOAT));
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
281 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
282 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
283 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
284 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
285 ((af_resample_t*)af->setup)->setup = RSMP_FLOAT;
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
286 return AF_OK;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
287 case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
288 // Reinit must be called after this function has been called
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
289
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
290 // Sanity check
7616
d09c125a88fa Changing frequency limit for resampling
anders
parents: 7615
diff changeset
291 if(((int*)arg)[0] < 8000 || ((int*)arg)[0] > 192000){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
292 mp_msg(MSGT_AFILTER, MSGL_ERR, "[resample] The output sample frequency "
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
293 "must be between 8kHz and 192kHz. Current value is %i \n",
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
294 ((int*)arg)[0]);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
295 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
296 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
297
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
298 af->data->rate=((int*)arg)[0];
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
299 mp_msg(MSGT_AFILTER, MSGL_V, "[resample] Changing sample rate "
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
300 "to %iHz\n",af->data->rate);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
301 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
302 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
303 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
304 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
305
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
306 // Deallocate memory
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
307 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
308 {
28812
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
309 af_resample_t *s = af->setup;
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
310 if (s) {
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
311 if (s->xq) free(s->xq[0]);
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
312 free(s->xq);
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
313 free(s->w);
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
314 free(s);
9dd2e47e5a06 Free af->setup and contents in af_resample uninit function.
reimar
parents: 28811
diff changeset
315 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
316 if(af->data)
22179
ecf562795caf Fix memory leaks.
uau
parents: 21058
diff changeset
317 free(af->data->audio);
ecf562795caf Fix memory leaks.
uau
parents: 21058
diff changeset
318 free(af->data);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
319 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
320
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
321 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
322 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
323 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
324 int len = 0; // Length of output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
325 af_data_t* c = data; // Current working data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
326 af_data_t* l = af->data; // Local data
28813
113ae1bae806 Remove several useless casts from af_resample
reimar
parents: 28812
diff changeset
327 af_resample_t* s = af->setup;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
328
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
329 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
330 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
331
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
332 // Run resampling
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
333 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
334 case(RSMP_INT):
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
335 # define FORMAT_I 1
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
336 if(s->up>s->dn){
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
337 # define UP
28201
4ff973912251 Rename libaf/af_resample.h to libaf/af_resample_template.c, it is used as
diego
parents: 24900
diff changeset
338 # include "af_resample_template.c"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
339 # undef UP
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
340 }
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
341 else{
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
342 # define DN
28201
4ff973912251 Rename libaf/af_resample.h to libaf/af_resample_template.c, it is used as
diego
parents: 24900
diff changeset
343 # include "af_resample_template.c"
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
344 # undef DN
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
345 }
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
346 break;
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
347 case(RSMP_FLOAT):
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
348 # undef FORMAT_I
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
349 # define FORMAT_F 1
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
350 if(s->up>s->dn){
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
351 # define UP
28201
4ff973912251 Rename libaf/af_resample.h to libaf/af_resample_template.c, it is used as
diego
parents: 24900
diff changeset
352 # include "af_resample_template.c"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
353 # undef UP
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
354 }
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
355 else{
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
356 # define DN
28201
4ff973912251 Rename libaf/af_resample.h to libaf/af_resample_template.c, it is used as
diego
parents: 24900
diff changeset
357 # include "af_resample_template.c"
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
358 # undef DN
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
359 }
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
360 break;
8867
558f0b1f45ee New auto config for volume and resample and added support for float flag in configuration
anders
parents: 8711
diff changeset
361 case(RSMP_LIN):
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
362 len = linint(c, l, s);
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
363 break;
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
364 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
365
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
366 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
367 c->audio = l->audio;
8607
d6f40a06867b Changes includes:
anders
parents: 8451
diff changeset
368 c->len = len*l->bps;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
369 c->rate = l->rate;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
370
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
371 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
372 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
373
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
374 // 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: 22179
diff changeset
375 static int af_open(af_instance_t* af){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
376 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
377 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
378 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 24595
diff changeset
379 af->mul=1;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
380 af->data=calloc(1,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
381 af->setup=calloc(1,sizeof(af_resample_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
382 if(af->data == NULL || af->setup == NULL)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
383 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
384 ((af_resample_t*)af->setup)->setup = RSMP_INT | FREQ_SLOPPY;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
385 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
386 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
387
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
388 // Description of this plugin
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
389 af_info_t af_info_resample = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
390 "Sample frequency conversion",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
391 "resample",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
392 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
393 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7602
diff changeset
394 AF_FLAGS_REENTRANT,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 22179
diff changeset
395 af_open
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
396 };