1 // Copyright (c) 2011 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"
9 AudioParameters::AudioParameters()
10 : format(AUDIO_PCM_LINEAR
),
11 channel_layout(CHANNEL_LAYOUT_NONE
),
14 samples_per_packet(0),
18 AudioParameters::AudioParameters(Format format
, ChannelLayout channel_layout
,
19 int sample_rate
, int bits_per_sample
,
20 int samples_per_packet
)
22 channel_layout(channel_layout
),
23 sample_rate(sample_rate
),
24 bits_per_sample(bits_per_sample
),
25 samples_per_packet(samples_per_packet
),
26 channels(ChannelLayoutToChannelCount(channel_layout
)) {
29 bool AudioParameters::IsValid() const {
30 return (format
>= 0) && (format
< AUDIO_LAST_FORMAT
) &&
31 (channels
> 0) && (channels
<= media::limits::kMaxChannels
) &&
32 (sample_rate
> 0) && (sample_rate
<= media::limits::kMaxSampleRate
) &&
33 (bits_per_sample
> 0) &&
34 (bits_per_sample
<= media::limits::kMaxBitsPerSample
) &&
35 (samples_per_packet
> 0) &&
36 (samples_per_packet
<= media::limits::kMaxSamplesPerPacket
);
39 int AudioParameters::GetPacketSize() const {
40 return samples_per_packet
* channels
* bits_per_sample
/ 8;
43 int AudioParameters::GetBytesPerSecond() const {
44 return sample_rate
* channels
* bits_per_sample
/ 8;
47 bool AudioParameters::Compare::operator()(
48 const AudioParameters
& a
,
49 const AudioParameters
& b
) const {
50 if (a
.format
< b
.format
)
52 if (a
.format
> b
.format
)
54 if (a
.channels
< b
.channels
)
56 if (a
.channels
> b
.channels
)
58 if (a
.sample_rate
< b
.sample_rate
)
60 if (a
.sample_rate
> b
.sample_rate
)
62 if (a
.bits_per_sample
< b
.bits_per_sample
)
64 if (a
.bits_per_sample
> b
.bits_per_sample
)
66 return a
.samples_per_packet
< b
.samples_per_packet
;