Changeset 109458 in webkit
- Timestamp:
- Mar 1, 2012 3:59:02 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r109455 r109458 1 2012-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 1 13 2012-03-01 Adam Klein <adamk@chromium.org> 2 14 -
trunk/LayoutTests/webaudio/resources/biquad-testing.js
r106621 r109458 378 378 var b2 = filterCoef.b2; 379 379 var a1 = filterCoef.a1; 380 var a2 = filterCoef. 380 var a2 = filterCoef.a2; 381 381 382 382 // Prime the pump. (Assumes the signal has length >= 2!) -
trunk/Source/WebCore/ChangeLog
r109451 r109458 1 2012-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 1 24 2012-03-01 Peter Kotwicz <pkotwicz@google.com> 2 25 -
trunk/Source/WebCore/platform/audio/Biquad.cpp
r106621 r109458 54 54 #endif 55 55 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 56 62 // 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); 62 64 63 65 reset(); // clear filter memory 66 } 67 68 Biquad::~Biquad() 69 { 70 #if USE(WEBAUDIO_IPP) 71 ippsFree(m_ippInternalBuffer); 72 #endif // USE(WEBAUDIO_IPP) 64 73 } 65 74 … … 69 78 // Use vecLib if available 70 79 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 72 85 int n = framesToProcess; 73 86 … … 172 185 void Biquad::reset() 173 186 { 174 m_x1 = m_x2 = m_y1 = m_y2 = 0;175 176 187 #if OS(DARWIN) 177 188 // Two extra samples for filter history … … 183 194 outputP[0] = 0; 184 195 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; 185 204 #endif 186 205 } … … 188 207 void Biquad::setLowpassParams(double cutoff, double resonance) 189 208 { 190 resonance = std::max(0.0, resonance); // can't go negative191 209 // Limit cutoff to 0 to 1. 192 210 cutoff = std::max(0.0, std::min(cutoff, 1.0)); 193 211 194 double g = pow(10.0, 0.05 * resonance);195 double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);196 197 212 if (cutoff == 1) { 198 213 // 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); 204 216 } else if (cutoff > 0) { 205 217 // 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 206 222 double theta = piDouble * cutoff; 207 223 double sn = 0.5 * d * sin(theta); … … 210 226 double alpha = 0.25 * (0.5 + beta - gamma); 211 227 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); 217 235 } else { 218 236 // When cutoff is zero, nothing gets through the filter, so set 219 237 // 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); 225 240 } 226 241 } … … 228 243 void Biquad::setHighpassParams(double cutoff, double resonance) 229 244 { 230 resonance = std::max(0.0, resonance); // can't go negative231 232 245 // Limit cutoff to 0 to 1. 233 246 cutoff = std::max(0.0, std::min(cutoff, 1.0)); 234 247 235 double g = pow(10.0, 0.05 * resonance);236 double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);237 238 248 if (cutoff == 1) { 239 249 // 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); 245 252 } else if (cutoff > 0) { 246 253 // 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 247 258 double theta = piDouble * cutoff; 248 259 double sn = 0.5 * d * sin(theta); … … 251 262 double alpha = 0.25 * (0.5 + beta + gamma); 252 263 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); 258 271 } else { 259 272 // When cutoff is zero, we need to be careful because the above … … 261 274 // and zeros on the unit circle in the same place. When cutoff 262 275 // 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); 268 278 } 269 279 } … … 278 288 m_a1 = a1 * a0Inverse; 279 289 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) 280 303 } 281 304 … … 502 525 void Biquad::setZeroPolePairs(const Complex &zero, const Complex &pole) 503 526 { 504 m_b0 = 1;505 m_b1 = -2 * zero.real();527 double b0 = 1; 528 double b1 = -2 * zero.real(); 506 529 507 530 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(); 511 534 512 535 double poleMag = abs(pole); 513 m_a2 = poleMag * poleMag; 536 double a2 = poleMag * poleMag; 537 setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); 514 538 } 515 539 -
trunk/Source/WebCore/platform/audio/Biquad.h
r99337 r109458 35 35 #include <wtf/Platform.h> 36 36 37 #if USE(WEBAUDIO_IPP) 38 #include <ipps.h> 39 #endif // USE(WEBAUDIO_IPP) 40 37 41 namespace WebCore { 38 42 … … 45 49 public: 46 50 Biquad(); 47 virtual ~Biquad() { }51 virtual ~Biquad(); 48 52 49 53 void process(const float* sourceP, float* destP, size_t framesToProcess); … … 90 94 double m_a2; 91 95 92 // Filter memory93 double m_x1; // input delayed by 1 sample94 double m_x2; // input delayed by 2 samples95 double m_y1; // output delayed by 1 sample96 double m_y2; // output delayed by 2 samples97 98 96 #if OS(DARWIN) 99 97 void processFast(const float* sourceP, float* destP, size_t framesToProcess); … … 102 100 AudioDoubleArray m_inputBuffer; 103 101 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 104 113 #endif 105 114 };
Note: See TracChangeset
for help on using the changeset viewer.