summaryrefslogtreecommitdiff
path: root/src/pulsecore/filter/crossover.h
blob: a88f5b6cfc27fc27a415c4a878b9ef5f0ad6765e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef CROSSOVER_H_
#define CROSSOVER_H_

#ifdef __cplusplus
extern "C" {
#endif

/* An LR4 filter is two biquads with the same parameters connected in series:
 *
 * x -- [BIQUAD] -- y -- [BIQUAD] -- z
 *
 * Both biquad filter has the same parameter b[012] and a[12],
 * The variable [xyz][12] keep the history values.
 */
struct lr4 {
	float b0, b1, b2;
	float a1, a2;
	float x1, x2;
	float y1, y2;
	float z1, z2;
};

void lr4_set(struct lr4 *lr4, enum biquad_type type, float freq);

void lr4_process_float32(struct lr4 *lr4, int samples, int channels, float *src, float *dest);
void lr4_process_s16(struct lr4 *lr4, int samples, int channels, short *src, short *dest);


/* Three bands crossover filter:
 *
 * INPUT --+-- lp0 --+-- lp1 --+---> LOW (0)
 *         |         |         |
 *         |         \-- hp1 --/
 *         |
 *         \-- hp0 --+-- lp2 ------> MID (1)
 *                   |
 *                   \-- hp2 ------> HIGH (2)
 *
 *            [f0]       [f1]
 *
 * Each lp or hp is an LR4 filter, which consists of two second-order
 * lowpass or highpass butterworth filters.
 */
struct crossover {
	struct lr4 lp[3], hp[3];
};

/* Initializes a crossover filter
 * Args:
 *    xo - The crossover filter we want to initialize.
 *    freq1 - The normalized frequency splits low and mid band.
 *    freq2 - The normalized frequency splits mid and high band.
 */
void crossover_init(struct crossover *xo, float freq1, float freq2);

/* Splits input samples to three bands.
 * Args:
 *    xo - The crossover filter to use.
 *    count - The number of input samples.
 *    data0 - The input samples, also the place to store low band output.
 *    data1 - The place to store mid band output.
 *    data2 - The place to store high band output.
 */
void crossover_process(struct crossover *xo, int count, float *data0,
		       float *data1, float *data2);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* CROSSOVER_H_ */