Line data Source code
1 : /*
2 : * Copyright (c) 2012 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_CODING_NETEQ_AUDIO_VECTOR_H_
12 : #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_
13 :
14 : #include <string.h> // Access to size_t.
15 : #include <memory>
16 :
17 : #include "webrtc/base/constructormagic.h"
18 : #include "webrtc/typedefs.h"
19 :
20 : namespace webrtc {
21 :
22 0 : class AudioVector {
23 : public:
24 : // Creates an empty AudioVector.
25 : AudioVector();
26 :
27 : // Creates an AudioVector with an initial size.
28 : explicit AudioVector(size_t initial_size);
29 :
30 : virtual ~AudioVector();
31 :
32 : // Deletes all values and make the vector empty.
33 : virtual void Clear();
34 :
35 : // Copies all values from this vector to |copy_to|. Any contents in |copy_to|
36 : // are deleted before the copy operation. After the operation is done,
37 : // |copy_to| will be an exact replica of this object.
38 : virtual void CopyTo(AudioVector* copy_to) const;
39 :
40 : // Copies |length| values from |position| in this vector to |copy_to|.
41 : virtual void CopyTo(size_t length, size_t position, int16_t* copy_to) const;
42 :
43 : // Prepends the contents of AudioVector |prepend_this| to this object. The
44 : // length of this object is increased with the length of |prepend_this|.
45 : virtual void PushFront(const AudioVector& prepend_this);
46 :
47 : // Same as above, but with an array |prepend_this| with |length| elements as
48 : // source.
49 : virtual void PushFront(const int16_t* prepend_this, size_t length);
50 :
51 : // Same as PushFront but will append to the end of this object.
52 : virtual void PushBack(const AudioVector& append_this);
53 :
54 : // Appends a segment of |append_this| to the end of this object. The segment
55 : // starts from |position| and has |length| samples.
56 : virtual void PushBack(const AudioVector& append_this,
57 : size_t length,
58 : size_t position);
59 :
60 : // Same as PushFront but will append to the end of this object.
61 : virtual void PushBack(const int16_t* append_this, size_t length);
62 :
63 : // Removes |length| elements from the beginning of this object.
64 : virtual void PopFront(size_t length);
65 :
66 : // Removes |length| elements from the end of this object.
67 : virtual void PopBack(size_t length);
68 :
69 : // Extends this object with |extra_length| elements at the end. The new
70 : // elements are initialized to zero.
71 : virtual void Extend(size_t extra_length);
72 :
73 : // Inserts |length| elements taken from the array |insert_this| and insert
74 : // them at |position|. The length of the AudioVector is increased by |length|.
75 : // |position| = 0 means that the new values are prepended to the vector.
76 : // |position| = Size() means that the new values are appended to the vector.
77 : virtual void InsertAt(const int16_t* insert_this, size_t length,
78 : size_t position);
79 :
80 : // Like InsertAt, but inserts |length| zero elements at |position|.
81 : virtual void InsertZerosAt(size_t length, size_t position);
82 :
83 : // Overwrites |length| elements of this AudioVector starting from |position|
84 : // with first values in |AudioVector|. The definition of |position|
85 : // is the same as for InsertAt(). If |length| and |position| are selected
86 : // such that the new data extends beyond the end of the current AudioVector,
87 : // the vector is extended to accommodate the new data.
88 : virtual void OverwriteAt(const AudioVector& insert_this,
89 : size_t length,
90 : size_t position);
91 :
92 : // Overwrites |length| elements of this AudioVector with values taken from the
93 : // array |insert_this|, starting at |position|. The definition of |position|
94 : // is the same as for InsertAt(). If |length| and |position| are selected
95 : // such that the new data extends beyond the end of the current AudioVector,
96 : // the vector is extended to accommodate the new data.
97 : virtual void OverwriteAt(const int16_t* insert_this,
98 : size_t length,
99 : size_t position);
100 :
101 : // Appends |append_this| to the end of the current vector. Lets the two
102 : // vectors overlap by |fade_length| samples, and cross-fade linearly in this
103 : // region.
104 : virtual void CrossFade(const AudioVector& append_this, size_t fade_length);
105 :
106 : // Returns the number of elements in this AudioVector.
107 : virtual size_t Size() const;
108 :
109 : // Returns true if this AudioVector is empty.
110 : virtual bool Empty() const;
111 :
112 : // Accesses and modifies an element of AudioVector.
113 : const int16_t& operator[](size_t index) const;
114 : int16_t& operator[](size_t index);
115 :
116 : private:
117 : static const size_t kDefaultInitialSize = 10;
118 :
119 : void Reserve(size_t n);
120 :
121 : void InsertByPushBack(const int16_t* insert_this, size_t length,
122 : size_t position);
123 :
124 : void InsertByPushFront(const int16_t* insert_this, size_t length,
125 : size_t position);
126 :
127 : void InsertZerosByPushBack(size_t length, size_t position);
128 :
129 : void InsertZerosByPushFront(size_t length, size_t position);
130 :
131 : std::unique_ptr<int16_t[]> array_;
132 :
133 : size_t capacity_; // Allocated number of samples in the array.
134 :
135 : // The index of the first sample in |array_|, except when
136 : // |begin_index_ == end_index_|, which indicates an empty buffer.
137 : size_t begin_index_;
138 :
139 : // The index of the sample after the last sample in |array_|.
140 : size_t end_index_;
141 :
142 : RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector);
143 : };
144 :
145 : } // namespace webrtc
146 : #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_
|