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
3 // found in the LICENSE file.
5 #include "media/audio/audio_parameters.h"
7 #include "media/base/limits.h"
11 AudioParameters::AudioParameters()
12 : format_(AUDIO_PCM_LINEAR
),
13 channel_layout_(CHANNEL_LAYOUT_NONE
),
16 frames_per_buffer_(0),
20 AudioParameters::AudioParameters(Format format
, ChannelLayout channel_layout
,
21 int sample_rate
, int bits_per_sample
,
22 int frames_per_buffer
)
24 channel_layout_(channel_layout
),
25 sample_rate_(sample_rate
),
26 bits_per_sample_(bits_per_sample
),
27 frames_per_buffer_(frames_per_buffer
),
28 channels_(ChannelLayoutToChannelCount(channel_layout
)) {
31 void AudioParameters::Reset(Format format
, ChannelLayout channel_layout
,
32 int sample_rate
, int bits_per_sample
,
33 int frames_per_buffer
) {
35 channel_layout_
= channel_layout
;
36 sample_rate_
= sample_rate
;
37 bits_per_sample_
= bits_per_sample
;
38 frames_per_buffer_
= frames_per_buffer
;
39 channels_
= ChannelLayoutToChannelCount(channel_layout
);
42 bool AudioParameters::IsValid() const {
43 return (format_
>= AUDIO_PCM_LINEAR
) &&
44 (format_
< AUDIO_LAST_FORMAT
) &&
46 (channels_
<= media::limits::kMaxChannels
) &&
47 (channel_layout_
> CHANNEL_LAYOUT_UNSUPPORTED
) &&
48 (channel_layout_
< CHANNEL_LAYOUT_MAX
) &&
49 (sample_rate_
>= media::limits::kMinSampleRate
) &&
50 (sample_rate_
<= media::limits::kMaxSampleRate
) &&
51 (bits_per_sample_
> 0) &&
52 (bits_per_sample_
<= media::limits::kMaxBitsPerSample
) &&
53 (frames_per_buffer_
> 0) &&
54 (frames_per_buffer_
<= media::limits::kMaxSamplesPerPacket
);
57 int AudioParameters::GetBytesPerBuffer() const {
58 return frames_per_buffer_
* GetBytesPerFrame();
61 int AudioParameters::GetBytesPerSecond() const {
62 return sample_rate_
* GetBytesPerFrame();
65 int AudioParameters::GetBytesPerFrame() const {
66 return channels_
* bits_per_sample_
/ 8;