| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webaudio/IIRProcessor.h" | 5 #include "modules/webaudio/IIRProcessor.h" |
| 6 | 6 |
| 7 #include "modules/webaudio/IIRDSPKernel.h" | 7 #include "modules/webaudio/IIRDSPKernel.h" |
| 8 #include "wtf/PtrUtil.h" | |
| 9 #include <memory> | |
| 10 | 8 |
| 11 namespace blink { | 9 namespace blink { |
| 12 | 10 |
| 13 IIRProcessor::IIRProcessor(float sampleRate, size_t numberOfChannels, const Vect
or<double>& feedforwardCoef, const Vector<double>& feedbackCoef) | 11 IIRProcessor::IIRProcessor(float sampleRate, size_t numberOfChannels, const Vect
or<double>& feedforwardCoef, const Vector<double>& feedbackCoef) |
| 14 : AudioDSPKernelProcessor(sampleRate, numberOfChannels) | 12 : AudioDSPKernelProcessor(sampleRate, numberOfChannels) |
| 15 { | 13 { |
| 16 unsigned feedbackLength = feedbackCoef.size(); | 14 unsigned feedbackLength = feedbackCoef.size(); |
| 17 unsigned feedforwardLength = feedforwardCoef.size(); | 15 unsigned feedforwardLength = feedforwardCoef.size(); |
| 18 ASSERT(feedbackLength > 0); | 16 ASSERT(feedbackLength > 0); |
| 19 ASSERT(feedforwardLength > 0); | 17 ASSERT(feedforwardLength > 0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 41 for (unsigned k = 1; k < feedbackLength; ++k) | 39 for (unsigned k = 1; k < feedbackLength; ++k) |
| 42 m_feedback[k] /= scale; | 40 m_feedback[k] /= scale; |
| 43 | 41 |
| 44 for (unsigned k = 0; k < feedforwardLength; ++k) | 42 for (unsigned k = 0; k < feedforwardLength; ++k) |
| 45 m_feedforward[k] /= scale; | 43 m_feedforward[k] /= scale; |
| 46 | 44 |
| 47 // The IIRFilter checks to make sure this coefficient is 1, so make it s
o. | 45 // The IIRFilter checks to make sure this coefficient is 1, so make it s
o. |
| 48 m_feedback[0] = 1; | 46 m_feedback[0] = 1; |
| 49 } | 47 } |
| 50 | 48 |
| 51 m_responseKernel = wrapUnique(new IIRDSPKernel(this)); | 49 m_responseKernel = adoptPtr(new IIRDSPKernel(this)); |
| 52 } | 50 } |
| 53 | 51 |
| 54 IIRProcessor::~IIRProcessor() | 52 IIRProcessor::~IIRProcessor() |
| 55 { | 53 { |
| 56 if (isInitialized()) | 54 if (isInitialized()) |
| 57 uninitialize(); | 55 uninitialize(); |
| 58 } | 56 } |
| 59 | 57 |
| 60 std::unique_ptr<AudioDSPKernel> IIRProcessor::createKernel() | 58 PassOwnPtr<AudioDSPKernel> IIRProcessor::createKernel() |
| 61 { | 59 { |
| 62 return wrapUnique(new IIRDSPKernel(this)); | 60 return adoptPtr(new IIRDSPKernel(this)); |
| 63 } | 61 } |
| 64 | 62 |
| 65 void IIRProcessor::process(const AudioBus* source, AudioBus* destination, size_t
framesToProcess) | 63 void IIRProcessor::process(const AudioBus* source, AudioBus* destination, size_t
framesToProcess) |
| 66 { | 64 { |
| 67 if (!isInitialized()) { | 65 if (!isInitialized()) { |
| 68 destination->zero(); | 66 destination->zero(); |
| 69 return; | 67 return; |
| 70 } | 68 } |
| 71 | 69 |
| 72 // For each channel of our input, process using the corresponding IIRDSPKern
el into the output | 70 // For each channel of our input, process using the corresponding IIRDSPKern
el into the output |
| 73 // channel. | 71 // channel. |
| 74 for (unsigned i = 0; i < m_kernels.size(); ++i) | 72 for (unsigned i = 0; i < m_kernels.size(); ++i) |
| 75 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i
)->mutableData(), framesToProcess); | 73 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i
)->mutableData(), framesToProcess); |
| 76 } | 74 } |
| 77 | 75 |
| 78 void IIRProcessor::getFrequencyResponse(int nFrequencies, const float* frequency
Hz, float* magResponse, float* phaseResponse) | 76 void IIRProcessor::getFrequencyResponse(int nFrequencies, const float* frequency
Hz, float* magResponse, float* phaseResponse) |
| 79 { | 77 { |
| 80 m_responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magRespons
e, phaseResponse); | 78 m_responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magRespons
e, phaseResponse); |
| 81 } | 79 } |
| 82 | 80 |
| 83 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |