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 #include "media/audio/audio_parameters.h" | 5 #include "media/audio/audio_parameters.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/base/limits.h" | 8 #include "media/base/limits.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 AudioParameters::AudioParameters() | 12 AudioParameters::AudioParameters() |
13 : format_(AUDIO_PCM_LINEAR), | 13 : AudioParameters(AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_NONE, 0, 0, 0) {} |
14 channel_layout_(CHANNEL_LAYOUT_NONE), | |
15 sample_rate_(0), | |
16 bits_per_sample_(0), | |
17 frames_per_buffer_(0), | |
18 channels_(0), | |
19 effects_(NO_EFFECTS) { | |
20 } | |
21 | 14 |
22 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, | 15 AudioParameters::AudioParameters(Format format, |
23 int sample_rate, int bits_per_sample, | 16 ChannelLayout channel_layout, |
24 int frames_per_buffer) | 17 int sample_rate, |
25 : format_(format), | 18 int bits_per_sample, |
26 channel_layout_(channel_layout), | 19 int frames_per_buffer, |
27 sample_rate_(sample_rate), | 20 const std::vector<Point>& mic_positions, |
28 bits_per_sample_(bits_per_sample), | 21 int effects) |
29 frames_per_buffer_(frames_per_buffer), | 22 : AudioParameters(format, |
30 channels_(ChannelLayoutToChannelCount(channel_layout)), | 23 ChannelLayoutToChannelCount(channel_layout), |
31 effects_(NO_EFFECTS) { | 24 channel_layout, |
32 } | 25 sample_rate, |
| 26 bits_per_sample, |
| 27 frames_per_buffer, |
| 28 mic_positions, |
| 29 effects) {} |
33 | 30 |
34 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, | 31 AudioParameters::AudioParameters(Format format, |
35 int sample_rate, int bits_per_sample, | 32 int channels, |
36 int frames_per_buffer, int effects) | 33 ChannelLayout channel_layout, |
37 : format_(format), | 34 int sample_rate, |
38 channel_layout_(channel_layout), | 35 int bits_per_sample, |
39 sample_rate_(sample_rate), | 36 int frames_per_buffer, |
40 bits_per_sample_(bits_per_sample), | 37 const std::vector<Point>& mic_positions, |
41 frames_per_buffer_(frames_per_buffer), | |
42 channels_(ChannelLayoutToChannelCount(channel_layout)), | |
43 effects_(effects) { | |
44 } | |
45 | |
46 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, | |
47 int channels, int sample_rate, | |
48 int bits_per_sample, int frames_per_buffer, | |
49 int effects) | 38 int effects) |
50 : format_(format), | 39 : format_(format), |
51 channel_layout_(channel_layout), | 40 channel_layout_(channel_layout), |
52 sample_rate_(sample_rate), | 41 sample_rate_(sample_rate), |
53 bits_per_sample_(bits_per_sample), | 42 bits_per_sample_(bits_per_sample), |
54 frames_per_buffer_(frames_per_buffer), | 43 frames_per_buffer_(frames_per_buffer), |
55 channels_(channels), | 44 channels_(channels), |
56 effects_(effects) { | 45 mic_positions_(mic_positions), |
57 } | 46 effects_(effects) {} |
| 47 |
| 48 AudioParameters::~AudioParameters() {} |
58 | 49 |
59 void AudioParameters::Reset(Format format, ChannelLayout channel_layout, | 50 void AudioParameters::Reset(Format format, ChannelLayout channel_layout, |
60 int channels, int sample_rate, | 51 int channels, int sample_rate, |
61 int bits_per_sample, int frames_per_buffer) { | 52 int bits_per_sample, int frames_per_buffer) { |
62 format_ = format; | 53 format_ = format; |
63 channel_layout_ = channel_layout; | 54 channel_layout_ = channel_layout; |
64 channels_ = channels; | 55 channels_ = channels; |
65 sample_rate_ = sample_rate; | 56 sample_rate_ = sample_rate; |
66 bits_per_sample_ = bits_per_sample; | 57 bits_per_sample_ = bits_per_sample; |
67 frames_per_buffer_ = frames_per_buffer; | 58 frames_per_buffer_ = frames_per_buffer; |
| 59 mic_positions_.clear(); |
| 60 effects_ = NO_EFFECTS; |
68 } | 61 } |
69 | 62 |
70 bool AudioParameters::IsValid() const { | 63 bool AudioParameters::IsValid() const { |
71 return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) && | 64 return (channels_ > 0) && (channels_ <= media::limits::kMaxChannels) && |
72 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && | 65 (channel_layout_ > CHANNEL_LAYOUT_UNSUPPORTED) && |
73 (sample_rate_ >= media::limits::kMinSampleRate) && | 66 (sample_rate_ >= media::limits::kMinSampleRate) && |
74 (sample_rate_ <= media::limits::kMaxSampleRate) && | 67 (sample_rate_ <= media::limits::kMaxSampleRate) && |
75 (bits_per_sample_ > 0) && | 68 (bits_per_sample_ > 0) && |
76 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) && | 69 (bits_per_sample_ <= media::limits::kMaxBitsPerSample) && |
77 (frames_per_buffer_ > 0) && | 70 (frames_per_buffer_ > 0) && |
(...skipping 25 matching lines...) Expand all Loading... |
103 return channels_ * bits_per_sample_ / 8; | 96 return channels_ * bits_per_sample_ / 8; |
104 } | 97 } |
105 | 98 |
106 base::TimeDelta AudioParameters::GetBufferDuration() const { | 99 base::TimeDelta AudioParameters::GetBufferDuration() const { |
107 return base::TimeDelta::FromMicroseconds(static_cast<int64>( | 100 return base::TimeDelta::FromMicroseconds(static_cast<int64>( |
108 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond / | 101 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond / |
109 static_cast<float>(sample_rate_))); | 102 static_cast<float>(sample_rate_))); |
110 } | 103 } |
111 | 104 |
112 bool AudioParameters::Equals(const AudioParameters& other) const { | 105 bool AudioParameters::Equals(const AudioParameters& other) const { |
113 return format_ == other.format() && | 106 return format_ == other.format() && sample_rate_ == other.sample_rate() && |
114 sample_rate_ == other.sample_rate() && | |
115 channel_layout_ == other.channel_layout() && | 107 channel_layout_ == other.channel_layout() && |
116 channels_ == other.channels() && | 108 channels_ == other.channels() && |
117 bits_per_sample_ == other.bits_per_sample() && | 109 bits_per_sample_ == other.bits_per_sample() && |
118 frames_per_buffer_ == other.frames_per_buffer() && | 110 frames_per_buffer_ == other.frames_per_buffer() && |
119 effects_ == other.effects(); | 111 mic_positions_ == other.mic_positions_ && effects_ == other.effects(); |
120 } | 112 } |
121 | 113 |
122 } // namespace media | 114 } // namespace media |
OLD | NEW |