1%% Design effect EQs and bundle them to parameter block
2
3% SPDX-License-Identifier: BSD-3-Clause
4%
5% Copyright (c) 2016-2020, Intel Corporation. All rights reserved.
6%
7% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
8
9function example_iir_bandsplit()
10
11%% Common definitions
12fs = 48e3;
13tpath =  '../../topology/topology1/m4';
14cpath = '../../ctl';
15priv = 'DEF_EQIIR_PRIV';
16
17%% --------------------------------------------------
18%% Example: Band-split 2ch to 4ch low and high bands
19%% --------------------------------------------------
20blob_fn = fullfile(cpath, 'eq_iir_bandsplit.bin');
21alsa_fn = fullfile(cpath, 'eq_iir_bandsplit.txt');
22tplg_fn = fullfile(tpath, 'eq_iir_bandsplit.m4');
23comment = 'Bandsplit, created with example_iir_bandsplit.m';
24
25%% Design IIR loudness equalizer
26eq_lo = lo_band_iir(fs);
27eq_hi = hi_band_iir(fs);
28
29%% Quantize and pack filter coefficients plus shifts etc.
30bq_lo = eq_iir_blob_quant(eq_lo.p_z, eq_lo.p_p, eq_lo.p_k);
31bq_hi = eq_iir_blob_quant(eq_hi.p_z, eq_hi.p_p, eq_hi.p_k);
32
33%% Build blob
34channels_in_config = 4;      % Setup max 4 channels EQ
35assign_response = [0 0 1 1]; % Order: lo, lo, hi, hi
36num_responses = 2;           % Two responses: lo, hi
37bm = eq_iir_blob_merge(channels_in_config, ...
38		       num_responses, ...
39		       assign_response, ...
40		       [bq_lo bq_hi]);
41
42%% Pack and write file
43eq_pack_export(bm, blob_fn, alsa_fn, tplg_fn, priv, comment)
44
45
46%% ------------------------------------
47%% Done.
48%% ------------------------------------
49
50end
51
52%% -------------------
53%% EQ design functions
54%% -------------------
55
56function eq = lo_band_iir(fs)
57
58
59%% Get defaults for equalizer design
60eq = eq_defaults();
61eq.fs = fs;
62eq.enable_iir = 1;
63eq.norm_type = 'peak';
64eq.norm_offs_db = 0;
65
66%% Manually setup low-shelf and high shelf parametric equalizers
67%
68% Parametric EQs are PEQ_HP1, PEQ_HP2, PEQ_LP1, PEQ_LP2, PEQ_LS1,
69% PEQ_LS2, PEQ_HS1, PEQ_HS2 = 8, PEQ_PN2, PEQ_LP4, and  PEQ_HP4.
70%
71% Parametric EQs take as second argument the cutoff frequency in Hz
72% and as second argument a dB value (or NaN when not applicable) . The
73% Third argument is a Q-value (or NaN when not applicable).
74
75% Low-pass at 2 kHz, add a high-pass at 80 Hz for a small woofer
76eq.peq = [ ...
77                 eq.PEQ_HP2 80 NaN NaN ; ...
78                 eq.PEQ_LP2 2000 NaN NaN ; ...
79         ];
80
81%% Design EQ
82eq = eq_compute(eq);
83
84%% Plot
85eq_plot(eq);
86
87end
88
89function eq = hi_band_iir(fs)
90
91
92%% Get defaults for equalizer design
93eq = eq_defaults();
94eq.fs = fs;
95eq.enable_iir = 1;
96eq.norm_type = 'peak';
97eq.norm_offs_db = 0;
98
99%% Manually setup low-shelf and high shelf parametric equalizers
100%
101% Parametric EQs are PEQ_HP1, PEQ_HP2, PEQ_LP1, PEQ_LP2, PEQ_LS1,
102% PEQ_LS2, PEQ_HS1, PEQ_HS2 = 8, PEQ_PN2, PEQ_LP4, and  PEQ_HP4.
103%
104% Parametric EQs take as second argument the cutoff frequency in Hz
105% and as second argument a dB value (or NaN when not applicable) . The
106% Third argument is a Q-value (or NaN when not applicable).
107
108% High-pass at 2 kHz for a tweeter
109eq.peq = [ ...
110                 eq.PEQ_HP2 2000 NaN NaN ; ...
111         ];
112
113%% Design EQ
114eq = eq_compute(eq);
115
116%% Plot
117eq_plot(eq);
118
119end
120
121
122
123% Pack and write file common function for all exports
124function eq_pack_export(bm, bin_fn, ascii_fn, tplg_fn, priv, note)
125
126bp = eq_iir_blob_pack(bm);
127
128if ~isempty(bin_fn)
129	eq_blob_write(bin_fn, bp);
130end
131
132if ~isempty(ascii_fn)
133	eq_alsactl_write(ascii_fn, bp);
134end
135
136if ~isempty(tplg_fn)
137	eq_tplg_write(tplg_fn, bp, priv, note);
138end
139
140end
141