| 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 : format_(AUDIO_PCM_LINEAR), |
| 14 channel_layout_(CHANNEL_LAYOUT_NONE), | 14 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 15 sample_rate_(0), | 15 sample_rate_(0), |
| 16 bits_per_sample_(0), | 16 bits_per_sample_(0), |
| 17 frames_per_buffer_(0), | 17 frames_per_buffer_(0), |
| 18 channels_(0), | 18 channels_(0), |
| 19 input_channels_(0), | 19 input_channels_(0) { |
| 20 effects_(NO_EFFECTS) { | |
| 21 } | 20 } |
| 22 | 21 |
| 23 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, | 22 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, |
| 24 int sample_rate, int bits_per_sample, | 23 int sample_rate, int bits_per_sample, |
| 25 int frames_per_buffer) | 24 int frames_per_buffer) |
| 26 : format_(format), | 25 : format_(format), |
| 27 channel_layout_(channel_layout), | 26 channel_layout_(channel_layout), |
| 28 sample_rate_(sample_rate), | 27 sample_rate_(sample_rate), |
| 29 bits_per_sample_(bits_per_sample), | 28 bits_per_sample_(bits_per_sample), |
| 30 frames_per_buffer_(frames_per_buffer), | 29 frames_per_buffer_(frames_per_buffer), |
| 31 channels_(ChannelLayoutToChannelCount(channel_layout)), | 30 channels_(ChannelLayoutToChannelCount(channel_layout)), |
| 32 input_channels_(0), | 31 input_channels_(0) { |
| 33 effects_(NO_EFFECTS) { | |
| 34 } | 32 } |
| 35 | 33 |
| 36 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, | 34 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, |
| 37 int input_channels, | 35 int input_channels, |
| 38 int sample_rate, int bits_per_sample, | 36 int sample_rate, int bits_per_sample, |
| 39 int frames_per_buffer, int effects) | 37 int frames_per_buffer) |
| 40 : format_(format), | 38 : format_(format), |
| 41 channel_layout_(channel_layout), | 39 channel_layout_(channel_layout), |
| 42 sample_rate_(sample_rate), | 40 sample_rate_(sample_rate), |
| 43 bits_per_sample_(bits_per_sample), | 41 bits_per_sample_(bits_per_sample), |
| 44 frames_per_buffer_(frames_per_buffer), | 42 frames_per_buffer_(frames_per_buffer), |
| 45 channels_(ChannelLayoutToChannelCount(channel_layout)), | 43 channels_(ChannelLayoutToChannelCount(channel_layout)), |
| 46 input_channels_(input_channels), | 44 input_channels_(input_channels) { |
| 47 effects_(effects) { | |
| 48 } | |
| 49 | |
| 50 AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, | |
| 51 int channels, int input_channels, | |
| 52 int sample_rate, int bits_per_sample, | |
| 53 int frames_per_buffer, int effects) | |
| 54 : format_(format), | |
| 55 channel_layout_(channel_layout), | |
| 56 sample_rate_(sample_rate), | |
| 57 bits_per_sample_(bits_per_sample), | |
| 58 frames_per_buffer_(frames_per_buffer), | |
| 59 channels_(channels), | |
| 60 input_channels_(input_channels), | |
| 61 effects_(effects) { | |
| 62 if (channel_layout != CHANNEL_LAYOUT_DISCRETE) | |
| 63 DCHECK_EQ(channels, ChannelLayoutToChannelCount(channel_layout)); | |
| 64 } | 45 } |
| 65 | 46 |
| 66 void AudioParameters::Reset(Format format, ChannelLayout channel_layout, | 47 void AudioParameters::Reset(Format format, ChannelLayout channel_layout, |
| 67 int channels, int input_channels, | 48 int channels, int input_channels, |
| 68 int sample_rate, int bits_per_sample, | 49 int sample_rate, int bits_per_sample, |
| 69 int frames_per_buffer) { | 50 int frames_per_buffer) { |
| 70 if (channel_layout != CHANNEL_LAYOUT_DISCRETE) | 51 if (channel_layout != CHANNEL_LAYOUT_DISCRETE) |
| 71 DCHECK_EQ(channels, ChannelLayoutToChannelCount(channel_layout)); | 52 DCHECK_EQ(channels, ChannelLayoutToChannelCount(channel_layout)); |
| 72 | 53 |
| 73 format_ = format; | 54 format_ = format; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 int AudioParameters::GetBytesPerFrame() const { | 88 int AudioParameters::GetBytesPerFrame() const { |
| 108 return channels_ * bits_per_sample_ / 8; | 89 return channels_ * bits_per_sample_ / 8; |
| 109 } | 90 } |
| 110 | 91 |
| 111 base::TimeDelta AudioParameters::GetBufferDuration() const { | 92 base::TimeDelta AudioParameters::GetBufferDuration() const { |
| 112 return base::TimeDelta::FromMicroseconds( | 93 return base::TimeDelta::FromMicroseconds( |
| 113 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond / | 94 frames_per_buffer_ * base::Time::kMicrosecondsPerSecond / |
| 114 static_cast<float>(sample_rate_)); | 95 static_cast<float>(sample_rate_)); |
| 115 } | 96 } |
| 116 | 97 |
| 98 void AudioParameters::SetDiscreteChannels(int channels) { |
| 99 channel_layout_ = CHANNEL_LAYOUT_DISCRETE; |
| 100 channels_ = channels; |
| 101 } |
| 102 |
| 117 } // namespace media | 103 } // namespace media |
| OLD | NEW |