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