| 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/audio/AudioDSPKernelProcessor.h" | 31 #include "platform/audio/AudioDSPKernelProcessor.h" |
| 32 #include "platform/audio/AudioDSPKernel.h" | 32 #include "platform/audio/AudioDSPKernel.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 // setNumberOfChannels() may later be called if the object is not yet in an "ini
tialized" state. | 36 // setNumberOfChannels() may later be called if the object is not yet in an |
| 37 // "initialized" state. |
| 37 AudioDSPKernelProcessor::AudioDSPKernelProcessor(float sampleRate, | 38 AudioDSPKernelProcessor::AudioDSPKernelProcessor(float sampleRate, |
| 38 unsigned numberOfChannels) | 39 unsigned numberOfChannels) |
| 39 : AudioProcessor(sampleRate, numberOfChannels), m_hasJustReset(true) {} | 40 : AudioProcessor(sampleRate, numberOfChannels), m_hasJustReset(true) {} |
| 40 | 41 |
| 41 void AudioDSPKernelProcessor::initialize() { | 42 void AudioDSPKernelProcessor::initialize() { |
| 42 if (isInitialized()) | 43 if (isInitialized()) |
| 43 return; | 44 return; |
| 44 | 45 |
| 45 MutexLocker locker(m_processLock); | 46 MutexLocker locker(m_processLock); |
| 46 ASSERT(!m_kernels.size()); | 47 ASSERT(!m_kernels.size()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| 98 // Resets filter state | 99 // Resets filter state |
| 99 void AudioDSPKernelProcessor::reset() { | 100 void AudioDSPKernelProcessor::reset() { |
| 100 ASSERT(isMainThread()); | 101 ASSERT(isMainThread()); |
| 101 if (!isInitialized()) | 102 if (!isInitialized()) |
| 102 return; | 103 return; |
| 103 | 104 |
| 104 // Forces snap to parameter values - first time. | 105 // Forces snap to parameter values - first time. |
| 105 // Any processing depending on this value must set it to false at the appropri
ate time. | 106 // Any processing depending on this value must set it to false at the |
| 107 // appropriate time. |
| 106 m_hasJustReset = true; | 108 m_hasJustReset = true; |
| 107 | 109 |
| 108 MutexLocker locker(m_processLock); | 110 MutexLocker locker(m_processLock); |
| 109 for (unsigned i = 0; i < m_kernels.size(); ++i) | 111 for (unsigned i = 0; i < m_kernels.size(); ++i) |
| 110 m_kernels[i]->reset(); | 112 m_kernels[i]->reset(); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void AudioDSPKernelProcessor::setNumberOfChannels(unsigned numberOfChannels) { | 115 void AudioDSPKernelProcessor::setNumberOfChannels(unsigned numberOfChannels) { |
| 114 if (numberOfChannels == m_numberOfChannels) | 116 if (numberOfChannels == m_numberOfChannels) |
| 115 return; | 117 return; |
| 116 | 118 |
| 117 ASSERT(!isInitialized()); | 119 ASSERT(!isInitialized()); |
| 118 if (!isInitialized()) | 120 if (!isInitialized()) |
| 119 m_numberOfChannels = numberOfChannels; | 121 m_numberOfChannels = numberOfChannels; |
| 120 } | 122 } |
| 121 | 123 |
| 122 double AudioDSPKernelProcessor::tailTime() const { | 124 double AudioDSPKernelProcessor::tailTime() const { |
| 123 ASSERT(!isMainThread()); | 125 ASSERT(!isMainThread()); |
| 124 MutexTryLocker tryLocker(m_processLock); | 126 MutexTryLocker tryLocker(m_processLock); |
| 125 if (tryLocker.locked()) { | 127 if (tryLocker.locked()) { |
| 126 // It is expected that all the kernels have the same tailTime. | 128 // It is expected that all the kernels have the same tailTime. |
| 127 return !m_kernels.isEmpty() ? m_kernels.first()->tailTime() : 0; | 129 return !m_kernels.isEmpty() ? m_kernels.first()->tailTime() : 0; |
| 128 } | 130 } |
| 129 // Since we don't want to block the Audio Device thread, we return a large val
ue | 131 // Since we don't want to block the Audio Device thread, we return a large |
| 130 // instead of trying to acquire the lock. | 132 // value instead of trying to acquire the lock. |
| 131 return std::numeric_limits<double>::infinity(); | 133 return std::numeric_limits<double>::infinity(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 double AudioDSPKernelProcessor::latencyTime() const { | 136 double AudioDSPKernelProcessor::latencyTime() const { |
| 135 ASSERT(!isMainThread()); | 137 ASSERT(!isMainThread()); |
| 136 MutexTryLocker tryLocker(m_processLock); | 138 MutexTryLocker tryLocker(m_processLock); |
| 137 if (tryLocker.locked()) { | 139 if (tryLocker.locked()) { |
| 138 // It is expected that all the kernels have the same latencyTime. | 140 // It is expected that all the kernels have the same latencyTime. |
| 139 return !m_kernels.isEmpty() ? m_kernels.first()->latencyTime() : 0; | 141 return !m_kernels.isEmpty() ? m_kernels.first()->latencyTime() : 0; |
| 140 } | 142 } |
| 141 // Since we don't want to block the Audio Device thread, we return a large val
ue | 143 // Since we don't want to block the Audio Device thread, we return a large |
| 142 // instead of trying to acquire the lock. | 144 // value instead of trying to acquire the lock. |
| 143 return std::numeric_limits<double>::infinity(); | 145 return std::numeric_limits<double>::infinity(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 } // namespace blink | 148 } // namespace blink |
| OLD | NEW |