diff --git a/webrtc/modules/audio_coding/neteq4/audio_multi_vector.cc b/webrtc/modules/audio_coding/neteq4/audio_multi_vector.cc index 03baebd77..d3f03a1c6 100644 --- a/webrtc/modules/audio_coding/neteq4/audio_multi_vector.cc +++ b/webrtc/modules/audio_coding/neteq4/audio_multi_vector.cc @@ -22,7 +22,7 @@ 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); + channels_.push_back(new AudioVector); } } @@ -30,12 +30,12 @@ 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(initial_size)); + channels_.push_back(new AudioVector(initial_size)); } } AudioMultiVector::~AudioMultiVector() { - std::vector*>::iterator it = channels_.begin(); + std::vector::iterator it = channels_.begin(); while (it != channels_.end()) { delete (*it); ++it; @@ -196,11 +196,11 @@ bool AudioMultiVector::Empty() const { return channels_[0]->Empty(); } -const AudioVector& AudioMultiVector::operator[](size_t index) const { +const AudioVector& AudioMultiVector::operator[](size_t index) const { return *(channels_[index]); } -AudioVector& AudioMultiVector::operator[](size_t index) { +AudioVector& AudioMultiVector::operator[](size_t index) { return *(channels_[index]); } diff --git a/webrtc/modules/audio_coding/neteq4/audio_multi_vector.h b/webrtc/modules/audio_coding/neteq4/audio_multi_vector.h index ef3a1cf8e..15dc1dc50 100644 --- a/webrtc/modules/audio_coding/neteq4/audio_multi_vector.h +++ b/webrtc/modules/audio_coding/neteq4/audio_multi_vector.h @@ -119,11 +119,11 @@ class AudioMultiVector { // Accesses and modifies a channel (i.e., an AudioVector object) of this // AudioMultiVector. - const AudioVector& operator[](size_t index) const; - AudioVector& operator[](size_t index); + const AudioVector& operator[](size_t index) const; + AudioVector& operator[](size_t index); protected: - std::vector*> channels_; + std::vector channels_; private: DISALLOW_COPY_AND_ASSIGN(AudioMultiVector); diff --git a/webrtc/modules/audio_coding/neteq4/audio_multi_vector_unittest.cc b/webrtc/modules/audio_coding/neteq4/audio_multi_vector_unittest.cc index 15e64d415..be05a8260 100644 --- a/webrtc/modules/audio_coding/neteq4/audio_multi_vector_unittest.cc +++ b/webrtc/modules/audio_coding/neteq4/audio_multi_vector_unittest.cc @@ -89,7 +89,7 @@ TEST_P(AudioMultiVectorTest, SubscriptOperator) { for (size_t i = 0; i < array_length(); ++i) { vec[channel][i] = static_cast(i); // Make sure to use the const version. - const AudioVector& audio_vec = vec[channel]; + const AudioVector& audio_vec = vec[channel]; EXPECT_EQ(static_cast(i), audio_vec[i]); } } diff --git a/webrtc/modules/audio_coding/neteq4/audio_vector.cc b/webrtc/modules/audio_coding/neteq4/audio_vector.cc index c1c2bc285..9711995fd 100644 --- a/webrtc/modules/audio_coding/neteq4/audio_vector.cc +++ b/webrtc/modules/audio_coding/neteq4/audio_vector.cc @@ -18,53 +18,46 @@ namespace webrtc { -template -void AudioVector::Clear() { +void AudioVector::Clear() { vector_.clear(); } -template -void AudioVector::CopyFrom(AudioVector* copy_to) const { +void AudioVector::CopyFrom(AudioVector* copy_to) const { if (copy_to) { copy_to->vector_.assign(vector_.begin(), vector_.end()); } } -template -void AudioVector::PushFront(const AudioVector& prepend_this) { +void AudioVector::PushFront(const AudioVector& prepend_this) { vector_.insert(vector_.begin(), prepend_this.vector_.begin(), prepend_this.vector_.end()); } -template -void AudioVector::PushFront(const T* prepend_this, size_t length) { +void AudioVector::PushFront(const int16_t* prepend_this, size_t length) { // Same operation as InsertAt beginning. InsertAt(prepend_this, length, 0); } -template -void AudioVector::PushBack(const AudioVector& append_this) { +void AudioVector::PushBack(const AudioVector& append_this) { vector_.reserve(vector_.size() + append_this.Size()); for (size_t i = 0; i < append_this.Size(); ++i) { vector_.push_back(append_this[i]); } } -template -void AudioVector::PushBack(const T* append_this, size_t length) { +void AudioVector::PushBack(const int16_t* append_this, size_t length) { vector_.reserve(vector_.size() + length); for (size_t i = 0; i < length; ++i) { vector_.push_back(append_this[i]); } } -template -void AudioVector::PopFront(size_t length) { +void AudioVector::PopFront(size_t length) { if (length >= vector_.size()) { // Remove all elements. vector_.clear(); } else { - typename std::vector::iterator end_range = vector_.begin(); + std::vector::iterator end_range = vector_.begin(); end_range += length; // Erase all elements in range vector_.begin() and |end_range| (not // including |end_range|). @@ -72,23 +65,20 @@ void AudioVector::PopFront(size_t length) { } } -template -void AudioVector::PopBack(size_t length) { +void AudioVector::PopBack(size_t length) { // Make sure that new_size is never negative (which causes wrap-around). size_t new_size = vector_.size() - std::min(length, vector_.size()); vector_.resize(new_size); } -template -void AudioVector::Extend(size_t extra_length) { +void AudioVector::Extend(size_t extra_length) { vector_.insert(vector_.end(), extra_length, 0); } -template -void AudioVector::InsertAt(const T* insert_this, - size_t length, - size_t position) { - typename std::vector::iterator insert_position = vector_.begin(); +void AudioVector::InsertAt(const int16_t* insert_this, + size_t length, + size_t position) { + std::vector::iterator insert_position = vector_.begin(); // Cap the position at the current vector length, to be sure the iterator // does not extend beyond the end of the vector. position = std::min(vector_.size(), position); @@ -102,10 +92,9 @@ void AudioVector::InsertAt(const T* insert_this, } } -template -void AudioVector::InsertZerosAt(size_t length, - size_t position) { - typename std::vector::iterator insert_position = vector_.begin(); +void AudioVector::InsertZerosAt(size_t length, + size_t position) { + std::vector::iterator insert_position = vector_.begin(); // Cap the position at the current vector length, to be sure the iterator // does not extend beyond the end of the vector. position = std::min(vector_.size(), position); @@ -115,10 +104,9 @@ void AudioVector::InsertZerosAt(size_t length, vector_.insert(insert_position, length, 0); } -template -void AudioVector::OverwriteAt(const T* insert_this, - size_t length, - size_t position) { +void AudioVector::OverwriteAt(const int16_t* insert_this, + size_t length, + size_t position) { // Cap the insert position at the current vector length. position = std::min(vector_.size(), position); // Extend the vector if needed. (It is valid to overwrite beyond the current @@ -131,9 +119,8 @@ void AudioVector::OverwriteAt(const T* insert_this, } } -template -void AudioVector::CrossFade(const AudioVector& append_this, - size_t fade_length) { +void AudioVector::CrossFade(const AudioVector& append_this, + size_t fade_length) { // Fade length cannot be longer than the current vector or |append_this|. assert(fade_length <= Size()); assert(fade_length <= append_this.Size()); @@ -158,49 +145,12 @@ void AudioVector::CrossFade(const AudioVector& append_this, PushBack(&append_this[fade_length], samples_to_push_back); } -// Template specialization for double. The only difference is in the calculation -// of the cross-faded value, where we divide by 16384 instead of shifting with -// 14 steps, and also not adding 8192 before scaling. -template<> -void AudioVector::CrossFade(const AudioVector& append_this, - size_t fade_length) { - // Fade length cannot be longer than the current vector or |append_this|. - assert(fade_length <= Size()); - assert(fade_length <= append_this.Size()); - fade_length = std::min(fade_length, Size()); - fade_length = std::min(fade_length, append_this.Size()); - size_t position = Size() - fade_length; - // Cross fade the overlapping regions. - // |alpha| is the mixing factor in Q14. - // TODO(hlundin): Consider skipping +1 in the denominator to produce a - // smoother cross-fade, in particular at the end of the fade. - int alpha_step = 16384 / (static_cast(fade_length) + 1); - int alpha = 16384; - for (size_t i = 0; i < fade_length; ++i) { - alpha -= alpha_step; - vector_[position + i] = (alpha * vector_[position + i] + - (16384 - alpha) * append_this[i]) / 16384; - } - assert(alpha >= 0); // Verify that the slope was correct. - // Append what is left of |append_this|. - size_t samples_to_push_back = append_this.Size() - fade_length; - if (samples_to_push_back > 0) - PushBack(&append_this[fade_length], samples_to_push_back); -} - -template -const T& AudioVector::operator[](size_t index) const { +const int16_t& AudioVector::operator[](size_t index) const { return vector_[index]; } -template -T& AudioVector::operator[](size_t index) { +int16_t& AudioVector::operator[](size_t index) { return vector_[index]; } -// Instantiate the template for a few types. -template class AudioVector; -template class AudioVector; -template class AudioVector; - } // namespace webrtc diff --git a/webrtc/modules/audio_coding/neteq4/audio_vector.h b/webrtc/modules/audio_coding/neteq4/audio_vector.h index 3fd23693d..d8a72ebe8 100644 --- a/webrtc/modules/audio_coding/neteq4/audio_vector.h +++ b/webrtc/modules/audio_coding/neteq4/audio_vector.h @@ -16,10 +16,10 @@ #include #include "webrtc/system_wrappers/interface/constructor_magic.h" +#include "webrtc/typedefs.h" namespace webrtc { -template class AudioVector { public: // Creates an empty AudioVector. @@ -37,21 +37,21 @@ class AudioVector { // Copies all values from this vector to |copy_to|. Any contents in |copy_to| // are deleted before the copy operation. After the operation is done, // |copy_to| will be an exact replica of this object. - virtual void CopyFrom(AudioVector* copy_to) const; + virtual void CopyFrom(AudioVector* copy_to) const; // Prepends the contents of AudioVector |prepend_this| to this object. The // length of this object is increased with the length of |prepend_this|. - virtual void PushFront(const AudioVector& prepend_this); + virtual void PushFront(const AudioVector& prepend_this); // Same as above, but with an array |prepend_this| with |length| elements as // source. - virtual void PushFront(const T* prepend_this, size_t length); + virtual void PushFront(const int16_t* prepend_this, size_t length); // Same as PushFront but will append to the end of this object. - virtual void PushBack(const AudioVector& append_this); + virtual void PushBack(const AudioVector& append_this); // Same as PushFront but will append to the end of this object. - virtual void PushBack(const T* append_this, size_t length); + virtual void PushBack(const int16_t* append_this, size_t length); // Removes |length| elements from the beginning of this object. virtual void PopFront(size_t length); @@ -67,7 +67,8 @@ class AudioVector { // them at |position|. The length of the AudioVector is increased by |length|. // |position| = 0 means that the new values are prepended to the vector. // |position| = Size() means that the new values are appended to the vector. - virtual void InsertAt(const T* insert_this, size_t length, size_t position); + virtual void InsertAt(const int16_t* insert_this, size_t length, + size_t position); // Like InsertAt, but inserts |length| zero elements at |position|. virtual void InsertZerosAt(size_t length, size_t position); @@ -77,14 +78,14 @@ class AudioVector { // is the same as for InsertAt(). If |length| and |position| are selected // such that the new data extends beyond the end of the current AudioVector, // the vector is extended to accommodate the new data. - virtual void OverwriteAt(const T* insert_this, + virtual void OverwriteAt(const int16_t* 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, and cross-fade linearly in this // region. - virtual void CrossFade(const AudioVector& append_this, size_t fade_length); + virtual void CrossFade(const AudioVector& append_this, size_t fade_length); // Returns the number of elements in this AudioVector. virtual size_t Size() const { return vector_.size(); } @@ -93,11 +94,11 @@ class AudioVector { virtual bool Empty() const { return vector_.empty(); } // Accesses and modifies an element of AudioVector. - const T& operator[](size_t index) const; - T& operator[](size_t index); + const int16_t& operator[](size_t index) const; + int16_t& operator[](size_t index); private: - std::vector vector_; + std::vector vector_; DISALLOW_COPY_AND_ASSIGN(AudioVector); }; diff --git a/webrtc/modules/audio_coding/neteq4/audio_vector_unittest.cc b/webrtc/modules/audio_coding/neteq4/audio_vector_unittest.cc index a7ddbb416..de5aac2d9 100644 --- a/webrtc/modules/audio_coding/neteq4/audio_vector_unittest.cc +++ b/webrtc/modules/audio_coding/neteq4/audio_vector_unittest.cc @@ -39,19 +39,19 @@ class AudioVectorTest : public ::testing::Test { // Create and destroy AudioVector objects, both empty and with a predefined // length. TEST_F(AudioVectorTest, CreateAndDestroy) { - AudioVector vec1; + AudioVector vec1; EXPECT_TRUE(vec1.Empty()); EXPECT_EQ(0u, vec1.Size()); size_t initial_size = 17; - AudioVector vec2(initial_size); + AudioVector vec2(initial_size); EXPECT_FALSE(vec2.Empty()); EXPECT_EQ(initial_size, vec2.Size()); } // Test the subscript operator [] for getting and setting. TEST_F(AudioVectorTest, SubscriptOperator) { - AudioVector vec(array_length()); + AudioVector vec(array_length()); for (size_t i = 0; i < array_length(); ++i) { vec[i] = static_cast(i); const int16_t& value = vec[i]; // Make sure to use the const version. @@ -62,8 +62,8 @@ TEST_F(AudioVectorTest, SubscriptOperator) { // Test the PushBack method and the CopyFrom method. The Clear method is also // invoked. TEST_F(AudioVectorTest, PushBackAndCopy) { - AudioVector vec; - AudioVector vec_copy; + AudioVector vec; + AudioVector vec_copy; vec.PushBack(array_, array_length()); vec.CopyFrom(&vec_copy); // Copy from |vec| to |vec_copy|. ASSERT_EQ(array_length(), vec.Size()); @@ -84,8 +84,8 @@ TEST_F(AudioVectorTest, PushBackAndCopy) { // Try to copy to a NULL pointer. Nothing should happen. TEST_F(AudioVectorTest, CopyToNull) { - AudioVector vec; - AudioVector* vec_copy = NULL; + AudioVector vec; + AudioVector* vec_copy = NULL; vec.PushBack(array_, array_length()); vec.CopyFrom(vec_copy); } @@ -93,8 +93,8 @@ TEST_F(AudioVectorTest, CopyToNull) { // Test the PushBack method with another AudioVector as input argument. TEST_F(AudioVectorTest, PushBackVector) { static const size_t kLength = 10; - AudioVector vec1(kLength); - AudioVector vec2(kLength); + AudioVector vec1(kLength); + AudioVector vec2(kLength); // Set the first vector to [0, 1, ..., kLength - 1]. // Set the second vector to [kLength, kLength + 1, ..., 2 * kLength - 1]. for (size_t i = 0; i < kLength; ++i) { @@ -111,7 +111,7 @@ TEST_F(AudioVectorTest, PushBackVector) { // Test the PushFront method. TEST_F(AudioVectorTest, PushFront) { - AudioVector vec; + AudioVector vec; vec.PushFront(array_, array_length()); ASSERT_EQ(array_length(), vec.Size()); for (size_t i = 0; i < array_length(); ++i) { @@ -122,8 +122,8 @@ TEST_F(AudioVectorTest, PushFront) { // Test the PushFront method with another AudioVector as input argument. TEST_F(AudioVectorTest, PushFrontVector) { static const size_t kLength = 10; - AudioVector vec1(kLength); - AudioVector vec2(kLength); + AudioVector vec1(kLength); + AudioVector vec2(kLength); // Set the first vector to [0, 1, ..., kLength - 1]. // Set the second vector to [kLength, kLength + 1, ..., 2 * kLength - 1]. for (size_t i = 0; i < kLength; ++i) { @@ -140,7 +140,7 @@ TEST_F(AudioVectorTest, PushFrontVector) { // Test the PopFront method. TEST_F(AudioVectorTest, PopFront) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); vec.PopFront(1); // Remove one element. EXPECT_EQ(array_length() - 1u, vec.Size()); @@ -153,7 +153,7 @@ TEST_F(AudioVectorTest, PopFront) { // Test the PopBack method. TEST_F(AudioVectorTest, PopBack) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); vec.PopBack(1); // Remove one element. EXPECT_EQ(array_length() - 1u, vec.Size()); @@ -166,7 +166,7 @@ TEST_F(AudioVectorTest, PopBack) { // Test the Extend method. TEST_F(AudioVectorTest, Extend) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); vec.Extend(5); // Extend with 5 elements, which should all be zeros. ASSERT_EQ(array_length() + 5u, vec.Size()); @@ -178,7 +178,7 @@ TEST_F(AudioVectorTest, Extend) { // Test the InsertAt method with an insert position in the middle of the vector. TEST_F(AudioVectorTest, InsertAt) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); static const int kNewLength = 5; int16_t new_array[kNewLength]; @@ -209,8 +209,8 @@ TEST_F(AudioVectorTest, InsertAt) { // Test the InsertZerosAt method with an insert position in the middle of the // vector. Use the InsertAt method as reference. TEST_F(AudioVectorTest, InsertZerosAt) { - AudioVector vec; - AudioVector vec_ref; + AudioVector vec; + AudioVector vec_ref; vec.PushBack(array_, array_length()); vec_ref.PushBack(array_, array_length()); static const int kNewLength = 5; @@ -227,7 +227,7 @@ TEST_F(AudioVectorTest, InsertZerosAt) { // Test the InsertAt method with an insert position at the start of the vector. TEST_F(AudioVectorTest, InsertAtBeginning) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); static const int kNewLength = 5; int16_t new_array[kNewLength]; @@ -253,7 +253,7 @@ TEST_F(AudioVectorTest, InsertAtBeginning) { // Test the InsertAt method with an insert position at the end of the vector. TEST_F(AudioVectorTest, InsertAtEnd) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); static const int kNewLength = 5; int16_t new_array[kNewLength]; @@ -282,7 +282,7 @@ TEST_F(AudioVectorTest, InsertAtEnd) { // input position. That is, the input position should be capped at the maximum // allowed value. TEST_F(AudioVectorTest, InsertBeyondEnd) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); static const int kNewLength = 5; int16_t new_array[kNewLength]; @@ -308,7 +308,7 @@ TEST_F(AudioVectorTest, InsertBeyondEnd) { // Test the OverwriteAt method with a position such that all of the new values // fit within the old vector. TEST_F(AudioVectorTest, OverwriteAt) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); static const int kNewLength = 5; int16_t new_array[kNewLength]; @@ -338,7 +338,7 @@ TEST_F(AudioVectorTest, OverwriteAt) { // extend beyond the end of the current vector. This is valid, and the vector is // expected to expand to accommodate the new values. TEST_F(AudioVectorTest, OverwriteBeyondEnd) { - AudioVector vec; + AudioVector vec; vec.PushBack(array_, array_length()); static const int kNewLength = 5; int16_t new_array[kNewLength]; @@ -367,8 +367,8 @@ TEST_F(AudioVectorTest, OverwriteBeyondEnd) { TEST_F(AudioVectorTest, CrossFade) { static const size_t kLength = 100; static const size_t kFadeLength = 10; - AudioVector vec1(kLength); - AudioVector vec2(kLength); + AudioVector vec1(kLength); + AudioVector vec2(kLength); // Set all vector elements to 0 in |vec1| and 100 in |vec2|. for (size_t i = 0; i < kLength; ++i) { vec1[i] = 0; diff --git a/webrtc/modules/audio_coding/neteq4/expand.h b/webrtc/modules/audio_coding/neteq4/expand.h index f7f19e262..25ae61903 100644 --- a/webrtc/modules/audio_coding/neteq4/expand.h +++ b/webrtc/modules/audio_coding/neteq4/expand.h @@ -116,8 +116,8 @@ class Expand { int16_t ar_gain_scale; int16_t voice_mix_factor; /* Q14 */ int16_t current_voice_mix_factor; /* Q14 */ - AudioVector expand_vector0; - AudioVector expand_vector1; + AudioVector expand_vector0; + AudioVector expand_vector1; bool onset; int16_t mute_slope; /* Q20 */ }; diff --git a/webrtc/modules/audio_coding/neteq4/sync_buffer.h b/webrtc/modules/audio_coding/neteq4/sync_buffer.h index cfd35fc88..e1e5daf1b 100644 --- a/webrtc/modules/audio_coding/neteq4/sync_buffer.h +++ b/webrtc/modules/audio_coding/neteq4/sync_buffer.h @@ -78,7 +78,7 @@ class SyncBuffer : public AudioMultiVector { // created. void Flush(); - const AudioVector& Channel(size_t n) { return *channels_[n]; } + const AudioVector& Channel(size_t n) { return *channels_[n]; } // Accessors and mutators. size_t next_index() const { return next_index_; }