| 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 ConvolverHandler::~ConvolverHandler() | 65 ConvolverHandler::~ConvolverHandler() |
| 66 { | 66 { |
| 67 uninitialize(); | 67 uninitialize(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ConvolverHandler::process(size_t framesToProcess) | 70 void ConvolverHandler::process(size_t framesToProcess) |
| 71 { | 71 { |
| 72 AudioBus* outputBus = output(0).bus(); | 72 AudioBus* outputBus = output(0).bus(); |
| 73 ASSERT(outputBus); | 73 DCHECK(outputBus); |
| 74 | 74 |
| 75 // Synchronize with possible dynamic changes to the impulse response. | 75 // Synchronize with possible dynamic changes to the impulse response. |
| 76 MutexTryLocker tryLocker(m_processLock); | 76 MutexTryLocker tryLocker(m_processLock); |
| 77 if (tryLocker.locked()) { | 77 if (tryLocker.locked()) { |
| 78 if (!isInitialized() || !m_reverb) { | 78 if (!isInitialized() || !m_reverb) { |
| 79 outputBus->zero(); | 79 outputBus->zero(); |
| 80 } else { | 80 } else { |
| 81 // Process using the convolution engine. | 81 // Process using the convolution engine. |
| 82 // Note that we can handle the case where nothing is connected to th
e input, in which case we'll just feed silence into the convolver. | 82 // Note that we can handle the case where nothing is connected to th
e input, in which case we'll just feed silence into the convolver. |
| 83 // FIXME: If we wanted to get fancy we could try to factor in the '
tail time' and stop processing once the tail dies down if | 83 // FIXME: If we wanted to get fancy we could try to factor in the '
tail time' and stop processing once the tail dies down if |
| 84 // we keep getting fed silence. | 84 // we keep getting fed silence. |
| 85 m_reverb->process(input(0).bus(), outputBus, framesToProcess); | 85 m_reverb->process(input(0).bus(), outputBus, framesToProcess); |
| 86 } | 86 } |
| 87 } else { | 87 } else { |
| 88 // Too bad - the tryLock() failed. We must be in the middle of setting
a new impulse response. | 88 // Too bad - the tryLock() failed. We must be in the middle of setting
a new impulse response. |
| 89 outputBus->zero(); | 89 outputBus->zero(); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 void ConvolverHandler::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionS
tate) | 93 void ConvolverHandler::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionS
tate) |
| 94 { | 94 { |
| 95 ASSERT(isMainThread()); | 95 DCHECK(isMainThread()); |
| 96 | 96 |
| 97 if (!buffer) | 97 if (!buffer) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 if (buffer->sampleRate() != context()->sampleRate()) { | 100 if (buffer->sampleRate() != context()->sampleRate()) { |
| 101 exceptionState.throwDOMException( | 101 exceptionState.throwDOMException( |
| 102 NotSupportedError, | 102 NotSupportedError, |
| 103 "The buffer sample rate of " + String::number(buffer->sampleRate()) | 103 "The buffer sample rate of " + String::number(buffer->sampleRate()) |
| 104 + " does not match the context rate of " + String::number(context()-
>sampleRate()) | 104 + " does not match the context rate of " + String::number(context()-
>sampleRate()) |
| 105 + " Hz."); | 105 + " Hz."); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 134 { | 134 { |
| 135 // Synchronize with process(). | 135 // Synchronize with process(). |
| 136 MutexLocker locker(m_processLock); | 136 MutexLocker locker(m_processLock); |
| 137 m_reverb = std::move(reverb); | 137 m_reverb = std::move(reverb); |
| 138 m_buffer = buffer; | 138 m_buffer = buffer; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 AudioBuffer* ConvolverHandler::buffer() | 142 AudioBuffer* ConvolverHandler::buffer() |
| 143 { | 143 { |
| 144 ASSERT(isMainThread()); | 144 DCHECK(isMainThread()); |
| 145 return m_buffer.get(); | 145 return m_buffer.get(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 double ConvolverHandler::tailTime() const | 148 double ConvolverHandler::tailTime() const |
| 149 { | 149 { |
| 150 MutexTryLocker tryLocker(m_processLock); | 150 MutexTryLocker tryLocker(m_processLock); |
| 151 if (tryLocker.locked()) | 151 if (tryLocker.locked()) |
| 152 return m_reverb ? m_reverb->impulseResponseLength() / static_cast<double
>(sampleRate()) : 0; | 152 return m_reverb ? m_reverb->impulseResponseLength() / static_cast<double
>(sampleRate()) : 0; |
| 153 // Since we don't want to block the Audio Device thread, we return a large v
alue | 153 // Since we don't want to block the Audio Device thread, we return a large v
alue |
| 154 // instead of trying to acquire the lock. | 154 // instead of trying to acquire the lock. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 return convolverHandler().normalize(); | 205 return convolverHandler().normalize(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void ConvolverNode::setNormalize(bool normalize) | 208 void ConvolverNode::setNormalize(bool normalize) |
| 209 { | 209 { |
| 210 convolverHandler().setNormalize(normalize); | 210 convolverHandler().setNormalize(normalize); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace blink | 213 } // namespace blink |
| 214 | 214 |
| OLD | NEW |