diff --git a/webrtc/common_audio/audio_converter.h b/webrtc/common_audio/audio_converter.h index 6365f58799..c71a3fdcc5 100644 --- a/webrtc/common_audio/audio_converter.h +++ b/webrtc/common_audio/audio_converter.h @@ -13,7 +13,7 @@ // TODO(ajm): Move channel buffer to common_audio. #include "webrtc/base/constructormagic.h" -#include "webrtc/modules/audio_processing/common.h" +#include "webrtc/modules/audio_processing/channel_buffer.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/system_wrappers/interface/scoped_vector.h" diff --git a/webrtc/common_audio/audio_converter_unittest.cc b/webrtc/common_audio/audio_converter_unittest.cc index 91836f9cef..3e509ceb01 100644 --- a/webrtc/common_audio/audio_converter_unittest.cc +++ b/webrtc/common_audio/audio_converter_unittest.cc @@ -15,7 +15,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/common_audio/audio_converter.h" #include "webrtc/common_audio/resampler/push_sinc_resampler.h" -#include "webrtc/modules/audio_processing/common.h" +#include "webrtc/modules/audio_processing/channel_buffer.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" namespace webrtc { diff --git a/webrtc/common_audio/blocker.h b/webrtc/common_audio/blocker.h index f3f99cd31e..1cf95dbc38 100644 --- a/webrtc/common_audio/blocker.h +++ b/webrtc/common_audio/blocker.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ #define WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ -#include "webrtc/modules/audio_processing/common.h" +#include "webrtc/modules/audio_processing/channel_buffer.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" namespace webrtc { diff --git a/webrtc/modules/audio_processing/audio_buffer.cc b/webrtc/modules/audio_processing/audio_buffer.cc index 5d542d038f..33af43e6b4 100644 --- a/webrtc/modules/audio_processing/audio_buffer.cc +++ b/webrtc/modules/audio_processing/audio_buffer.cc @@ -13,6 +13,7 @@ #include "webrtc/common_audio/resampler/push_sinc_resampler.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_processing/channel_buffer.h" +#include "webrtc/modules/audio_processing/common.h" namespace webrtc { namespace { diff --git a/webrtc/modules/audio_processing/audio_buffer.h b/webrtc/modules/audio_processing/audio_buffer.h index b92e499e4c..fe2cf36c30 100644 --- a/webrtc/modules/audio_processing/audio_buffer.h +++ b/webrtc/modules/audio_processing/audio_buffer.h @@ -14,7 +14,7 @@ #include #include "webrtc/common_audio/include/audio_util.h" -#include "webrtc/modules/audio_processing/common.h" +#include "webrtc/modules/audio_processing/channel_buffer.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/splitting_filter.h" #include "webrtc/modules/interface/module_common_types.h" diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index 1b16c7c609..0c50ecb060 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -16,6 +16,7 @@ #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_processing/audio_buffer.h" +#include "webrtc/modules/audio_processing/channel_buffer.h" #include "webrtc/modules/audio_processing/common.h" #include "webrtc/modules/audio_processing/echo_cancellation_impl.h" #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" diff --git a/webrtc/modules/audio_processing/channel_buffer.h b/webrtc/modules/audio_processing/channel_buffer.h index 07990e7326..6ecc07ab53 100644 --- a/webrtc/modules/audio_processing/channel_buffer.h +++ b/webrtc/modules/audio_processing/channel_buffer.h @@ -11,11 +11,86 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ +#include + +#include "webrtc/base/checks.h" #include "webrtc/common_audio/include/audio_util.h" -#include "webrtc/modules/audio_processing/common.h" namespace webrtc { +// Helper to encapsulate a contiguous data buffer with access to a pointer +// array of the deinterleaved channels. +template +class ChannelBuffer { + public: + ChannelBuffer(int samples_per_channel, int num_channels) + : data_(new T[samples_per_channel * num_channels]), + channels_(new T*[num_channels]), + samples_per_channel_(samples_per_channel), + num_channels_(num_channels) { + Initialize(); + } + + ChannelBuffer(const T* data, int samples_per_channel, int num_channels) + : data_(new T[samples_per_channel * num_channels]), + channels_(new T*[num_channels]), + samples_per_channel_(samples_per_channel), + num_channels_(num_channels) { + Initialize(); + memcpy(data_.get(), data, length() * sizeof(T)); + } + + ChannelBuffer(const T* const* channels, int samples_per_channel, + int num_channels) + : data_(new T[samples_per_channel * num_channels]), + channels_(new T*[num_channels]), + samples_per_channel_(samples_per_channel), + num_channels_(num_channels) { + Initialize(); + for (int i = 0; i < num_channels_; ++i) + CopyFrom(channels[i], i); + } + + ~ChannelBuffer() {} + + void CopyFrom(const void* channel_ptr, int i) { + DCHECK_LT(i, num_channels_); + memcpy(channels_[i], channel_ptr, samples_per_channel_ * sizeof(T)); + } + + T* data() { return data_.get(); } + const T* data() const { return data_.get(); } + + const T* channel(int i) const { + DCHECK_GE(i, 0); + DCHECK_LT(i, num_channels_); + return channels_[i]; + } + T* channel(int i) { + const ChannelBuffer* t = this; + return const_cast(t->channel(i)); + } + + T* const* channels() { return channels_.get(); } + const T* const* channels() const { return channels_.get(); } + + int samples_per_channel() const { return samples_per_channel_; } + int num_channels() const { return num_channels_; } + int length() const { return samples_per_channel_ * num_channels_; } + + private: + void Initialize() { + memset(data_.get(), 0, sizeof(T) * length()); + for (int i = 0; i < num_channels_; ++i) + channels_[i] = &data_[i * samples_per_channel_]; + } + + scoped_ptr data_; + scoped_ptr channels_; + const int samples_per_channel_; + const int num_channels_; +}; + // One int16_t and one float ChannelBuffer that are kept in sync. The sync is // broken when someone requests write access to either ChannelBuffer, and // reestablished when someone requests the outdated ChannelBuffer. It is diff --git a/webrtc/modules/audio_processing/common.h b/webrtc/modules/audio_processing/common.h index 98c624127c..ed8a0544c3 100644 --- a/webrtc/modules/audio_processing/common.h +++ b/webrtc/modules/audio_processing/common.h @@ -12,11 +12,8 @@ #define WEBRTC_MODULES_AUDIO_PROCESSING_COMMON_H_ #include -#include -#include "webrtc/base/checks.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" -#include "webrtc/system_wrappers/interface/scoped_ptr.h" namespace webrtc { @@ -33,79 +30,6 @@ static inline int ChannelsFromLayout(AudioProcessing::ChannelLayout layout) { return -1; } -// Helper to encapsulate a contiguous data buffer with access to a pointer -// array of the deinterleaved channels. -template -class ChannelBuffer { - public: - ChannelBuffer(int samples_per_channel, int num_channels) - : data_(new T[samples_per_channel * num_channels]), - channels_(new T*[num_channels]), - samples_per_channel_(samples_per_channel), - num_channels_(num_channels) { - Initialize(); - } - - ChannelBuffer(const T* data, int samples_per_channel, int num_channels) - : data_(new T[samples_per_channel * num_channels]), - channels_(new T*[num_channels]), - samples_per_channel_(samples_per_channel), - num_channels_(num_channels) { - Initialize(); - memcpy(data_.get(), data, length() * sizeof(T)); - } - - ChannelBuffer(const T* const* channels, int samples_per_channel, - int num_channels) - : data_(new T[samples_per_channel * num_channels]), - channels_(new T*[num_channels]), - samples_per_channel_(samples_per_channel), - num_channels_(num_channels) { - Initialize(); - for (int i = 0; i < num_channels_; ++i) - CopyFrom(channels[i], i); - } - - ~ChannelBuffer() {} - - void CopyFrom(const void* channel_ptr, int i) { - DCHECK_LT(i, num_channels_); - memcpy(channels_[i], channel_ptr, samples_per_channel_ * sizeof(T)); - } - - T* data() { return data_.get(); } - const T* data() const { return data_.get(); } - - const T* channel(int i) const { - DCHECK_GE(i, 0); - DCHECK_LT(i, num_channels_); - return channels_[i]; - } - T* channel(int i) { - const ChannelBuffer* t = this; - return const_cast(t->channel(i)); - } - - T* const* channels() { return channels_.get(); } - const T* const* channels() const { return channels_.get(); } - - int samples_per_channel() const { return samples_per_channel_; } - int num_channels() const { return num_channels_; } - int length() const { return samples_per_channel_ * num_channels_; } - - private: - void Initialize() { - memset(data_.get(), 0, sizeof(T) * length()); - for (int i = 0; i < num_channels_; ++i) - channels_[i] = &data_[i * samples_per_channel_]; - } - - scoped_ptr data_; - scoped_ptr channels_; - const int samples_per_channel_; - const int num_channels_; -}; - } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_PROCESSING_COMMON_H_ diff --git a/webrtc/modules/audio_processing/test/audio_processing_unittest.cc b/webrtc/modules/audio_processing/test/audio_processing_unittest.cc index 401391aa2b..78e79a5eb9 100644 --- a/webrtc/modules/audio_processing/test/audio_processing_unittest.cc +++ b/webrtc/modules/audio_processing/test/audio_processing_unittest.cc @@ -18,6 +18,7 @@ #include "webrtc/common_audio/resampler/include/push_resampler.h" #include "webrtc/common_audio/resampler/push_sinc_resampler.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +#include "webrtc/modules/audio_processing/common.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/test/test_utils.h" #include "webrtc/modules/interface/module_common_types.h" diff --git a/webrtc/modules/audio_processing/test/test_utils.h b/webrtc/modules/audio_processing/test/test_utils.h index d0d08cb8cf..2243590bb1 100644 --- a/webrtc/modules/audio_processing/test/test_utils.h +++ b/webrtc/modules/audio_processing/test/test_utils.h @@ -14,7 +14,7 @@ #include "webrtc/audio_processing/debug.pb.h" #include "webrtc/common_audio/include/audio_util.h" #include "webrtc/common_audio/wav_file.h" -#include "webrtc/modules/audio_processing/common.h" +#include "webrtc/modules/audio_processing/channel_buffer.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/interface/module_common_types.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h"