2 * Experimental audio filter that mixes 5.1 and 5.1 with matrix
3 * encoded rear channels into headphone signal using FIR filtering
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 /* HRTF filter coefficients and adjustable parameters */
36 typedef struct af_hrtf_s
{
38 int dlbuflen
, hrflen
, basslen
;
39 /* L, C, R, Ls, Rs channels */
40 float *lf
, *rf
, *lr
, *rr
, *cf
, *cr
;
41 const float *cf_ir
, *af_ir
, *of_ir
, *ar_ir
, *or_ir
, *cr_ir
;
42 int cf_o
, af_o
, of_o
, ar_o
, or_o
, cr_o
;
46 /* Whether to matrix decode the rear center channel */
48 /* How to decode the input:
51 2 = matrix encoded 2 channels */
53 /* Full wave rectified (FWR) amplitudes and gain used to steer the
54 active matrix decoding of front channels (variable names
55 lpr/lmr means Lt + Rt, Lt - Rt) */
56 float l_fwr
, r_fwr
, lpr_fwr
, lmr_fwr
;
57 float adapt_l_gain
, adapt_r_gain
, adapt_lpr_gain
, adapt_lmr_gain
;
58 /* Matrix input decoding require special FWR buffer, since the
59 decoding is done in place. */
60 float *fwrbuf_l
, *fwrbuf_r
, *fwrbuf_lr
, *fwrbuf_rr
;
61 /* Rear channel delay buffer for matrix decoding */
63 /* Full wave rectified amplitude and gain used to steer the active
64 matrix decoding of center rear channel */
65 float lr_fwr
, rr_fwr
, lrprr_fwr
, lrmrr_fwr
;
66 float adapt_lr_gain
, adapt_rr_gain
;
67 float adapt_lrprr_gain
, adapt_lrmrr_gain
;
68 /* Cyclic position on the ring buffer */
73 /* Convolution on a ring buffer
74 * nx: length of the ring buffer
75 * nk: length of the convolution kernel
77 * sk: convolution kernel
78 * offset: offset on the ring buffer, can be
80 static float conv(const int nx
, const int nk
, const float *sx
, const float *sk
,
83 /* k = reminder of offset / nx */
84 int k
= offset
>= 0 ? offset
% nx
: nx
+ (offset
% nx
);
87 return af_filter_fir(nk
, sx
+ k
, sk
);
89 return af_filter_fir(nk
+ k
- nx
, sx
, sk
+ nx
- k
) +
90 af_filter_fir(nx
- k
, sx
+ k
, sk
);
93 /* Detect when the impulse response starts (significantly) */
94 static int pulse_detect(const float *sx
)
96 /* nmax must be the reference impulse response length (128) minus
98 const int nmax
= 128 - HRTFFILTLEN
;
99 const float thresh
= IRTHRESH
;
102 for(i
= 0; i
< nmax
; i
++)
103 if(fabs(sx
[i
]) > thresh
)
108 /* Fuzzy matrix coefficient transfer function to "lock" the matrix on
109 a effectively passive mode if the gain is approximately 1 */
110 static inline float passive_lock(float x
)
112 const float x1
= x
- 1;
113 const float ax1s
= fabs(x
- 1) * (1.0 / MATAGCLOCK
);
115 return x1
- x1
/ (1 + ax1s
* ax1s
) + 1;
118 /* Unified active matrix decoder for 2 channel matrix encoded surround
120 static inline void matrix_decode(short *in
, const int k
, const int il
,
121 const int ir
, const int decode_rear
,
123 float l_fwr
, float r_fwr
,
124 float lpr_fwr
, float lmr_fwr
,
125 float *adapt_l_gain
, float *adapt_r_gain
,
126 float *adapt_lpr_gain
, float *adapt_lmr_gain
,
127 float *lf
, float *rf
, float *lr
,
128 float *rr
, float *cf
)
130 const int kr
= (k
+ MATREARDELAY
) % dlbuflen
;
131 float l_gain
= (l_fwr
+ r_fwr
) /
133 float r_gain
= (l_fwr
+ r_fwr
) /
135 /* The 2nd axis has strong gain fluctuations, and therefore require
136 limits. The factor corresponds to the 1 / amplification of (Lt
137 - Rt) when (Lt, Rt) is strongly correlated. (e.g. during
138 dialogues). It should be bigger than -12 dB to prevent
140 float lmr_lim_fwr
= lmr_fwr
> M9_03DB
* lpr_fwr
?
141 lmr_fwr
: M9_03DB
* lpr_fwr
;
142 float lpr_gain
= (lpr_fwr
+ lmr_lim_fwr
) /
143 (1 + lpr_fwr
+ lpr_fwr
);
144 float lmr_gain
= (lpr_fwr
+ lmr_lim_fwr
) /
145 (1 + lmr_lim_fwr
+ lmr_lim_fwr
);
146 float lmr_unlim_gain
= (lpr_fwr
+ lmr_fwr
) /
147 (1 + lmr_fwr
+ lmr_fwr
);
149 float l_agc
, r_agc
, lpr_agc
, lmr_agc
;
150 float f
, d_gain
, c_gain
, c_agc_cfk
;
153 static int counter
= 0;
157 fp_out
= fopen("af_hrtf.log", "w");
158 if(counter
% 240 == 0)
159 fprintf(fp_out
, "%g %g %g %g %g ", counter
* (1.0 / 48000),
160 l_gain
, r_gain
, lpr_gain
, lmr_gain
);
163 /*** AXIS NO. 1: (Lt, Rt) -> (C, Ls, Rs) ***/
165 d_gain
= (fabs(l_gain
- *adapt_l_gain
) +
166 fabs(r_gain
- *adapt_r_gain
)) * 0.5;
167 f
= d_gain
* (1.0 / MATAGCTRIG
);
168 f
= MATAGCDECAY
- MATAGCDECAY
/ (1 + f
* f
);
169 *adapt_l_gain
= (1 - f
) * *adapt_l_gain
+ f
* l_gain
;
170 *adapt_r_gain
= (1 - f
) * *adapt_r_gain
+ f
* r_gain
;
172 l_agc
= in
[il
] * passive_lock(*adapt_l_gain
);
173 r_agc
= in
[ir
] * passive_lock(*adapt_r_gain
);
174 cf
[k
] = (l_agc
+ r_agc
) * M_SQRT1_2
;
176 lr
[kr
] = rr
[kr
] = (l_agc
- r_agc
) * M_SQRT1_2
;
177 /* Stereo rear channel is steered with the same AGC steering as
178 the decoding matrix. Note this requires a fast updating AGC
179 at the order of 20 ms (which is the case here). */
180 lr
[kr
] *= (l_fwr
+ l_fwr
) /
182 rr
[kr
] *= (r_fwr
+ r_fwr
) /
186 /*** AXIS NO. 2: (Lt + Rt, Lt - Rt) -> (L, R) ***/
187 lpr
= (in
[il
] + in
[ir
]) * M_SQRT1_2
;
188 lmr
= (in
[il
] - in
[ir
]) * M_SQRT1_2
;
190 d_gain
= fabs(lmr_unlim_gain
- *adapt_lmr_gain
);
191 f
= d_gain
* (1.0 / MATAGCTRIG
);
192 f
= MATAGCDECAY
- MATAGCDECAY
/ (1 + f
* f
);
193 *adapt_lpr_gain
= (1 - f
) * *adapt_lpr_gain
+ f
* lpr_gain
;
194 *adapt_lmr_gain
= (1 - f
) * *adapt_lmr_gain
+ f
* lmr_gain
;
196 lpr_agc
= lpr
* passive_lock(*adapt_lpr_gain
);
197 lmr_agc
= lmr
* passive_lock(*adapt_lmr_gain
);
198 lf
[k
] = (lpr_agc
+ lmr_agc
) * M_SQRT1_2
;
199 rf
[k
] = (lpr_agc
- lmr_agc
) * M_SQRT1_2
;
201 /*** CENTER FRONT CANCELLATION ***/
202 /* A heuristic approach exploits that Lt + Rt gain contains the
203 information about Lt, Rt correlation. This effectively reshapes
204 the front and rear "cones" to concentrate Lt + Rt to C and
205 introduce Lt - Rt in L, R. */
206 /* 0.67677 is the emprical lower bound for lpr_gain. */
207 c_gain
= 8 * (*adapt_lpr_gain
- 0.67677);
208 c_gain
= c_gain
> 0 ? c_gain
: 0;
209 /* c_gain should not be too high, not even reaching full
210 cancellation (~ 0.50 - 0.55 at current AGC implementation), or
211 the center will s0und too narrow. */
212 c_gain
= MATCOMPGAIN
/ (1 + c_gain
* c_gain
);
213 c_agc_cfk
= c_gain
* cf
[k
];
216 cf
[k
] += c_agc_cfk
+ c_agc_cfk
;
218 if(counter
% 240 == 0)
219 fprintf(fp_out
, "%g %g %g %g %g\n",
220 *adapt_l_gain
, *adapt_r_gain
,
221 *adapt_lpr_gain
, *adapt_lmr_gain
,
227 static inline void update_ch(af_hrtf_t
*s
, short *in
, const int k
)
229 const int fwr_pos
= (k
+ FWRDURATION
) % s
->dlbuflen
;
230 /* Update the full wave rectified total amplitude */
231 /* Input matrix decoder */
232 if(s
->decode_mode
== HRTF_MIX_MATRIX2CH
) {
233 s
->l_fwr
+= abs(in
[0]) - fabs(s
->fwrbuf_l
[fwr_pos
]);
234 s
->r_fwr
+= abs(in
[1]) - fabs(s
->fwrbuf_r
[fwr_pos
]);
235 s
->lpr_fwr
+= abs(in
[0] + in
[1]) -
236 fabs(s
->fwrbuf_l
[fwr_pos
] + s
->fwrbuf_r
[fwr_pos
]);
237 s
->lmr_fwr
+= abs(in
[0] - in
[1]) -
238 fabs(s
->fwrbuf_l
[fwr_pos
] - s
->fwrbuf_r
[fwr_pos
]);
240 /* Rear matrix decoder */
242 s
->lr_fwr
+= abs(in
[2]) - fabs(s
->fwrbuf_lr
[fwr_pos
]);
243 s
->rr_fwr
+= abs(in
[3]) - fabs(s
->fwrbuf_rr
[fwr_pos
]);
244 s
->lrprr_fwr
+= abs(in
[2] + in
[3]) -
245 fabs(s
->fwrbuf_lr
[fwr_pos
] + s
->fwrbuf_rr
[fwr_pos
]);
246 s
->lrmrr_fwr
+= abs(in
[2] - in
[3]) -
247 fabs(s
->fwrbuf_lr
[fwr_pos
] - s
->fwrbuf_rr
[fwr_pos
]);
250 switch (s
->decode_mode
) {
252 /* 5/5+1 channel sources */
256 s
->fwrbuf_lr
[k
] = s
->lr
[k
] = in
[2];
257 s
->fwrbuf_rr
[k
] = s
->rr
[k
] = in
[3];
259 case HRTF_MIX_MATRIX2CH
:
260 /* Matrix encoded 2 channel sources */
261 s
->fwrbuf_l
[k
] = in
[0];
262 s
->fwrbuf_r
[k
] = in
[1];
263 matrix_decode(in
, k
, 0, 1, 1, s
->dlbuflen
,
265 s
->lpr_fwr
, s
->lmr_fwr
,
266 &(s
->adapt_l_gain
), &(s
->adapt_r_gain
),
267 &(s
->adapt_lpr_gain
), &(s
->adapt_lmr_gain
),
268 s
->lf
, s
->rf
, s
->lr
, s
->rr
, s
->cf
);
270 case HRTF_MIX_STEREO
:
274 s
->cf
[k
] = s
->lr
[k
] = s
->rr
[k
] = 0;
278 /* We need to update the bass compensation delay line, too. */
279 s
->ba_l
[k
] = in
[0] + in
[4] + in
[2];
280 s
->ba_r
[k
] = in
[4] + in
[1] + in
[3];
283 /* Initialization and runtime control */
284 static int control(struct af_instance_s
*af
, int cmd
, void* arg
)
286 af_hrtf_t
*s
= af
->setup
;
291 case AF_CONTROL_REINIT
:
292 af
->data
->rate
= ((af_data_t
*)arg
)->rate
;
293 if(af
->data
->rate
!= 48000) {
294 // automatic samplerate adjustment in the filter chain
295 // is not yet supported.
296 mp_msg(MSGT_AFILTER
, MSGL_ERR
,
297 "[hrtf] ERROR: Sampling rate is not 48000 Hz (%d)!\n",
301 af
->data
->nch
= ((af_data_t
*)arg
)->nch
;
302 if(af
->data
->nch
== 2) {
303 /* 2 channel input */
304 if(s
->decode_mode
!= HRTF_MIX_MATRIX2CH
) {
305 /* Default behavior is stereo mixing. */
306 s
->decode_mode
= HRTF_MIX_STEREO
;
309 else if (af
->data
->nch
< 5)
311 af
->data
->format
= AF_FORMAT_S16_NE
;
313 test_output_res
= af_test_output(af
, (af_data_t
*)arg
);
314 af
->mul
= 2.0 / af
->data
->nch
;
315 // after testing input set the real output format
318 return test_output_res
;
319 case AF_CONTROL_COMMAND_LINE
:
320 sscanf((char*)arg
, "%c", &mode
);
323 /* Use matrix rear decoding. */
327 /* Input needs matrix decoding. */
328 s
->decode_mode
= HRTF_MIX_MATRIX2CH
;
334 mp_msg(MSGT_AFILTER
, MSGL_ERR
,
335 "[hrtf] Mode is neither 'm', 's', nor '0' (%c).\n",
346 /* Deallocate memory */
347 static void uninit(struct af_instance_s
*af
)
350 af_hrtf_t
*s
= af
->setup
;
381 free(af
->data
->audio
);
385 /* Filter data through filter
387 Two "tricks" are used to compensate the "color" of the KEMAR data:
389 1. The KEMAR data is refiltered to ensure that the front L, R channels
390 on the same side of the ear are equalized (especially in the high
393 2. A bass compensation is introduced to ensure that 0-200 Hz are not
394 damped (without any real 3D acoustical image, however).
396 static af_data_t
* play(struct af_instance_s
*af
, af_data_t
*data
)
398 af_hrtf_t
*s
= af
->setup
;
399 short *in
= data
->audio
; // Input audio data
400 short *out
= NULL
; // Output audio data
401 short *end
= in
+ data
->len
/ sizeof(short); // Loop end
402 float common
, left
, right
, diff
, left_b
, right_b
;
403 const int dblen
= s
->dlbuflen
, hlen
= s
->hrflen
, blen
= s
->basslen
;
405 if(AF_OK
!= RESIZE_LOCAL_BUFFER(af
, data
))
410 switch (s
->decode_mode
) {
412 mp_msg(MSGT_AFILTER
, MSGL_INFO
,
413 "[hrtf] Using HRTF to mix %s discrete surround into "
414 "L, R channels\n", s
->matrix_mode
? "5+1" : "5");
416 case HRTF_MIX_STEREO
:
417 mp_msg(MSGT_AFILTER
, MSGL_INFO
,
418 "[hrtf] Using HRTF to mix stereo into "
421 case HRTF_MIX_MATRIX2CH
:
422 mp_msg(MSGT_AFILTER
, MSGL_INFO
,
423 "[hrtf] Using active matrix to decode 2 channel "
424 "input, HRTF to mix %s matrix surround into "
425 "L, R channels\n", "3/2");
428 mp_msg(MSGT_AFILTER
, MSGL_WARN
,
429 "[hrtf] bogus decode_mode: %d\n", s
->decode_mode
);
434 mp_msg(MSGT_AFILTER
, MSGL_INFO
,
435 "[hrtf] Using active matrix to decode rear center "
439 out
= af
->data
->audio
;
441 /* MPlayer's 5 channel layout (notation for the variable):
443 * 0: L (LF), 1: R (RF), 2: Ls (LR), 3: Rs (RR), 4: C (CF), matrix
446 * or: L = left, C = center, R = right, F = front, R = rear
456 * or: C = center, A = same side, O = opposite, F = front, R = rear
460 const int k
= s
->cyc_pos
;
464 /* Simulate a 7.5 ms -20 dB echo of the center channel in the
465 front channels (like reflection from a room wall) - a kind of
466 psycho-acoustically "cheating" to focus the center front
467 channel, which is normally hard to be perceived as front */
468 s
->lf
[k
] += CFECHOAMPL
* s
->cf
[(k
+ CFECHODELAY
) % s
->dlbuflen
];
469 s
->rf
[k
] += CFECHOAMPL
* s
->cf
[(k
+ CFECHODELAY
) % s
->dlbuflen
];
471 switch (s
->decode_mode
) {
473 case HRTF_MIX_MATRIX2CH
:
474 /* Mixer filter matrix */
475 common
= conv(dblen
, hlen
, s
->cf
, s
->cf_ir
, k
+ s
->cf_o
);
477 /* In matrix decoding mode, the rear channel gain must be
478 renormalized, as there is an additional channel. */
479 matrix_decode(in
, k
, 2, 3, 0, s
->dlbuflen
,
480 s
->lr_fwr
, s
->rr_fwr
,
481 s
->lrprr_fwr
, s
->lrmrr_fwr
,
482 &(s
->adapt_lr_gain
), &(s
->adapt_rr_gain
),
483 &(s
->adapt_lrprr_gain
), &(s
->adapt_lrmrr_gain
),
484 s
->lr
, s
->rr
, NULL
, NULL
, s
->cr
);
486 conv(dblen
, hlen
, s
->cr
, s
->cr_ir
, k
+ s
->cr_o
) *
489 ( conv(dblen
, hlen
, s
->lf
, s
->af_ir
, k
+ s
->af_o
) +
490 conv(dblen
, hlen
, s
->rf
, s
->of_ir
, k
+ s
->of_o
) +
491 (conv(dblen
, hlen
, s
->lr
, s
->ar_ir
, k
+ s
->ar_o
) +
492 conv(dblen
, hlen
, s
->rr
, s
->or_ir
, k
+ s
->or_o
)) *
495 ( conv(dblen
, hlen
, s
->rf
, s
->af_ir
, k
+ s
->af_o
) +
496 conv(dblen
, hlen
, s
->lf
, s
->of_ir
, k
+ s
->of_o
) +
497 (conv(dblen
, hlen
, s
->rr
, s
->ar_ir
, k
+ s
->ar_o
) +
498 conv(dblen
, hlen
, s
->lr
, s
->or_ir
, k
+ s
->or_o
)) *
502 ( conv(dblen
, hlen
, s
->lf
, s
->af_ir
, k
+ s
->af_o
) +
503 conv(dblen
, hlen
, s
->rf
, s
->of_ir
, k
+ s
->of_o
) +
504 conv(dblen
, hlen
, s
->lr
, s
->ar_ir
, k
+ s
->ar_o
) +
505 conv(dblen
, hlen
, s
->rr
, s
->or_ir
, k
+ s
->or_o
) +
508 ( conv(dblen
, hlen
, s
->rf
, s
->af_ir
, k
+ s
->af_o
) +
509 conv(dblen
, hlen
, s
->lf
, s
->of_ir
, k
+ s
->of_o
) +
510 conv(dblen
, hlen
, s
->rr
, s
->ar_ir
, k
+ s
->ar_o
) +
511 conv(dblen
, hlen
, s
->lr
, s
->or_ir
, k
+ s
->or_o
) +
515 case HRTF_MIX_STEREO
:
517 ( conv(dblen
, hlen
, s
->lf
, s
->af_ir
, k
+ s
->af_o
) +
518 conv(dblen
, hlen
, s
->rf
, s
->of_ir
, k
+ s
->of_o
));
520 ( conv(dblen
, hlen
, s
->rf
, s
->af_ir
, k
+ s
->af_o
) +
521 conv(dblen
, hlen
, s
->lf
, s
->of_ir
, k
+ s
->of_o
));
530 /* Bass compensation for the lower frequency cut of the HRTF. A
531 cross talk of the left and right channel is introduced to
532 match the directional characteristics of higher frequencies.
533 The bass will not have any real 3D perception, but that is
534 OK (note at 180 Hz, the wavelength is about 2 m, and any
535 spatial perception is impossible). */
536 left_b
= conv(dblen
, blen
, s
->ba_l
, s
->ba_ir
, k
);
537 right_b
= conv(dblen
, blen
, s
->ba_r
, s
->ba_ir
, k
);
538 left
+= (1 - BASSCROSS
) * left_b
+ BASSCROSS
* right_b
;
539 right
+= (1 - BASSCROSS
) * right_b
+ BASSCROSS
* left_b
;
540 /* Also mix the LFE channel (if available) */
542 left
+= in
[5] * M3_01DB
;
543 right
+= in
[5] * M3_01DB
;
546 /* Amplitude renormalization. */
550 switch (s
->decode_mode
) {
552 case HRTF_MIX_STEREO
:
553 /* "Cheating": linear stereo expansion to amplify the 3D
554 perception. Note: Too much will destroy the acoustic space
555 and may even result in headaches. */
556 diff
= STEXPAND2
* (left
- right
);
557 out
[0] = (int16_t)(left
+ diff
);
558 out
[1] = (int16_t)(right
- diff
);
560 case HRTF_MIX_MATRIX2CH
:
561 /* Do attempt any stereo expansion with matrix encoded
562 sources. The L, R channels are already stereo expanded
563 by the steering, any further stereo expansion will sound
565 out
[0] = (int16_t)left
;
566 out
[1] = (int16_t)right
;
572 out
= &out
[af
->data
->nch
];
578 /* Set output data */
579 data
->audio
= af
->data
->audio
;
580 data
->len
= data
->len
/ data
->nch
* 2;
586 static int allocate(af_hrtf_t
*s
)
588 if ((s
->lf
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
589 if ((s
->rf
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
590 if ((s
->lr
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
591 if ((s
->rr
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
592 if ((s
->cf
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
593 if ((s
->cr
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
594 if ((s
->ba_l
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
595 if ((s
->ba_r
= malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
597 malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
599 malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
601 malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
603 malloc(s
->dlbuflen
* sizeof(float))) == NULL
) return -1;
607 /* Allocate memory and set function pointers */
608 static int af_open(af_instance_t
* af
)
614 af
->control
= control
;
618 af
->data
= calloc(1, sizeof(af_data_t
));
619 af
->setup
= calloc(1, sizeof(af_hrtf_t
));
620 if((af
->data
== NULL
) || (af
->setup
== NULL
))
625 s
->dlbuflen
= DELAYBUFLEN
;
626 s
->hrflen
= HRTFFILTLEN
;
627 s
->basslen
= BASSFILTLEN
;
629 s
->cyc_pos
= s
->dlbuflen
- 1;
630 /* With a full (two axis) steering matrix decoder, s->matrix_mode
631 should not be enabled lightly (it will also steer the Ls, Rs
634 s
->decode_mode
= HRTF_MIX_51
;
638 if (allocate(s
) != 0) {
639 mp_msg(MSGT_AFILTER
, MSGL_ERR
, "[hrtf] Memory allocation error.\n");
643 for(i
= 0; i
< s
->dlbuflen
; i
++)
644 s
->lf
[i
] = s
->rf
[i
] = s
->lr
[i
] = s
->rr
[i
] = s
->cf
[i
] =
650 s
->cf_ir
= cf_filt
+ (s
->cf_o
= pulse_detect(cf_filt
));
651 s
->af_ir
= af_filt
+ (s
->af_o
= pulse_detect(af_filt
));
652 s
->of_ir
= of_filt
+ (s
->of_o
= pulse_detect(of_filt
));
653 s
->ar_ir
= ar_filt
+ (s
->ar_o
= pulse_detect(ar_filt
));
654 s
->or_ir
= or_filt
+ (s
->or_o
= pulse_detect(or_filt
));
655 s
->cr_ir
= cr_filt
+ (s
->cr_o
= pulse_detect(cr_filt
));
657 if((s
->ba_ir
= malloc(s
->basslen
* sizeof(float))) == NULL
) {
658 mp_msg(MSGT_AFILTER
, MSGL_ERR
, "[hrtf] Memory allocation error.\n");
661 fc
= 2.0 * BASSFILTFREQ
/ (float)af
->data
->rate
;
662 if(af_filter_design_fir(s
->basslen
, s
->ba_ir
, &fc
, LP
| KAISER
, 4 * M_PI
) ==
664 mp_msg(MSGT_AFILTER
, MSGL_ERR
, "[hrtf] Unable to design low-pass "
668 for(i
= 0; i
< s
->basslen
; i
++)
669 s
->ba_ir
[i
] *= BASSGAIN
;
674 /* Description of this filter */
675 af_info_t af_info_hrtf
= {