| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 4 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 5 #define _USE_MATH_DEFINES | 5 #define _USE_MATH_DEFINES |
| 6 #include <cmath> | 6 #include <cmath> |
| 7 | 7 |
| 8 #include "media/audio/simple_sources.h" | 8 #include "media/audio/simple_sources.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 f_(freq / sample_freq), | 22 f_(freq / sample_freq), |
| 23 time_state_(0), | 23 time_state_(0), |
| 24 cap_(0), | 24 cap_(0), |
| 25 callbacks_(0), | 25 callbacks_(0), |
| 26 errors_(0) { | 26 errors_(0) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 // The implementation could be more efficient if a lookup table is constructed | 29 // The implementation could be more efficient if a lookup table is constructed |
| 30 // but it is efficient enough for our simple needs. | 30 // but it is efficient enough for our simple needs. |
| 31 int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, | 31 int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, |
| 32 int total_bytes_delay) { | 32 AudioBuffersState audio_buffers) { |
| 33 base::AutoLock auto_lock(time_lock_); | 33 base::AutoLock auto_lock(time_lock_); |
| 34 callbacks_++; | 34 callbacks_++; |
| 35 | 35 |
| 36 // The table is filled with s(t) = kint16max*sin(Theta*t), | 36 // The table is filled with s(t) = kint16max*sin(Theta*t), |
| 37 // where Theta = 2*PI*fs. | 37 // where Theta = 2*PI*fs. |
| 38 // We store the discrete time value |t| in a member to ensure that the | 38 // We store the discrete time value |t| in a member to ensure that the |
| 39 // next pass starts at a correct state. | 39 // next pass starts at a correct state. |
| 40 int max_frames = cap_ > 0 ? | 40 int max_frames = cap_ > 0 ? |
| 41 std::min(audio_bus->frames(), cap_ - time_state_) : audio_bus->frames(); | 41 std::min(audio_bus->frames(), cap_ - time_state_) : audio_bus->frames(); |
| 42 for (int i = 0; i < max_frames; ++i) | 42 for (int i = 0; i < max_frames; ++i) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 DCHECK_GT(cap, 0); | 57 DCHECK_GT(cap, 0); |
| 58 cap_ = cap; | 58 cap_ = cap; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SineWaveAudioSource::Reset() { | 61 void SineWaveAudioSource::Reset() { |
| 62 base::AutoLock auto_lock(time_lock_); | 62 base::AutoLock auto_lock(time_lock_); |
| 63 time_state_ = 0; | 63 time_state_ = 0; |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace media | 66 } // namespace media |
| OLD | NEW |