Changeset 109458 in webkit


Ignore:
Timestamp:
Mar 1, 2012 3:59:02 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Enable IPP for Biquad filter
https://bugs.webkit.org/show_bug.cgi?id=77509

Patch by Xingnan Wang <xingnan.wang@intel.com> on 2012-03-01
Reviewed by Chris Rogers.

Source/WebCore:

Use IIR filter in IPP and improve ~27% performance in linux.
Changes are covered by current tests.

  • platform/audio/Biquad.cpp:

(WebCore::Biquad::Biquad):
(WebCore::Biquad::~Biquad):
(WebCore):
(WebCore::Biquad::process):
(WebCore::Biquad::reset):
(WebCore::Biquad::setLowpassParams):
(WebCore::Biquad::setHighpassParams):
(WebCore::Biquad::setNormalizedCoefficients):
(WebCore::Biquad::setZeroPolePairs):

  • platform/audio/Biquad.h:

(Biquad):

LayoutTests:

Adjust a code format issue.

  • webaudio/resources/biquad-testing.js:

(filterData):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109455 r109458  
     12012-03-01  Xingnan Wang  <xingnan.wang@intel.com>
     2
     3        Enable IPP for Biquad filter
     4        https://bugs.webkit.org/show_bug.cgi?id=77509
     5
     6        Reviewed by Chris Rogers.
     7
     8        Adjust a code format issue.
     9
     10        * webaudio/resources/biquad-testing.js:
     11        (filterData):
     12
    1132012-03-01  Adam Klein  <adamk@chromium.org>
    214
  • trunk/LayoutTests/webaudio/resources/biquad-testing.js

    r106621 r109458  
    378378    var b2 = filterCoef.b2;
    379379    var a1 = filterCoef.a1;
    380     var a2 = filterCoef. a2;
     380    var a2 = filterCoef.a2;
    381381
    382382    // Prime the pump. (Assumes the signal has length >= 2!)
  • trunk/Source/WebCore/ChangeLog

    r109451 r109458  
     12012-03-01  Xingnan Wang  <xingnan.wang@intel.com>
     2
     3        Enable IPP for Biquad filter
     4        https://bugs.webkit.org/show_bug.cgi?id=77509
     5
     6        Reviewed by Chris Rogers.
     7
     8        Use IIR filter in IPP and improve ~27% performance in linux.
     9        Changes are covered by current tests.
     10
     11        * platform/audio/Biquad.cpp:
     12        (WebCore::Biquad::Biquad):
     13        (WebCore::Biquad::~Biquad):
     14        (WebCore):
     15        (WebCore::Biquad::process):
     16        (WebCore::Biquad::reset):
     17        (WebCore::Biquad::setLowpassParams):
     18        (WebCore::Biquad::setHighpassParams):
     19        (WebCore::Biquad::setNormalizedCoefficients):
     20        (WebCore::Biquad::setZeroPolePairs):
     21        * platform/audio/Biquad.h:
     22        (Biquad):
     23
    1242012-03-01  Peter Kotwicz  <pkotwicz@google.com>
    225
  • trunk/Source/WebCore/platform/audio/Biquad.cpp

    r106621 r109458  
    5454#endif
    5555
     56#if USE(WEBAUDIO_IPP)
     57    int bufferSize;
     58    ippsIIRGetStateSize64f_BiQuad_32f(1, &bufferSize);
     59    m_ippInternalBuffer = ippsMalloc_8u(bufferSize);
     60#endif // USE(WEBAUDIO_IPP)
     61
    5662    // Initialize as pass-thru (straight-wire, no filter effect)
    57     m_b0 = 1;
    58     m_b1 = 0;
    59     m_b2 = 0;
    60     m_a1 = 0;
    61     m_a2 = 0;
     63    setNormalizedCoefficients(1, 0, 0, 1, 0, 0);
    6264
    6365    reset(); // clear filter memory
     66}
     67
     68Biquad::~Biquad()
     69{
     70#if USE(WEBAUDIO_IPP)
     71    ippsFree(m_ippInternalBuffer);
     72#endif // USE(WEBAUDIO_IPP)
    6473}
    6574
     
    6978    // Use vecLib if available
    7079    processFast(sourceP, destP, framesToProcess);
    71 #else
     80
     81#elif USE(WEBAUDIO_IPP)
     82    ippsIIR64f_32f(sourceP, destP, static_cast<int>(framesToProcess), m_biquadState);
     83#else // USE(WEBAUDIO_IPP)
     84
    7285    int n = framesToProcess;
    7386
     
    172185void Biquad::reset()
    173186{
    174     m_x1 = m_x2 = m_y1 = m_y2 = 0;
    175 
    176187#if OS(DARWIN)
    177188    // Two extra samples for filter history
     
    183194    outputP[0] = 0;
    184195    outputP[1] = 0;
     196
     197#elif USE(WEBAUDIO_IPP)
     198    int bufferSize;
     199    ippsIIRGetStateSize64f_BiQuad_32f(1, &bufferSize);
     200    ippsZero_8u(m_ippInternalBuffer, bufferSize);
     201
     202#else
     203    m_x1 = m_x2 = m_y1 = m_y2 = 0;
    185204#endif
    186205}
     
    188207void Biquad::setLowpassParams(double cutoff, double resonance)
    189208{
    190     resonance = std::max(0.0, resonance); // can't go negative
    191209    // Limit cutoff to 0 to 1.
    192210    cutoff = std::max(0.0, std::min(cutoff, 1.0));
    193211   
    194     double g = pow(10.0, 0.05 * resonance);
    195     double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
    196 
    197212    if (cutoff == 1) {
    198213        // When cutoff is 1, the z-transform is 1.
    199         m_b0 = 1;
    200         m_b1 = 0;
    201         m_b2 = 0;
    202         m_a1 = 0;
    203         m_a2 = 0;
     214        setNormalizedCoefficients(1, 0, 0,
     215                                  1, 0, 0);
    204216    } else if (cutoff > 0) {
    205217        // Compute biquad coefficients for lowpass filter
     218        resonance = std::max(0.0, resonance); // can't go negative
     219        double g = pow(10.0, 0.05 * resonance);
     220        double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
     221
    206222        double theta = piDouble * cutoff;
    207223        double sn = 0.5 * d * sin(theta);
     
    210226        double alpha = 0.25 * (0.5 + beta - gamma);
    211227
    212         m_b0 = 2 * alpha;
    213         m_b1 = 2 * 2 * alpha;
    214         m_b2 = 2 * alpha;
    215         m_a1 = 2 * -gamma;
    216         m_a2 = 2 * beta;
     228        double b0 = 2 * alpha;
     229        double b1 = 2 * 2 * alpha;
     230        double b2 = 2 * alpha;
     231        double a1 = 2 * -gamma;
     232        double a2 = 2 * beta;
     233
     234        setNormalizedCoefficients(b0, b1, b2, 1, a1, a2);
    217235    } else {
    218236        // When cutoff is zero, nothing gets through the filter, so set
    219237        // coefficients up correctly.
    220         m_b0 = 0;
    221         m_b1 = 0;
    222         m_b2 = 0;
    223         m_a1 = 0;
    224         m_a2 = 0;
     238        setNormalizedCoefficients(0, 0, 0,
     239                                  1, 0, 0);
    225240    }
    226241}
     
    228243void Biquad::setHighpassParams(double cutoff, double resonance)
    229244{
    230     resonance = std::max(0.0, resonance); // can't go negative
    231 
    232245    // Limit cutoff to 0 to 1.
    233246    cutoff = std::max(0.0, std::min(cutoff, 1.0));
    234247
    235     double g = pow(10.0, 0.05 * resonance);
    236     double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
    237 
    238248    if (cutoff == 1) {
    239249        // The z-transform is 0.
    240         m_b0 = 0;
    241         m_b1 = 0;
    242         m_b2 = 0;
    243         m_a1 = 0;
    244         m_a2 = 0;
     250        setNormalizedCoefficients(0, 0, 0,
     251                                  1, 0, 0);
    245252    } else if (cutoff > 0) {
    246253        // Compute biquad coefficients for highpass filter
     254        resonance = std::max(0.0, resonance); // can't go negative
     255        double g = pow(10.0, 0.05 * resonance);
     256        double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
     257
    247258        double theta = piDouble * cutoff;
    248259        double sn = 0.5 * d * sin(theta);
     
    251262        double alpha = 0.25 * (0.5 + beta + gamma);
    252263
    253         m_b0 = 2 * alpha;
    254         m_b1 = 2 * -2 * alpha;
    255         m_b2 = 2 * alpha;
    256         m_a1 = 2 * -gamma;
    257         m_a2 = 2 * beta;
     264        double b0 = 2 * alpha;
     265        double b1 = 2 * -2 * alpha;
     266        double b2 = 2 * alpha;
     267        double a1 = 2 * -gamma;
     268        double a2 = 2 * beta;
     269
     270        setNormalizedCoefficients(b0, b1, b2, 1, a1, a2);
    258271    } else {
    259272      // When cutoff is zero, we need to be careful because the above
     
    261274      // and zeros on the unit circle in the same place. When cutoff
    262275      // is zero, the z-transform is 1.
    263       m_b0 = 1;
    264       m_b1 = 0;
    265       m_b2 = 0;
    266       m_a1 = 0;
    267       m_a2 = 0;
     276        setNormalizedCoefficients(1, 0, 0,
     277                                  1, 0, 0);
    268278    }
    269279}
     
    278288    m_a1 = a1 * a0Inverse;
    279289    m_a2 = a2 * a0Inverse;
     290
     291#if USE(WEBAUDIO_IPP)
     292    Ipp64f taps[6];
     293    taps[0] = m_b0;
     294    taps[1] = m_b1;
     295    taps[2] = m_b2;
     296    taps[3] = 1;
     297    taps[4] = m_a1;
     298    taps[5] = m_a2;
     299    m_biquadState = 0;
     300
     301    ippsIIRInit64f_BiQuad_32f(&m_biquadState, taps, 1, 0, m_ippInternalBuffer);
     302#endif // USE(WEBAUDIO_IPP)
    280303}
    281304
     
    502525void Biquad::setZeroPolePairs(const Complex &zero, const Complex &pole)
    503526{
    504     m_b0 = 1;
    505     m_b1 = -2 * zero.real();
     527    double b0 = 1;
     528    double b1 = -2 * zero.real();
    506529
    507530    double zeroMag = abs(zero);
    508     m_b2 = zeroMag * zeroMag;
    509 
    510     m_a1 = -2 * pole.real();
     531    double b2 = zeroMag * zeroMag;
     532
     533    double a1 = -2 * pole.real();
    511534
    512535    double poleMag = abs(pole);
    513     m_a2 = poleMag * poleMag;
     536    double a2 = poleMag * poleMag;
     537    setNormalizedCoefficients(b0, b1, b2, 1, a1, a2);
    514538}
    515539
  • trunk/Source/WebCore/platform/audio/Biquad.h

    r99337 r109458  
    3535#include <wtf/Platform.h>
    3636 
     37#if USE(WEBAUDIO_IPP)
     38#include <ipps.h>
     39#endif // USE(WEBAUDIO_IPP)
     40
    3741namespace WebCore {
    3842
     
    4549public:   
    4650    Biquad();
    47     virtual ~Biquad() { }
     51    virtual ~Biquad();
    4852
    4953    void process(const float* sourceP, float* destP, size_t framesToProcess);
     
    9094    double m_a2;
    9195
    92     // Filter memory
    93     double m_x1; // input delayed by 1 sample
    94     double m_x2; // input delayed by 2 samples
    95     double m_y1; // output delayed by 1 sample
    96     double m_y2; // output delayed by 2 samples
    97 
    9896#if OS(DARWIN)
    9997    void processFast(const float* sourceP, float* destP, size_t framesToProcess);
     
    102100    AudioDoubleArray m_inputBuffer;
    103101    AudioDoubleArray m_outputBuffer;
     102
     103#elif USE(WEBAUDIO_IPP)
     104    IppsIIRState64f_32f* m_biquadState;
     105    Ipp8u* m_ippInternalBuffer;
     106
     107#else
     108    // Filter memory
     109    double m_x1; // input delayed by 1 sample
     110    double m_x2; // input delayed by 2 samples
     111    double m_y1; // output delayed by 1 sample
     112    double m_y2; // output delayed by 2 samples
    104113#endif
    105114};
Note: See TracChangeset for help on using the changeset viewer.