NetEq4: Removing templatization for AudioMultiVector
This saves approx 6% runtime for neteq4_speed_test. $ time out/Release/neteq4_speed_test --runtime_ms=50000000 BUG=1363 R=minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2320006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4885 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
6ad6a07fd3
commit
fd11bbfb56
@ -17,7 +17,7 @@ namespace webrtc {
|
||||
Accelerate::ReturnCodes Accelerate::Process(
|
||||
const int16_t* input,
|
||||
size_t input_length,
|
||||
AudioMultiVector<int16_t>* output,
|
||||
AudioMultiVector* output,
|
||||
int16_t* length_change_samples) {
|
||||
// Input length must be (almost) 30 ms.
|
||||
static const int k15ms = 120; // 15 ms = 120 samples at 8 kHz sample rate.
|
||||
@ -43,7 +43,7 @@ void Accelerate::SetParametersForPassiveSpeech(size_t /*len*/,
|
||||
Accelerate::ReturnCodes Accelerate::CheckCriteriaAndStretch(
|
||||
const int16_t* input, size_t input_length, size_t peak_index,
|
||||
int16_t best_correlation, bool active_speech,
|
||||
AudioMultiVector<int16_t>* output) const {
|
||||
AudioMultiVector* output) const {
|
||||
// Check for strong correlation or passive speech.
|
||||
if ((best_correlation > kCorrelationThreshold) || !active_speech) {
|
||||
// Do accelerate operation by overlap add.
|
||||
@ -56,7 +56,7 @@ Accelerate::ReturnCodes Accelerate::CheckCriteriaAndStretch(
|
||||
// Copy first part; 0 to 15 ms.
|
||||
output->PushBackInterleaved(input, fs_mult_120 * num_channels_);
|
||||
// Copy the |peak_index| starting at 15 ms to |temp_vector|.
|
||||
AudioMultiVector<int16_t> temp_vector(num_channels_);
|
||||
AudioMultiVector temp_vector(num_channels_);
|
||||
temp_vector.PushBackInterleaved(&input[fs_mult_120 * num_channels_],
|
||||
peak_index * num_channels_);
|
||||
// Cross-fade |temp_vector| onto the end of |output|.
|
||||
|
@ -43,7 +43,7 @@ class Accelerate : public TimeStretch {
|
||||
// the outcome of the operation as an enumerator value.
|
||||
ReturnCodes Process(const int16_t* input,
|
||||
size_t input_length,
|
||||
AudioMultiVector<int16_t>* output,
|
||||
AudioMultiVector* output,
|
||||
int16_t* length_change_samples);
|
||||
|
||||
protected:
|
||||
@ -58,7 +58,7 @@ class Accelerate : public TimeStretch {
|
||||
virtual ReturnCodes CheckCriteriaAndStretch(
|
||||
const int16_t* input, size_t input_length, size_t peak_index,
|
||||
int16_t best_correlation, bool active_speech,
|
||||
AudioMultiVector<int16_t>* output) const OVERRIDE;
|
||||
AudioMultiVector* output) const OVERRIDE;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Accelerate);
|
||||
|
@ -18,50 +18,44 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template<typename T>
|
||||
AudioMultiVector<T>::AudioMultiVector(size_t N) {
|
||||
AudioMultiVector::AudioMultiVector(size_t N) {
|
||||
assert(N > 0);
|
||||
if (N < 1) N = 1;
|
||||
for (size_t n = 0; n < N; ++n) {
|
||||
channels_.push_back(new AudioVector<T>);
|
||||
channels_.push_back(new AudioVector<int16_t>);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AudioMultiVector<T>::AudioMultiVector(size_t N, size_t initial_size) {
|
||||
AudioMultiVector::AudioMultiVector(size_t N, size_t initial_size) {
|
||||
assert(N > 0);
|
||||
if (N < 1) N = 1;
|
||||
for (size_t n = 0; n < N; ++n) {
|
||||
channels_.push_back(new AudioVector<T>(initial_size));
|
||||
channels_.push_back(new AudioVector<int16_t>(initial_size));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AudioMultiVector<T>::~AudioMultiVector() {
|
||||
typename std::vector<AudioVector<T>*>::iterator it = channels_.begin();
|
||||
AudioMultiVector::~AudioMultiVector() {
|
||||
std::vector<AudioVector<int16_t>*>::iterator it = channels_.begin();
|
||||
while (it != channels_.end()) {
|
||||
delete (*it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::Clear() {
|
||||
void AudioMultiVector::Clear() {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
channels_[i]->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::Zeros(size_t length) {
|
||||
void AudioMultiVector::Zeros(size_t length) {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
channels_[i]->Clear();
|
||||
channels_[i]->Extend(length);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::CopyFrom(AudioMultiVector<T>* copy_to) const {
|
||||
void AudioMultiVector::CopyFrom(AudioMultiVector* copy_to) const {
|
||||
if (copy_to) {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
channels_[i]->CopyFrom(&(*copy_to)[i]);
|
||||
@ -69,9 +63,8 @@ void AudioMultiVector<T>::CopyFrom(AudioMultiVector<T>* copy_to) const {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::PushBackInterleaved(const T* append_this,
|
||||
size_t length) {
|
||||
void AudioMultiVector::PushBackInterleaved(const int16_t* append_this,
|
||||
size_t length) {
|
||||
assert(length % Channels() == 0);
|
||||
if (Channels() == 1) {
|
||||
// Special case to avoid extra allocation and data shuffling.
|
||||
@ -79,11 +72,12 @@ void AudioMultiVector<T>::PushBackInterleaved(const T* append_this,
|
||||
return;
|
||||
}
|
||||
size_t length_per_channel = length / Channels();
|
||||
T* temp_array = new T[length_per_channel]; // Intermediate storage.
|
||||
int16_t* temp_array =
|
||||
new int16_t[length_per_channel]; // Intermediate storage.
|
||||
for (size_t channel = 0; channel < Channels(); ++channel) {
|
||||
// Copy elements to |temp_array|.
|
||||
// Set |source_ptr| to first element of this channel.
|
||||
const T* source_ptr = &append_this[channel];
|
||||
const int16_t* source_ptr = &append_this[channel];
|
||||
for (size_t i = 0; i < length_per_channel; ++i) {
|
||||
temp_array[i] = *source_ptr;
|
||||
source_ptr += Channels(); // Jump to next element of this channel.
|
||||
@ -93,8 +87,7 @@ void AudioMultiVector<T>::PushBackInterleaved(const T* append_this,
|
||||
delete [] temp_array;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::PushBack(const AudioMultiVector<T>& append_this) {
|
||||
void AudioMultiVector::PushBack(const AudioMultiVector& append_this) {
|
||||
assert(Channels() == append_this.Channels());
|
||||
if (Channels() == append_this.Channels()) {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
@ -103,10 +96,8 @@ void AudioMultiVector<T>::PushBack(const AudioMultiVector<T>& append_this) {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::PushBackFromIndex(
|
||||
const AudioMultiVector<T>& append_this,
|
||||
size_t index) {
|
||||
void AudioMultiVector::PushBackFromIndex(const AudioMultiVector& append_this,
|
||||
size_t index) {
|
||||
assert(index < append_this.Size());
|
||||
index = std::min(index, append_this.Size() - 1);
|
||||
size_t length = append_this.Size() - index;
|
||||
@ -118,30 +109,26 @@ void AudioMultiVector<T>::PushBackFromIndex(
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::PopFront(size_t length) {
|
||||
void AudioMultiVector::PopFront(size_t length) {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
channels_[i]->PopFront(length);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::PopBack(size_t length) {
|
||||
void AudioMultiVector::PopBack(size_t length) {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
channels_[i]->PopBack(length);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t AudioMultiVector<T>::ReadInterleaved(size_t length,
|
||||
T* destination) const {
|
||||
size_t AudioMultiVector::ReadInterleaved(size_t length,
|
||||
int16_t* destination) const {
|
||||
return ReadInterleavedFromIndex(0, length, destination);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t AudioMultiVector<T>::ReadInterleavedFromIndex(size_t start_index,
|
||||
size_t length,
|
||||
T* destination) const {
|
||||
size_t AudioMultiVector::ReadInterleavedFromIndex(size_t start_index,
|
||||
size_t length,
|
||||
int16_t* destination) const {
|
||||
if (!destination) {
|
||||
return 0;
|
||||
}
|
||||
@ -160,17 +147,15 @@ size_t AudioMultiVector<T>::ReadInterleavedFromIndex(size_t start_index,
|
||||
return index;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t AudioMultiVector<T>::ReadInterleavedFromEnd(size_t length,
|
||||
T* destination) const {
|
||||
size_t AudioMultiVector::ReadInterleavedFromEnd(size_t length,
|
||||
int16_t* destination) const {
|
||||
length = std::min(length, Size()); // Cannot read more than Size() elements.
|
||||
return ReadInterleavedFromIndex(Size() - length, length, destination);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::OverwriteAt(const AudioMultiVector<T>& insert_this,
|
||||
size_t length,
|
||||
size_t position) {
|
||||
void AudioMultiVector::OverwriteAt(const AudioMultiVector& insert_this,
|
||||
size_t length,
|
||||
size_t position) {
|
||||
assert(Channels() == insert_this.Channels());
|
||||
// Cap |length| at the length of |insert_this|.
|
||||
assert(length <= insert_this.Size());
|
||||
@ -182,9 +167,8 @@ void AudioMultiVector<T>::OverwriteAt(const AudioMultiVector<T>& insert_this,
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::CrossFade(const AudioMultiVector<T>& append_this,
|
||||
size_t fade_length) {
|
||||
void AudioMultiVector::CrossFade(const AudioMultiVector& append_this,
|
||||
size_t fade_length) {
|
||||
assert(Channels() == append_this.Channels());
|
||||
if (Channels() == append_this.Channels()) {
|
||||
for (size_t i = 0; i < Channels(); ++i) {
|
||||
@ -193,14 +177,12 @@ void AudioMultiVector<T>::CrossFade(const AudioMultiVector<T>& append_this,
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t AudioMultiVector<T>::Size() const {
|
||||
size_t AudioMultiVector::Size() const {
|
||||
assert(channels_[0]);
|
||||
return channels_[0]->Size();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AudioMultiVector<T>::AssertSize(size_t required_size) {
|
||||
void AudioMultiVector::AssertSize(size_t required_size) {
|
||||
if (Size() < required_size) {
|
||||
size_t extend_length = required_size - Size();
|
||||
for (size_t channel = 0; channel < Channels(); ++channel) {
|
||||
@ -209,25 +191,17 @@ void AudioMultiVector<T>::AssertSize(size_t required_size) {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool AudioMultiVector<T>::Empty() const {
|
||||
bool AudioMultiVector::Empty() const {
|
||||
assert(channels_[0]);
|
||||
return channels_[0]->Empty();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const AudioVector<T>& AudioMultiVector<T>::operator[](size_t index) const {
|
||||
const AudioVector<int16_t>& AudioMultiVector::operator[](size_t index) const {
|
||||
return *(channels_[index]);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
AudioVector<T>& AudioMultiVector<T>::operator[](size_t index) {
|
||||
AudioVector<int16_t>& AudioMultiVector::operator[](size_t index) {
|
||||
return *(channels_[index]);
|
||||
}
|
||||
|
||||
// Instantiate the template for a few types.
|
||||
template class AudioMultiVector<int16_t>;
|
||||
template class AudioMultiVector<int32_t>;
|
||||
template class AudioMultiVector<double>;
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
#include "webrtc/modules/audio_coding/neteq4/audio_vector.h"
|
||||
#include "webrtc/system_wrappers/interface/constructor_magic.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <typename T>
|
||||
class AudioMultiVector {
|
||||
public:
|
||||
// Creates an empty AudioMultiVector with |N| audio channels. |N| must be
|
||||
@ -43,23 +43,23 @@ class AudioMultiVector {
|
||||
// are deleted. After the operation is done, |copy_to| will be an exact
|
||||
// replica of this object. The source and the destination must have the same
|
||||
// number of channels.
|
||||
virtual void CopyFrom(AudioMultiVector<T>* copy_to) const;
|
||||
virtual void CopyFrom(AudioMultiVector* copy_to) const;
|
||||
|
||||
// Appends the contents of array |append_this| to the end of this
|
||||
// object. The array is assumed to be channel-interleaved. |length| must be
|
||||
// an even multiple of this object's number of channels.
|
||||
// The length of this object is increased with the |length| divided by the
|
||||
// number of channels.
|
||||
virtual void PushBackInterleaved(const T* append_this, size_t length);
|
||||
virtual void PushBackInterleaved(const int16_t* append_this, size_t length);
|
||||
|
||||
// Appends the contents of AudioMultiVector |append_this| to this object. The
|
||||
// length of this object is increased with the length of |append_this|.
|
||||
virtual void PushBack(const AudioMultiVector<T>& append_this);
|
||||
virtual void PushBack(const AudioMultiVector& append_this);
|
||||
|
||||
// Appends the contents of AudioMultiVector |append_this| to this object,
|
||||
// taken from |index| up until the end of |append_this|. The length of this
|
||||
// object is increased.
|
||||
virtual void PushBackFromIndex(const AudioMultiVector<T>& append_this,
|
||||
virtual void PushBackFromIndex(const AudioMultiVector& append_this,
|
||||
size_t index);
|
||||
|
||||
// Removes |length| elements from the beginning of this object, from each
|
||||
@ -75,18 +75,18 @@ class AudioMultiVector {
|
||||
// returned, i.e., |length| * number of channels. If the AudioMultiVector
|
||||
// contains less than |length| samples per channel, this is reflected in the
|
||||
// return value.
|
||||
virtual size_t ReadInterleaved(size_t length, T* destination) const;
|
||||
virtual size_t ReadInterleaved(size_t length, int16_t* destination) const;
|
||||
|
||||
// Like ReadInterleaved() above, but reads from |start_index| instead of from
|
||||
// the beginning.
|
||||
virtual size_t ReadInterleavedFromIndex(size_t start_index,
|
||||
size_t length,
|
||||
T* destination) const;
|
||||
int16_t* destination) const;
|
||||
|
||||
// Like ReadInterleaved() above, but reads from the end instead of from
|
||||
// the beginning.
|
||||
virtual size_t ReadInterleavedFromEnd(size_t length,
|
||||
T* destination) const;
|
||||
int16_t* destination) const;
|
||||
|
||||
// Overwrites each channel in this AudioMultiVector with values taken from
|
||||
// |insert_this|. The values are taken from the beginning of |insert_this| and
|
||||
@ -95,14 +95,14 @@ class AudioMultiVector {
|
||||
// extends beyond the end of the current AudioVector, the vector is extended
|
||||
// to accommodate the new data. |length| is limited to the length of
|
||||
// |insert_this|.
|
||||
virtual void OverwriteAt(const AudioMultiVector<T>& insert_this,
|
||||
virtual void OverwriteAt(const AudioMultiVector& insert_this,
|
||||
size_t length,
|
||||
size_t position);
|
||||
|
||||
// Appends |append_this| to the end of the current vector. Lets the two
|
||||
// vectors overlap by |fade_length| samples (per channel), and cross-fade
|
||||
// linearly in this region.
|
||||
virtual void CrossFade(const AudioMultiVector<T>& append_this,
|
||||
virtual void CrossFade(const AudioMultiVector& append_this,
|
||||
size_t fade_length);
|
||||
|
||||
// Returns the number of channels.
|
||||
@ -119,11 +119,11 @@ class AudioMultiVector {
|
||||
|
||||
// Accesses and modifies a channel (i.e., an AudioVector object) of this
|
||||
// AudioMultiVector.
|
||||
const AudioVector<T>& operator[](size_t index) const;
|
||||
AudioVector<T>& operator[](size_t index);
|
||||
const AudioVector<int16_t>& operator[](size_t index) const;
|
||||
AudioVector<int16_t>& operator[](size_t index);
|
||||
|
||||
protected:
|
||||
std::vector<AudioVector<T>*> channels_;
|
||||
std::vector<AudioVector<int16_t>*> channels_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AudioMultiVector);
|
||||
|
@ -30,12 +30,10 @@ namespace webrtc {
|
||||
|
||||
class AudioMultiVectorTest : public ::testing::TestWithParam<size_t> {
|
||||
protected:
|
||||
typedef int16_t T; // Use this value type for all tests.
|
||||
|
||||
AudioMultiVectorTest()
|
||||
: num_channels_(GetParam()), // Get the test parameter.
|
||||
interleaved_length_(num_channels_ * array_length()) {
|
||||
array_interleaved_ = new T[num_channels_ * array_length()];
|
||||
array_interleaved_ = new int16_t[num_channels_ * array_length()];
|
||||
}
|
||||
|
||||
~AudioMultiVectorTest() {
|
||||
@ -45,9 +43,9 @@ class AudioMultiVectorTest : public ::testing::TestWithParam<size_t> {
|
||||
virtual void SetUp() {
|
||||
// Populate test arrays.
|
||||
for (size_t i = 0; i < array_length(); ++i) {
|
||||
array_[i] = static_cast<T>(i);
|
||||
array_[i] = static_cast<int16_t>(i);
|
||||
}
|
||||
T* ptr = array_interleaved_;
|
||||
int16_t* ptr = array_interleaved_;
|
||||
// Write 100, 101, 102, ... for first channel.
|
||||
// Write 200, 201, 202, ... for second channel.
|
||||
// And so on.
|
||||
@ -65,20 +63,20 @@ class AudioMultiVectorTest : public ::testing::TestWithParam<size_t> {
|
||||
|
||||
const size_t num_channels_;
|
||||
size_t interleaved_length_;
|
||||
T array_[10];
|
||||
T* array_interleaved_;
|
||||
int16_t array_[10];
|
||||
int16_t* array_interleaved_;
|
||||
};
|
||||
|
||||
// Create and destroy AudioMultiVector objects, both empty and with a predefined
|
||||
// length.
|
||||
TEST_P(AudioMultiVectorTest, CreateAndDestroy) {
|
||||
AudioMultiVector<T> vec1(num_channels_);
|
||||
AudioMultiVector vec1(num_channels_);
|
||||
EXPECT_TRUE(vec1.Empty());
|
||||
EXPECT_EQ(num_channels_, vec1.Channels());
|
||||
EXPECT_EQ(0u, vec1.Size());
|
||||
|
||||
size_t initial_size = 17;
|
||||
AudioMultiVector<T> vec2(num_channels_, initial_size);
|
||||
AudioMultiVector vec2(num_channels_, initial_size);
|
||||
EXPECT_FALSE(vec2.Empty());
|
||||
EXPECT_EQ(num_channels_, vec2.Channels());
|
||||
EXPECT_EQ(initial_size, vec2.Size());
|
||||
@ -86,13 +84,13 @@ TEST_P(AudioMultiVectorTest, CreateAndDestroy) {
|
||||
|
||||
// Test the subscript operator [] for getting and setting.
|
||||
TEST_P(AudioMultiVectorTest, SubscriptOperator) {
|
||||
AudioMultiVector<T> vec(num_channels_, array_length());
|
||||
AudioMultiVector vec(num_channels_, array_length());
|
||||
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
||||
for (size_t i = 0; i < array_length(); ++i) {
|
||||
vec[channel][i] = static_cast<T>(i);
|
||||
vec[channel][i] = static_cast<int16_t>(i);
|
||||
// Make sure to use the const version.
|
||||
const AudioVector<T>& audio_vec = vec[channel];
|
||||
EXPECT_EQ(static_cast<T>(i), audio_vec[i]);
|
||||
const AudioVector<int16_t>& audio_vec = vec[channel];
|
||||
EXPECT_EQ(static_cast<int16_t>(i), audio_vec[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,9 +98,9 @@ TEST_P(AudioMultiVectorTest, SubscriptOperator) {
|
||||
// Test the PushBackInterleaved method and the CopyFrom method. The Clear
|
||||
// method is also invoked.
|
||||
TEST_P(AudioMultiVectorTest, PushBackInterleavedAndCopy) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector vec(num_channels_);
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
AudioMultiVector<T> vec_copy(num_channels_);
|
||||
AudioMultiVector vec_copy(num_channels_);
|
||||
vec.CopyFrom(&vec_copy); // Copy from |vec| to |vec_copy|.
|
||||
ASSERT_EQ(num_channels_, vec.Channels());
|
||||
ASSERT_EQ(array_length(), vec.Size());
|
||||
@ -110,7 +108,7 @@ TEST_P(AudioMultiVectorTest, PushBackInterleavedAndCopy) {
|
||||
ASSERT_EQ(array_length(), vec_copy.Size());
|
||||
for (size_t channel = 0; channel < vec.Channels(); ++channel) {
|
||||
for (size_t i = 0; i < array_length(); ++i) {
|
||||
EXPECT_EQ(static_cast<T>((channel + 1) * 100 + i), vec[channel][i]);
|
||||
EXPECT_EQ(static_cast<int16_t>((channel + 1) * 100 + i), vec[channel][i]);
|
||||
EXPECT_EQ(vec[channel][i], vec_copy[channel][i]);
|
||||
}
|
||||
}
|
||||
@ -126,24 +124,25 @@ TEST_P(AudioMultiVectorTest, PushBackInterleavedAndCopy) {
|
||||
|
||||
// Try to copy to a NULL pointer. Nothing should happen.
|
||||
TEST_P(AudioMultiVectorTest, CopyToNull) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector<T>* vec_copy = NULL;
|
||||
AudioMultiVector vec(num_channels_);
|
||||
AudioMultiVector* vec_copy = NULL;
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
vec.CopyFrom(vec_copy);
|
||||
}
|
||||
|
||||
// Test the PushBack method with another AudioMultiVector as input argument.
|
||||
TEST_P(AudioMultiVectorTest, PushBackVector) {
|
||||
AudioMultiVector<T> vec1(num_channels_, array_length());
|
||||
AudioMultiVector<T> vec2(num_channels_, array_length());
|
||||
AudioMultiVector vec1(num_channels_, array_length());
|
||||
AudioMultiVector vec2(num_channels_, array_length());
|
||||
// Set the first vector to [0, 1, ..., array_length() - 1] +
|
||||
// 100 * channel_number.
|
||||
// Set the second vector to [array_length(), array_length() + 1, ...,
|
||||
// 2 * array_length() - 1] + 100 * channel_number.
|
||||
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
||||
for (size_t i = 0; i < array_length(); ++i) {
|
||||
vec1[channel][i] = static_cast<T>(i + 100 * channel);
|
||||
vec2[channel][i] = static_cast<T>(i + 100 * channel + array_length());
|
||||
vec1[channel][i] = static_cast<int16_t>(i + 100 * channel);
|
||||
vec2[channel][i] =
|
||||
static_cast<int16_t>(i + 100 * channel + array_length());
|
||||
}
|
||||
}
|
||||
// Append vec2 to the back of vec1.
|
||||
@ -151,16 +150,16 @@ TEST_P(AudioMultiVectorTest, PushBackVector) {
|
||||
ASSERT_EQ(2u * array_length(), vec1.Size());
|
||||
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
||||
for (size_t i = 0; i < 2 * array_length(); ++i) {
|
||||
EXPECT_EQ(static_cast<T>(i + 100 * channel), vec1[channel][i]);
|
||||
EXPECT_EQ(static_cast<int16_t>(i + 100 * channel), vec1[channel][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test the PushBackFromIndex method.
|
||||
TEST_P(AudioMultiVectorTest, PushBackFromIndex) {
|
||||
AudioMultiVector<T> vec1(num_channels_);
|
||||
AudioMultiVector vec1(num_channels_);
|
||||
vec1.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
AudioMultiVector<T> vec2(num_channels_);
|
||||
AudioMultiVector vec2(num_channels_);
|
||||
|
||||
// Append vec1 to the back of vec2 (which is empty). Read vec1 from the second
|
||||
// last element.
|
||||
@ -176,7 +175,7 @@ TEST_P(AudioMultiVectorTest, PushBackFromIndex) {
|
||||
|
||||
// Starts with pushing some values to the vector, then test the Zeros method.
|
||||
TEST_P(AudioMultiVectorTest, Zeros) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector vec(num_channels_);
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
vec.Zeros(2 * array_length());
|
||||
ASSERT_EQ(num_channels_, vec.Channels());
|
||||
@ -190,28 +189,30 @@ TEST_P(AudioMultiVectorTest, Zeros) {
|
||||
|
||||
// Test the ReadInterleaved method
|
||||
TEST_P(AudioMultiVectorTest, ReadInterleaved) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector vec(num_channels_);
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
T* output = new T[interleaved_length_];
|
||||
int16_t* output = new int16_t[interleaved_length_];
|
||||
// Read 5 samples.
|
||||
size_t read_samples = 5;
|
||||
EXPECT_EQ(num_channels_ * read_samples,
|
||||
vec.ReadInterleaved(read_samples, output));
|
||||
EXPECT_EQ(0, memcmp(array_interleaved_, output, read_samples * sizeof(T)));
|
||||
EXPECT_EQ(0,
|
||||
memcmp(array_interleaved_, output, read_samples * sizeof(int16_t)));
|
||||
|
||||
// Read too many samples. Expect to get all samples from the vector.
|
||||
EXPECT_EQ(interleaved_length_,
|
||||
vec.ReadInterleaved(array_length() + 1, output));
|
||||
EXPECT_EQ(0, memcmp(array_interleaved_, output, read_samples * sizeof(T)));
|
||||
EXPECT_EQ(0,
|
||||
memcmp(array_interleaved_, output, read_samples * sizeof(int16_t)));
|
||||
|
||||
delete [] output;
|
||||
}
|
||||
|
||||
// Try to read to a NULL pointer. Expected to return 0.
|
||||
TEST_P(AudioMultiVectorTest, ReadInterleavedToNull) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector vec(num_channels_);
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
T* output = NULL;
|
||||
int16_t* output = NULL;
|
||||
// Read 5 samples.
|
||||
size_t read_samples = 5;
|
||||
EXPECT_EQ(0u, vec.ReadInterleaved(read_samples, output));
|
||||
@ -219,13 +220,13 @@ TEST_P(AudioMultiVectorTest, ReadInterleavedToNull) {
|
||||
|
||||
// Test the PopFront method.
|
||||
TEST_P(AudioMultiVectorTest, PopFront) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector vec(num_channels_);
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
vec.PopFront(1); // Remove one element from each channel.
|
||||
ASSERT_EQ(array_length() - 1u, vec.Size());
|
||||
// Let |ptr| point to the second element of the first channel in the
|
||||
// interleaved array.
|
||||
T* ptr = &array_interleaved_[num_channels_];
|
||||
int16_t* ptr = &array_interleaved_[num_channels_];
|
||||
for (size_t i = 0; i < array_length() - 1; ++i) {
|
||||
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
||||
EXPECT_EQ(*ptr, vec[channel][i]);
|
||||
@ -238,13 +239,13 @@ TEST_P(AudioMultiVectorTest, PopFront) {
|
||||
|
||||
// Test the PopBack method.
|
||||
TEST_P(AudioMultiVectorTest, PopBack) {
|
||||
AudioMultiVector<T> vec(num_channels_);
|
||||
AudioMultiVector vec(num_channels_);
|
||||
vec.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
vec.PopBack(1); // Remove one element from each channel.
|
||||
ASSERT_EQ(array_length() - 1u, vec.Size());
|
||||
// Let |ptr| point to the first element of the first channel in the
|
||||
// interleaved array.
|
||||
T* ptr = array_interleaved_;
|
||||
int16_t* ptr = array_interleaved_;
|
||||
for (size_t i = 0; i < array_length() - 1; ++i) {
|
||||
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
||||
EXPECT_EQ(*ptr, vec[channel][i]);
|
||||
@ -257,7 +258,7 @@ TEST_P(AudioMultiVectorTest, PopBack) {
|
||||
|
||||
// Test the AssertSize method.
|
||||
TEST_P(AudioMultiVectorTest, AssertSize) {
|
||||
AudioMultiVector<T> vec(num_channels_, array_length());
|
||||
AudioMultiVector vec(num_channels_, array_length());
|
||||
EXPECT_EQ(array_length(), vec.Size());
|
||||
// Start with asserting with smaller sizes than already allocated.
|
||||
vec.AssertSize(0);
|
||||
@ -276,16 +277,16 @@ TEST_P(AudioMultiVectorTest, AssertSize) {
|
||||
|
||||
// Test the PushBack method with another AudioMultiVector as input argument.
|
||||
TEST_P(AudioMultiVectorTest, OverwriteAt) {
|
||||
AudioMultiVector<T> vec1(num_channels_);
|
||||
AudioMultiVector vec1(num_channels_);
|
||||
vec1.PushBackInterleaved(array_interleaved_, interleaved_length_);
|
||||
AudioMultiVector<T> vec2(num_channels_);
|
||||
AudioMultiVector vec2(num_channels_);
|
||||
vec2.Zeros(3); // 3 zeros in each channel.
|
||||
// Overwrite vec2 at position 5.
|
||||
vec1.OverwriteAt(vec2, 3, 5);
|
||||
// Verify result.
|
||||
// Length remains the same.
|
||||
ASSERT_EQ(array_length(), vec1.Size());
|
||||
T* ptr = array_interleaved_;
|
||||
int16_t* ptr = array_interleaved_;
|
||||
for (size_t i = 0; i < array_length() - 1; ++i) {
|
||||
for (size_t channel = 0; channel < num_channels_; ++channel) {
|
||||
if (i >= 5 && i <= 7) {
|
||||
|
@ -38,7 +38,7 @@ void BackgroundNoise::Reset() {
|
||||
// Keep _bgnMode as it is.
|
||||
}
|
||||
|
||||
void BackgroundNoise::Update(const AudioMultiVector<int16_t>& input,
|
||||
void BackgroundNoise::Update(const AudioMultiVector& input,
|
||||
const PostDecodeVad& vad) {
|
||||
if (vad.running() && vad.active_speech()) {
|
||||
// Do not update the background noise parameters if we know that the signal
|
||||
|
@ -38,7 +38,7 @@ class BackgroundNoise {
|
||||
|
||||
// Updates the parameter estimates based on the signal currently in the
|
||||
// |sync_buffer|, and on the latest decision in |vad| if it is running.
|
||||
void Update(const AudioMultiVector<int16_t>& sync_buffer,
|
||||
void Update(const AudioMultiVector& sync_buffer,
|
||||
const PostDecodeVad& vad);
|
||||
|
||||
// Returns |energy_| for |channel|.
|
||||
|
@ -50,7 +50,7 @@ int ComfortNoise::UpdateParameters(Packet* packet) {
|
||||
}
|
||||
|
||||
int ComfortNoise::Generate(size_t requested_length,
|
||||
AudioMultiVector<int16_t>* output) {
|
||||
AudioMultiVector* output) {
|
||||
// TODO(hlundin): Change to an enumerator and skip assert.
|
||||
assert(fs_hz_ == 8000 || fs_hz_ == 16000 || fs_hz_ == 32000 ||
|
||||
fs_hz_ == 48000);
|
||||
|
@ -53,7 +53,7 @@ class ComfortNoise {
|
||||
// |output|. If this is the first in call after Reset (or first after creating
|
||||
// the object), it will also mix in comfort noise at the end of the
|
||||
// SyncBuffer object provided in the constructor.
|
||||
int Generate(size_t requested_length, AudioMultiVector<int16_t>* output);
|
||||
int Generate(size_t requested_length, AudioMultiVector* output);
|
||||
|
||||
// Returns the last error code that was produced by the comfort noise
|
||||
// decoder. Returns 0 if no error has been encountered since the last reset.
|
||||
|
@ -80,7 +80,7 @@ int DspHelper::RampSignal(int16_t* signal,
|
||||
return RampSignal(signal, length, factor, increment, signal);
|
||||
}
|
||||
|
||||
int DspHelper::RampSignal(AudioMultiVector<int16_t>* signal,
|
||||
int DspHelper::RampSignal(AudioMultiVector* signal,
|
||||
size_t start_index,
|
||||
size_t length,
|
||||
int factor,
|
||||
|
@ -67,7 +67,7 @@ class DspHelper {
|
||||
|
||||
// Same as above, but processes |length| samples from |signal|, starting at
|
||||
// |start_index|.
|
||||
static int RampSignal(AudioMultiVector<int16_t>* signal,
|
||||
static int RampSignal(AudioMultiVector* signal,
|
||||
size_t start_index,
|
||||
size_t length,
|
||||
int factor,
|
||||
|
@ -48,7 +48,7 @@ TEST(DspHelper, RampSignalArray) {
|
||||
TEST(DspHelper, RampSignalAudioMultiVector) {
|
||||
static const int kLen = 100;
|
||||
static const int kChannels = 5;
|
||||
AudioMultiVector<int16_t> input(kChannels, kLen * 3);
|
||||
AudioMultiVector input(kChannels, kLen * 3);
|
||||
// Fill input with 1000.
|
||||
for (int i = 0; i < kLen * 3; ++i) {
|
||||
for (int channel = 0; channel < kChannels; ++channel) {
|
||||
|
@ -150,7 +150,7 @@ void DtmfToneGenerator::Reset() {
|
||||
|
||||
// Generate num_samples of DTMF signal and write to |output|.
|
||||
int DtmfToneGenerator::Generate(int num_samples,
|
||||
AudioMultiVector<int16_t>* output) {
|
||||
AudioMultiVector* output) {
|
||||
if (!initialized_) {
|
||||
return kNotInitialized;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class DtmfToneGenerator {
|
||||
virtual ~DtmfToneGenerator() {}
|
||||
virtual int Init(int fs, int event, int attenuation);
|
||||
virtual void Reset();
|
||||
virtual int Generate(int num_samples, AudioMultiVector<int16_t>* output);
|
||||
virtual int Generate(int num_samples, AudioMultiVector* output);
|
||||
virtual bool initialized() const { return initialized_; }
|
||||
|
||||
private:
|
||||
|
@ -27,7 +27,7 @@ TEST(DtmfToneGenerator, CreateAndDestroy) {
|
||||
TEST(DtmfToneGenerator, TestErrors) {
|
||||
DtmfToneGenerator tone_gen;
|
||||
const int kNumSamples = 10;
|
||||
AudioMultiVector<int16_t> signal(1); // One channel.
|
||||
AudioMultiVector signal(1); // One channel.
|
||||
|
||||
// Try to generate tones without initializing.
|
||||
EXPECT_EQ(DtmfToneGenerator::kNotInitialized,
|
||||
@ -62,7 +62,7 @@ TEST(DtmfToneGenerator, TestTones) {
|
||||
DtmfToneGenerator tone_gen;
|
||||
const int kAttenuation = 0;
|
||||
const int kNumSamples = 10;
|
||||
AudioMultiVector<int16_t> signal(1); // One channel.
|
||||
AudioMultiVector signal(1); // One channel.
|
||||
|
||||
// Low and high frequencies for events 0 through 15.
|
||||
const double low_freq_hz[] = { 941.0, 697.0, 697.0, 697.0, 770.0, 770.0,
|
||||
@ -106,8 +106,8 @@ TEST(DtmfToneGenerator, TestTones) {
|
||||
TEST(DtmfToneGenerator, TestAmplitudes) {
|
||||
DtmfToneGenerator tone_gen;
|
||||
const int kNumSamples = 10;
|
||||
AudioMultiVector<int16_t> signal(1); // One channel.
|
||||
AudioMultiVector<int16_t> ref_signal(1); // One channel.
|
||||
AudioMultiVector signal(1); // One channel.
|
||||
AudioMultiVector ref_signal(1); // One channel.
|
||||
|
||||
const int fs_vec[] = { 8000, 16000, 32000, 48000 };
|
||||
const int event_vec[] = { 0, 4, 9, 13 }; // Test a few events.
|
||||
|
@ -34,7 +34,7 @@ void Expand::Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
int Expand::Process(AudioMultiVector<int16_t>* output) {
|
||||
int Expand::Process(AudioMultiVector* output) {
|
||||
int16_t random_vector[kMaxSampleRate / 8000 * 120 + 30];
|
||||
int16_t scaled_random_vector[kMaxSampleRate / 8000 * 125];
|
||||
static const int kTempDataSize = 3600;
|
||||
|
@ -61,7 +61,7 @@ class Expand {
|
||||
|
||||
// The main method to produce concealment data. The data is appended to the
|
||||
// end of |output|.
|
||||
int Process(AudioMultiVector<int16_t>* output);
|
||||
int Process(AudioMultiVector* output);
|
||||
|
||||
// Prepare the object to do extra expansion during normal operation following
|
||||
// a period of expands.
|
||||
|
@ -25,7 +25,7 @@ namespace webrtc {
|
||||
|
||||
int Merge::Process(int16_t* input, size_t input_length,
|
||||
int16_t* external_mute_factor_array,
|
||||
AudioMultiVector<int16_t>* output) {
|
||||
AudioMultiVector* output) {
|
||||
// TODO(hlundin): Change to an enumerator and skip assert.
|
||||
assert(fs_hz_ == 8000 || fs_hz_ == 16000 || fs_hz_ == 32000 ||
|
||||
fs_hz_ == 48000);
|
||||
@ -37,7 +37,7 @@ int Merge::Process(int16_t* input, size_t input_length,
|
||||
int expanded_length = GetExpandedSignal(&old_length, &expand_period);
|
||||
|
||||
// Transfer input signal to an AudioMultiVector.
|
||||
AudioMultiVector<int16_t> input_vector(num_channels_);
|
||||
AudioMultiVector input_vector(num_channels_);
|
||||
input_vector.PushBackInterleaved(input, input_length);
|
||||
size_t input_length_per_channel = input_vector.Size();
|
||||
assert(input_length_per_channel == input_length / num_channels_);
|
||||
@ -162,7 +162,7 @@ int Merge::GetExpandedSignal(int* old_length, int* expand_period) {
|
||||
// This assert should always be true thanks to the if statement above.
|
||||
assert(210 * kMaxSampleRate / 8000 - *old_length >= 0);
|
||||
|
||||
AudioMultiVector<int16_t> expanded_temp(num_channels_);
|
||||
AudioMultiVector expanded_temp(num_channels_);
|
||||
expand_->Process(&expanded_temp);
|
||||
*expand_period = static_cast<int>(expanded_temp.Size()); // Samples per
|
||||
// channel.
|
||||
|
@ -53,7 +53,7 @@ class Merge {
|
||||
// must have |num_channels_| elements.
|
||||
int Process(int16_t* input, size_t input_length,
|
||||
int16_t* external_mute_factor_array,
|
||||
AudioMultiVector<int16_t>* output);
|
||||
AudioMultiVector* output);
|
||||
|
||||
private:
|
||||
static const int kMaxSampleRate = 48000;
|
||||
@ -95,7 +95,7 @@ class Merge {
|
||||
SyncBuffer* sync_buffer_;
|
||||
int16_t expanded_downsampled_[kExpandDownsampLength];
|
||||
int16_t input_downsampled_[kInputDownsampLength];
|
||||
AudioMultiVector<int16_t> expanded_;
|
||||
AudioMultiVector expanded_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Merge);
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ class MockDtmfToneGenerator : public DtmfToneGenerator {
|
||||
MOCK_METHOD0(Reset,
|
||||
void());
|
||||
MOCK_METHOD2(Generate,
|
||||
int(int num_samples, AudioMultiVector<int16_t>* output));
|
||||
int(int num_samples, AudioMultiVector* output));
|
||||
MOCK_CONST_METHOD0(initialized,
|
||||
bool());
|
||||
};
|
||||
|
@ -1685,7 +1685,7 @@ int NetEqImpl::DtmfOverdub(const DtmfEvent& dtmf_event, size_t num_channels,
|
||||
overdub_length = output_size_samples_ - static_cast<int>(out_index);
|
||||
}
|
||||
|
||||
AudioMultiVector<int16_t> dtmf_output(num_channels);
|
||||
AudioMultiVector dtmf_output(num_channels);
|
||||
int dtmf_return_value = 0;
|
||||
if (!dtmf_tone_generator_->initialized()) {
|
||||
dtmf_return_value = dtmf_tone_generator_->Init(fs_hz_, dtmf_event.event_no,
|
||||
@ -1811,7 +1811,7 @@ void NetEqImpl::SetSampleRateAndChannels(int fs_hz, size_t channels) {
|
||||
vad_->Init();
|
||||
|
||||
// Delete algorithm buffer and create a new one.
|
||||
algorithm_buffer_.reset(new AudioMultiVector<int16_t>(channels));
|
||||
algorithm_buffer_.reset(new AudioMultiVector(channels));
|
||||
|
||||
// Delete sync buffer and create a new one.
|
||||
sync_buffer_.reset(new SyncBuffer(channels, kSyncBufferSize * fs_mult_));
|
||||
|
@ -312,7 +312,7 @@ class NetEqImpl : public webrtc::NetEq {
|
||||
scoped_ptr<TimestampScaler> timestamp_scaler_;
|
||||
scoped_ptr<DecisionLogic> decision_logic_;
|
||||
scoped_ptr<PostDecodeVad> vad_;
|
||||
scoped_ptr<AudioMultiVector<int16_t> > algorithm_buffer_;
|
||||
scoped_ptr<AudioMultiVector> algorithm_buffer_;
|
||||
scoped_ptr<SyncBuffer> sync_buffer_;
|
||||
scoped_ptr<Expand> expand_;
|
||||
scoped_ptr<Normal> normal_;
|
||||
|
@ -28,7 +28,7 @@ int Normal::Process(const int16_t* input,
|
||||
size_t length,
|
||||
Modes last_mode,
|
||||
int16_t* external_mute_factor_array,
|
||||
AudioMultiVector<int16_t>* output) {
|
||||
AudioMultiVector* output) {
|
||||
if (length == 0) {
|
||||
// Nothing to process.
|
||||
output->Clear();
|
||||
@ -55,7 +55,7 @@ int Normal::Process(const int16_t* input,
|
||||
expand_->SetParametersForNormalAfterExpand();
|
||||
|
||||
// Call Expand.
|
||||
AudioMultiVector<int16_t> expanded(output->Channels());
|
||||
AudioMultiVector expanded(output->Channels());
|
||||
expand_->Process(&expanded);
|
||||
expand_->Reset();
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Normal {
|
||||
int Process(const int16_t* input, size_t length,
|
||||
Modes last_mode,
|
||||
int16_t* external_mute_factor_array,
|
||||
AudioMultiVector<int16_t>* output);
|
||||
AudioMultiVector* output);
|
||||
|
||||
private:
|
||||
int fs_hz_;
|
||||
|
@ -20,7 +20,7 @@ PreemptiveExpand::ReturnCodes PreemptiveExpand::Process(
|
||||
const int16_t* input,
|
||||
int input_length,
|
||||
int old_data_length,
|
||||
AudioMultiVector<int16_t>* output,
|
||||
AudioMultiVector* output,
|
||||
int16_t* length_change_samples) {
|
||||
old_data_length_per_channel_ = old_data_length;
|
||||
// Input length must be (almost) 30 ms.
|
||||
@ -56,7 +56,7 @@ void PreemptiveExpand::SetParametersForPassiveSpeech(size_t len,
|
||||
PreemptiveExpand::ReturnCodes PreemptiveExpand::CheckCriteriaAndStretch(
|
||||
const int16_t *input, size_t input_length, size_t peak_index,
|
||||
int16_t best_correlation, bool active_speech,
|
||||
AudioMultiVector<int16_t>* output) const {
|
||||
AudioMultiVector* output) const {
|
||||
// Pre-calculate common multiplication with |fs_mult_|.
|
||||
// 120 corresponds to 15 ms.
|
||||
int fs_mult_120 = fs_mult_ * 120;
|
||||
@ -75,7 +75,7 @@ PreemptiveExpand::ReturnCodes PreemptiveExpand::CheckCriteriaAndStretch(
|
||||
output->PushBackInterleaved(
|
||||
input, (unmodified_length + peak_index) * num_channels_);
|
||||
// Copy the last |peak_index| samples up to 15 ms to |temp_vector|.
|
||||
AudioMultiVector<int16_t> temp_vector(num_channels_);
|
||||
AudioMultiVector temp_vector(num_channels_);
|
||||
temp_vector.PushBackInterleaved(
|
||||
&input[(unmodified_length - peak_index) * num_channels_],
|
||||
peak_index * num_channels_);
|
||||
|
@ -46,7 +46,7 @@ class PreemptiveExpand : public TimeStretch {
|
||||
ReturnCodes Process(const int16_t *pw16_decoded,
|
||||
int len,
|
||||
int old_data_len,
|
||||
AudioMultiVector<int16_t>* output,
|
||||
AudioMultiVector* output,
|
||||
int16_t* length_change_samples);
|
||||
|
||||
protected:
|
||||
@ -61,7 +61,7 @@ class PreemptiveExpand : public TimeStretch {
|
||||
virtual ReturnCodes CheckCriteriaAndStretch(
|
||||
const int16_t *pw16_decoded, size_t len, size_t w16_bestIndex,
|
||||
int16_t w16_bestCorr, bool w16_VAD,
|
||||
AudioMultiVector<int16_t>* output) const;
|
||||
AudioMultiVector* output) const;
|
||||
|
||||
private:
|
||||
int old_data_length_per_channel_;
|
||||
|
@ -20,10 +20,10 @@ size_t SyncBuffer::FutureLength() const {
|
||||
return Size() - next_index_;
|
||||
}
|
||||
|
||||
void SyncBuffer::PushBack(const AudioMultiVector<int16_t>& append_this) {
|
||||
void SyncBuffer::PushBack(const AudioMultiVector& append_this) {
|
||||
size_t samples_added = append_this.Size();
|
||||
AudioMultiVector<int16_t>::PushBack(append_this);
|
||||
AudioMultiVector<int16_t>::PopFront(samples_added);
|
||||
AudioMultiVector::PushBack(append_this);
|
||||
AudioMultiVector::PopFront(samples_added);
|
||||
if (samples_added <= next_index_) {
|
||||
next_index_ -= samples_added;
|
||||
} else {
|
||||
@ -44,7 +44,7 @@ void SyncBuffer::PushFrontZeros(size_t length) {
|
||||
void SyncBuffer::InsertZerosAtIndex(size_t length, size_t position) {
|
||||
position = std::min(position, Size());
|
||||
length = std::min(length, Size() - position);
|
||||
AudioMultiVector<int16_t>::PopBack(length);
|
||||
AudioMultiVector::PopBack(length);
|
||||
for (size_t channel = 0; channel < Channels(); ++channel) {
|
||||
channels_[channel]->InsertZerosAt(length, position);
|
||||
}
|
||||
@ -58,15 +58,15 @@ void SyncBuffer::InsertZerosAtIndex(size_t length, size_t position) {
|
||||
}
|
||||
}
|
||||
|
||||
void SyncBuffer::ReplaceAtIndex(const AudioMultiVector<int16_t>& insert_this,
|
||||
void SyncBuffer::ReplaceAtIndex(const AudioMultiVector& insert_this,
|
||||
size_t length,
|
||||
size_t position) {
|
||||
position = std::min(position, Size()); // Cap |position| in the valid range.
|
||||
length = std::min(length, Size() - position);
|
||||
AudioMultiVector<int16_t>::OverwriteAt(insert_this, length, position);
|
||||
AudioMultiVector::OverwriteAt(insert_this, length, position);
|
||||
}
|
||||
|
||||
void SyncBuffer::ReplaceAtIndex(const AudioMultiVector<int16_t>& insert_this,
|
||||
void SyncBuffer::ReplaceAtIndex(const AudioMultiVector& insert_this,
|
||||
size_t position) {
|
||||
ReplaceAtIndex(insert_this, insert_this.Size(), position);
|
||||
}
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class SyncBuffer : public AudioMultiVector<int16_t> {
|
||||
class SyncBuffer : public AudioMultiVector {
|
||||
public:
|
||||
SyncBuffer(size_t channels, size_t length)
|
||||
: AudioMultiVector<int16_t>(channels, length),
|
||||
: AudioMultiVector(channels, length),
|
||||
next_index_(length),
|
||||
end_timestamp_(0),
|
||||
dtmf_index_(0) {}
|
||||
@ -34,7 +34,7 @@ class SyncBuffer : public AudioMultiVector<int16_t> {
|
||||
// the same number of samples from the beginning of the SyncBuffer, to
|
||||
// maintain a constant buffer size. The |next_index_| is updated to reflect
|
||||
// the move of the beginning of "future" data.
|
||||
void PushBack(const AudioMultiVector<int16_t>& append_this);
|
||||
void PushBack(const AudioMultiVector& append_this);
|
||||
|
||||
// Adds |length| zeros to the beginning of each channel. Removes
|
||||
// the same number of samples from the end of the SyncBuffer, to
|
||||
@ -56,13 +56,13 @@ class SyncBuffer : public AudioMultiVector<int16_t> {
|
||||
// and |position| are selected such that the new data would extend beyond the
|
||||
// end of the current SyncBuffer, the buffer is not extended.
|
||||
// The |next_index_| is not updated.
|
||||
virtual void ReplaceAtIndex(const AudioMultiVector<int16_t>& insert_this,
|
||||
virtual void ReplaceAtIndex(const AudioMultiVector& insert_this,
|
||||
size_t length,
|
||||
size_t position);
|
||||
|
||||
// Same as the above method, but where all of |insert_this| is written (with
|
||||
// the same constraints as above, that the SyncBuffer is not extended).
|
||||
virtual void ReplaceAtIndex(const AudioMultiVector<int16_t>& insert_this,
|
||||
virtual void ReplaceAtIndex(const AudioMultiVector& insert_this,
|
||||
size_t position);
|
||||
|
||||
// Reads |requested_len| samples from each channel and writes them interleaved
|
||||
|
@ -53,7 +53,7 @@ TEST(SyncBuffer, PushBackAndFlush) {
|
||||
static const size_t kChannels = 2;
|
||||
SyncBuffer sync_buffer(kChannels, kLen);
|
||||
static const size_t kNewLen = 10;
|
||||
AudioMultiVector<int16_t> new_data(kChannels, kNewLen);
|
||||
AudioMultiVector new_data(kChannels, kNewLen);
|
||||
// Populate |new_data|.
|
||||
for (size_t channel = 0; channel < kChannels; ++channel) {
|
||||
for (size_t i = 0; i < kNewLen; ++i) {
|
||||
@ -93,7 +93,7 @@ TEST(SyncBuffer, PushFrontZeros) {
|
||||
static const size_t kChannels = 2;
|
||||
SyncBuffer sync_buffer(kChannels, kLen);
|
||||
static const size_t kNewLen = 10;
|
||||
AudioMultiVector<int16_t> new_data(kChannels, kNewLen);
|
||||
AudioMultiVector new_data(kChannels, kNewLen);
|
||||
// Populate |new_data|.
|
||||
for (size_t channel = 0; channel < kChannels; ++channel) {
|
||||
for (size_t i = 0; i < kNewLen; ++i) {
|
||||
@ -126,7 +126,7 @@ TEST(SyncBuffer, GetNextAudioInterleaved) {
|
||||
static const size_t kChannels = 2;
|
||||
SyncBuffer sync_buffer(kChannels, kLen);
|
||||
static const size_t kNewLen = 10;
|
||||
AudioMultiVector<int16_t> new_data(kChannels, kNewLen);
|
||||
AudioMultiVector new_data(kChannels, kNewLen);
|
||||
// Populate |new_data|.
|
||||
for (size_t channel = 0; channel < kChannels; ++channel) {
|
||||
for (size_t i = 0; i < kNewLen; ++i) {
|
||||
|
@ -22,7 +22,7 @@ namespace webrtc {
|
||||
TimeStretch::ReturnCodes TimeStretch::Process(
|
||||
const int16_t* input,
|
||||
size_t input_len,
|
||||
AudioMultiVector<int16_t>* output,
|
||||
AudioMultiVector* output,
|
||||
int16_t* length_change_samples) {
|
||||
|
||||
// Pre-calculate common multiplication with |fs_mult_|.
|
||||
|
@ -58,7 +58,7 @@ class TimeStretch {
|
||||
// PreemptiveExpand.
|
||||
ReturnCodes Process(const int16_t* input,
|
||||
size_t input_len,
|
||||
AudioMultiVector<int16_t>* output,
|
||||
AudioMultiVector* output,
|
||||
int16_t* length_change_samples);
|
||||
|
||||
protected:
|
||||
@ -75,7 +75,7 @@ class TimeStretch {
|
||||
virtual ReturnCodes CheckCriteriaAndStretch(
|
||||
const int16_t* input, size_t input_length, size_t peak_index,
|
||||
int16_t best_correlation, bool active_speech,
|
||||
AudioMultiVector<int16_t>* output) const = 0;
|
||||
AudioMultiVector* output) const = 0;
|
||||
|
||||
static const int kCorrelationLen = 50;
|
||||
static const int kLogCorrelationLen = 6; // >= log2(kCorrelationLen).
|
||||
|
Loading…
x
Reference in New Issue
Block a user