2011-06-08 Chris Rogers <crogers@google.com>
authorcrogers@google.com <crogers@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Jun 2011 20:29:12 +0000 (20:29 +0000)
committercrogers@google.com <crogers@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Jun 2011 20:29:12 +0000 (20:29 +0000)
        Reviewed by Kenneth Russell.

        Implement BiquadFilterNode for filter types: LOWPASS, HIGHPASS, BANDPASS, LOWSHELF, HIGHSHELF, PEAKING, NOTCH, ALLPASS
        https://bugs.webkit.org/show_bug.cgi?id=62078

        No new tests since audio API is not yet implemented.

        * DerivedSources.make:
        * WebCore.gypi:
        * WebCore.xcodeproj/project.pbxproj:
        * platform/audio/Biquad.cpp:
        (WebCore::Biquad::Biquad):
        (WebCore::Biquad::reset):
        (WebCore::Biquad::setLowpassParams):
        (WebCore::Biquad::setHighpassParams):
        (WebCore::Biquad::setNormalizedCoefficients):
        (WebCore::Biquad::setLowShelfParams):
        (WebCore::Biquad::setHighShelfParams):
        (WebCore::Biquad::setPeakingParams):
        (WebCore::Biquad::setAllpassParams):
        (WebCore::Biquad::setNotchParams):
        (WebCore::Biquad::setBandpassParams):
        (WebCore::Biquad::setZeroPolePairs):
        (WebCore::Biquad::setAllpassPole):
        * platform/audio/Biquad.h:
        * webaudio/AudioContext.cpp:
        (WebCore::AudioContext::createBiquadFilter):
        (WebCore::AudioContext::createLowPass2Filter):
        (WebCore::AudioContext::createHighPass2Filter):
        * webaudio/AudioContext.h:
        * webaudio/AudioContext.idl:
        * webaudio/AudioNode.h:
        * webaudio/BiquadDSPKernel.cpp:
        (WebCore::BiquadDSPKernel::process):
        * webaudio/BiquadFilterNode.cpp: Added.
        (WebCore::BiquadFilterNode::BiquadFilterNode):
        * webaudio/BiquadFilterNode.h: Added.
        (WebCore::BiquadFilterNode::create):
        (WebCore::BiquadFilterNode::type):
        (WebCore::BiquadFilterNode::setType):
        (WebCore::BiquadFilterNode::frequency):
        (WebCore::BiquadFilterNode::q):
        (WebCore::BiquadFilterNode::gain):
        (WebCore::BiquadFilterNode::biquadProcessor):
        * webaudio/BiquadFilterNode.idl: Added.
        * webaudio/BiquadProcessor.cpp:
        (WebCore::BiquadProcessor::BiquadProcessor):
        * webaudio/BiquadProcessor.h:
        (WebCore::BiquadProcessor::setType):
        * webaudio/HighPass2FilterNode.cpp:
        (WebCore::HighPass2FilterNode::HighPass2FilterNode):
        * webaudio/LowPass2FilterNode.cpp:
        (WebCore::LowPass2FilterNode::LowPass2FilterNode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@88380 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/audio/Biquad.cpp
Source/WebCore/platform/audio/Biquad.h
Source/WebCore/webaudio/AudioContext.cpp
Source/WebCore/webaudio/AudioContext.h
Source/WebCore/webaudio/AudioContext.idl
Source/WebCore/webaudio/AudioNode.h
Source/WebCore/webaudio/BiquadDSPKernel.cpp
Source/WebCore/webaudio/BiquadFilterNode.cpp [new file with mode: 0644]
Source/WebCore/webaudio/BiquadFilterNode.h [new file with mode: 0644]
Source/WebCore/webaudio/BiquadFilterNode.idl [new file with mode: 0644]
Source/WebCore/webaudio/BiquadProcessor.cpp
Source/WebCore/webaudio/BiquadProcessor.h
Source/WebCore/webaudio/HighPass2FilterNode.cpp
Source/WebCore/webaudio/LowPass2FilterNode.cpp

index 34c9662defe97196d63985999b8a3829c7036e84..2cc393b01e5b625fe201a3a525312a3c722cee9d 100644 (file)
@@ -1,3 +1,59 @@
+2011-06-08  Chris Rogers  <crogers@google.com>
+
+        Reviewed by Kenneth Russell.
+
+        Implement BiquadFilterNode for filter types: LOWPASS, HIGHPASS, BANDPASS, LOWSHELF, HIGHSHELF, PEAKING, NOTCH, ALLPASS
+        https://bugs.webkit.org/show_bug.cgi?id=62078
+
+        No new tests since audio API is not yet implemented.
+
+        * DerivedSources.make:
+        * WebCore.gypi:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/audio/Biquad.cpp:
+        (WebCore::Biquad::Biquad):
+        (WebCore::Biquad::reset):
+        (WebCore::Biquad::setLowpassParams):
+        (WebCore::Biquad::setHighpassParams):
+        (WebCore::Biquad::setNormalizedCoefficients):
+        (WebCore::Biquad::setLowShelfParams):
+        (WebCore::Biquad::setHighShelfParams):
+        (WebCore::Biquad::setPeakingParams):
+        (WebCore::Biquad::setAllpassParams):
+        (WebCore::Biquad::setNotchParams):
+        (WebCore::Biquad::setBandpassParams):
+        (WebCore::Biquad::setZeroPolePairs):
+        (WebCore::Biquad::setAllpassPole):
+        * platform/audio/Biquad.h:
+        * webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::createBiquadFilter):
+        (WebCore::AudioContext::createLowPass2Filter):
+        (WebCore::AudioContext::createHighPass2Filter):
+        * webaudio/AudioContext.h:
+        * webaudio/AudioContext.idl:
+        * webaudio/AudioNode.h:
+        * webaudio/BiquadDSPKernel.cpp:
+        (WebCore::BiquadDSPKernel::process):
+        * webaudio/BiquadFilterNode.cpp: Added.
+        (WebCore::BiquadFilterNode::BiquadFilterNode):
+        * webaudio/BiquadFilterNode.h: Added.
+        (WebCore::BiquadFilterNode::create):
+        (WebCore::BiquadFilterNode::type):
+        (WebCore::BiquadFilterNode::setType):
+        (WebCore::BiquadFilterNode::frequency):
+        (WebCore::BiquadFilterNode::q):
+        (WebCore::BiquadFilterNode::gain):
+        (WebCore::BiquadFilterNode::biquadProcessor):
+        * webaudio/BiquadFilterNode.idl: Added.
+        * webaudio/BiquadProcessor.cpp:
+        (WebCore::BiquadProcessor::BiquadProcessor):
+        * webaudio/BiquadProcessor.h:
+        (WebCore::BiquadProcessor::setType):
+        * webaudio/HighPass2FilterNode.cpp:
+        (WebCore::HighPass2FilterNode::HighPass2FilterNode):
+        * webaudio/LowPass2FilterNode.cpp:
+        (WebCore::LowPass2FilterNode::LowPass2FilterNode):
+
 2011-06-08  No'am Rosenthal  <noam.rosenthal@nokia.com>
 
         Reviewed by Kenneth Rohde Christiansen.
index 1fcb7f972fa9e1a0faa0aeef2e81e24fba5ce78b..0c990ecdd1c1a5681079e43f26b13ba7414ab785 100644 (file)
@@ -68,6 +68,7 @@ DOM_CLASSES = \
     AudioParam \
     AudioProcessingEvent \
     AudioSourceNode \
+    BiquadFilterNode \
     ConvolverNode \
     DelayNode \
     DynamicsCompressorNode \
index 28fa847c926b6555cfbbea2df01c6901e53e072c..74925889e8e8f651dac94288f4094a76e07518a6 100644 (file)
             'webaudio/AudioParam.idl',
             'webaudio/AudioProcessingEvent.idl',
             'webaudio/AudioSourceNode.idl',
+            'webaudio/BiquadFilterNode.idl',
             'webaudio/ConvolverNode.idl',
             'webaudio/DelayNode.idl',
             'webaudio/DynamicsCompressorNode.idl',
             'webaudio/AudioSourceNode.h',
             'webaudio/BiquadDSPKernel.cpp',
             'webaudio/BiquadDSPKernel.h',
+            'webaudio/BiquadFilterNode.cpp',
+            'webaudio/BiquadFilterNode.h',
             'webaudio/BiquadProcessor.cpp',
             'webaudio/BiquadProcessor.h',
             'webaudio/ConvolverNode.cpp',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBeforeLoadEvent.h',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBeforeProcessEvent.cpp',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBeforeProcessEvent.h',
+            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBiquadFilterNode.cpp',
+            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBiquadFilterNode.h',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBlob.cpp',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/JSBlob.h',
             '<(PRODUCT_DIR)/DerivedSources/WebCore/JSCDATASection.cpp',
index 5b11384f5dd0e1dcb5fccb274f18e6f69edc7f0d..3463355b17f31e58357135cb10733579bfd8a7ee 100644 (file)
                FDA3E95A134A49EF008D4B5A /* OfflineAudioCompletionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA3E956134A49EF008D4B5A /* OfflineAudioCompletionEvent.h */; };
                FDA3E95B134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDA3E957134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp */; };
                FDA3E95C134A49EF008D4B5A /* OfflineAudioDestinationNode.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA3E958134A49EF008D4B5A /* OfflineAudioDestinationNode.h */; };
+               FDC54F041399B0DA008D9117 /* BiquadFilterNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDC54F011399B0DA008D9117 /* BiquadFilterNode.cpp */; };
+               FDC54F051399B0DA008D9117 /* BiquadFilterNode.h in Headers */ = {isa = PBXBuildFile; fileRef = FDC54F021399B0DA008D9117 /* BiquadFilterNode.h */; };
                FDEAAAF312B02EE400DCF33B /* JSAudioBufferSourceNodeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDEAAAEF12B02EE400DCF33B /* JSAudioBufferSourceNodeCustom.cpp */; };
                FDEAAAF412B02EE400DCF33B /* JSAudioContextCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDEAAAF012B02EE400DCF33B /* JSAudioContextCustom.cpp */; };
                FDEAAAF512B02EE400DCF33B /* JSAudioNodeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDEAAAF112B02EE400DCF33B /* JSAudioNodeCustom.cpp */; };
                FDEAAAF612B02EE400DCF33B /* JSConvolverNodeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDEAAAF212B02EE400DCF33B /* JSConvolverNodeCustom.cpp */; };
                FDEAAAFE12B02F4900DCF33B /* JSJavaScriptAudioNodeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDEAAAFD12B02F4900DCF33B /* JSJavaScriptAudioNodeCustom.cpp */; };
+               FDF09DC81399B62200688E5B /* JSBiquadFilterNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDF09DC61399B62200688E5B /* JSBiquadFilterNode.cpp */; };
+               FDF09DC91399B62200688E5B /* JSBiquadFilterNode.h in Headers */ = {isa = PBXBuildFile; fileRef = FDF09DC71399B62200688E5B /* JSBiquadFilterNode.h */; };
                FDF6BAF8134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDF6BAF6134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp */; };
                FDF6BAF9134A4C9800822920 /* JSOfflineAudioCompletionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = FDF6BAF7134A4C9800822920 /* JSOfflineAudioCompletionEvent.h */; };
                FE6FD4880F676E5700092873 /* Coordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD4850F676E5700092873 /* Coordinates.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FDA3E957134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OfflineAudioDestinationNode.cpp; sourceTree = "<group>"; };
                FDA3E958134A49EF008D4B5A /* OfflineAudioDestinationNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OfflineAudioDestinationNode.h; sourceTree = "<group>"; };
                FDA3E95D134A49FF008D4B5A /* OfflineAudioCompletionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OfflineAudioCompletionEvent.idl; sourceTree = "<group>"; };
+               FDC54F011399B0DA008D9117 /* BiquadFilterNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BiquadFilterNode.cpp; sourceTree = "<group>"; };
+               FDC54F021399B0DA008D9117 /* BiquadFilterNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BiquadFilterNode.h; sourceTree = "<group>"; };
+               FDC54F031399B0DA008D9117 /* BiquadFilterNode.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = BiquadFilterNode.idl; sourceTree = "<group>"; };
                FDEAAAEF12B02EE400DCF33B /* JSAudioBufferSourceNodeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioBufferSourceNodeCustom.cpp; sourceTree = "<group>"; };
                FDEAAAF012B02EE400DCF33B /* JSAudioContextCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioContextCustom.cpp; sourceTree = "<group>"; };
                FDEAAAF112B02EE400DCF33B /* JSAudioNodeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioNodeCustom.cpp; sourceTree = "<group>"; };
                FDEAAAF212B02EE400DCF33B /* JSConvolverNodeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSConvolverNodeCustom.cpp; sourceTree = "<group>"; };
                FDEAAAFD12B02F4900DCF33B /* JSJavaScriptAudioNodeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptAudioNodeCustom.cpp; sourceTree = "<group>"; };
+               FDF09DC61399B62200688E5B /* JSBiquadFilterNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSBiquadFilterNode.cpp; sourceTree = "<group>"; };
+               FDF09DC71399B62200688E5B /* JSBiquadFilterNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBiquadFilterNode.h; sourceTree = "<group>"; };
                FDF6BAF6134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSOfflineAudioCompletionEvent.cpp; sourceTree = "<group>"; };
                FDF6BAF7134A4C9800822920 /* JSOfflineAudioCompletionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSOfflineAudioCompletionEvent.h; sourceTree = "<group>"; };
                FE49EF970DC51462004266E1 /* DashboardSupportCSSPropertyNames.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DashboardSupportCSSPropertyNames.in; sourceTree = "<group>"; };
                                FD315FD912B0267600C1A359 /* AudioSourceNode.idl */,
                                FD315FDA12B0267600C1A359 /* BiquadDSPKernel.cpp */,
                                FD315FDB12B0267600C1A359 /* BiquadDSPKernel.h */,
+                               FDC54F011399B0DA008D9117 /* BiquadFilterNode.cpp */,
+                               FDC54F021399B0DA008D9117 /* BiquadFilterNode.h */,
+                               FDC54F031399B0DA008D9117 /* BiquadFilterNode.idl */,
                                FD315FDC12B0267600C1A359 /* BiquadProcessor.cpp */,
                                FD315FDD12B0267600C1A359 /* BiquadProcessor.h */,
                                FD315FDE12B0267600C1A359 /* ConvolverNode.cpp */,
                                FDA15E9A12B03EE1003A583A /* JSAudioProcessingEvent.h */,
                                FDA15E9B12B03EE1003A583A /* JSAudioSourceNode.cpp */,
                                FDA15E9C12B03EE1003A583A /* JSAudioSourceNode.h */,
+                               FDF09DC61399B62200688E5B /* JSBiquadFilterNode.cpp */,
+                               FDF09DC71399B62200688E5B /* JSBiquadFilterNode.h */,
                                FDA15EBB12B03F0B003A583A /* JSConvolverNode.cpp */,
                                FDA15EBC12B03F0B003A583A /* JSConvolverNode.h */,
                                FDA15ECF12B03F94003A583A /* JSDelayNode.cpp */,
                                4496E3A0139813A5003EE32A /* JSSVGMPathElement.h in Headers */,
                                2E2445F71395893A004B6C19 /* OperationNotAllowedException.h in Headers */,
                                2E24476913959173004B6C19 /* JSOperationNotAllowedException.h in Headers */,
+                               FDC54F051399B0DA008D9117 /* BiquadFilterNode.h in Headers */,
+                               FDF09DC91399B62200688E5B /* JSBiquadFilterNode.h in Headers */,
                                49A85B6C138D573A00ECB7B3 /* StreamEvent.h in Headers */,
                                49A85B78138D58EE00ECB7B3 /* JSStreamEvent.h in Headers */,
                        );
                                4496E39D1398136C003EE32A /* JSSVGAnimateMotionElement.cpp in Sources */,
                                4496E3A2139813CB003EE32A /* JSSVGMPathElement.cpp in Sources */,
                                2E24476813959173004B6C19 /* JSOperationNotAllowedException.cpp in Sources */,
+                               FDC54F041399B0DA008D9117 /* BiquadFilterNode.cpp in Sources */,
+                               FDF09DC81399B62200688E5B /* JSBiquadFilterNode.cpp in Sources */,
                                49A85B6B138D573A00ECB7B3 /* StreamEvent.cpp in Sources */,
                                49A85B77138D58EE00ECB7B3 /* JSStreamEvent.cpp in Sources */,
                        );
index 25ed16be9ab572a36a383242613f27e98ba5a54f..73a77265362548c6a656d487ff013d7c09f90732 100644 (file)
@@ -53,11 +53,11 @@ Biquad::Biquad()
 #endif
 
     // Initialize as pass-thru (straight-wire, no filter effect)
-    m_b0 = 1.0;
-    m_b1 = 0.0;
-    m_b2 = 0.0;
-    m_a1 = 0.0;
-    m_a2 = 0.0;
+    m_b0 = 1;
+    m_b1 = 0;
+    m_b2 = 0;
+    m_a1 = 0;
+    m_a2 = 0;
 
     reset(); // clear filter memory
 }
@@ -169,17 +169,17 @@ void Biquad::processSliceFast(double* sourceP, double* destP, double* coefficien
 
 void Biquad::reset()
 {
-    m_x1 = m_x2 = m_y1 = m_y2 = 0.0;
+    m_x1 = m_x2 = m_y1 = m_y2 = 0;
 
 #if OS(DARWIN)
     // Two extra samples for filter history
     double* inputP = m_inputBuffer.data();
-    inputP[0] = 0.0;
-    inputP[1] = 0.0;
+    inputP[0] = 0;
+    inputP[1] = 0;
 
     double* outputP = m_outputBuffer.data();
-    outputP[0] = 0.0;
-    outputP[1] = 0.0;
+    outputP[0] = 0;
+    outputP[1] = 0;
 #endif
 }
 
@@ -188,20 +188,20 @@ void Biquad::setLowpassParams(double cutoff, double resonance)
     resonance = std::max(0.0, resonance); // can't go negative
 
     double g = pow(10.0, 0.05 * resonance);
-    double d = sqrt((4.0 - sqrt(16.0 - 16.0 / (g * g))) / 2.0);
+    double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
 
     // Compute biquad coefficients for lopass filter
     double theta = piDouble * cutoff;
     double sn = 0.5 * d * sin(theta);
-    double beta = 0.5 * (1.0 - sn) / (1.0 + sn);
+    double beta = 0.5 * (1 - sn) / (1 + sn);
     double gamma = (0.5 + beta) * cos(theta);
     double alpha = 0.25 * (0.5 + beta - gamma);
 
-    m_b0 = 2.0 * alpha;
-    m_b1 = 2.0 * 2.0*alpha;
-    m_b2 = 2.0 * alpha;
-    m_a1 = 2.0 * -gamma;
-    m_a2 = 2.0 * beta;
+    m_b0 = 2 * alpha;
+    m_b1 = 2 * 2 * alpha;
+    m_b2 = 2 * alpha;
+    m_a1 = 2 * -gamma;
+    m_a2 = 2 * beta;
 }
 
 void Biquad::setHighpassParams(double cutoff, double resonance)
@@ -209,41 +209,25 @@ void Biquad::setHighpassParams(double cutoff, double resonance)
     resonance = std::max(0.0, resonance); // can't go negative
 
     double g = pow(10.0, 0.05 * resonance);
-    double d = sqrt((4.0 - sqrt(16.0 - 16.0 / (g * g))) / 2.0);
+    double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
 
     // Compute biquad coefficients for highpass filter
     double theta = piDouble * cutoff;
     double sn = 0.5 * d * sin(theta);
-    double beta = 0.5 * (1.0 - sn) / (1.0 + sn);
+    double beta = 0.5 * (1 - sn) / (1 + sn);
     double gamma = (0.5 + beta) * cos(theta);
     double alpha = 0.25 * (0.5 + beta + gamma);
 
-    m_b0 = 2.0 * alpha;
-    m_b1 = 2.0 * -2.0*alpha;
-    m_b2 = 2.0 * alpha;
-    m_a1 = 2.0 * -gamma;
-    m_a2 = 2.0 * beta;
+    m_b0 = 2 * alpha;
+    m_b1 = 2 * -2 * alpha;
+    m_b2 = 2 * alpha;
+    m_a1 = 2 * -gamma;
+    m_a2 = 2 * beta;
 }
 
-void Biquad::setLowShelfParams(double cutoff, double dbGain)
+void Biquad::setNormalizedCoefficients(double b0, double b1, double b2, double a0, double a1, double a2)
 {
-    double theta = piDouble * cutoff;
-
-    double A = pow(10.0, dbGain / 40.0);
-    double S = 1.0; // filter slope (1.0 is max value)
-    double alpha = 0.5 * sin(theta) * sqrt((A + 1.0 / A) * (1.0 / S - 1.0) + 2.0);
-
-    double k = cos(theta);
-    double k2 = 2.0 * sqrt(A) * alpha;
-
-    double b0 = A * ((A + 1.0) - (A - 1.0) * k + k2);
-    double b1 = 2.0 * A * ((A - 1.0) - (A + 1.0) * k);
-    double b2 = A * ((A + 1.0) - (A - 1.0) * k - k2);
-    double a0 = (A + 1.0) + (A - 1.0) * k + k2;
-    double a1 = -2.0 * ((A - 1.0) + (A + 1.0) * k);
-    double a2 = (A + 1.0) + (A - 1.0) * k - k2;
-
-    double a0Inverse = 1.0 / a0;
+    double a0Inverse = 1 / a0;
     
     m_b0 = b0 * a0Inverse;
     m_b1 = b1 * a0Inverse;
@@ -252,15 +236,132 @@ void Biquad::setLowShelfParams(double cutoff, double dbGain)
     m_a2 = a2 * a0Inverse;
 }
 
+void Biquad::setLowShelfParams(double frequency, double dbGain)
+{
+    double w0 = piDouble * frequency;
+
+    double A = pow(10.0, dbGain / 40);
+    double S = 1; // filter slope (1 is max value)
+    double alpha = 0.5 * sin(w0) * sqrt((A + 1 / A) * (1 / S - 1) + 2);
+
+    double k = cos(w0);
+    double k2 = 2 * sqrt(A) * alpha;
+
+    double aPlusOne = A + 1;
+    double aMinusOne = A - 1;
+    
+    double b0 = A * (aPlusOne - aMinusOne * k + k2);
+    double b1 = 2 * A * (aMinusOne - aPlusOne * k);
+    double b2 = A * (aPlusOne - aMinusOne * k - k2);
+    double a0 = aPlusOne + aMinusOne * k + k2;
+    double a1 = -2 * (aMinusOne + aPlusOne * k);
+    double a2 = aPlusOne + aMinusOne * k - k2;
+
+    setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
+}
+
+void Biquad::setHighShelfParams(double frequency, double dbGain)
+{
+    double w0 = piDouble * frequency;
+
+    double A = pow(10.0, dbGain / 40);
+    double S = 1; // filter slope (1 is max value)
+    double alpha = 0.5 * sin(w0) * sqrt((A + 1 / A) * (1 / S - 1) + 2);
+
+    double k = cos(w0);
+    double k2 = 2 * sqrt(A) * alpha;
+
+    double aPlusOne = A + 1;
+    double aMinusOne = A - 1;
+    
+    double b0 = A * (aPlusOne + aMinusOne * k + k2);
+    double b1 = -2 * A * (aMinusOne + aPlusOne * k);
+    double b2 = A * (aPlusOne + aMinusOne * k - k2);
+    double a0 = aPlusOne - aMinusOne * k + k2;
+    double a1 = 2 * (aMinusOne - aPlusOne * k);
+    double a2 = aPlusOne - aMinusOne * k - k2;
+
+    setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
+}
+
+void Biquad::setPeakingParams(double frequency, double Q, double dbGain)
+{
+    double w0 = piDouble * frequency;
+    double alpha = sin(w0) / (2 * Q);
+    double A = pow(10.0, dbGain / 40);
+
+    double k = cos(w0);
+
+    double b0 = 1 + alpha * A;
+    double b1 = -2 * k;
+    double b2 = 1 - alpha * A;
+    double a0 = 1 + alpha / A;
+    double a1 = -2 * k;
+    double a2 = 1 - alpha / A;
+
+    setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
+}
+
+void Biquad::setAllpassParams(double frequency, double Q)
+{
+    double w0 = piDouble * frequency;
+    double alpha = sin(w0) / (2 * Q);
+
+    double k = cos(w0);
+
+    double b0 = 1 - alpha;
+    double b1 = -2 * k;
+    double b2 = 1 + alpha;
+    double a0 = 1 + alpha;
+    double a1 = -2 * k;
+    double a2 = 1 - alpha;
+
+    setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
+}
+
+void Biquad::setNotchParams(double frequency, double Q)
+{
+    double w0 = piDouble * frequency;
+    double alpha = sin(w0) / (2 * Q);
+
+    double k = cos(w0);
+
+    double b0 = 1;
+    double b1 = -2 * k;
+    double b2 = 1;
+    double a0 = 1 + alpha;
+    double a1 = -2 * k;
+    double a2 = 1 - alpha;
+
+    setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
+}
+
+void Biquad::setBandpassParams(double frequency, double Q)
+{
+    double w0 = piDouble * frequency;
+    double alpha = sin(w0) / (2 * Q);
+
+    double k = cos(w0);
+    
+    double b0 = alpha;
+    double b1 = 0;
+    double b2 = -alpha;
+    double a0 = 1 + alpha;
+    double a1 = -2 * k;
+    double a2 = 1 - alpha;
+
+    setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
+}
+
 void Biquad::setZeroPolePairs(const Complex &zero, const Complex &pole)
 {
-    m_b0 = 1.0;
-    m_b1 = -2.0 * zero.real();
+    m_b0 = 1;
+    m_b1 = -2 * zero.real();
 
     double zeroMag = abs(zero);
     m_b2 = zeroMag * zeroMag;
 
-    m_a1 = -2.0 * pole.real();
+    m_a1 = -2 * pole.real();
 
     double poleMag = abs(pole);
     m_a2 = poleMag * poleMag;
@@ -268,7 +369,7 @@ void Biquad::setZeroPolePairs(const Complex &zero, const Complex &pole)
 
 void Biquad::setAllpassPole(const Complex &pole)
 {
-    Complex zero = Complex(1.0, 0.0) / pole;
+    Complex zero = Complex(10) / pole;
     setZeroPolePairs(zero, pole);
 }
 
index d059604bc64f71ceca6fad0f14665767a18dccbb..3fce7db97d7403ce01442b85e694caddb800edf0 100644 (file)
@@ -48,15 +48,16 @@ public:
 
     void process(const float* sourceP, float* destP, size_t framesToProcess);
 
-    // cutoff is 0-1 normalized, resonance is in dB >= 0.0
-    void setLowpassParams(double cutoff, double resonance);
-    void setHighpassParams(double cutoff, double resonance);
-
-    void setLowShelfParams(double cutoff, double dbGain);
-
-    // FIXME: need to implement a few more common filters
-    // void setHighShelfParams(double cutoff, double dbGain);
-    // void setParametricEQParams(double cutoff, double resonance);
+    // frequency is 0 - 1 normalized, resonance and dbGain are in decibels.
+    // Q is a unitless quality factor.
+    void setLowpassParams(double frequency, double resonance);
+    void setHighpassParams(double frequency, double resonance);
+    void setBandpassParams(double frequency, double Q);
+    void setLowShelfParams(double frequency, double dbGain);
+    void setHighShelfParams(double frequency, double dbGain);
+    void setPeakingParams(double frequency, double Q, double dbGain);
+    void setAllpassParams(double frequency, double Q);
+    void setNotchParams(double frequency, double Q);
 
     // Set the biquad coefficients given a single zero (other zero will be conjugate)
     // and a single pole (other pole will be conjugate)
@@ -70,6 +71,8 @@ public:
     void reset();
 
 private:
+    void setNormalizedCoefficients(double b0, double b1, double b2, double a0, double a1, double a2);
+
     // Filter coefficients
     double m_b0;
     double m_b1;
index 19c706d5c0c467a6e1002d8bb5e30a02db09e61c..f25bcec5c54ce88a0e36ae039d28ec3ba6885149 100644 (file)
@@ -38,6 +38,7 @@
 #include "AudioNodeInput.h"
 #include "AudioNodeOutput.h"
 #include "AudioPannerNode.h"
+#include "BiquadFilterNode.h"
 #include "ConvolverNode.h"
 #include "DefaultAudioDestinationNode.h"
 #include "DelayNode.h"
@@ -53,6 +54,7 @@
 #include "OfflineAudioDestinationNode.h"
 #include "PlatformString.h"
 #include "RealtimeAnalyserNode.h"
+#include "ScriptCallStack.h"
 
 #if DEBUG_AUDIONODE_REFERENCES
 #include <stdio.h>
@@ -264,10 +266,20 @@ PassRefPtr<JavaScriptAudioNode> AudioContext::createJavaScriptNode(size_t buffer
     return node;
 }
 
+PassRefPtr<BiquadFilterNode> AudioContext::createBiquadFilter()
+{
+    ASSERT(isMainThread());
+    lazyInitialize();
+    return BiquadFilterNode::create(this, m_destinationNode->sampleRate());
+}
+
 PassRefPtr<LowPass2FilterNode> AudioContext::createLowPass2Filter()
 {
     ASSERT(isMainThread());
     lazyInitialize();
+    if (document())
+        document()->addMessage(JSMessageSource, LogMessageType, WarningMessageLevel, "createLowPass2Filter() is deprecated.  Use createBiquadFilter() instead.", 1, String(), 0);
+        
     return LowPass2FilterNode::create(this, m_destinationNode->sampleRate());
 }
 
@@ -275,6 +287,9 @@ PassRefPtr<HighPass2FilterNode> AudioContext::createHighPass2Filter()
 {
     ASSERT(isMainThread());
     lazyInitialize();
+    if (document())
+        document()->addMessage(JSMessageSource, LogMessageType, WarningMessageLevel, "createHighPass2Filter() is deprecated.  Use createBiquadFilter() instead.", 1, String(), 0);
+
     return HighPass2FilterNode::create(this, m_destinationNode->sampleRate());
 }
 
index 666a353e165dc975ac391eed73b8a3c7c89a49a0..3999664190a61d259bea5a94c0ce49186eabbdeb 100644 (file)
@@ -50,6 +50,7 @@ class AudioChannelSplitter;
 class AudioGainNode;
 class AudioPannerNode;
 class AudioListener;
+class BiquadFilterNode;
 class DelayNode;
 class Document;
 class LowPass2FilterNode;
@@ -100,6 +101,7 @@ public:
     // The AudioNode create methods are called on the main thread (from JavaScript).
     PassRefPtr<AudioBufferSourceNode> createBufferSource();
     PassRefPtr<AudioGainNode> createGainNode();
+    PassRefPtr<BiquadFilterNode> createBiquadFilter();
     PassRefPtr<DelayNode> createDelayNode();
     PassRefPtr<LowPass2FilterNode> createLowPass2Filter();
     PassRefPtr<HighPass2FilterNode> createHighPass2Filter();
index f45d94af82170485a82de15a395a2ee2ee75909e..d30df866e50a16f77baf1dea286c2c0b417a24df 100644 (file)
@@ -58,6 +58,7 @@ module webaudio {
         // Processing nodes
         AudioGainNode createGainNode();
         DelayNode createDelayNode();
+        BiquadFilterNode createBiquadFilter();
         LowPass2FilterNode createLowPass2Filter();
         HighPass2FilterNode createHighPass2Filter();
         AudioPannerNode createPanner();
index 48f59f680c5c7a44d0d9e30d66931e4983d551a3..50dca8058ef771c1f80888e550ffe507e1c83fc5 100644 (file)
@@ -58,6 +58,7 @@ public:
         NodeTypeDestination,
         NodeTypeAudioBufferSource,
         NodeTypeJavaScript,
+        NodeTypeBiquadFilter,
         NodeTypeLowPass2Filter,
         NodeTypeHighPass2Filter,
         NodeTypePanner,
index a4b28be659954ca06eab52569995172012a351bc..a2204b41a92effc8f48b7ae47df1ca6d3be1d7e1 100644 (file)
@@ -42,29 +42,44 @@ void BiquadDSPKernel::process(const float* source, float* destination, size_t fr
     if (biquadProcessor()->filterCoefficientsDirty()) {
         double value1 = biquadProcessor()->parameter1()->smoothedValue();
         double value2 = biquadProcessor()->parameter2()->smoothedValue();
+        double gain = biquadProcessor()->parameter3()->smoothedValue();
         
         // Convert from Hertz to normalized frequency 0 -> 1.
         double nyquist = this->nyquist();
-        double normalizedValue1 = value1 / nyquist;
+        double normalizedFrequency = value1 / nyquist;
 
         // Configure the biquad with the new filter parameters for the appropriate type of filter.
         switch (biquadProcessor()->type()) {
-        case BiquadProcessor::LowPass2:
-            m_biquad.setLowpassParams(normalizedValue1, value2);
+        case BiquadProcessor::LowPass:
+            m_biquad.setLowpassParams(normalizedFrequency, value2);
             break;
 
-        case BiquadProcessor::HighPass2:
-            m_biquad.setHighpassParams(normalizedValue1, value2);
+        case BiquadProcessor::HighPass:
+            m_biquad.setHighpassParams(normalizedFrequency, value2);
+            break;
+
+        case BiquadProcessor::BandPass:
+            m_biquad.setBandpassParams(normalizedFrequency, value2);
             break;
 
         case BiquadProcessor::LowShelf:
-            m_biquad.setLowShelfParams(normalizedValue1, value2);
+            m_biquad.setLowShelfParams(normalizedFrequency, gain);
+            break;
+
+        case BiquadProcessor::HighShelf:
+            m_biquad.setHighShelfParams(normalizedFrequency, gain);
             break;
 
-        // FIXME: add other biquad filter types...
         case BiquadProcessor::Peaking:
+            m_biquad.setPeakingParams(normalizedFrequency, value2, gain);
+            break;
+
+        case BiquadProcessor::Notch:
+            m_biquad.setNotchParams(normalizedFrequency, value2);
+            break;
+
         case BiquadProcessor::Allpass:
-        case BiquadProcessor::HighShelf:
+            m_biquad.setAllpassParams(normalizedFrequency, value2);
             break;
         }
     }
diff --git a/Source/WebCore/webaudio/BiquadFilterNode.cpp b/Source/WebCore/webaudio/BiquadFilterNode.cpp
new file mode 100644 (file)
index 0000000..a61ee5b
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(WEB_AUDIO)
+
+#include "BiquadFilterNode.h"
+
+namespace WebCore {
+
+BiquadFilterNode::BiquadFilterNode(AudioContext* context, double sampleRate)
+    : AudioBasicProcessorNode(context, sampleRate)
+{
+    // Initially setup as lowpass filter.
+    m_processor = adoptPtr(new BiquadProcessor(BiquadProcessor::LowPass, sampleRate, 1, false));
+    biquadProcessor()->parameter1()->setContext(context);
+    biquadProcessor()->parameter2()->setContext(context);
+    biquadProcessor()->parameter3()->setContext(context);
+    setType(NodeTypeBiquadFilter);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_AUDIO)
diff --git a/Source/WebCore/webaudio/BiquadFilterNode.h b/Source/WebCore/webaudio/BiquadFilterNode.h
new file mode 100644 (file)
index 0000000..579905b
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BiquadFilterNode_h
+#define BiquadFilterNode_h
+
+#include "AudioBasicProcessorNode.h"
+#include "BiquadProcessor.h"
+
+namespace WebCore {
+
+class AudioParam;
+    
+class BiquadFilterNode : public AudioBasicProcessorNode {
+public:
+    // These must be defined as in the .idl file and must match those in the BiquadProcessor class.
+    enum {
+        LOWPASS = 0,
+        HIGHPASS = 1,
+        BANDPASS = 2,
+        LOWSHELF = 3,
+        HIGHSHELF = 4,
+        PEAKING = 5,
+        NOTCH = 6,
+        ALLPASS = 7
+    };
+
+    static PassRefPtr<BiquadFilterNode> create(AudioContext* context, double sampleRate)
+    {
+        return adoptRef(new BiquadFilterNode(context, sampleRate));      
+    }
+    
+    unsigned short type() { return biquadProcessor()->type(); }
+    void setType(unsigned short type) { biquadProcessor()->setType(static_cast<BiquadProcessor::FilterType>(type)); }
+
+    AudioParam* frequency() { return biquadProcessor()->parameter1(); }
+    AudioParam* q() { return biquadProcessor()->parameter2(); }
+    AudioParam* gain() { return biquadProcessor()->parameter3(); }
+    
+private:
+    BiquadFilterNode(AudioContext*, double sampleRate);
+
+    BiquadProcessor* biquadProcessor() { return static_cast<BiquadProcessor*>(processor()); }
+};
+
+} // namespace WebCore
+
+#endif // BiquadFilterNode_h
diff --git a/Source/WebCore/webaudio/BiquadFilterNode.idl b/Source/WebCore/webaudio/BiquadFilterNode.idl
new file mode 100644 (file)
index 0000000..817f658
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module audio {
+    interface [
+        Conditional=WEB_AUDIO,
+        GenerateToJS
+    ] BiquadFilterNode : AudioNode {
+        // Filter type.
+        const unsigned short LOWPASS = 0;
+        const unsigned short HIGHPASS = 1;
+        const unsigned short BANDPASS = 2;
+        const unsigned short LOWSHELF = 3;
+        const unsigned short HIGHSHELF = 4;
+        const unsigned short PEAKING = 5;
+        const unsigned short NOTCH = 6;
+        const unsigned short ALLPASS = 7;
+
+        attribute unsigned short type;
+        readonly attribute AudioParam frequency; // in Hertz
+        readonly attribute AudioParam Q; // Quality factor
+        readonly attribute AudioParam gain; // in Decibels
+    };
+}
index 97a480ea97bfcb329bbcbc47a0fcd3652eb7009c..540e1fa1095d76fc89fc519d5aa55944b9b9a8ad 100644 (file)
 #include "BiquadDSPKernel.h"
 
 namespace WebCore {
+    
+BiquadProcessor::BiquadProcessor(double sampleRate, size_t numberOfChannels, bool autoInitialize)
+    : AudioDSPKernelProcessor(sampleRate, numberOfChannels)
+    , m_type(LowPass)
+    , m_parameter1(0)
+    , m_parameter2(0)
+    , m_parameter3(0)
+    , m_filterCoefficientsDirty(true)
+{
+    double nyquist = 0.5 * this->sampleRate();
+
+    // Create parameters for BiquadFilterNode.
+    m_parameter1 = AudioParam::create("frequency", 350.0, 10.0, nyquist);
+    m_parameter2 = AudioParam::create("Q", 1, 0.0001, 1000.0);
+    m_parameter3 = AudioParam::create("gain", 0.0, -40, 40);
+
+    if (autoInitialize)
+        initialize();
+}
 
 BiquadProcessor::BiquadProcessor(FilterType type, double sampleRate, size_t numberOfChannels, bool autoInitialize)
     : AudioDSPKernelProcessor(sampleRate, numberOfChannels)
@@ -42,35 +61,18 @@ BiquadProcessor::BiquadProcessor(FilterType type, double sampleRate, size_t numb
 {
     double nyquist = 0.5 * this->sampleRate();
     
+    // Handle the deprecated LowPass2FilterNode and HighPass2FilterNode.
     switch (type) {
     // Highpass and lowpass share the same parameters and only differ in filter type.
-    case LowPass2:
-    case HighPass2:
+    case LowPass:
+    case HighPass:
         m_parameter1 = AudioParam::create("frequency", 350.0, 20.0, nyquist);
         m_parameter2 = AudioParam::create("resonance", 0.0, -20.0, 20.0);
         m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
         break;
 
-    case Peaking:
-        m_parameter1 = AudioParam::create("frequency", 2500.0, 20.0, nyquist);
-        m_parameter2 = AudioParam::create("gain", 0.0, -20.0, 20.0);
-        m_parameter3 = AudioParam::create("Q", 0.5, 0.0, 1000.0);
-        break;
-    case Allpass:
-        m_parameter1 = AudioParam::create("frequency", 2500.0, 20.0, nyquist);
-        m_parameter2 = AudioParam::create("Q", 0.5, 0.0, 1000.0);
-        m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
-        break;
-    case LowShelf:
-        m_parameter1 = AudioParam::create("frequency", 80.0, 20.0, nyquist);
-        m_parameter2 = AudioParam::create("gain", 0.0, 0.0, 1.0);
-        m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
-        break;
-    case HighShelf:
-        m_parameter1 = AudioParam::create("frequency", 10000.0, 20.0, nyquist);
-        m_parameter2 = AudioParam::create("gain", 0.0, 0.0, 1.0);
-        m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
-        break;
+    default:
+        ASSERT_NOT_REACHED();
     }
 
     if (autoInitialize)
index 55dca334a1bf7f1039765d755830136f405de0bd..3bb7a015059d2daf1aef1ebd4d8e1fd4e5b17604 100644 (file)
@@ -39,15 +39,21 @@ namespace WebCore {
 class BiquadProcessor : public AudioDSPKernelProcessor {
 public:
     enum FilterType {
-        LowPass2,
-        HighPass2,
-        Peaking,
-        Allpass,
-        LowShelf,
-        HighShelf
+        LowPass = 0,
+        HighPass = 1,
+        BandPass = 2,
+        LowShelf = 3,
+        HighShelf = 4,
+        Peaking = 5,
+        Notch = 6,
+        Allpass = 7
     };
-    
+
+    BiquadProcessor(double sampleRate, size_t numberOfChannels, bool autoInitialize);
+
+    // Old constructor used by deprecated LowPass2FilterNode and HighPass2FilterNode
     BiquadProcessor(FilterType, double sampleRate, size_t numberOfChannels, bool autoInitialize = true);
+
     virtual ~BiquadProcessor();
     
     virtual PassOwnPtr<AudioDSPKernel> createKernel();
@@ -61,6 +67,7 @@ public:
     AudioParam* parameter3() { return m_parameter3.get(); }
 
     FilterType type() const { return m_type; }
+    void setType(FilterType type) { m_type = type; }
 
 private:
     FilterType m_type;
index 12d58a8edf804f83f61bd4739c30ab50e2a3a709..0ec1defc76625460efacd498611dfface9bcf205 100644 (file)
@@ -33,7 +33,7 @@ namespace WebCore {
 HighPass2FilterNode::HighPass2FilterNode(AudioContext* context, double sampleRate)
     : AudioBasicProcessorNode(context, sampleRate)
 {
-    m_processor = adoptPtr(new BiquadProcessor(BiquadProcessor::HighPass2, sampleRate, 1, false));
+    m_processor = adoptPtr(new BiquadProcessor(BiquadProcessor::HighPass, sampleRate, 1, false));
     biquadProcessor()->parameter1()->setContext(context);
     biquadProcessor()->parameter2()->setContext(context);
     biquadProcessor()->parameter3()->setContext(context);
index 8e627634daffaa5b2d5d73f409c90bddab12068e..149bd45d9201f9ab06ae24eda992819abdc47e99 100644 (file)
@@ -33,7 +33,7 @@ namespace WebCore {
 LowPass2FilterNode::LowPass2FilterNode(AudioContext* context, double sampleRate)
     : AudioBasicProcessorNode(context, sampleRate)
 {
-    m_processor = adoptPtr(new BiquadProcessor(BiquadProcessor::LowPass2, sampleRate, 1, false));
+    m_processor = adoptPtr(new BiquadProcessor(BiquadProcessor::LowPass, sampleRate, 1, false));
     biquadProcessor()->parameter1()->setContext(context);
     biquadProcessor()->parameter2()->setContext(context);
     biquadProcessor()->parameter3()->setContext(context);