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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 callbacks_(0), | 103 callbacks_(0), |
104 errors_(0) { | 104 errors_(0) { |
105 } | 105 } |
106 | 106 |
107 SineWaveAudioSource::~SineWaveAudioSource() { | 107 SineWaveAudioSource::~SineWaveAudioSource() { |
108 } | 108 } |
109 | 109 |
110 // The implementation could be more efficient if a lookup table is constructed | 110 // The implementation could be more efficient if a lookup table is constructed |
111 // but it is efficient enough for our simple needs. | 111 // but it is efficient enough for our simple needs. |
112 int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, | 112 int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, |
113 uint32_t total_bytes_delay, | 113 uint32 total_bytes_delay) { |
114 uint32_t frames_skipped) { | |
115 base::AutoLock auto_lock(time_lock_); | 114 base::AutoLock auto_lock(time_lock_); |
116 callbacks_++; | 115 callbacks_++; |
117 | 116 |
118 // The table is filled with s(t) = kint16max*sin(Theta*t), | 117 // The table is filled with s(t) = kint16max*sin(Theta*t), |
119 // where Theta = 2*PI*fs. | 118 // where Theta = 2*PI*fs. |
120 // We store the discrete time value |t| in a member to ensure that the | 119 // We store the discrete time value |t| in a member to ensure that the |
121 // next pass starts at a correct state. | 120 // next pass starts at a correct state. |
122 int max_frames = cap_ > 0 ? | 121 int max_frames = cap_ > 0 ? |
123 std::min(audio_bus->frames(), cap_ - time_state_) : audio_bus->frames(); | 122 std::min(audio_bus->frames(), cap_ - time_state_) : audio_bus->frames(); |
124 for (int i = 0; i < max_frames; ++i) | 123 for (int i = 0; i < max_frames; ++i) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 AudioParameters::AUDIO_PCM_LOW_LATENCY, | 186 AudioParameters::AUDIO_PCM_LOW_LATENCY, |
188 GuessChannelLayout(wav_audio_handler_->num_channels()), | 187 GuessChannelLayout(wav_audio_handler_->num_channels()), |
189 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), | 188 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), |
190 params_.frames_per_buffer()); | 189 params_.frames_per_buffer()); |
191 | 190 |
192 file_audio_converter_.reset( | 191 file_audio_converter_.reset( |
193 new AudioConverter(file_audio_slice, params_, false)); | 192 new AudioConverter(file_audio_slice, params_, false)); |
194 file_audio_converter_->AddInput(this); | 193 file_audio_converter_->AddInput(this); |
195 } | 194 } |
196 | 195 |
197 int FileSource::OnMoreData(AudioBus* audio_bus, | 196 int FileSource::OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) { |
198 uint32_t total_bytes_delay, | |
199 uint32_t frames_skipped) { | |
200 // Load the file if we haven't already. This load needs to happen on the | 197 // Load the file if we haven't already. This load needs to happen on the |
201 // audio thread, otherwise we'll run on the UI thread on Mac for instance. | 198 // audio thread, otherwise we'll run on the UI thread on Mac for instance. |
202 // This will massively delay the first OnMoreData, but we'll catch up. | 199 // This will massively delay the first OnMoreData, but we'll catch up. |
203 if (!wav_audio_handler_) | 200 if (!wav_audio_handler_) |
204 LoadWavFile(path_to_wav_file_); | 201 LoadWavFile(path_to_wav_file_); |
205 if (load_failed_) | 202 if (load_failed_) |
206 return 0; | 203 return 0; |
207 | 204 |
208 DCHECK(wav_audio_handler_.get()); | 205 DCHECK(wav_audio_handler_.get()); |
209 | 206 |
(...skipping 28 matching lines...) Expand all Loading... |
238 params.sample_rate() / | 235 params.sample_rate() / |
239 params.frames_per_buffer() / | 236 params.frames_per_buffer() / |
240 1000), | 237 1000), |
241 beep_generated_in_buffers_(0), | 238 beep_generated_in_buffers_(0), |
242 beep_period_in_frames_(params.sample_rate() / kBeepFrequency) { | 239 beep_period_in_frames_(params.sample_rate() / kBeepFrequency) { |
243 } | 240 } |
244 | 241 |
245 BeepingSource::~BeepingSource() { | 242 BeepingSource::~BeepingSource() { |
246 } | 243 } |
247 | 244 |
248 int BeepingSource::OnMoreData(AudioBus* audio_bus, | 245 int BeepingSource::OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) { |
249 uint32_t total_bytes_delay, | |
250 uint32_t frames_skipped) { | |
251 // Accumulate the time from the last beep. | 246 // Accumulate the time from the last beep. |
252 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; | 247 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; |
253 | 248 |
254 memset(buffer_.get(), 0, buffer_size_); | 249 memset(buffer_.get(), 0, buffer_size_); |
255 bool should_beep = false; | 250 bool should_beep = false; |
256 BeepContext* beep_context = g_beep_context.Pointer(); | 251 BeepContext* beep_context = g_beep_context.Pointer(); |
257 if (beep_context->automatic_beep()) { | 252 if (beep_context->automatic_beep()) { |
258 base::TimeDelta delta = interval_from_last_beep_ - | 253 base::TimeDelta delta = interval_from_last_beep_ - |
259 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); | 254 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); |
260 if (delta > base::TimeDelta()) { | 255 if (delta > base::TimeDelta()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 292 } |
298 | 293 |
299 void BeepingSource::OnError(AudioOutputStream* stream) { | 294 void BeepingSource::OnError(AudioOutputStream* stream) { |
300 } | 295 } |
301 | 296 |
302 void BeepingSource::BeepOnce() { | 297 void BeepingSource::BeepOnce() { |
303 g_beep_context.Pointer()->SetBeepOnce(true); | 298 g_beep_context.Pointer()->SetBeepOnce(true); |
304 } | 299 } |
305 | 300 |
306 } // namespace media | 301 } // namespace media |
OLD | NEW |