File: FilterVisualizerHelper.h

package info (click to toggle)
iem-plugin-suite 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,080 kB
  • sloc: cpp: 58,973; python: 269; sh: 79; makefile: 41
file content (75 lines) | stat: -rw-r--r-- 2,706 bytes parent folder | download | duplicates (2)
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
/*
 ==============================================================================
 This file is part of the IEM plug-in suite.
 Author: Daniel Rudrich
 Copyright (c) 2017 - Institute of Electronic Music and Acoustics (IEM)
 https://iem.at

 The IEM plug-in suite is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 The IEM plug-in suite is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this software.  If not, see <https://www.gnu.org/licenses/>.
 ==============================================================================
 */

#pragma once

/* Hard coded convolution of IIR coefficients.
 Use double! */

template <typename type>
class FilterVisualizerHelper
{
public:
    static juce::Array<type> cascadeSecondOrderCoefficients (juce::Array<type>& c0,
                                                             juce::Array<type>& c1)
    {
        juce::Array<type> c12;
        c12.resize (9);
        const int o = 2;

        c12.setUnchecked (0, c0[0] * c1[0]);
        c12.setUnchecked (1, c0[0] * c1[1] + c0[1] * c1[0]);
        c12.setUnchecked (2, c0[0] * c1[2] + c0[1] * c1[1] + c0[2] * c1[0]);
        c12.setUnchecked (3, c0[1] * c1[2] + c0[2] * c1[1]);
        c12.setUnchecked (4, c0[2] * c1[2]);

        c12.setUnchecked (5, c1[1 + o] + c0[1 + o]);
        c12.setUnchecked (6, c1[2 + o] + c0[1 + o] * c1[1 + o] + c0[2 + o]);
        c12.setUnchecked (7, c0[1 + o] * c1[2 + o] + c0[2 + o] * c1[1 + o]);
        c12.setUnchecked (8, c0[2 + o] * c1[2 + o]);

        return c12;
    }

    static juce::Array<type> cascadeFirstAndSecondOrderCoefficients (juce::Array<type>& firstOrder,
                                                                     juce::Array<type>& secondOrder)
    {
        juce::Array<type>& c1 = firstOrder;
        juce::Array<type>& c2 = secondOrder;

        juce::Array<type> c12;
        c12.resize (7);

        //b
        c12.setUnchecked (0, c1[0] * c2[0]);
        c12.setUnchecked (1, c1[0] * c2[1] + c1[1] * c2[0]);
        c12.setUnchecked (2, c1[0] * c2[2] + c1[1] * c2[1]);
        c12.setUnchecked (3, c1[1] * c2[2]);

        //a
        c12.setUnchecked (4, c1[2] + c2[3]);
        c12.setUnchecked (5, c1[2] * c2[3] + c2[4]);
        c12.setUnchecked (6, c1[2] * c2[4]);

        return c12;
    }
};