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/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // |sample_freq| or else you will get aliasing. | 24 // |sample_freq| or else you will get aliasing. |
25 SineWaveAudioSource(int channels, double freq, double sample_freq); | 25 SineWaveAudioSource(int channels, double freq, double sample_freq); |
26 ~SineWaveAudioSource() override; | 26 ~SineWaveAudioSource() override; |
27 | 27 |
28 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to | 28 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to |
29 // allow more data to be served. | 29 // allow more data to be served. |
30 void CapSamples(int cap); | 30 void CapSamples(int cap); |
31 void Reset(); | 31 void Reset(); |
32 | 32 |
33 // Implementation of AudioSourceCallback. | 33 // Implementation of AudioSourceCallback. |
34 int OnMoreData(AudioBus* audio_bus, | 34 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; |
35 uint32_t total_bytes_delay, | |
36 uint32_t frames_skipped) override; | |
37 void OnError(AudioOutputStream* stream) override; | 35 void OnError(AudioOutputStream* stream) override; |
38 | 36 |
39 // The number of OnMoreData() and OnError() calls respectively. | 37 // The number of OnMoreData() and OnError() calls respectively. |
40 int callbacks() { return callbacks_; } | 38 int callbacks() { return callbacks_; } |
41 int errors() { return errors_; } | 39 int errors() { return errors_; } |
42 | 40 |
43 protected: | 41 protected: |
44 int channels_; | 42 int channels_; |
45 double f_; | 43 double f_; |
46 int time_state_; | 44 int time_state_; |
47 int cap_; | 45 int cap_; |
48 int callbacks_; | 46 int callbacks_; |
49 int errors_; | 47 int errors_; |
50 base::Lock time_lock_; | 48 base::Lock time_lock_; |
51 }; | 49 }; |
52 | 50 |
53 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, | 51 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, |
54 public AudioConverter::InputCallback { | 52 public AudioConverter::InputCallback { |
55 public: | 53 public: |
56 FileSource(const AudioParameters& params, | 54 FileSource(const AudioParameters& params, |
57 const base::FilePath& path_to_wav_file); | 55 const base::FilePath& path_to_wav_file); |
58 ~FileSource() override; | 56 ~FileSource() override; |
59 | 57 |
60 // Implementation of AudioSourceCallback. | 58 // Implementation of AudioSourceCallback. |
61 int OnMoreData(AudioBus* audio_bus, | 59 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; |
62 uint32_t total_bytes_delay, | |
63 uint32_t frames_skipped) override; | |
64 void OnError(AudioOutputStream* stream) override; | 60 void OnError(AudioOutputStream* stream) override; |
65 | 61 |
66 private: | 62 private: |
67 AudioParameters params_; | 63 AudioParameters params_; |
68 base::FilePath path_to_wav_file_; | 64 base::FilePath path_to_wav_file_; |
69 | 65 |
70 // The WAV data at |path_to_wav_file_| is read into memory and kept here. | 66 // The WAV data at |path_to_wav_file_| is read into memory and kept here. |
71 // This memory needs to survive for the lifetime of |wav_audio_handler_|, | 67 // This memory needs to survive for the lifetime of |wav_audio_handler_|, |
72 // so declare it first. Do not access this member directly. | 68 // so declare it first. Do not access this member directly. |
73 scoped_ptr<char[]> raw_wav_data_; | 69 scoped_ptr<char[]> raw_wav_data_; |
(...skipping 10 matching lines...) Expand all Loading... |
84 // Loads the wav file on the first OnMoreData invocation. | 80 // Loads the wav file on the first OnMoreData invocation. |
85 void LoadWavFile(const base::FilePath& path_to_wav_file); | 81 void LoadWavFile(const base::FilePath& path_to_wav_file); |
86 }; | 82 }; |
87 | 83 |
88 class BeepingSource : public AudioOutputStream::AudioSourceCallback { | 84 class BeepingSource : public AudioOutputStream::AudioSourceCallback { |
89 public: | 85 public: |
90 BeepingSource(const AudioParameters& params); | 86 BeepingSource(const AudioParameters& params); |
91 ~BeepingSource() override; | 87 ~BeepingSource() override; |
92 | 88 |
93 // Implementation of AudioSourceCallback. | 89 // Implementation of AudioSourceCallback. |
94 int OnMoreData(AudioBus* audio_bus, | 90 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; |
95 uint32_t total_bytes_delay, | |
96 uint32_t frames_skipped) override; | |
97 void OnError(AudioOutputStream* stream) override; | 91 void OnError(AudioOutputStream* stream) override; |
98 | 92 |
99 static void BeepOnce(); | 93 static void BeepOnce(); |
100 private: | 94 private: |
101 int buffer_size_; | 95 int buffer_size_; |
102 scoped_ptr<uint8[]> buffer_; | 96 scoped_ptr<uint8[]> buffer_; |
103 AudioParameters params_; | 97 AudioParameters params_; |
104 base::TimeTicks last_callback_time_; | 98 base::TimeTicks last_callback_time_; |
105 base::TimeDelta interval_from_last_beep_; | 99 base::TimeDelta interval_from_last_beep_; |
106 int beep_duration_in_buffers_; | 100 int beep_duration_in_buffers_; |
107 int beep_generated_in_buffers_; | 101 int beep_generated_in_buffers_; |
108 int beep_period_in_frames_; | 102 int beep_period_in_frames_; |
109 }; | 103 }; |
110 | 104 |
111 } // namespace media | 105 } // namespace media |
112 | 106 |
113 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 107 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
OLD | NEW |