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/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
9 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
11 #include "media/base/audio_converter.h" | |
10 #include "media/base/seekable_buffer.h" | 12 #include "media/base/seekable_buffer.h" |
11 | 13 |
12 namespace media { | 14 namespace media { |
13 | 15 |
16 class WavAudioHandler; | |
17 | |
18 class SimpleSource : public AudioOutputStream::AudioSourceCallback { | |
DaleCurtis
2015/02/19 19:54:54
Why is this necessary? Open() is only used in the
phoglund_chromium
2015/02/20 14:22:00
All right.
| |
19 public: | |
20 ~SimpleSource() override {}; | |
21 | |
22 virtual void Open() {} | |
23 }; | |
24 | |
14 // An audio source that produces a pure sinusoidal tone. | 25 // An audio source that produces a pure sinusoidal tone. |
15 class MEDIA_EXPORT SineWaveAudioSource | 26 class MEDIA_EXPORT SineWaveAudioSource : public SimpleSource { |
16 : public AudioOutputStream::AudioSourceCallback { | |
17 public: | 27 public: |
18 // |channels| is the number of audio channels, |freq| is the frequency in | 28 // |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 | 29 // hertz and it has to be less than half of the sampling frequency |
20 // |sample_freq| or else you will get aliasing. | 30 // |sample_freq| or else you will get aliasing. |
21 SineWaveAudioSource(int channels, double freq, double sample_freq); | 31 SineWaveAudioSource(int channels, double freq, double sample_freq); |
22 ~SineWaveAudioSource() override {} | 32 ~SineWaveAudioSource() override {} |
23 | 33 |
24 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to | 34 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to |
25 // allow more data to be served. | 35 // allow more data to be served. |
26 void CapSamples(int cap); | 36 void CapSamples(int cap); |
(...skipping 10 matching lines...) Expand all Loading... | |
37 protected: | 47 protected: |
38 int channels_; | 48 int channels_; |
39 double f_; | 49 double f_; |
40 int time_state_; | 50 int time_state_; |
41 int cap_; | 51 int cap_; |
42 int callbacks_; | 52 int callbacks_; |
43 int errors_; | 53 int errors_; |
44 base::Lock time_lock_; | 54 base::Lock time_lock_; |
45 }; | 55 }; |
46 | 56 |
57 class FileSource : public SimpleSource, | |
58 public AudioConverter::InputCallback{ | |
DaleCurtis
2015/02/19 19:54:54
Space after InputCallback
phoglund_chromium
2015/02/20 14:22:00
Done.
| |
59 public: | |
60 FileSource(const AudioParameters& params, | |
61 const base::FilePath& path_to_wav_file); | |
62 ~FileSource() override; | |
63 | |
64 void Open() override; | |
65 | |
66 // Implementation of AudioSourceCallback. | |
67 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; | |
68 void OnError(AudioOutputStream* stream) override {} | |
69 | |
70 private: | |
71 AudioParameters params_; | |
72 base::FilePath path_to_wav_file_; | |
73 scoped_ptr<uint8[]> wav_file_data_; | |
74 scoped_ptr<media::WavAudioHandler> wav_audio_handler_; | |
DaleCurtis
2015/02/19 19:54:54
No need for media:: prefix on anything in this .h
phoglund_chromium
2015/02/20 14:22:00
Done.
| |
75 scoped_ptr<media::AudioConverter> file_audio_converter_; | |
76 int wav_file_read_pos_; | |
77 int buffer_size_; | |
78 | |
79 // Provides audio data from wav_audio_handler_ into the file audio converter. | |
80 double ProvideInput(AudioBus* audio_bus, | |
81 base::TimeDelta buffer_delay) override; | |
82 }; | |
83 | |
84 class BeepingSource : public SimpleSource { | |
85 public: | |
86 BeepingSource(const AudioParameters& params); | |
87 ~BeepingSource() override; | |
88 | |
89 // Implementation of AudioSourceCallback. | |
90 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; | |
91 void OnError(AudioOutputStream* stream) override {} | |
DaleCurtis
2015/02/19 19:54:54
Inline methods aren't allowed for virtual function
phoglund_chromium
2015/02/20 14:22:00
Done.
phoglund_chromium
2015/02/20 14:22:00
Done.
| |
92 | |
93 static void BeepOnce(); | |
94 private: | |
95 scoped_ptr<uint8[]> buffer_; | |
96 int buffer_size_; | |
97 AudioParameters params_; | |
98 base::TimeTicks last_callback_time_; | |
99 base::TimeDelta interval_from_last_beep_; | |
100 int beep_duration_in_buffers_; | |
101 int beep_generated_in_buffers_; | |
102 int beep_period_in_frames_; | |
103 }; | |
104 | |
47 } // namespace media | 105 } // namespace media |
48 | 106 |
49 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 107 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
OLD | NEW |