| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 DCHECK_GT(cap, 0); | 145 DCHECK_GT(cap, 0); |
| 146 cap_ = cap; | 146 cap_ = cap; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void SineWaveAudioSource::Reset() { | 149 void SineWaveAudioSource::Reset() { |
| 150 base::AutoLock auto_lock(time_lock_); | 150 base::AutoLock auto_lock(time_lock_); |
| 151 time_state_ = 0; | 151 time_state_ = 0; |
| 152 } | 152 } |
| 153 | 153 |
| 154 FileSource::FileSource(const AudioParameters& params, | 154 FileSource::FileSource(const AudioParameters& params, |
| 155 const base::FilePath& path_to_wav_file) | 155 const base::FilePath& path_to_wav_file, |
| 156 bool looping) |
| 156 : params_(params), | 157 : params_(params), |
| 157 path_to_wav_file_(path_to_wav_file), | 158 path_to_wav_file_(path_to_wav_file), |
| 158 wav_file_read_pos_(0), | 159 wav_file_read_pos_(0), |
| 159 load_failed_(false) { | 160 load_failed_(false), |
| 160 } | 161 looping_(looping) {} |
| 161 | 162 |
| 162 FileSource::~FileSource() { | 163 FileSource::~FileSource() { |
| 163 } | 164 } |
| 164 | 165 |
| 165 void FileSource::LoadWavFile(const base::FilePath& path_to_wav_file) { | 166 void FileSource::LoadWavFile(const base::FilePath& path_to_wav_file) { |
| 166 // Don't try again if we already failed. | 167 // Don't try again if we already failed. |
| 167 if (load_failed_) | 168 if (load_failed_) |
| 168 return; | 169 return; |
| 169 | 170 |
| 170 // Read the file, and put its data in a scoped_ptr so it gets deleted when | 171 // Read the file, and put its data in a scoped_ptr so it gets deleted when |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // Load the file if we haven't already. This load needs to happen on the | 207 // 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. | 208 // 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. | 209 // This will massively delay the first OnMoreData, but we'll catch up. |
| 209 if (!wav_audio_handler_) | 210 if (!wav_audio_handler_) |
| 210 LoadWavFile(path_to_wav_file_); | 211 LoadWavFile(path_to_wav_file_); |
| 211 if (load_failed_) | 212 if (load_failed_) |
| 212 return 0; | 213 return 0; |
| 213 | 214 |
| 214 DCHECK(wav_audio_handler_.get()); | 215 DCHECK(wav_audio_handler_.get()); |
| 215 | 216 |
| 216 // Stop playing if we've played out the whole file. | 217 if (wav_audio_handler_->AtEnd(wav_file_read_pos_)) { |
| 217 if (wav_audio_handler_->AtEnd(wav_file_read_pos_)) | 218 Rewind(); |
| 218 return 0; | 219 if (!looping_) |
| 220 return 0; |
| 221 } |
| 219 | 222 |
| 220 // This pulls data from ProvideInput. | 223 // This pulls data from ProvideInput. |
| 221 file_audio_converter_->Convert(audio_bus); | 224 file_audio_converter_->Convert(audio_bus); |
| 222 return audio_bus->frames(); | 225 return audio_bus->frames(); |
| 223 } | 226 } |
| 224 | 227 |
| 228 void FileSource::Rewind() { |
| 229 wav_file_read_pos_ = 0; |
| 230 } |
| 231 |
| 225 double FileSource::ProvideInput(AudioBus* audio_bus_into_converter, | 232 double FileSource::ProvideInput(AudioBus* audio_bus_into_converter, |
| 226 uint32_t frames_delayed) { | 233 uint32_t frames_delayed) { |
| 227 // Unfilled frames will be zeroed by CopyTo. | 234 // Unfilled frames will be zeroed by CopyTo. |
| 228 size_t bytes_written; | 235 size_t bytes_written; |
| 229 wav_audio_handler_->CopyTo(audio_bus_into_converter, wav_file_read_pos_, | 236 wav_audio_handler_->CopyTo(audio_bus_into_converter, wav_file_read_pos_, |
| 230 &bytes_written); | 237 &bytes_written); |
| 231 wav_file_read_pos_ += bytes_written; | 238 wav_file_read_pos_ += bytes_written; |
| 232 return 1.0; | 239 return 1.0; |
| 233 } | 240 } |
| 234 | 241 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 309 } |
| 303 | 310 |
| 304 void BeepingSource::OnError(AudioOutputStream* stream) { | 311 void BeepingSource::OnError(AudioOutputStream* stream) { |
| 305 } | 312 } |
| 306 | 313 |
| 307 void BeepingSource::BeepOnce() { | 314 void BeepingSource::BeepOnce() { |
| 308 g_beep_context.Pointer()->SetBeepOnce(true); | 315 g_beep_context.Pointer()->SetBeepOnce(true); |
| 309 } | 316 } |
| 310 | 317 |
| 311 } // namespace media | 318 } // namespace media |
| OLD | NEW |