| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // When the cutoff is zero, the z-transform approaches 0, if Q | 517 // When the cutoff is zero, the z-transform approaches 0, if Q |
| 518 // > 0. When both Q and cutoff are zero, the z-transform is | 518 // > 0. When both Q and cutoff are zero, the z-transform is |
| 519 // pretty much undefined. What should we do in this case? | 519 // pretty much undefined. What should we do in this case? |
| 520 // For now, just make the filter 0. When the cutoff is 1, the | 520 // For now, just make the filter 0. When the cutoff is 1, the |
| 521 // z-transform also approaches 0. | 521 // z-transform also approaches 0. |
| 522 setNormalizedCoefficients(0, 0, 0, | 522 setNormalizedCoefficients(0, 0, 0, |
| 523 1, 0, 0); | 523 1, 0, 0); |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 | 526 |
| 527 void Biquad::setZeroPolePairs(const Complex &zero, const Complex &pole) | 527 void Biquad::setZeroPolePairs(const std::complex<double>&zero, const std::comple
x<double>&pole) |
| 528 { | 528 { |
| 529 double b0 = 1; | 529 double b0 = 1; |
| 530 double b1 = -2 * zero.real(); | 530 double b1 = -2 * zero.real(); |
| 531 | 531 |
| 532 double zeroMag = abs(zero); | 532 double zeroMag = abs(zero); |
| 533 double b2 = zeroMag * zeroMag; | 533 double b2 = zeroMag * zeroMag; |
| 534 | 534 |
| 535 double a1 = -2 * pole.real(); | 535 double a1 = -2 * pole.real(); |
| 536 | 536 |
| 537 double poleMag = abs(pole); | 537 double poleMag = abs(pole); |
| 538 double a2 = poleMag * poleMag; | 538 double a2 = poleMag * poleMag; |
| 539 setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); | 539 setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); |
| 540 } | 540 } |
| 541 | 541 |
| 542 void Biquad::setAllpassPole(const Complex &pole) | 542 void Biquad::setAllpassPole(const std::complex<double>&pole) |
| 543 { | 543 { |
| 544 Complex zero = Complex(1, 0) / pole; | 544 std::complex<double> zero = std::complex<double>(1, 0) / pole; |
| 545 setZeroPolePairs(zero, pole); | 545 setZeroPolePairs(zero, pole); |
| 546 } | 546 } |
| 547 | 547 |
| 548 void Biquad::getFrequencyResponse(int nFrequencies, | 548 void Biquad::getFrequencyResponse(int nFrequencies, |
| 549 const float* frequency, | 549 const float* frequency, |
| 550 float* magResponse, | 550 float* magResponse, |
| 551 float* phaseResponse) | 551 float* phaseResponse) |
| 552 { | 552 { |
| 553 // Evaluate the Z-transform of the filter at given normalized | 553 // Evaluate the Z-transform of the filter at given normalized |
| 554 // frequency from 0 to 1. (1 corresponds to the Nyquist | 554 // frequency from 0 to 1. (1 corresponds to the Nyquist |
| (...skipping 13 matching lines...) Expand all Loading... |
| 568 | 568 |
| 569 // Make local copies of the coefficients as a micro-optimization. | 569 // Make local copies of the coefficients as a micro-optimization. |
| 570 double b0 = m_b0; | 570 double b0 = m_b0; |
| 571 double b1 = m_b1; | 571 double b1 = m_b1; |
| 572 double b2 = m_b2; | 572 double b2 = m_b2; |
| 573 double a1 = m_a1; | 573 double a1 = m_a1; |
| 574 double a2 = m_a2; | 574 double a2 = m_a2; |
| 575 | 575 |
| 576 for (int k = 0; k < nFrequencies; ++k) { | 576 for (int k = 0; k < nFrequencies; ++k) { |
| 577 double omega = -piDouble * frequency[k]; | 577 double omega = -piDouble * frequency[k]; |
| 578 Complex z = Complex(cos(omega), sin(omega)); | 578 std::complex<double> z = std::complex<double> (cos(omega), sin(omega)); |
| 579 Complex numerator = b0 + (b1 + b2 * z) * z; | 579 std::complex<double> numerator = b0 + (b1 + b2 * z) * z; |
| 580 Complex denominator = Complex(1, 0) + (a1 + a2 * z) * z; | 580 std::complex<double> denominator = |
| 581 Complex response = numerator / denominator; | 581 std::complex<double>(1, 0) + (a1 + a2 * z) * z; |
| 582 std::complex<double> response = numerator / denominator; |
| 582 magResponse[k] = static_cast<float>(abs(response)); | 583 magResponse[k] = static_cast<float>(abs(response)); |
| 583 phaseResponse[k] = static_cast<float>(atan2(imag(response), real(respons
e))); | 584 phaseResponse[k] = static_cast<float>(atan2(imag(response), real(respons
e))); |
| 584 } | 585 } |
| 585 } | 586 } |
| 586 | 587 |
| 587 } // namespace blink | 588 } // namespace blink |
| 588 | 589 |
| 589 #endif // ENABLE(WEB_AUDIO) | 590 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |