summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_parameters.h
blob: 26204b05878cc78a78dd945f47e5b9dfadcf258c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_AUDIO_AUDIO_PARAMETERS_H_
#define MEDIA_AUDIO_AUDIO_PARAMETERS_H_

#include "base/basictypes.h"
#include "media/base/audio_decoder_config.h"

struct AudioParameters {
  // Compare is useful when AudioParameters is used as a key in std::map.
  class Compare {
   public:
    bool operator()(const AudioParameters& a, const AudioParameters& b) const;
  };

  enum Format {
    AUDIO_PCM_LINEAR = 0,     // PCM is 'raw' amplitude samples.
    AUDIO_PCM_LOW_LATENCY,    // Linear PCM, low latency requested.
    AUDIO_MOCK,               // Creates a dummy AudioOutputStream object.
    AUDIO_LAST_FORMAT         // Only used for validation of format.
  };

  // Telephone quality sample rate, mostly for speech-only audio.
  static const uint32 kTelephoneSampleRate = 8000;
  // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7.
  static const uint32 kAudioCDSampleRate = 44100;
  // Digital Audio Tape sample rate.
  static const uint32 kAudioDATSampleRate = 48000;

  AudioParameters();

  explicit AudioParameters(const media::AudioDecoderConfig& config);

  AudioParameters(Format format, ChannelLayout channel_layout, int sample_rate,
                  int bits_per_sample, int samples_per_packet);

  // Checks that all values are in the expected range. All limits are specified
  // in media::Limits.
  bool IsValid() const;

  // Returns size of audio packets in bytes.
  int GetPacketSize() const;

  // Returns the number of bytes representing one second of audio.
  int GetBytesPerSecond() const;

  Format format;                 // Format of the stream.
  ChannelLayout channel_layout;  // Order of surround sound channels.
  int sample_rate;               // Sampling frequency/rate.
  int bits_per_sample;           // Number of bits per sample.
  int samples_per_packet;        // Size of a packet in frames.

  int channels;                  // Number of channels. Value set based on
                                 // |channel_layout|.
};

#endif  // MEDIA_AUDIO_AUDIO_PARAMETERS_H_