| 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 // Bitmasks to determine whether certain platform (typically hardware) audio | |
| 48 // effects should be enabled. | |
| 49 enum PlatformEffectsMask { | |
| 50 NO_EFFECTS = 0x0, | |
| 51 ECHO_CANCELLER = 0x1 | |
| 52 }; | |
| 53 | |
| 54 AudioParameters(); | 47 AudioParameters(); |
| 55 AudioParameters(Format format, ChannelLayout channel_layout, | 48 AudioParameters(Format format, ChannelLayout channel_layout, |
| 56 int sample_rate, int bits_per_sample, | 49 int sample_rate, int bits_per_sample, |
| 57 int frames_per_buffer); | 50 int frames_per_buffer); |
| 58 AudioParameters(Format format, ChannelLayout channel_layout, | 51 AudioParameters(Format format, ChannelLayout channel_layout, |
| 59 int input_channels, | 52 int input_channels, |
| 60 int sample_rate, int bits_per_sample, | 53 int sample_rate, int bits_per_sample, |
| 61 int frames_per_buffer, int effects); | 54 int frames_per_buffer); |
| 62 AudioParameters(Format format, ChannelLayout channel_layout, | |
| 63 int channels, int input_channels, | |
| 64 int sample_rate, int bits_per_sample, | |
| 65 int frames_per_buffer, int effects); | |
| 66 | |
| 67 void Reset(Format format, ChannelLayout channel_layout, | 55 void Reset(Format format, ChannelLayout channel_layout, |
| 68 int channels, int input_channels, | 56 int channels, int input_channels, |
| 69 int sample_rate, int bits_per_sample, | 57 int sample_rate, int bits_per_sample, |
| 70 int frames_per_buffer); | 58 int frames_per_buffer); |
| 71 | 59 |
| 72 // Checks that all values are in the expected range. All limits are specified | 60 // Checks that all values are in the expected range. All limits are specified |
| 73 // in media::Limits. | 61 // in media::Limits. |
| 74 bool IsValid() const; | 62 bool IsValid() const; |
| 75 | 63 |
| 76 // Returns size of audio buffer in bytes. | 64 // Returns size of audio buffer in bytes. |
| 77 int GetBytesPerBuffer() const; | 65 int GetBytesPerBuffer() const; |
| 78 | 66 |
| 79 // Returns the number of bytes representing one second of audio. | 67 // Returns the number of bytes representing one second of audio. |
| 80 int GetBytesPerSecond() const; | 68 int GetBytesPerSecond() const; |
| 81 | 69 |
| 82 // Returns the number of bytes representing a frame of audio. | 70 // Returns the number of bytes representing a frame of audio. |
| 83 int GetBytesPerFrame() const; | 71 int GetBytesPerFrame() const; |
| 84 | 72 |
| 85 // Returns the duration of this buffer as calculated from frames_per_buffer() | 73 // Returns the duration of this buffer as calculated from frames_per_buffer() |
| 86 // and sample_rate(). | 74 // and sample_rate(). |
| 87 base::TimeDelta GetBufferDuration() const; | 75 base::TimeDelta GetBufferDuration() const; |
| 88 | 76 |
| 89 Format format() const { return format_; } | 77 Format format() const { return format_; } |
| 90 ChannelLayout channel_layout() const { return channel_layout_; } | 78 ChannelLayout channel_layout() const { return channel_layout_; } |
| 91 int sample_rate() const { return sample_rate_; } | 79 int sample_rate() const { return sample_rate_; } |
| 92 int bits_per_sample() const { return bits_per_sample_; } | 80 int bits_per_sample() const { return bits_per_sample_; } |
| 93 int frames_per_buffer() const { return frames_per_buffer_; } | 81 int frames_per_buffer() const { return frames_per_buffer_; } |
| 94 int channels() const { return channels_; } | 82 int channels() const { return channels_; } |
| 95 int input_channels() const { return input_channels_; } | 83 int input_channels() const { return input_channels_; } |
| 96 int effects() const { return effects_; } | 84 |
| 85 // Set to CHANNEL_LAYOUT_DISCRETE with given number of channels. |
| 86 void SetDiscreteChannels(int channels); |
| 97 | 87 |
| 98 // Comparison with other AudioParams. | 88 // Comparison with other AudioParams. |
| 99 bool operator==(const AudioParameters& other) const { | 89 bool operator==(const AudioParameters& other) const { |
| 100 return format_ == other.format() && | 90 return format_ == other.format() && |
| 101 sample_rate_ == other.sample_rate() && | 91 sample_rate_ == other.sample_rate() && |
| 102 channel_layout_ == other.channel_layout() && | 92 channel_layout_ == other.channel_layout() && |
| 103 channels_ == other.channels() && | 93 channels_ == other.channels() && |
| 104 input_channels_ == other.input_channels() && | 94 input_channels_ == other.input_channels() && |
| 105 bits_per_sample_ == other.bits_per_sample() && | 95 bits_per_sample_ == other.bits_per_sample() && |
| 106 frames_per_buffer_ == other.frames_per_buffer() && | 96 frames_per_buffer_ == other.frames_per_buffer(); |
| 107 effects_ == other.effects(); | |
| 108 } | 97 } |
| 109 | 98 |
| 110 private: | 99 private: |
| 111 // These members are mutable to support entire struct assignment. They should | |
| 112 // not be mutated individually. | |
| 113 Format format_; // Format of the stream. | 100 Format format_; // Format of the stream. |
| 114 ChannelLayout channel_layout_; // Order of surround sound channels. | 101 ChannelLayout channel_layout_; // Order of surround sound channels. |
| 115 int sample_rate_; // Sampling frequency/rate. | 102 int sample_rate_; // Sampling frequency/rate. |
| 116 int bits_per_sample_; // Number of bits per sample. | 103 int bits_per_sample_; // Number of bits per sample. |
| 117 int frames_per_buffer_; // Number of frames in a buffer. | 104 int frames_per_buffer_; // Number of frames in a buffer. |
| 118 | 105 |
| 119 int channels_; // Number of channels. Value set based on | 106 int channels_; // Number of channels. Value set based on |
| 120 // |channel_layout|. | 107 // |channel_layout|. |
| 121 int input_channels_; // Optional number of input channels. | 108 int input_channels_; // Optional number of input channels. |
| 122 // Normally 0, but can be set to specify | 109 // Normally 0, but can be set to specify |
| 123 // synchronized I/O. | 110 // synchronized I/O. |
| 124 int effects_; // Bitmask using PlatformEffectsMask. | |
| 125 }; | 111 }; |
| 126 | 112 |
| 127 // Comparison is useful when AudioParameters is used with std structures. | 113 // Comparison is useful when AudioParameters is used with std structures. |
| 128 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { | 114 inline bool operator<(const AudioParameters& a, const AudioParameters& b) { |
| 129 if (a.format() != b.format()) | 115 if (a.format() != b.format()) |
| 130 return a.format() < b.format(); | 116 return a.format() < b.format(); |
| 131 if (a.channels() != b.channels()) | 117 if (a.channels() != b.channels()) |
| 132 return a.channels() < b.channels(); | 118 return a.channels() < b.channels(); |
| 133 if (a.input_channels() != b.input_channels()) | 119 if (a.input_channels() != b.input_channels()) |
| 134 return a.input_channels() < b.input_channels(); | 120 return a.input_channels() < b.input_channels(); |
| 135 if (a.sample_rate() != b.sample_rate()) | 121 if (a.sample_rate() != b.sample_rate()) |
| 136 return a.sample_rate() < b.sample_rate(); | 122 return a.sample_rate() < b.sample_rate(); |
| 137 if (a.bits_per_sample() != b.bits_per_sample()) | 123 if (a.bits_per_sample() != b.bits_per_sample()) |
| 138 return a.bits_per_sample() < b.bits_per_sample(); | 124 return a.bits_per_sample() < b.bits_per_sample(); |
| 139 return a.frames_per_buffer() < b.frames_per_buffer(); | 125 return a.frames_per_buffer() < b.frames_per_buffer(); |
| 140 } | 126 } |
| 141 | 127 |
| 142 } // namespace media | 128 } // namespace media |
| 143 | 129 |
| 144 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ | 130 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ |
| OLD | NEW |