| 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 | 4 |
| 5 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 5 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
| 6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
| 7 | 7 |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "media/audio/audio_io.h" | 9 #include "media/audio/audio_io.h" |
| 10 #include "media/base/seekable_buffer.h" | 10 #include "media/base/seekable_buffer.h" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 | 13 |
| 14 // An audio source that produces a pure sinusoidal tone. | 14 // An audio source that produces a pure sinusoidal tone. |
| 15 class MEDIA_EXPORT SineWaveAudioSource | 15 class MEDIA_EXPORT SineWaveAudioSource |
| 16 : public AudioOutputStream::AudioSourceCallback { | 16 : public AudioOutputStream::AudioSourceCallback { |
| 17 public: | 17 public: |
| 18 // |channels| is the number of audio channels, |freq| is the frequency in | 18 // |channels| is the number of audio channels, |freq| is the frequency in |
| 19 // hertz and it has to be less than half of the sampling frequency | 19 // hertz and it has to be less than half of the sampling frequency |
| 20 // |sample_freq| or else you will get aliasing. | 20 // |sample_freq| or else you will get aliasing. |
| 21 SineWaveAudioSource(int channels, double freq, double sample_freq); | 21 SineWaveAudioSource(int channels, double freq, double sample_freq); |
| 22 virtual ~SineWaveAudioSource() {} | 22 ~SineWaveAudioSource() override {} |
| 23 | 23 |
| 24 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to | 24 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to |
| 25 // allow more data to be served. | 25 // allow more data to be served. |
| 26 void CapSamples(int cap); | 26 void CapSamples(int cap); |
| 27 void Reset(); | 27 void Reset(); |
| 28 | 28 |
| 29 // Implementation of AudioSourceCallback. | 29 // Implementation of AudioSourceCallback. |
| 30 virtual int OnMoreData(AudioBus* audio_bus, | 30 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; |
| 31 uint32 total_bytes_delay) override; | 31 void OnError(AudioOutputStream* stream) override; |
| 32 virtual void OnError(AudioOutputStream* stream) override; | |
| 33 | 32 |
| 34 // The number of OnMoreData() and OnError() calls respectively. | 33 // The number of OnMoreData() and OnError() calls respectively. |
| 35 int callbacks() { return callbacks_; } | 34 int callbacks() { return callbacks_; } |
| 36 int errors() { return errors_; } | 35 int errors() { return errors_; } |
| 37 | 36 |
| 38 protected: | 37 protected: |
| 39 int channels_; | 38 int channels_; |
| 40 double f_; | 39 double f_; |
| 41 int time_state_; | 40 int time_state_; |
| 42 int cap_; | 41 int cap_; |
| 43 int callbacks_; | 42 int callbacks_; |
| 44 int errors_; | 43 int errors_; |
| 45 base::Lock time_lock_; | 44 base::Lock time_lock_; |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 } // namespace media | 47 } // namespace media |
| 49 | 48 |
| 50 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 49 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
| OLD | NEW |