annotate libaf/af_bs2b.c @ 36425:e89214f37501

Remove unused definitions.
author ib
date Sun, 24 Nov 2013 00:44:44 +0000
parents a93891202051
children
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
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 29203
diff changeset
29 #include "mp_msg.h"
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 29203
diff changeset
30 #include "subopt-helper.h"
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
31 #include "af.h"
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
32
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
33 /// Internal specific data of the filter
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
34 struct af_bs2b {
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
35 int fcut; ///< cut frequency in Hz
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
36 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
37 char *profile; ///< profile (available crossfeed presets)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
38 t_bs2bdp filter; ///< instance of a library filter
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
39 };
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
40
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
41 #define PLAY(name, type) \
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
42 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
43 { \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
44 /* filter is called for all pairs of samples available in the buffer */ \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
45 bs2b_cross_feed_##name(((struct af_bs2b*)(af->setup))->filter, \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
46 (type*)(data->audio), data->len/data->bps/2); \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
47 \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
48 return data; \
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
49 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
50
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
51 PLAY(f, float)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
52 PLAY(fbe, float)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
53 PLAY(fle, float)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
54 PLAY(s32be, int32_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
55 PLAY(u32be, uint32_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
56 PLAY(s32le, int32_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
57 PLAY(u32le, uint32_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
58 PLAY(s24be, bs2b_int24_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
59 PLAY(u24be, bs2b_uint24_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
60 PLAY(s24le, bs2b_int24_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
61 PLAY(u24le, bs2b_uint24_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
62 PLAY(s16be, int16_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
63 PLAY(u16be, uint16_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
64 PLAY(s16le, int16_t)
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
65 PLAY(u16le, uint16_t)
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
66 PLAY(s8, int8_t)
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
67 PLAY(u8, uint8_t)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
68
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
69 /// Sanity check for fcut value
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
70 static int test_fcut(void *par)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
71 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
72 const int val = *(int*)par;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
73 if (val >= BS2B_MINFCUT && val <= BS2B_MAXFCUT)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
74 return 1;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
75
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
76 mp_msg(MSGT_AFILTER, MSGL_ERR,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
77 "[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
78 BS2B_MINFCUT, BS2B_MAXFCUT, val);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
79 return 0;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
80 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
81
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
82 /// Sanity check for feed value
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
83 static int test_feed(void *par)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
84 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
85 const int val = *(int*)par;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
86 if (val >= BS2B_MINFEED && val <= BS2B_MAXFEED)
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
87 return 1;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
88
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
89 mp_msg(MSGT_AFILTER, MSGL_ERR,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
90 "[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
91 BS2B_MINFEED, BS2B_MAXFEED, val);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
92 return 0;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
93 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
94
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
95 /// Initialization and runtime control
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
96 static int control(struct af_instance_s *af, int cmd, void *arg)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
97 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
98 struct af_bs2b *s = af->setup;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
99
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
100 switch (cmd) {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
101 case AF_CONTROL_REINIT: {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
102 int format;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
103 char buf[256];
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
104 // Sanity check
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
105 if (!arg) return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
106
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
107 format = ((af_data_t*)arg)->format;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
108 af->data->rate = ((af_data_t*)arg)->rate;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
109 af->data->nch = 2; // bs2b is useful only for 2ch audio
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
110 af->data->bps = ((af_data_t*)arg)->bps;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
111 af->data->format = format;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
112
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
113 /* check for formats supported by libbs2b
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
114 and assign corresponding handlers */
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
115 switch (format) {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
116 case AF_FORMAT_FLOAT_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
117 af->play = play_fbe;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
118 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
119 case AF_FORMAT_FLOAT_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
120 af->play = play_fle;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
121 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
122 case AF_FORMAT_S32_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
123 af->play = play_s32be;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
124 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
125 case AF_FORMAT_U32_BE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
126 af->play = play_u32be;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
127 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
128 case AF_FORMAT_S32_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
129 af->play = play_s32le;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
130 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
131 case AF_FORMAT_U32_LE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
132 af->play = play_u32le;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
133 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
134 case AF_FORMAT_S24_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
135 af->play = play_s24be;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
136 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
137 case AF_FORMAT_U24_BE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
138 af->play = play_u24be;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
139 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
140 case AF_FORMAT_S24_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
141 af->play = play_s24le;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
142 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
143 case AF_FORMAT_U24_LE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
144 af->play = play_u24le;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
145 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
146 case AF_FORMAT_S16_BE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
147 af->play = play_s16be;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
148 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
149 case AF_FORMAT_U16_BE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
150 af->play = play_u16be;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
151 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
152 case AF_FORMAT_S16_LE:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
153 af->play = play_s16le;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
154 break;
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
155 case AF_FORMAT_U16_LE:
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
156 af->play = play_u16le;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
157 break;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
158 case AF_FORMAT_S8:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
159 af->play = play_s8;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
160 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
161 case AF_FORMAT_U8:
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
162 af->play = play_u8;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
163 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
164 default:
29095
3afe8b737f43 Use native endian float filter provided by libbs2b instead of
bircoph
parents: 29093
diff changeset
165 af->play = play_f;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
166 af->data->format = AF_FORMAT_FLOAT_NE;
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
167 af->data->bps = 4;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
168 break;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
169 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
170
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
171 // bs2b have srate limits, try to resample if needed
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
172 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
173 af->data->rate = BS2B_DEFAULT_SRATE;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
174 mp_msg(MSGT_AFILTER, MSGL_WARN,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
175 "[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
176 "[bs2b] Trying to resample to %d Hz.\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
177 af->data->rate, BS2B_MINSRATE, BS2B_MAXSRATE, BS2B_DEFAULT_SRATE);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
178 }
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
179 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
180 mp_msg(MSGT_AFILTER, MSGL_V, "[bs2b] using format %s\n",
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
181 af_fmt2str(af->data->format,buf,256));
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
182
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
183 return af_test_output(af,(af_data_t*)arg);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
184 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
185 case AF_CONTROL_COMMAND_LINE: {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
186 const opt_t subopts[] = {
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
187 {"fcut", OPT_ARG_INT, &s->fcut, test_fcut},
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
188 {"feed", OPT_ARG_INT, &s->feed, test_feed},
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
189 {"profile", OPT_ARG_MSTRZ, &s->profile, NULL},
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
190 {NULL}
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
191 };
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
192 if (subopt_parse(arg, subopts) != 0) {
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
193 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
194 free(s->profile);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
195 return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
196 }
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
197 // parse profile if specified
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
198 if (s->profile) {
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
199 if (!strcmp(s->profile, "default"))
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
200 bs2b_set_level(s->filter, BS2B_DEFAULT_CLEVEL);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
201 else if (!strcmp(s->profile, "cmoy"))
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
202 bs2b_set_level(s->filter, BS2B_CMOY_CLEVEL);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
203 else if (!strcmp(s->profile, "jmeier"))
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
204 bs2b_set_level(s->filter, BS2B_JMEIER_CLEVEL);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
205 else {
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
206 mp_msg(MSGT_AFILTER, MSGL_ERR,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
207 "[bs2b] Invalid profile specified: %s.\n"
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
208 "[bs2b] Available profiles are: default, cmoy, jmeier.\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
209 s->profile);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
210 free(s->profile);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
211 return AF_ERROR;
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 }
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
214 // 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
215 if (s->fcut)
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
216 bs2b_set_level_fcut(s->filter, s->fcut);
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
217 if (s->feed)
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
218 bs2b_set_level_feed(s->filter, s->feed);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
219
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
220 mp_msg(MSGT_AFILTER, MSGL_V,
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
221 "[bs2b] using cut frequency %d, LF feed level %d\n",
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
222 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
223 free(s->profile);
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
224 return AF_OK;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
225 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
226 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
227 return AF_UNKNOWN;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
228 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
229
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
230 /// Deallocate memory and close library
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
231 static void uninit(struct af_instance_s *af)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
232 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
233 struct af_bs2b *s = af->setup;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
234 free(af->data);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
235 if (s && s->filter)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
236 bs2b_close(s->filter);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
237 free(s);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
238 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
239
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
240 /// Allocate memory, set function pointers and init library
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
241 static int af_open(af_instance_t *af)
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
242 {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
243 struct af_bs2b *s;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
244 af->control = control;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
245 af->uninit = uninit;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
246 af->mul = 1;
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
247 if (!(af->data = calloc(1, sizeof(af_data_t))))
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
248 return AF_ERROR;
29203
80865c30ee80 Cosmetics for r29244 to follow K&R style closely.
bircoph
parents: 29202
diff changeset
249 if (!(af->setup = s = calloc(1, sizeof(struct af_bs2b)))) {
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
250 free(af->data);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
251 return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
252 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
253
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
254 // NULL means failed initialization
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
255 if (!(s->filter = bs2b_open())) {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
256 free(af->data);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
257 free(af->setup);
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
258 return AF_ERROR;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
259 }
29202
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
260 // Set zero defaults indicating no option was specified.
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
261 s->profile = NULL;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
262 s->fcut = 0;
239573db53a1 Support for libbs2b ver. 3.0.0 API.
bircoph
parents: 29095
diff changeset
263 s->feed = 0;
29093
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
264 return AF_OK;
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
265 }
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
266
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
267 /// Description of this filter
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
268 af_info_t af_info_bs2b = {
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
269 "Bauer stereophonic-to-binaural audio filter",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
270 "bs2b",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
271 "Andrew Savchenko",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
272 "",
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
273 AF_FLAGS_REENTRANT,
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
274 af_open
9d220a44caae Add libbs2b audio filter itself.
bircoph
parents:
diff changeset
275 };