1c55a96383497a772a307b346368133960b02ad03Eric Laurent/*
2c55a96383497a772a307b346368133960b02ad03Eric Laurent *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3c55a96383497a772a307b346368133960b02ad03Eric Laurent *
4c55a96383497a772a307b346368133960b02ad03Eric Laurent *  Use of this source code is governed by a BSD-style license
5c55a96383497a772a307b346368133960b02ad03Eric Laurent *  that can be found in the LICENSE file in the root of the source
6c55a96383497a772a307b346368133960b02ad03Eric Laurent *  tree. An additional intellectual property rights grant can be found
7c55a96383497a772a307b346368133960b02ad03Eric Laurent *  in the file PATENTS.  All contributing project authors may
8c55a96383497a772a307b346368133960b02ad03Eric Laurent *  be found in the AUTHORS file in the root of the source tree.
9c55a96383497a772a307b346368133960b02ad03Eric Laurent */
10c55a96383497a772a307b346368133960b02ad03Eric Laurent
11c55a96383497a772a307b346368133960b02ad03Eric Laurent#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_
12c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_
13c55a96383497a772a307b346368133960b02ad03Eric Laurent
14c55a96383497a772a307b346368133960b02ad03Eric Laurent#include "module_common_types.h"
15c55a96383497a772a307b346368133960b02ad03Eric Laurent#include "scoped_ptr.h"
16c55a96383497a772a307b346368133960b02ad03Eric Laurent#include "typedefs.h"
17c55a96383497a772a307b346368133960b02ad03Eric Laurent
18c55a96383497a772a307b346368133960b02ad03Eric Laurentnamespace webrtc {
19c55a96383497a772a307b346368133960b02ad03Eric Laurent
20c55a96383497a772a307b346368133960b02ad03Eric Laurentstruct AudioChannel;
21c55a96383497a772a307b346368133960b02ad03Eric Laurentstruct SplitAudioChannel;
22c55a96383497a772a307b346368133960b02ad03Eric Laurent
23c55a96383497a772a307b346368133960b02ad03Eric Laurentclass AudioBuffer {
24c55a96383497a772a307b346368133960b02ad03Eric Laurent public:
25c55a96383497a772a307b346368133960b02ad03Eric Laurent  AudioBuffer(int max_num_channels, int samples_per_channel);
26c55a96383497a772a307b346368133960b02ad03Eric Laurent  virtual ~AudioBuffer();
27c55a96383497a772a307b346368133960b02ad03Eric Laurent
28c55a96383497a772a307b346368133960b02ad03Eric Laurent  int num_channels() const;
29c55a96383497a772a307b346368133960b02ad03Eric Laurent  int samples_per_channel() const;
30c55a96383497a772a307b346368133960b02ad03Eric Laurent  int samples_per_split_channel() const;
31c55a96383497a772a307b346368133960b02ad03Eric Laurent
32c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* data(int channel) const;
33c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* low_pass_split_data(int channel) const;
34c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* high_pass_split_data(int channel) const;
35c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* mixed_data(int channel) const;
36c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* mixed_low_pass_data(int channel) const;
37c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* low_pass_reference(int channel) const;
38c55a96383497a772a307b346368133960b02ad03Eric Laurent
39c55a96383497a772a307b346368133960b02ad03Eric Laurent  int32_t* analysis_filter_state1(int channel) const;
40c55a96383497a772a307b346368133960b02ad03Eric Laurent  int32_t* analysis_filter_state2(int channel) const;
41c55a96383497a772a307b346368133960b02ad03Eric Laurent  int32_t* synthesis_filter_state1(int channel) const;
42c55a96383497a772a307b346368133960b02ad03Eric Laurent  int32_t* synthesis_filter_state2(int channel) const;
43c55a96383497a772a307b346368133960b02ad03Eric Laurent
44c55a96383497a772a307b346368133960b02ad03Eric Laurent  void set_activity(AudioFrame::VADActivity activity);
45c55a96383497a772a307b346368133960b02ad03Eric Laurent  AudioFrame::VADActivity activity() const;
46c55a96383497a772a307b346368133960b02ad03Eric Laurent
47c55a96383497a772a307b346368133960b02ad03Eric Laurent  bool is_muted() const;
48c55a96383497a772a307b346368133960b02ad03Eric Laurent
49c55a96383497a772a307b346368133960b02ad03Eric Laurent  void DeinterleaveFrom(AudioFrame* audioFrame);
50c55a96383497a772a307b346368133960b02ad03Eric Laurent  void InterleaveTo(AudioFrame* audioFrame) const;
51c55a96383497a772a307b346368133960b02ad03Eric Laurent  // If |data_changed| is false, only the non-audio data members will be copied
52c55a96383497a772a307b346368133960b02ad03Eric Laurent  // to |frame|.
53c55a96383497a772a307b346368133960b02ad03Eric Laurent  void InterleaveTo(AudioFrame* frame, bool data_changed) const;
54c55a96383497a772a307b346368133960b02ad03Eric Laurent  void Mix(int num_mixed_channels);
55c55a96383497a772a307b346368133960b02ad03Eric Laurent  void CopyAndMix(int num_mixed_channels);
56c55a96383497a772a307b346368133960b02ad03Eric Laurent  void CopyAndMixLowPass(int num_mixed_channels);
57c55a96383497a772a307b346368133960b02ad03Eric Laurent  void CopyLowPassToReference();
58c55a96383497a772a307b346368133960b02ad03Eric Laurent
59c55a96383497a772a307b346368133960b02ad03Eric Laurent private:
60c55a96383497a772a307b346368133960b02ad03Eric Laurent  const int max_num_channels_;
61c55a96383497a772a307b346368133960b02ad03Eric Laurent  int num_channels_;
62c55a96383497a772a307b346368133960b02ad03Eric Laurent  int num_mixed_channels_;
63c55a96383497a772a307b346368133960b02ad03Eric Laurent  int num_mixed_low_pass_channels_;
64c55a96383497a772a307b346368133960b02ad03Eric Laurent  // Whether the original data was replaced with mixed data.
65c55a96383497a772a307b346368133960b02ad03Eric Laurent  bool data_was_mixed_;
66c55a96383497a772a307b346368133960b02ad03Eric Laurent  const int samples_per_channel_;
67c55a96383497a772a307b346368133960b02ad03Eric Laurent  int samples_per_split_channel_;
68c55a96383497a772a307b346368133960b02ad03Eric Laurent  bool reference_copied_;
69c55a96383497a772a307b346368133960b02ad03Eric Laurent  AudioFrame::VADActivity activity_;
70c55a96383497a772a307b346368133960b02ad03Eric Laurent  bool is_muted_;
71c55a96383497a772a307b346368133960b02ad03Eric Laurent
72c55a96383497a772a307b346368133960b02ad03Eric Laurent  int16_t* data_;
73c55a96383497a772a307b346368133960b02ad03Eric Laurent  scoped_array<AudioChannel> channels_;
74c55a96383497a772a307b346368133960b02ad03Eric Laurent  scoped_array<SplitAudioChannel> split_channels_;
75c55a96383497a772a307b346368133960b02ad03Eric Laurent  scoped_array<AudioChannel> mixed_channels_;
76c55a96383497a772a307b346368133960b02ad03Eric Laurent  // TODO(andrew): improve this, we don't need the full 32 kHz space here.
77c55a96383497a772a307b346368133960b02ad03Eric Laurent  scoped_array<AudioChannel> mixed_low_pass_channels_;
78c55a96383497a772a307b346368133960b02ad03Eric Laurent  scoped_array<AudioChannel> low_pass_reference_channels_;
79c55a96383497a772a307b346368133960b02ad03Eric Laurent};
80c55a96383497a772a307b346368133960b02ad03Eric Laurent}  // namespace webrtc
81c55a96383497a772a307b346368133960b02ad03Eric Laurent
82c55a96383497a772a307b346368133960b02ad03Eric Laurent#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_
83