annotate libaf/af_bs2b.c @ 33179:218edd8fc782

Cosmetic: Format to MPlayer coding style. Additionally: remove needless includes, group and sort includes, group and sort variables, rename gtkAOFakeSurround declaration gtkAOSurround, add #ifdefs to variable declarations, group statements by adding or removing new lines to ease reading, move assignments outside conditions, add parentheses, avoid mixing declaration and code, revise comments and add new ones.
author ib
date Fri, 15 Apr 2011 14:30:58 +0000
parents 80865c30ee80
children a93891202051
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
1 /*
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
2 * The Bauer stereophonic-to-binaural DSP using bs2b library:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
3 * http://bs2b.sourceforge.net/
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
4 *
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
5 * Copyright (c) 2009 Andrew Savchenko
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
6 *
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
7 * This file is part of MPlayer.
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
8 *
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
12 * (at your option) any later version.
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
13 *
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
17 * GNU General Public License for more details.
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
18 *
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License along
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
22 */
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
23
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
24 #include <bs2b.h>
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
25 #include <inttypes.h>
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
26 #include <stdlib.h>
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
27 #include <string.h>
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
28
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
29 #include "af.h"
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
30 #include "subopt-helper.h"
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
31
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
32 /// Internal specific data of the filter
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
33 struct af_bs2b {
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
34 int fcut; ///< cut frequency in Hz
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
35 int feed; ///< feed level for low frequencies in 0.1*dB
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
36 char *profile; ///< profile (available crossfeed presets)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
37 t_bs2bdp filter; ///< instance of a library filter
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
38 };
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
39
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
40 #define PLAY(name, type) \
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
41 static af_data_t *play_##name(struct af_instance_s *af, af_data_t *data) \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
42 { \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
43 /* filter is called for all pairs of samples available in the buffer */ \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
44 bs2b_cross_feed_##name(((struct af_bs2b*)(af->setup))->filter, \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
45 (type*)(data->audio), data->len/data->bps/2); \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
46 \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
47 return data; \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
48 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
49
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
50 PLAY(f, float)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
51 PLAY(fbe, float)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
52 PLAY(fle, float)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
53 PLAY(s32be, int32_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
54 PLAY(u32be, uint32_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
55 PLAY(s32le, int32_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
56 PLAY(u32le, uint32_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
57 PLAY(s24be, bs2b_int24_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
58 PLAY(u24be, bs2b_uint24_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
59 PLAY(s24le, bs2b_int24_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
60 PLAY(u24le, bs2b_uint24_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
61 PLAY(s16be, int16_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
62 PLAY(u16be, uint16_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
63 PLAY(s16le, int16_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
64 PLAY(u16le, uint16_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
65 PLAY(s8, int8_t)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
66 PLAY(u8, uint8_t)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
67
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
68 /// Sanity check for fcut value
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
69 static int test_fcut(void *par)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
70 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
71 const int val = *(int*)par;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
72 if (val >= BS2B_MINFCUT && val <= BS2B_MAXFCUT)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
73 return 1;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
74
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
75 mp_msg(MSGT_AFILTER, MSGL_ERR,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
76 "[bs2b] Cut frequency must be in range [%d..%d], but current value is %d.\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
77 BS2B_MINFCUT, BS2B_MAXFCUT, val);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
78 return 0;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
79 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
80
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
81 /// Sanity check for feed value
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
82 static int test_feed(void *par)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
83 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
84 const int val = *(int*)par;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
85 if (val >= BS2B_MINFEED && val <= BS2B_MAXFEED)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
86 return 1;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
87
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
88 mp_msg(MSGT_AFILTER, MSGL_ERR,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
89 "[bs2b] Feed level must be in range [%d..%d], but current value is %d.\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
90 BS2B_MINFEED, BS2B_MAXFEED, val);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
91 return 0;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
92 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
93
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
94 /// Initialization and runtime control
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
95 static int control(struct af_instance_s *af, int cmd, void *arg)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
96 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
97 struct af_bs2b *s = af->setup;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
98
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
99 switch (cmd) {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
100 case AF_CONTROL_REINIT: {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
101 int format;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
102 char buf[256];
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
103 // Sanity check
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
104 if (!arg) return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
105
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
106 format = ((af_data_t*)arg)->format;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
107 af->data->rate = ((af_data_t*)arg)->rate;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
108 af->data->nch = 2; // bs2b is useful only for 2ch audio
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
109 af->data->bps = ((af_data_t*)arg)->bps;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
110 af->data->format = format;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
111
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
112 /* check for formats supported by libbs2b
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
113 and assign corresponding handlers */
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
114 switch (format) {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
115 case AF_FORMAT_FLOAT_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
116 af->play = play_fbe;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
117 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
118 case AF_FORMAT_FLOAT_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
119 af->play = play_fle;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
120 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
121 case AF_FORMAT_S32_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
122 af->play = play_s32be;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
123 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
124 case AF_FORMAT_U32_BE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
125 af->play = play_u32be;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
126 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
127 case AF_FORMAT_S32_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
128 af->play = play_s32le;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
129 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
130 case AF_FORMAT_U32_LE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
131 af->play = play_u32le;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
132 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
133 case AF_FORMAT_S24_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
134 af->play = play_s24be;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
135 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
136 case AF_FORMAT_U24_BE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
137 af->play = play_u24be;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
138 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
139 case AF_FORMAT_S24_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
140 af->play = play_s24le;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
141 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
142 case AF_FORMAT_U24_LE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
143 af->play = play_u24le;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
144 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
145 case AF_FORMAT_S16_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
146 af->play = play_s16be;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
147 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
148 case AF_FORMAT_U16_BE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
149 af->play = play_u16be;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
150 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
151 case AF_FORMAT_S16_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
152 af->play = play_s16le;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
153 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
154 case AF_FORMAT_U16_LE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
155 af->play = play_u16le;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
156 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
157 case AF_FORMAT_S8:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
158 af->play = play_s8;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
159 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
160 case AF_FORMAT_U8:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
161 af->play = play_u8;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
162 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
163 default:
29095
3afe8b737f43 Use native endian float filter provided by libbs2b instead of
bircoph
parents: 29093
diff changeset
164 af->play = play_f;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
165 af->data->format = AF_FORMAT_FLOAT_NE;
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
166 af->data->bps = 4;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
167 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
168 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
169
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
170 // bs2b have srate limits, try to resample if needed
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
171 if (af->data->rate > BS2B_MAXSRATE || af->data->rate < BS2B_MINSRATE) {
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
172 af->data->rate = BS2B_DEFAULT_SRATE;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
173 mp_msg(MSGT_AFILTER, MSGL_WARN,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
174 "[bs2b] Requested sample rate %d Hz is out of bounds [%d..%d] Hz.\n"
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
175 "[bs2b] Trying to resample to %d Hz.\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
176 af->data->rate, BS2B_MINSRATE, BS2B_MAXSRATE, BS2B_DEFAULT_SRATE);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
177 }
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
178 bs2b_set_srate(s->filter, (long)af->data->rate);
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
179 mp_msg(MSGT_AFILTER, MSGL_V, "[bs2b] using format %s\n",
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
180 af_fmt2str(af->data->format,buf,256));
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
181
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
182 return af_test_output(af,(af_data_t*)arg);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
183 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
184 case AF_CONTROL_COMMAND_LINE: {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
185 const opt_t subopts[] = {
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
186 {"fcut", OPT_ARG_INT, &s->fcut, test_fcut},
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
187 {"feed", OPT_ARG_INT, &s->feed, test_feed},
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
188 {"profile", OPT_ARG_MSTRZ, &s->profile, NULL},
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
189 {NULL}
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
190 };
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
191 if (subopt_parse(arg, subopts) != 0) {
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
192 mp_msg(MSGT_AFILTER, MSGL_ERR, "[bs2b] Invalid option specified.\n");
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
193 free(s->profile);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
194 return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
195 }
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
196 // parse profile if specified
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
197 if (s->profile) {
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
198 if (!strcmp(s->profile, "default"))
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
199 bs2b_set_level(s->filter, BS2B_DEFAULT_CLEVEL);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
200 else if (!strcmp(s->profile, "cmoy"))
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
201 bs2b_set_level(s->filter, BS2B_CMOY_CLEVEL);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
202 else if (!strcmp(s->profile, "jmeier"))
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
203 bs2b_set_level(s->filter, BS2B_JMEIER_CLEVEL);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
204 else {
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
205 mp_msg(MSGT_AFILTER, MSGL_ERR,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
206 "[bs2b] Invalid profile specified: %s.\n"
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
207 "[bs2b] Available profiles are: default, cmoy, jmeier.\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
208 s->profile);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
209 free(s->profile);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
210 return AF_ERROR;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
211 }
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
212 }
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
213 // set fcut and feed only if specified, otherwise defaults will be used
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
214 if (s->fcut)
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
215 bs2b_set_level_fcut(s->filter, s->fcut);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
216 if (s->feed)
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
217 bs2b_set_level_feed(s->filter, s->feed);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
218
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
219 mp_msg(MSGT_AFILTER, MSGL_V,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
220 "[bs2b] using cut frequency %d, LF feed level %d\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
221 bs2b_get_level_fcut(s->filter), bs2b_get_level_feed(s->filter));
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
222 free(s->profile);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
223 return AF_OK;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
224 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
225 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
226 return AF_UNKNOWN;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
227 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
228
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
229 /// Deallocate memory and close library
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
230 static void uninit(struct af_instance_s *af)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
231 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
232 struct af_bs2b *s = af->setup;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
233 free(af->data);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
234 if (s && s->filter)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
235 bs2b_close(s->filter);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
236 free(s);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
237 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
238
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
239 /// Allocate memory, set function pointers and init library
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
240 static int af_open(af_instance_t *af)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
241 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
242 struct af_bs2b *s;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
243 af->control = control;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
244 af->uninit = uninit;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
245 af->mul = 1;
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
246 if (!(af->data = calloc(1, sizeof(af_data_t))))
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
247 return AF_ERROR;
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
248 if (!(af->setup = s = calloc(1, sizeof(struct af_bs2b)))) {
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
249 free(af->data);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
250 return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
251 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
252
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
253 // NULL means failed initialization
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
254 if (!(s->filter = bs2b_open())) {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
255 free(af->data);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
256 free(af->setup);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
257 return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
258 }
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
259 // Set zero defaults indicating no option was specified.
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
260 s->profile = NULL;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
261 s->fcut = 0;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
262 s->feed = 0;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
263 return AF_OK;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
264 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
265
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
266 /// Description of this filter
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
267 af_info_t af_info_bs2b = {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
268 "Bauer stereophonic-to-binaural audio filter",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
269 "bs2b",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
270 "Andrew Savchenko",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
271 "",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
272 AF_FLAGS_REENTRANT,
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
273 af_open
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
274 };