blob: 2638bef6058d2e22795458f599012aae657d2a5e [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_
12#define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_
13
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000014#include "webrtc/modules/interface/module_common_types.h"
15#include "webrtc/system_wrappers/interface/scoped_ptr.h"
16#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
niklase@google.com470e71d2011-07-07 08:21:25 +000018namespace webrtc {
19
20struct AudioChannel;
21struct SplitAudioChannel;
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23class AudioBuffer {
24 public:
andrew@webrtc.orged083d42011-09-19 15:28:51 +000025 AudioBuffer(int max_num_channels, int samples_per_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +000026 virtual ~AudioBuffer();
27
andrew@webrtc.orged083d42011-09-19 15:28:51 +000028 int num_channels() const;
29 int samples_per_channel() const;
30 int samples_per_split_channel() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000032 int16_t* data(int channel) const;
33 int16_t* low_pass_split_data(int channel) const;
34 int16_t* high_pass_split_data(int channel) const;
35 int16_t* mixed_data(int channel) const;
36 int16_t* mixed_low_pass_data(int channel) const;
37 int16_t* low_pass_reference(int channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000039 int32_t* analysis_filter_state1(int channel) const;
40 int32_t* analysis_filter_state2(int channel) const;
41 int32_t* synthesis_filter_state1(int channel) const;
42 int32_t* synthesis_filter_state2(int channel) const;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000043
44 void set_activity(AudioFrame::VADActivity activity);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000045 AudioFrame::VADActivity activity() const;
46
47 bool is_muted() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
49 void DeinterleaveFrom(AudioFrame* audioFrame);
50 void InterleaveTo(AudioFrame* audioFrame) const;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000051 // If |data_changed| is false, only the non-audio data members will be copied
52 // to |frame|.
53 void InterleaveTo(AudioFrame* frame, bool data_changed) const;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000054 void Mix(int num_mixed_channels);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000055 void CopyAndMix(int num_mixed_channels);
andrew@webrtc.orged083d42011-09-19 15:28:51 +000056 void CopyAndMixLowPass(int num_mixed_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000057 void CopyLowPassToReference();
58
59 private:
andrew@webrtc.orged083d42011-09-19 15:28:51 +000060 const int max_num_channels_;
61 int num_channels_;
62 int num_mixed_channels_;
63 int num_mixed_low_pass_channels_;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000064 // Whether the original data was replaced with mixed data.
65 bool data_was_mixed_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000066 const int samples_per_channel_;
67 int samples_per_split_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +000068 bool reference_copied_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000069 AudioFrame::VADActivity activity_;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000070 bool is_muted_;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000072 int16_t* data_;
73 scoped_array<AudioChannel> channels_;
74 scoped_array<SplitAudioChannel> split_channels_;
75 scoped_array<AudioChannel> mixed_channels_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000076 // TODO(andrew): improve this, we don't need the full 32 kHz space here.
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000077 scoped_array<AudioChannel> mixed_low_pass_channels_;
78 scoped_array<AudioChannel> low_pass_reference_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +000079};
80} // namespace webrtc
81
82#endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_