| 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 13 matching lines...) Expand all Loading... |
| 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 "platform/audio/AudioResamplerKernel.h" | 29 #include "platform/audio/AudioResamplerKernel.h" |
| 30 | 30 |
| 31 #include <algorithm> | 31 #include <algorithm> |
| 32 #include "platform/audio/AudioResampler.h" | 32 #include "platform/audio/AudioResampler.h" |
| 33 | 33 |
| 34 using namespace std; | |
| 35 | |
| 36 namespace blink { | 34 namespace blink { |
| 37 | 35 |
| 38 const size_t AudioResamplerKernel::MaxFramesToProcess = 128; | 36 const size_t AudioResamplerKernel::MaxFramesToProcess = 128; |
| 39 | 37 |
| 40 AudioResamplerKernel::AudioResamplerKernel(AudioResampler* resampler) | 38 AudioResamplerKernel::AudioResamplerKernel(AudioResampler* resampler) |
| 41 : m_resampler(resampler) | 39 : m_resampler(resampler) |
| 42 // The buffer size must be large enough to hold up to two extra sample frame
s for the linear interpolation. | 40 // The buffer size must be large enough to hold up to two extra sample frame
s for the linear interpolation. |
| 43 , m_sourceBuffer(2 + static_cast<int>(MaxFramesToProcess * AudioResampler::M
axRate)) | 41 , m_sourceBuffer(2 + static_cast<int>(MaxFramesToProcess * AudioResampler::M
axRate)) |
| 44 , m_virtualReadIndex(0.0) | 42 , m_virtualReadIndex(0.0) |
| 45 , m_fillIndex(0) | 43 , m_fillIndex(0) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 return m_sourceBuffer.data() + m_fillIndex; | 71 return m_sourceBuffer.data() + m_fillIndex; |
| 74 } | 72 } |
| 75 | 73 |
| 76 void AudioResamplerKernel::process(float* destination, size_t framesToProcess) | 74 void AudioResamplerKernel::process(float* destination, size_t framesToProcess) |
| 77 { | 75 { |
| 78 ASSERT(framesToProcess <= MaxFramesToProcess); | 76 ASSERT(framesToProcess <= MaxFramesToProcess); |
| 79 | 77 |
| 80 float* source = m_sourceBuffer.data(); | 78 float* source = m_sourceBuffer.data(); |
| 81 | 79 |
| 82 double rate = this->rate(); | 80 double rate = this->rate(); |
| 83 rate = max(0.0, rate); | 81 rate = std::max(0.0, rate); |
| 84 rate = min(AudioResampler::MaxRate, rate); | 82 rate = std::min(AudioResampler::MaxRate, rate); |
| 85 | 83 |
| 86 // Start out with the previous saved values (if any). | 84 // Start out with the previous saved values (if any). |
| 87 if (m_fillIndex > 0) { | 85 if (m_fillIndex > 0) { |
| 88 source[0] = m_lastValues[0]; | 86 source[0] = m_lastValues[0]; |
| 89 source[1] = m_lastValues[1]; | 87 source[1] = m_lastValues[1]; |
| 90 } | 88 } |
| 91 | 89 |
| 92 // Make a local copy. | 90 // Make a local copy. |
| 93 double virtualReadIndex = m_virtualReadIndex; | 91 double virtualReadIndex = m_virtualReadIndex; |
| 94 | 92 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 132 } |
| 135 | 133 |
| 136 double AudioResamplerKernel::rate() const | 134 double AudioResamplerKernel::rate() const |
| 137 { | 135 { |
| 138 return m_resampler->rate(); | 136 return m_resampler->rate(); |
| 139 } | 137 } |
| 140 | 138 |
| 141 } // namespace blink | 139 } // namespace blink |
| 142 | 140 |
| 143 #endif // ENABLE(WEB_AUDIO) | 141 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |