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 | 6 |
7 #include "media/audio/simple_sources.h" | 7 #include "media/audio/simple_sources.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 errors_(0) { | 110 errors_(0) { |
111 } | 111 } |
112 | 112 |
113 SineWaveAudioSource::~SineWaveAudioSource() { | 113 SineWaveAudioSource::~SineWaveAudioSource() { |
114 } | 114 } |
115 | 115 |
116 // The implementation could be more efficient if a lookup table is constructed | 116 // The implementation could be more efficient if a lookup table is constructed |
117 // but it is efficient enough for our simple needs. | 117 // but it is efficient enough for our simple needs. |
118 int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, | 118 int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus, |
119 uint32_t total_bytes_delay, | 119 uint32_t total_bytes_delay, |
120 uint32_t frames_skipped) { | 120 uint32_t frames_skipped, |
| 121 const AudioTimestamp& timestamp) { |
121 base::AutoLock auto_lock(time_lock_); | 122 base::AutoLock auto_lock(time_lock_); |
122 callbacks_++; | 123 callbacks_++; |
123 | 124 |
124 // The table is filled with s(t) = kint16max*sin(Theta*t), | 125 // The table is filled with s(t) = kint16max*sin(Theta*t), |
125 // where Theta = 2*PI*fs. | 126 // where Theta = 2*PI*fs. |
126 // We store the discrete time value |t| in a member to ensure that the | 127 // We store the discrete time value |t| in a member to ensure that the |
127 // next pass starts at a correct state. | 128 // next pass starts at a correct state. |
128 int max_frames = cap_ > 0 ? | 129 int max_frames = cap_ > 0 ? |
129 std::min(audio_bus->frames(), cap_ - time_state_) : audio_bus->frames(); | 130 std::min(audio_bus->frames(), cap_ - time_state_) : audio_bus->frames(); |
130 for (int i = 0; i < max_frames; ++i) | 131 for (int i = 0; i < max_frames; ++i) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), | 197 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), |
197 params_.frames_per_buffer()); | 198 params_.frames_per_buffer()); |
198 | 199 |
199 file_audio_converter_.reset( | 200 file_audio_converter_.reset( |
200 new AudioConverter(file_audio_slice, params_, false)); | 201 new AudioConverter(file_audio_slice, params_, false)); |
201 file_audio_converter_->AddInput(this); | 202 file_audio_converter_->AddInput(this); |
202 } | 203 } |
203 | 204 |
204 int FileSource::OnMoreData(AudioBus* audio_bus, | 205 int FileSource::OnMoreData(AudioBus* audio_bus, |
205 uint32_t total_bytes_delay, | 206 uint32_t total_bytes_delay, |
206 uint32_t frames_skipped) { | 207 uint32_t frames_skipped, |
| 208 const AudioTimestamp& timestamp) { |
207 // Load the file if we haven't already. This load needs to happen on the | 209 // Load the file if we haven't already. This load needs to happen on the |
208 // audio thread, otherwise we'll run on the UI thread on Mac for instance. | 210 // audio thread, otherwise we'll run on the UI thread on Mac for instance. |
209 // This will massively delay the first OnMoreData, but we'll catch up. | 211 // This will massively delay the first OnMoreData, but we'll catch up. |
210 if (!wav_audio_handler_) | 212 if (!wav_audio_handler_) |
211 LoadWavFile(path_to_wav_file_); | 213 LoadWavFile(path_to_wav_file_); |
212 if (load_failed_) | 214 if (load_failed_) |
213 return 0; | 215 return 0; |
214 | 216 |
215 DCHECK(wav_audio_handler_.get()); | 217 DCHECK(wav_audio_handler_.get()); |
216 | 218 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 params.frames_per_buffer() / | 255 params.frames_per_buffer() / |
254 1000), | 256 1000), |
255 beep_generated_in_buffers_(0), | 257 beep_generated_in_buffers_(0), |
256 beep_period_in_frames_(params.sample_rate() / kBeepFrequency) {} | 258 beep_period_in_frames_(params.sample_rate() / kBeepFrequency) {} |
257 | 259 |
258 BeepingSource::~BeepingSource() { | 260 BeepingSource::~BeepingSource() { |
259 } | 261 } |
260 | 262 |
261 int BeepingSource::OnMoreData(AudioBus* audio_bus, | 263 int BeepingSource::OnMoreData(AudioBus* audio_bus, |
262 uint32_t total_bytes_delay, | 264 uint32_t total_bytes_delay, |
263 uint32_t frames_skipped) { | 265 uint32_t frames_skipped, |
| 266 const AudioTimestamp& timestamp) { |
264 // Accumulate the time from the last beep. | 267 // Accumulate the time from the last beep. |
265 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; | 268 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; |
266 | 269 |
267 memset(buffer_.get(), 0, buffer_size_); | 270 memset(buffer_.get(), 0, buffer_size_); |
268 bool should_beep = false; | 271 bool should_beep = false; |
269 BeepContext* beep_context = g_beep_context.Pointer(); | 272 BeepContext* beep_context = g_beep_context.Pointer(); |
270 if (beep_context->automatic_beep()) { | 273 if (beep_context->automatic_beep()) { |
271 base::TimeDelta delta = interval_from_last_beep_ - | 274 base::TimeDelta delta = interval_from_last_beep_ - |
272 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); | 275 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); |
273 if (delta > base::TimeDelta()) { | 276 if (delta > base::TimeDelta()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 313 } |
311 | 314 |
312 void BeepingSource::OnError(AudioOutputStream* stream) { | 315 void BeepingSource::OnError(AudioOutputStream* stream) { |
313 } | 316 } |
314 | 317 |
315 void BeepingSource::BeepOnce() { | 318 void BeepingSource::BeepOnce() { |
316 g_beep_context.Pointer()->SetBeepOnce(true); | 319 g_beep_context.Pointer()->SetBeepOnce(true); |
317 } | 320 } |
318 | 321 |
319 } // namespace media | 322 } // namespace media |
OLD | NEW |