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, | |
tommi (sloooow) - chröme
2015/09/05 09:49:58
this is a great improvement over how things were.
ajm
2015/09/06 07:24:14
I could see using an enum for bits_per_sample, sin
| |
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 Format format() const { return format_; } | 121 Format format() const { return format_; } |
122 | |
123 // A setter for channel_layout_ is intentionally excluded. | |
122 ChannelLayout channel_layout() const { return channel_layout_; } | 124 ChannelLayout channel_layout() const { return channel_layout_; } |
125 | |
126 // The number of channels is usually computed from channel_layout_. Setting | |
127 // this explictly is only required with CHANNEL_LAYOUT_DISCRETE. | |
128 void set_channels_for_discrete(int channels) { | |
129 DCHECK(channel_layout_ == CHANNEL_LAYOUT_DISCRETE || | |
130 channels == ChannelLayoutToChannelCount(channel_layout_)); | |
131 channels_ = channels; | |
132 } | |
133 int channels() const { return channels_; } | |
134 | |
135 void set_sample_rate(int sample_rate) { sample_rate_ = sample_rate; } | |
123 int sample_rate() const { return sample_rate_; } | 136 int sample_rate() const { return sample_rate_; } |
137 | |
138 void set_bits_per_sample(int bits_per_sample) { | |
139 bits_per_sample_ = bits_per_sample; | |
140 } | |
124 int bits_per_sample() const { return bits_per_sample_; } | 141 int bits_per_sample() const { return bits_per_sample_; } |
142 | |
143 void set_frames_per_buffer(int frames_per_buffer) { | |
144 frames_per_buffer_ = frames_per_buffer; | |
145 } | |
125 int frames_per_buffer() const { return frames_per_buffer_; } | 146 int frames_per_buffer() const { return frames_per_buffer_; } |
126 int channels() const { return channels_; } | 147 |
148 void set_effects(int effects) { effects_ = effects; } | |
127 int effects() const { return effects_; } | 149 int effects() const { return effects_; } |
128 | 150 |
151 AudioParameters(const AudioParameters&) = default; | |
152 AudioParameters& operator=(const AudioParameters&) = default; | |
153 | |
129 private: | 154 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. | 155 Format format_; // Format of the stream. |
133 ChannelLayout channel_layout_; // Order of surround sound channels. | 156 ChannelLayout channel_layout_; // Order of surround sound channels. |
157 int channels_; // Number of channels. Value set based on | |
158 // |channel_layout|. | |
134 int sample_rate_; // Sampling frequency/rate. | 159 int sample_rate_; // Sampling frequency/rate. |
135 int bits_per_sample_; // Number of bits per sample. | 160 int bits_per_sample_; // Number of bits per sample. |
136 int frames_per_buffer_; // Number of frames in a buffer. | 161 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. | 162 int effects_; // Bitmask using PlatformEffectsMask. |
141 }; | 163 }; |
142 | 164 |
143 // Comparison is useful when AudioParameters is used with std structures. | 165 // Comparison is useful when AudioParameters is used with std structures. |
144 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { | 166 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { |
145 if (a.format() != b.format()) | 167 if (a.format() != b.format()) |
146 return a.format() < b.format(); | 168 return a.format() < b.format(); |
147 if (a.channels() != b.channels()) | 169 if (a.channels() != b.channels()) |
148 return a.channels() < b.channels(); | 170 return a.channels() < b.channels(); |
149 if (a.sample_rate() != b.sample_rate()) | 171 if (a.sample_rate() != b.sample_rate()) |
150 return a.sample_rate() < b.sample_rate(); | 172 return a.sample_rate() < b.sample_rate(); |
151 if (a.bits_per_sample() != b.bits_per_sample()) | 173 if (a.bits_per_sample() != b.bits_per_sample()) |
152 return a.bits_per_sample() < b.bits_per_sample(); | 174 return a.bits_per_sample() < b.bits_per_sample(); |
153 return a.frames_per_buffer() < b.frames_per_buffer(); | 175 return a.frames_per_buffer() < b.frames_per_buffer(); |
154 } | 176 } |
155 | 177 |
156 } // namespace media | 178 } // namespace media |
157 | 179 |
158 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 180 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
OLD | NEW |