Reimplementing NetEq4's AudioVector
The current implementation using std::vector is too slow. This CL introduces a new implementation, using a regular array as data container. In AudioMultiVector::ReadInterleavedFromIndex, a special case for 1 channel was implemented, to further reduce runtime. Finally, AudioMultiVector::Channels was reimplemented. The changes in this CL reduces the runtime of neteq4_speed_test by 33%. BUG=1363 R=turaj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/3509004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5115 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -13,9 +13,8 @@
|
||||
|
||||
#include <string.h> // Access to size_t.
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/system_wrappers/interface/constructor_magic.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -23,11 +22,18 @@ namespace webrtc {
|
||||
class AudioVector {
|
||||
public:
|
||||
// Creates an empty AudioVector.
|
||||
AudioVector() {}
|
||||
AudioVector()
|
||||
: array_(new int16_t[kDefaultInitialSize]),
|
||||
first_free_ix_(0),
|
||||
capacity_(kDefaultInitialSize) {}
|
||||
|
||||
// Creates an AudioVector with an initial size.
|
||||
explicit AudioVector(size_t initial_size)
|
||||
: vector_(initial_size, 0) {}
|
||||
: array_(new int16_t[initial_size]),
|
||||
first_free_ix_(initial_size),
|
||||
capacity_(initial_size) {
|
||||
memset(array_.get(), 0, initial_size * sizeof(int16_t));
|
||||
}
|
||||
|
||||
virtual ~AudioVector() {}
|
||||
|
||||
@ -88,17 +94,24 @@ class AudioVector {
|
||||
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(); }
|
||||
virtual size_t Size() const { return first_free_ix_; }
|
||||
|
||||
// Returns true if this AudioVector is empty.
|
||||
virtual bool Empty() const { return vector_.empty(); }
|
||||
virtual bool Empty() const { return (first_free_ix_ == 0); }
|
||||
|
||||
// Accesses and modifies an element of AudioVector.
|
||||
const int16_t& operator[](size_t index) const;
|
||||
int16_t& operator[](size_t index);
|
||||
|
||||
private:
|
||||
std::vector<int16_t> vector_;
|
||||
static const size_t kDefaultInitialSize = 10;
|
||||
|
||||
void Reserve(size_t n);
|
||||
|
||||
scoped_ptr<int16_t[]> array_;
|
||||
size_t first_free_ix_; // The first index after the last sample in array_.
|
||||
// Note that this index may point outside of array_.
|
||||
size_t capacity_; // Allocated number of samples in the array.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AudioVector);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user