| 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 11 matching lines...) Expand all Loading... |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
| 28 | 28 |
| 29 #include "modules/webaudio/DelayDSPKernel.h" | 29 #include "modules/webaudio/DelayDSPKernel.h" |
| 30 | 30 |
| 31 #include "platform/audio/AudioUtilities.h" | 31 #include "platform/audio/AudioUtilities.h" |
| 32 #include "wtf/MathExtras.h" |
| 32 #include <algorithm> | 33 #include <algorithm> |
| 33 | 34 |
| 34 using namespace std; | 35 using namespace std; |
| 35 | 36 |
| 36 namespace WebCore { | 37 namespace WebCore { |
| 37 | 38 |
| 38 const float SmoothingTimeConstant = 0.020f; // 20ms | 39 const float SmoothingTimeConstant = 0.020f; // 20ms |
| 39 | 40 |
| 40 DelayDSPKernel::DelayDSPKernel(DelayProcessor* processor) | 41 DelayDSPKernel::DelayDSPKernel(DelayProcessor* processor) |
| 41 : AudioDelayDSPKernel(processor, AudioNode::ProcessingSizeInFrames) | 42 : AudioDelayDSPKernel(processor, AudioNode::ProcessingSizeInFrames) |
| 42 { | 43 { |
| 43 ASSERT(processor && processor->sampleRate() > 0); | 44 ASSERT(processor && processor->sampleRate() > 0); |
| 44 if (!(processor && processor->sampleRate() > 0)) | 45 if (!(processor && processor->sampleRate() > 0)) |
| 45 return; | 46 return; |
| 46 | 47 |
| 47 m_maxDelayTime = processor->maxDelayTime(); | 48 m_maxDelayTime = processor->maxDelayTime(); |
| 48 ASSERT(m_maxDelayTime >= 0); | 49 ASSERT(m_maxDelayTime >= 0 && !std::isnan(m_maxDelayTime)); |
| 49 if (m_maxDelayTime < 0) | 50 if (m_maxDelayTime < 0 || std::isnan(m_maxDelayTime)) |
| 50 return; | 51 return; |
| 51 | 52 |
| 52 m_buffer.allocate(bufferLengthForDelay(m_maxDelayTime, processor->sampleRate
())); | 53 m_buffer.allocate(bufferLengthForDelay(m_maxDelayTime, processor->sampleRate
())); |
| 53 m_buffer.zero(); | 54 m_buffer.zero(); |
| 54 | 55 |
| 55 m_smoothingRate = AudioUtilities::discreteTimeConstantForSampleRate(Smoothin
gTimeConstant, processor->sampleRate()); | 56 m_smoothingRate = AudioUtilities::discreteTimeConstantForSampleRate(Smoothin
gTimeConstant, processor->sampleRate()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 bool DelayDSPKernel::hasSampleAccurateValues() | 59 bool DelayDSPKernel::hasSampleAccurateValues() |
| 59 { | 60 { |
| 60 return delayProcessor()->delayTime()->hasSampleAccurateValues(); | 61 return delayProcessor()->delayTime()->hasSampleAccurateValues(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void DelayDSPKernel::calculateSampleAccurateValues(float* delayTimes, size_t fra
mesToProcess) | 64 void DelayDSPKernel::calculateSampleAccurateValues(float* delayTimes, size_t fra
mesToProcess) |
| 64 { | 65 { |
| 65 delayProcessor()->delayTime()->calculateSampleAccurateValues(delayTimes, fra
mesToProcess); | 66 delayProcessor()->delayTime()->calculateSampleAccurateValues(delayTimes, fra
mesToProcess); |
| 66 } | 67 } |
| 67 | 68 |
| 68 double DelayDSPKernel::delayTime(float) | 69 double DelayDSPKernel::delayTime(float) |
| 69 { | 70 { |
| 70 return delayProcessor()->delayTime()->finalValue(); | 71 return delayProcessor()->delayTime()->finalValue(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 } // namespace WebCore | 74 } // namespace WebCore |
| 74 | 75 |
| 75 #endif // ENABLE(WEB_AUDIO) | 76 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |