blob: 0be012c96842bc39131cc7eb311c7781e07a73f0 [file] [log] [blame]
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +03001/*
2 * Copyright (c) 2017, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Intel Corporation nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
29 */
30
31#ifndef EQ_H
32#define EQ_H
33
34/* FIR EQ type */
35
36/* Component will reject non-matching configuration. The version number need
37 * to be incremented with any ABI changes in function fir_cmd().
38 */
Seppo Ingalsuo26aa4ae2017-10-20 20:15:57 +030039#define SOF_EQ_FIR_ABI_VERSION 1
40
41#define SOF_EQ_FIR_IDX_SWITCH 0
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030042
43#define SOF_EQ_FIR_MAX_SIZE 4096 /* Max size allowed for coef data in bytes */
44
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030045#define SOF_EQ_FIR_MAX_LENGTH 192 /* Max length for individual filter */
46
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030047/*
48 * eq_fir_configuration data structure contains this information
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030049 * uint32_t size
50 * This is the number of bytes need to store the received EQ
51 * configuration.
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030052 * uint16_t channels_in_config
53 * This describes the number of channels in this EQ config data. It
54 * can be different from PLATFORM_MAX_CHANNELS.
55 * uint16_t number_of_responses
56 * 0=no responses, 1=one response defined, 2=two responses defined, etc.
57 * int16_t data[]
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030058 * assign_response[channels_in_config]
59 * 0 = use first response, 1 = use 2nd response, etc.
60 * E.g. {0, 0, 0, 0, 1, 1, 1, 1} would apply to channels 0-3 the
61 * same first defined response and for to channels 4-7 the second.
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030062 * coef_data[]
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030063 * Repeated data
64 * { filter_length, output_shift, h[] }
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030065 * for every EQ response defined where vector h has filter_length
66 * number of coefficients. Coefficients in h[] are in Q1.15 format.
67 * E.g. 16384 (Q1.15) = 0.5. The shifts are number of right shifts.
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030068 *
69 * NOTE: The channels_in_config must be even to have coef_data aligned to
70 * 32 bit word in RAM. Therefore a mono EQ assign must be duplicated to 2ch
71 * even if it would never used. Similarly a 5ch EQ assign must be increased
72 * to 6ch. EQ init will return an error if this is not met.
73 *
74 * NOTE: The filter_length must be multiple of four. Therefore the filter must
75 * be padded from the end with zeros have this condition met.
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030076 */
77
78struct sof_eq_fir_config {
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030079 uint32_t size;
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030080 uint16_t channels_in_config;
81 uint16_t number_of_responses;
82 int16_t data[];
83};
84
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +030085struct sof_eq_fir_coef_data {
86 int16_t length; /* Number of FIR taps */
87 int16_t out_shift; /* Amount of right shifts at output */
88 int16_t coef[]; /* FIR coefficients */
89};
90
91/* In the struct above there's two words (length, shift) before the actual
92 * FIR coefficients. This information is used in parsing of the config blob.
93 */
94#define SOF_EQ_FIR_COEF_NHEADER 2
95
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +030096/* IIR EQ type */
97
98/* Component will reject non-matching configuration. The version number need
99 * to be incremented with any ABI changes in function fir_cmd().
100 */
Seppo Ingalsuo6b936a32018-08-03 14:44:11 +0300101#define SOF_EQ_IIR_ABI_VERSION 1
Seppo Ingalsuo2b3f0ab2017-10-20 20:15:58 +0300102
103#define SOF_EQ_IIR_IDX_SWITCH 0
Seppo Ingalsuoc46d66d2017-09-25 14:09:13 +0300104
105#define SOF_EQ_IIR_MAX_SIZE 1024 /* Max size allowed for coef data in bytes */
106
107/* eq_iir_configuration
108 * uint32_t channels_in_config
109 * This describes the number of channels in this EQ config data. It
110 * can be different from PLATFORM_MAX_CHANNELS.
111 * uint32_t number_of_responses_defined
112 * 0=no responses, 1=one response defined, 2=two responses defined, etc.
113 * int32_t data[]
114 * Data consist of two parts. First is the response assign vector that
115 * has length of channels_in_config. The latter part is coefficient
116 * data.
117 * uint32_t assign_response[channels_in_config]
118 * -1 = not defined, 0 = use first response, 1 = use 2nd, etc.
119 * E.g. {0, 0, 0, 0, -1, -1, -1, -1} would apply to channels 0-3 the
120 * same first defined response and leave channels 4-7 unequalized.
121 * coefficient_data[]
122 * <1st EQ>
123 * uint32_t num_biquads
124 * uint32_t num_biquads_in_series
125 * <1st biquad>
126 * int32_t coef_a2 Q2.30 format
127 * int32_t coef_a1 Q2.30 format
128 * int32_t coef_b2 Q2.30 format
129 * int32_t coef_b1 Q2.30 format
130 * int32_t coef_b0 Q2.30 format
131 * int32_t output_shift number of shifts right, shift left is negative
132 * int32_t output_gain Q2.14 format
133 * <2nd biquad>
134 * ...
135 * <2nd EQ>
136 *
137 * Note: A flat response biquad can be made with a section set to
138 * b0 = 1.0, gain = 1.0, and other parameters set to 0
139 * {0, 0, 0, 0, 1073741824, 0, 16484}
140 */
141
142struct sof_eq_iir_config {
143 uint32_t channels_in_config;
144 uint32_t number_of_responses;
145 int32_t data[];
146};
147
148#endif /* EQ_H */