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 #ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_
6 #define MEDIA_AUDIO_AUDIO_PARAMETERS_H_
8 #include "base/basictypes.h"
9 #include "media/base/channel_layout.h"
10 #include "media/base/media_export.h"
14 struct MEDIA_EXPORT AudioInputBufferParameters
{
19 // Use a struct-in-struct approach to ensure that we can calculate the required
20 // size as sizeof(AudioInputBufferParameters) + #(bytes in audio buffer) without
22 struct MEDIA_EXPORT AudioInputBuffer
{
23 AudioInputBufferParameters params
;
27 class MEDIA_EXPORT AudioParameters
{
29 // Compare is useful when AudioParameters is used as a key in std::map.
30 class MEDIA_EXPORT Compare
{
32 bool operator()(const AudioParameters
& a
, const AudioParameters
& b
) const;
36 AUDIO_PCM_LINEAR
= 0, // PCM is 'raw' amplitude samples.
37 AUDIO_PCM_LOW_LATENCY
, // Linear PCM, low latency requested.
38 AUDIO_MOCK
, // Creates a dummy AudioOutputStream object.
39 AUDIO_LAST_FORMAT
// Only used for validation of format.y
42 // Telephone quality sample rate, mostly for speech-only audio.
43 static const uint32 kTelephoneSampleRate
= 8000;
44 // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7.
45 static const uint32 kAudioCDSampleRate
= 44100;
46 // Digital Audio Tape sample rate.
47 static const uint32 kAudioDATSampleRate
= 48000;
50 AudioParameters(Format format
, ChannelLayout channel_layout
,
51 int sample_rate
, int bits_per_sample
,
52 int frames_per_buffer
);
53 void Reset(Format format
, ChannelLayout channel_layout
,
54 int sample_rate
, int bits_per_sample
,
55 int frames_per_buffer
);
57 // Checks that all values are in the expected range. All limits are specified
61 // Returns size of audio buffer in bytes.
62 int GetBytesPerBuffer() const;
64 // Returns the number of bytes representing one second of audio.
65 int GetBytesPerSecond() const;
67 // Returns the number of bytes representing a frame of audio.
68 int GetBytesPerFrame() const;
70 Format
format() const { return format_
; }
71 ChannelLayout
channel_layout() const { return channel_layout_
; }
72 int sample_rate() const { return sample_rate_
; }
73 int bits_per_sample() const { return bits_per_sample_
; }
74 int frames_per_buffer() const { return frames_per_buffer_
; }
75 int channels() const { return channels_
; }
78 Format format_
; // Format of the stream.
79 ChannelLayout channel_layout_
; // Order of surround sound channels.
80 int sample_rate_
; // Sampling frequency/rate.
81 int bits_per_sample_
; // Number of bits per sample.
82 int frames_per_buffer_
; // Number of frames in a buffer.
84 int channels_
; // Number of channels. Value set based on
90 #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_