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 <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // effects should be enabled. | 73 // effects should be enabled. |
74 enum PlatformEffectsMask { | 74 enum PlatformEffectsMask { |
75 NO_EFFECTS = 0x0, | 75 NO_EFFECTS = 0x0, |
76 ECHO_CANCELLER = 0x1, | 76 ECHO_CANCELLER = 0x1, |
77 DUCKING = 0x2, // Enables ducking if the OS supports it. | 77 DUCKING = 0x2, // Enables ducking if the OS supports it. |
78 KEYBOARD_MIC = 0x4, | 78 KEYBOARD_MIC = 0x4, |
79 HOTWORD = 0x8, | 79 HOTWORD = 0x8, |
80 }; | 80 }; |
81 | 81 |
82 AudioParameters(); | 82 AudioParameters(); |
83 AudioParameters(Format format, ChannelLayout channel_layout, | 83 AudioParameters(Format format, |
84 int sample_rate, int bits_per_sample, | 84 ChannelLayout channel_layout, |
| 85 int sample_rate, |
| 86 int bits_per_sample, |
85 int frames_per_buffer); | 87 int frames_per_buffer); |
86 AudioParameters(Format format, ChannelLayout channel_layout, | |
87 int sample_rate, int bits_per_sample, | |
88 int frames_per_buffer, int effects); | |
89 AudioParameters(Format format, ChannelLayout channel_layout, | |
90 int channels, int sample_rate, int bits_per_sample, | |
91 int frames_per_buffer, int effects); | |
92 | 88 |
93 void Reset(Format format, ChannelLayout channel_layout, | 89 // Re-initializes all members. |
94 int channels, int sample_rate, int bits_per_sample, | 90 void Reset(Format format, |
| 91 ChannelLayout channel_layout, |
| 92 int sample_rate, |
| 93 int bits_per_sample, |
95 int frames_per_buffer); | 94 int frames_per_buffer); |
96 | 95 |
97 // Checks that all values are in the expected range. All limits are specified | 96 // Checks that all values are in the expected range. All limits are specified |
98 // in media::Limits. | 97 // in media::Limits. |
99 bool IsValid() const; | 98 bool IsValid() const; |
100 | 99 |
101 // Returns a human-readable string describing |*this|. For debugging & test | 100 // Returns a human-readable string describing |*this|. For debugging & test |
102 // output only. | 101 // output only. |
103 std::string AsHumanReadableString() const; | 102 std::string AsHumanReadableString() const; |
104 | 103 |
105 // Returns size of audio buffer in bytes. | 104 // Returns size of audio buffer in bytes. |
106 int GetBytesPerBuffer() const; | 105 int GetBytesPerBuffer() const; |
107 | 106 |
108 // Returns the number of bytes representing one second of audio. | 107 // Returns the number of bytes representing one second of audio. |
109 int GetBytesPerSecond() const; | 108 int GetBytesPerSecond() const; |
110 | 109 |
111 // Returns the number of bytes representing a frame of audio. | 110 // Returns the number of bytes representing a frame of audio. |
112 int GetBytesPerFrame() const; | 111 int GetBytesPerFrame() const; |
113 | 112 |
114 // Returns the duration of this buffer as calculated from frames_per_buffer() | 113 // Returns the duration of this buffer as calculated from frames_per_buffer() |
115 // and sample_rate(). | 114 // and sample_rate(). |
116 base::TimeDelta GetBufferDuration() const; | 115 base::TimeDelta GetBufferDuration() const; |
117 | 116 |
118 // Comparison with other AudioParams. | 117 // Comparison with other AudioParams. |
119 bool Equals(const AudioParameters& other) const; | 118 bool Equals(const AudioParameters& other) const; |
120 | 119 |
| 120 void set_format(Format format) { format_ = format; } |
| 121 |
| 122 // The number of channels is usually computed from channel_layout_. Setting |
| 123 // this explictly is only required with CHANNEL_LAYOUT_DISCRETE. |
| 124 // |
| 125 // A setter for channel_layout_ is intentionally excluded. |
| 126 void set_channels_for_discrete(int channels) { |
| 127 DCHECK(channel_layout_ == CHANNEL_LAYOUT_DISCRETE || |
| 128 channels == ChannelLayoutToChannelCount(channel_layout_)); |
| 129 channels_ = channels; |
| 130 } |
| 131 |
| 132 void set_sample_rate(int sample_rate) { sample_rate_ = sample_rate; } |
| 133 |
| 134 void set_frames_per_buffer(int frames_per_buffer) { |
| 135 frames_per_buffer_ = frames_per_buffer; |
| 136 } |
| 137 |
| 138 void set_effects(int effects) { effects_ = effects; } |
| 139 |
121 Format format() const { return format_; } | 140 Format format() const { return format_; } |
122 ChannelLayout channel_layout() const { return channel_layout_; } | 141 ChannelLayout channel_layout() const { return channel_layout_; } |
| 142 int channels() const { return channels_; } |
123 int sample_rate() const { return sample_rate_; } | 143 int sample_rate() const { return sample_rate_; } |
124 int bits_per_sample() const { return bits_per_sample_; } | 144 int bits_per_sample() const { return bits_per_sample_; } |
125 int frames_per_buffer() const { return frames_per_buffer_; } | 145 int frames_per_buffer() const { return frames_per_buffer_; } |
126 int channels() const { return channels_; } | |
127 int effects() const { return effects_; } | 146 int effects() const { return effects_; } |
128 | 147 |
| 148 AudioParameters(const AudioParameters&) = default; |
| 149 AudioParameters& operator=(const AudioParameters&) = default; |
| 150 |
129 private: | 151 private: |
130 // These members are mutable to support entire struct assignment. They should | |
131 // not be mutated individually. | |
132 Format format_; // Format of the stream. | 152 Format format_; // Format of the stream. |
133 ChannelLayout channel_layout_; // Order of surround sound channels. | 153 ChannelLayout channel_layout_; // Order of surround sound channels. |
| 154 int channels_; // Number of channels. Value set based on |
| 155 // |channel_layout|. |
134 int sample_rate_; // Sampling frequency/rate. | 156 int sample_rate_; // Sampling frequency/rate. |
135 int bits_per_sample_; // Number of bits per sample. | 157 int bits_per_sample_; // Number of bits per sample. |
136 int frames_per_buffer_; // Number of frames in a buffer. | 158 int frames_per_buffer_; // Number of frames in a buffer. |
137 | |
138 int channels_; // Number of channels. Value set based on | |
139 // |channel_layout|. | |
140 int effects_; // Bitmask using PlatformEffectsMask. | 159 int effects_; // Bitmask using PlatformEffectsMask. |
141 }; | 160 }; |
142 | 161 |
143 // Comparison is useful when AudioParameters is used with std structures. | 162 // Comparison is useful when AudioParameters is used with std structures. |
144 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { | 163 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { |
145 if (a.format() != b.format()) | 164 if (a.format() != b.format()) |
146 return a.format() < b.format(); | 165 return a.format() < b.format(); |
147 if (a.channels() != b.channels()) | 166 if (a.channels() != b.channels()) |
148 return a.channels() < b.channels(); | 167 return a.channels() < b.channels(); |
149 if (a.sample_rate() != b.sample_rate()) | 168 if (a.sample_rate() != b.sample_rate()) |
150 return a.sample_rate() < b.sample_rate(); | 169 return a.sample_rate() < b.sample_rate(); |
151 if (a.bits_per_sample() != b.bits_per_sample()) | 170 if (a.bits_per_sample() != b.bits_per_sample()) |
152 return a.bits_per_sample() < b.bits_per_sample(); | 171 return a.bits_per_sample() < b.bits_per_sample(); |
153 return a.frames_per_buffer() < b.frames_per_buffer(); | 172 return a.frames_per_buffer() < b.frames_per_buffer(); |
154 } | 173 } |
155 | 174 |
156 } // namespace media | 175 } // namespace media |
157 | 176 |
158 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 177 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
OLD | NEW |