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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), | 196 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), |
196 params_.frames_per_buffer()); | 197 params_.frames_per_buffer()); |
197 | 198 |
198 file_audio_converter_.reset( | 199 file_audio_converter_.reset( |
199 new AudioConverter(file_audio_slice, params_, false)); | 200 new AudioConverter(file_audio_slice, params_, false)); |
200 file_audio_converter_->AddInput(this); | 201 file_audio_converter_->AddInput(this); |
201 } | 202 } |
202 | 203 |
203 int FileSource::OnMoreData(AudioBus* audio_bus, | 204 int FileSource::OnMoreData(AudioBus* audio_bus, |
204 uint32_t total_bytes_delay, | 205 uint32_t total_bytes_delay, |
205 uint32_t frames_skipped) { | 206 uint32_t frames_skipped, |
| 207 const AudioTimestamp& timestamp) { |
206 // Load the file if we haven't already. This load needs to happen on the | 208 // Load the file if we haven't already. This load needs to happen on the |
207 // audio thread, otherwise we'll run on the UI thread on Mac for instance. | 209 // audio thread, otherwise we'll run on the UI thread on Mac for instance. |
208 // This will massively delay the first OnMoreData, but we'll catch up. | 210 // This will massively delay the first OnMoreData, but we'll catch up. |
209 if (!wav_audio_handler_) | 211 if (!wav_audio_handler_) |
210 LoadWavFile(path_to_wav_file_); | 212 LoadWavFile(path_to_wav_file_); |
211 if (load_failed_) | 213 if (load_failed_) |
212 return 0; | 214 return 0; |
213 | 215 |
214 DCHECK(wav_audio_handler_.get()); | 216 DCHECK(wav_audio_handler_.get()); |
215 | 217 |
(...skipping 29 matching lines...) Expand all Loading... |
245 params.frames_per_buffer() / | 247 params.frames_per_buffer() / |
246 1000), | 248 1000), |
247 beep_generated_in_buffers_(0), | 249 beep_generated_in_buffers_(0), |
248 beep_period_in_frames_(params.sample_rate() / kBeepFrequency) {} | 250 beep_period_in_frames_(params.sample_rate() / kBeepFrequency) {} |
249 | 251 |
250 BeepingSource::~BeepingSource() { | 252 BeepingSource::~BeepingSource() { |
251 } | 253 } |
252 | 254 |
253 int BeepingSource::OnMoreData(AudioBus* audio_bus, | 255 int BeepingSource::OnMoreData(AudioBus* audio_bus, |
254 uint32_t total_bytes_delay, | 256 uint32_t total_bytes_delay, |
255 uint32_t frames_skipped) { | 257 uint32_t frames_skipped, |
| 258 const AudioTimestamp& timestamp) { |
256 // Accumulate the time from the last beep. | 259 // Accumulate the time from the last beep. |
257 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; | 260 interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_; |
258 | 261 |
259 memset(buffer_.get(), 0, buffer_size_); | 262 memset(buffer_.get(), 0, buffer_size_); |
260 bool should_beep = false; | 263 bool should_beep = false; |
261 BeepContext* beep_context = g_beep_context.Pointer(); | 264 BeepContext* beep_context = g_beep_context.Pointer(); |
262 if (beep_context->automatic_beep()) { | 265 if (beep_context->automatic_beep()) { |
263 base::TimeDelta delta = interval_from_last_beep_ - | 266 base::TimeDelta delta = interval_from_last_beep_ - |
264 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); | 267 base::TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); |
265 if (delta > base::TimeDelta()) { | 268 if (delta > base::TimeDelta()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 305 } |
303 | 306 |
304 void BeepingSource::OnError(AudioOutputStream* stream) { | 307 void BeepingSource::OnError(AudioOutputStream* stream) { |
305 } | 308 } |
306 | 309 |
307 void BeepingSource::BeepOnce() { | 310 void BeepingSource::BeepOnce() { |
308 g_beep_context.Pointer()->SetBeepOnce(true); | 311 g_beep_context.Pointer()->SetBeepOnce(true); |
309 } | 312 } |
310 | 313 |
311 } // namespace media | 314 } // namespace media |
OLD | NEW |