2 * The Bauer stereophonic-to-binaural DSP using bs2b library:
3 * http://bs2b.sourceforge.net/
5 * Copyright (c) 2009 Andrew Savchenko
7 * This file is part of MPlayer.
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * MPlayer is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "subopt-helper.h"
31 /// Internal specific data of the filter
33 int level
; ///< crossfeed level
34 int profile
; ///< profile (easy or normal)
35 t_bs2bdp filter
; ///< instance of a library filter
38 #define PLAY(name,type) \
39 static af_data_t *play_##name(struct af_instance_s *af, af_data_t *data) \
41 /* filter is called for all pairs of samples available in the buffer */ \
42 bs2b_cross_feed_##name(((struct af_bs2b*)(af->setup))->filter, \
43 (type*)(data->audio), data->len/data->bps/2); \
53 PLAY(s24be
,bs2b_int24_t
)
54 PLAY(s24le
,bs2b_int24_t
)
60 /// Sanity check for level value
61 static int test_level(void *par
)
63 const int val
= *(int*)par
;
64 if (val
>= 1 && val
<= BS2B_CLEVELS
)
67 mp_msg(MSGT_AFILTER
,MSGL_ERR
, "[bs2b] Level must be in range 1..%i, but "
68 "current value is %i.\n", BS2B_CLEVELS
, val
);
72 /// Sanity check for profile value
73 static int test_profile(void *par
)
75 const int val
= *(int*)par
;
76 if (val
>= 0 && val
<= 1)
79 mp_msg(MSGT_AFILTER
,MSGL_ERR
, "[bs2b] Profile must be either 0 or 1, but "
80 "current value is %i.\n", val
);
84 /// Initialization and runtime control
85 static int control(struct af_instance_s
*af
, int cmd
, void *arg
)
87 struct af_bs2b
*s
= af
->setup
;
90 case AF_CONTROL_REINIT
: {
94 if (!arg
) return AF_ERROR
;
96 format
= ((af_data_t
*)arg
)->format
;
97 af
->data
->rate
= ((af_data_t
*)arg
)->rate
;
98 af
->data
->nch
= 2; // bs2b is useful only for 2ch audio
99 af
->data
->bps
= ((af_data_t
*)arg
)->bps
;
100 af
->data
->format
= format
;
102 /* check for formats supported by libbs2b
103 and assign corresponding handlers */
105 case AF_FORMAT_FLOAT_BE
:
108 case AF_FORMAT_FLOAT_LE
:
111 case AF_FORMAT_S32_BE
:
112 af
->play
= play_s32be
;
114 case AF_FORMAT_S32_LE
:
115 af
->play
= play_s32le
;
117 case AF_FORMAT_S24_BE
:
118 af
->play
= play_s24be
;
120 case AF_FORMAT_S24_LE
:
121 af
->play
= play_s24le
;
123 case AF_FORMAT_S16_BE
:
124 af
->play
= play_s16be
;
126 case AF_FORMAT_S16_LE
:
127 af
->play
= play_s16le
;
137 af
->data
->format
= AF_FORMAT_FLOAT_NE
;
142 bs2b_set_srate(s
->filter
, (long)af
->data
->rate
);
143 mp_msg(MSGT_AFILTER
,MSGL_V
, "[bs2b] using format %s\n",
144 af_fmt2str(af
->data
->format
,buf
,256));
146 return af_test_output(af
,(af_data_t
*)arg
);
148 case AF_CONTROL_COMMAND_LINE
: {
149 const opt_t subopts
[] = {
150 {"level", OPT_ARG_INT
, &s
->level
, test_level
},
151 {"profile", OPT_ARG_INT
, &s
->profile
, test_profile
},
154 if (subopt_parse(arg
, subopts
) != 0) {
155 mp_msg(MSGT_AFILTER
,MSGL_ERR
, "[bs2b] Invalid option specified.\n");
159 bs2b_set_level(s
->filter
, s
->level
+ s
->profile
? BS2B_CLEVELS
: 0);
160 mp_msg(MSGT_AFILTER
,MSGL_V
, "[bs2b] using profile %i, level %i\n",
161 s
->profile
, s
->level
);
168 /// Deallocate memory and close library
169 static void uninit(struct af_instance_s
*af
)
171 struct af_bs2b
*s
= af
->setup
;
174 bs2b_close(s
->filter
);
178 /// Allocate memory, set function pointers and init library
179 static int af_open(af_instance_t
*af
)
182 af
->control
= control
;
185 if (!(af
->data
= calloc(1,sizeof(af_data_t
))))
187 if (!(af
->setup
= s
= calloc(1,sizeof(struct af_bs2b
)))) {
192 // NULL means failed initialization
193 if (!(s
->filter
= bs2b_open())) {
198 // Set defaults the same as in the library:
204 /// Description of this filter
205 af_info_t af_info_bs2b
= {
206 "Bauer stereophonic-to-binaural audio filter",