summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/modules/webaudio/IIRDSPKernel.cpp
blob: 47a31c564377323165b606eb549f88df02cc9566 (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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "modules/webaudio/IIRDSPKernel.h"

#include "platform/FloatConversion.h"

namespace blink {

void IIRDSPKernel::process(const float* source, float* destination, size_t framesToProcess)
{
    ASSERT(source);
    ASSERT(destination);

    m_iir.process(source, destination, framesToProcess);
}

void IIRDSPKernel::getFrequencyResponse(int nFrequencies, const float* frequencyHz, float* magResponse, float* phaseResponse)
{
    bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseResponse;
    ASSERT(isGood);
    if (!isGood)
        return;

    Vector<float> frequency(nFrequencies);

    double nyquist = this->nyquist();

    // Convert from frequency in Hz to normalized frequency (0 -> 1),
    // with 1 equal to the Nyquist frequency.
    for (int k = 0; k < nFrequencies; ++k)
        frequency[k] = narrowPrecisionToFloat(frequencyHz[k] / nyquist);

    m_iir.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, phaseResponse);
}

double IIRDSPKernel::tailTime() const
{
    // TODO(rtoy): This is true mathematically (infinite impulse response), but perhaps it should be
    // limited to a smaller value, possibly based on the actual filter coefficients.  To do that, we
    // would probably need to find the pole, r, with largest magnitude and select some threshold,
    // eps, such that |r|^n < eps for all n >= N.  N is then the tailTime for the filter.  If the
    // the magnitude of r is greater than or equal to 1, the infinity is the right answer. (There is
    // no constraint on the IIR filter that it be stable.)
    return std::numeric_limits<double>::infinity();
}

double IIRDSPKernel::latencyTime() const
{
    return 0;
}

} // namespace blink