blob: 1030fec35c89de26a99489ec855b26d2dd8f538d [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
andrew@webrtc.org17e40642014-03-04 20:58:13 +000049 // Use for int16 interleaved data.
niklase@google.com470e71d2011-07-07 08:21:25 +000050 void DeinterleaveFrom(AudioFrame* audioFrame);
51 void InterleaveTo(AudioFrame* audioFrame) const;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000052 // If |data_changed| is false, only the non-audio data members will be copied
53 // to |frame|.
54 void InterleaveTo(AudioFrame* frame, bool data_changed) const;
andrew@webrtc.org17e40642014-03-04 20:58:13 +000055
56 // Use for float deinterleaved data.
57 void CopyFrom(const float* const* data, int samples_per_channel,
58 int num_channels);
59 void CopyTo(int samples_per_channel, int num_channels,
60 float* const* data) const;
61
andrew@webrtc.orged083d42011-09-19 15:28:51 +000062 void Mix(int num_mixed_channels);
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000063 void CopyAndMix(int num_mixed_channels);
andrew@webrtc.orged083d42011-09-19 15:28:51 +000064 void CopyAndMixLowPass(int num_mixed_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000065 void CopyLowPassToReference();
66
67 private:
andrew@webrtc.org17e40642014-03-04 20:58:13 +000068 // Called from DeinterleaveFrom() and CopyFrom().
69 void InitForNewData(int num_channels);
70
andrew@webrtc.orged083d42011-09-19 15:28:51 +000071 const int max_num_channels_;
72 int num_channels_;
73 int num_mixed_channels_;
74 int num_mixed_low_pass_channels_;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000075 // Whether the original data was replaced with mixed data.
76 bool data_was_mixed_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000077 const int samples_per_channel_;
78 int samples_per_split_channel_;
niklase@google.com470e71d2011-07-07 08:21:25 +000079 bool reference_copied_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000080 AudioFrame::VADActivity activity_;
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000081 bool is_muted_;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000083 int16_t* data_;
84 scoped_array<AudioChannel> channels_;
85 scoped_array<SplitAudioChannel> split_channels_;
86 scoped_array<AudioChannel> mixed_channels_;
andrew@webrtc.orged083d42011-09-19 15:28:51 +000087 // TODO(andrew): improve this, we don't need the full 32 kHz space here.
andrew@webrtc.org755b04a2011-11-15 16:57:56 +000088 scoped_array<AudioChannel> mixed_low_pass_channels_;
89 scoped_array<AudioChannel> low_pass_reference_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +000090};
91} // namespace webrtc
92
93#endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_BUFFER_H_