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_AUDIO_PARAMETERS_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "media/base/channel_layout.h" | 10 #include "media/base/channel_layout.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 AUDIO_LAST_FORMAT // Only used for validation of format. | 37 AUDIO_LAST_FORMAT // Only used for validation of format. |
38 }; | 38 }; |
39 | 39 |
40 enum { | 40 enum { |
41 // Telephone quality sample rate, mostly for speech-only audio. | 41 // Telephone quality sample rate, mostly for speech-only audio. |
42 kTelephoneSampleRate = 8000, | 42 kTelephoneSampleRate = 8000, |
43 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. | 43 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. |
44 kAudioCDSampleRate = 44100, | 44 kAudioCDSampleRate = 44100, |
45 }; | 45 }; |
46 | 46 |
47 // Used to carry whether certin platform (typically hardware) audio effects | |
48 // should be enabled. | |
49 struct PlatformEffects { | |
50 PlatformEffects() : echo_canceller(false) {} | |
51 bool operator==(const PlatformEffects& other) const { | |
tommi (sloooow) - chröme
2013/12/11 12:14:36
document why you need the comparison operator. Usu
ajm
2013/12/11 17:46:49
It was only to support the AudioParameters compari
| |
52 return echo_canceller == other.echo_canceller; | |
53 } | |
54 bool echo_canceller; | |
55 }; | |
56 | |
47 AudioParameters(); | 57 AudioParameters(); |
48 AudioParameters(Format format, ChannelLayout channel_layout, | 58 AudioParameters(Format format, ChannelLayout channel_layout, |
49 int sample_rate, int bits_per_sample, | 59 int sample_rate, int bits_per_sample, |
50 int frames_per_buffer); | 60 int frames_per_buffer); |
51 AudioParameters(Format format, ChannelLayout channel_layout, | 61 AudioParameters(Format format, ChannelLayout channel_layout, |
52 int input_channels, | 62 int input_channels, |
53 int sample_rate, int bits_per_sample, | 63 int sample_rate, int bits_per_sample, |
54 int frames_per_buffer); | 64 int frames_per_buffer); |
55 void Reset(Format format, ChannelLayout channel_layout, | 65 void Reset(Format format, ChannelLayout channel_layout, |
56 int channels, int input_channels, | 66 int channels, int input_channels, |
(...skipping 17 matching lines...) Expand all Loading... | |
74 // and sample_rate(). | 84 // and sample_rate(). |
75 base::TimeDelta GetBufferDuration() const; | 85 base::TimeDelta GetBufferDuration() const; |
76 | 86 |
77 Format format() const { return format_; } | 87 Format format() const { return format_; } |
78 ChannelLayout channel_layout() const { return channel_layout_; } | 88 ChannelLayout channel_layout() const { return channel_layout_; } |
79 int sample_rate() const { return sample_rate_; } | 89 int sample_rate() const { return sample_rate_; } |
80 int bits_per_sample() const { return bits_per_sample_; } | 90 int bits_per_sample() const { return bits_per_sample_; } |
81 int frames_per_buffer() const { return frames_per_buffer_; } | 91 int frames_per_buffer() const { return frames_per_buffer_; } |
82 int channels() const { return channels_; } | 92 int channels() const { return channels_; } |
83 int input_channels() const { return input_channels_; } | 93 int input_channels() const { return input_channels_; } |
94 const PlatformEffects& effects() const { return effects_; } | |
84 | 95 |
85 // Set to CHANNEL_LAYOUT_DISCRETE with given number of channels. | 96 // Set to CHANNEL_LAYOUT_DISCRETE with given number of channels. |
86 void SetDiscreteChannels(int channels); | 97 void SetDiscreteChannels(int channels); |
98 void SetPlatformEffects(const PlatformEffects& effects); | |
87 | 99 |
88 // Comparison with other AudioParams. | 100 // Comparison with other AudioParams. |
89 bool operator==(const AudioParameters& other) const { | 101 bool operator==(const AudioParameters& other) const { |
90 return format_ == other.format() && | 102 return format_ == other.format() && |
91 sample_rate_ == other.sample_rate() && | 103 sample_rate_ == other.sample_rate() && |
92 channel_layout_ == other.channel_layout() && | 104 channel_layout_ == other.channel_layout() && |
93 channels_ == other.channels() && | 105 channels_ == other.channels() && |
94 input_channels_ == other.input_channels() && | 106 input_channels_ == other.input_channels() && |
95 bits_per_sample_ == other.bits_per_sample() && | 107 bits_per_sample_ == other.bits_per_sample() && |
96 frames_per_buffer_ == other.frames_per_buffer(); | 108 frames_per_buffer_ == other.frames_per_buffer() && |
109 effects_ == other.effects(); | |
97 } | 110 } |
98 | 111 |
99 private: | 112 private: |
100 Format format_; // Format of the stream. | 113 Format format_; // Format of the stream. |
101 ChannelLayout channel_layout_; // Order of surround sound channels. | 114 ChannelLayout channel_layout_; // Order of surround sound channels. |
102 int sample_rate_; // Sampling frequency/rate. | 115 int sample_rate_; // Sampling frequency/rate. |
103 int bits_per_sample_; // Number of bits per sample. | 116 int bits_per_sample_; // Number of bits per sample. |
104 int frames_per_buffer_; // Number of frames in a buffer. | 117 int frames_per_buffer_; // Number of frames in a buffer. |
105 | 118 |
106 int channels_; // Number of channels. Value set based on | 119 int channels_; // Number of channels. Value set based on |
107 // |channel_layout|. | 120 // |channel_layout|. |
108 int input_channels_; // Optional number of input channels. | 121 int input_channels_; // Optional number of input channels. |
109 // Normally 0, but can be set to specify | 122 // Normally 0, but can be set to specify |
110 // synchronized I/O. | 123 // synchronized I/O. |
124 PlatformEffects effects_; // See PlatformEffects. | |
111 }; | 125 }; |
112 | 126 |
113 // Comparison is useful when AudioParameters is used with std structures. | 127 // Comparison is useful when AudioParameters is used with std structures. |
114 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { | 128 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { |
115 if (a.format() != b.format()) | 129 if (a.format() != b.format()) |
116 return a.format() < b.format(); | 130 return a.format() < b.format(); |
117 if (a.channels() != b.channels()) | 131 if (a.channels() != b.channels()) |
118 return a.channels() < b.channels(); | 132 return a.channels() < b.channels(); |
119 if (a.input_channels() != b.input_channels()) | 133 if (a.input_channels() != b.input_channels()) |
120 return a.input_channels() < b.input_channels(); | 134 return a.input_channels() < b.input_channels(); |
121 if (a.sample_rate() != b.sample_rate()) | 135 if (a.sample_rate() != b.sample_rate()) |
122 return a.sample_rate() < b.sample_rate(); | 136 return a.sample_rate() < b.sample_rate(); |
123 if (a.bits_per_sample() != b.bits_per_sample()) | 137 if (a.bits_per_sample() != b.bits_per_sample()) |
124 return a.bits_per_sample() < b.bits_per_sample(); | 138 return a.bits_per_sample() < b.bits_per_sample(); |
125 return a.frames_per_buffer() < b.frames_per_buffer(); | 139 return a.frames_per_buffer() < b.frames_per_buffer(); |
126 } | 140 } |
127 | 141 |
128 } // namespace media | 142 } // namespace media |
129 | 143 |
130 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 144 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
OLD | NEW |