| 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 loop) |
| 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_(loop) {} |
| 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 if (looping_) |
| 218 return 0; | 219 Rewind(); |
| 220 else |
| 221 return 0; |
| 222 } |
| 219 | 223 |
| 220 // This pulls data from ProvideInput. | 224 // This pulls data from ProvideInput. |
| 221 file_audio_converter_->Convert(audio_bus); | 225 file_audio_converter_->Convert(audio_bus); |
| 222 return audio_bus->frames(); | 226 return audio_bus->frames(); |
| 223 } | 227 } |
| 224 | 228 |
| 229 void FileSource::Rewind() { |
| 230 wav_file_read_pos_ = 0; |
| 231 } |
| 232 |
| 225 double FileSource::ProvideInput(AudioBus* audio_bus_into_converter, | 233 double FileSource::ProvideInput(AudioBus* audio_bus_into_converter, |
| 226 uint32_t frames_delayed) { | 234 uint32_t frames_delayed) { |
| 227 // Unfilled frames will be zeroed by CopyTo. | 235 // Unfilled frames will be zeroed by CopyTo. |
| 228 size_t bytes_written; | 236 size_t bytes_written; |
| 229 wav_audio_handler_->CopyTo(audio_bus_into_converter, wav_file_read_pos_, | 237 wav_audio_handler_->CopyTo(audio_bus_into_converter, wav_file_read_pos_, |
| 230 &bytes_written); | 238 &bytes_written); |
| 231 wav_file_read_pos_ += bytes_written; | 239 wav_file_read_pos_ += bytes_written; |
| 232 return 1.0; | 240 return 1.0; |
| 233 } | 241 } |
| 234 | 242 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 310 } |
| 303 | 311 |
| 304 void BeepingSource::OnError(AudioOutputStream* stream) { | 312 void BeepingSource::OnError(AudioOutputStream* stream) { |
| 305 } | 313 } |
| 306 | 314 |
| 307 void BeepingSource::BeepOnce() { | 315 void BeepingSource::BeepOnce() { |
| 308 g_beep_context.Pointer()->SetBeepOnce(true); | 316 g_beep_context.Pointer()->SetBeepOnce(true); |
| 309 } | 317 } |
| 310 | 318 |
| 311 } // namespace media | 319 } // namespace media |
| OLD | NEW |