OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 19 matching lines...) Loading... |
30 virtual ~AudioVector(); | 30 virtual ~AudioVector(); |
31 | 31 |
32 // Deletes all values and make the vector empty. | 32 // Deletes all values and make the vector empty. |
33 virtual void Clear(); | 33 virtual void Clear(); |
34 | 34 |
35 // Copies all values from this vector to |copy_to|. Any contents in |copy_to| | 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, | 36 // are deleted before the copy operation. After the operation is done, |
37 // |copy_to| will be an exact replica of this object. | 37 // |copy_to| will be an exact replica of this object. |
38 virtual void CopyTo(AudioVector* copy_to) const; | 38 virtual void CopyTo(AudioVector* copy_to) const; |
39 | 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 |
40 // Prepends the contents of AudioVector |prepend_this| to this object. The | 43 // Prepends the contents of AudioVector |prepend_this| to this object. The |
41 // length of this object is increased with the length of |prepend_this|. | 44 // length of this object is increased with the length of |prepend_this|. |
42 virtual void PushFront(const AudioVector& prepend_this); | 45 virtual void PushFront(const AudioVector& prepend_this); |
43 | 46 |
44 // Same as above, but with an array |prepend_this| with |length| elements as | 47 // Same as above, but with an array |prepend_this| with |length| elements as |
45 // source. | 48 // source. |
46 virtual void PushFront(const int16_t* prepend_this, size_t length); | 49 virtual void PushFront(const int16_t* prepend_this, size_t length); |
47 | 50 |
48 // Same as PushFront but will append to the end of this object. | 51 // Same as PushFront but will append to the end of this object. |
49 virtual void PushBack(const AudioVector& append_this); | 52 virtual void PushBack(const AudioVector& append_this); |
50 | 53 |
| 54 // Appends a segment of |append_this| to the end of this object. |
| 55 virtual void PushBack(const AudioVector& append_this, |
| 56 size_t length, |
| 57 size_t position); |
| 58 |
51 // Same as PushFront but will append to the end of this object. | 59 // Same as PushFront but will append to the end of this object. |
52 virtual void PushBack(const int16_t* append_this, size_t length); | 60 virtual void PushBack(const int16_t* append_this, size_t length); |
53 | 61 |
54 // Removes |length| elements from the beginning of this object. | 62 // Removes |length| elements from the beginning of this object. |
55 virtual void PopFront(size_t length); | 63 virtual void PopFront(size_t length); |
56 | 64 |
57 // Removes |length| elements from the end of this object. | 65 // Removes |length| elements from the end of this object. |
58 virtual void PopBack(size_t length); | 66 virtual void PopBack(size_t length); |
59 | 67 |
60 // Extends this object with |extra_length| elements at the end. The new | 68 // Extends this object with |extra_length| elements at the end. The new |
61 // elements are initialized to zero. | 69 // elements are initialized to zero. |
62 virtual void Extend(size_t extra_length); | 70 virtual void Extend(size_t extra_length); |
63 | 71 |
64 // Inserts |length| elements taken from the array |insert_this| and insert | 72 // Inserts |length| elements taken from the array |insert_this| and insert |
65 // them at |position|. The length of the AudioVector is increased by |length|. | 73 // them at |position|. The length of the AudioVector is increased by |length|. |
66 // |position| = 0 means that the new values are prepended to the vector. | 74 // |position| = 0 means that the new values are prepended to the vector. |
67 // |position| = Size() means that the new values are appended to the vector. | 75 // |position| = Size() means that the new values are appended to the vector. |
68 virtual void InsertAt(const int16_t* insert_this, size_t length, | 76 virtual void InsertAt(const int16_t* insert_this, size_t length, |
69 size_t position); | 77 size_t position); |
70 | 78 |
71 // Like InsertAt, but inserts |length| zero elements at |position|. | 79 // Like InsertAt, but inserts |length| zero elements at |position|. |
72 virtual void InsertZerosAt(size_t length, size_t position); | 80 virtual void InsertZerosAt(size_t length, size_t position); |
73 | 81 |
| 82 // Overwrites |length| elements of this AudioVector starting from |position| |
| 83 // with first values in |AudioVector|. The definition of |position| |
| 84 // is the same as for InsertAt(). If |length| and |position| are selected |
| 85 // such that the new data extends beyond the end of the current AudioVector, |
| 86 // the vector is extended to accommodate the new data. |
| 87 virtual void OverwriteAt(const AudioVector& insert_this, |
| 88 size_t length, |
| 89 size_t position); |
| 90 |
74 // Overwrites |length| elements of this AudioVector with values taken from the | 91 // Overwrites |length| elements of this AudioVector with values taken from the |
75 // array |insert_this|, starting at |position|. The definition of |position| | 92 // array |insert_this|, starting at |position|. The definition of |position| |
76 // is the same as for InsertAt(). If |length| and |position| are selected | 93 // is the same as for InsertAt(). If |length| and |position| are selected |
77 // such that the new data extends beyond the end of the current AudioVector, | 94 // such that the new data extends beyond the end of the current AudioVector, |
78 // the vector is extended to accommodate the new data. | 95 // the vector is extended to accommodate the new data. |
79 virtual void OverwriteAt(const int16_t* insert_this, | 96 virtual void OverwriteAt(const int16_t* insert_this, |
80 size_t length, | 97 size_t length, |
81 size_t position); | 98 size_t position); |
82 | 99 |
83 // Appends |append_this| to the end of the current vector. Lets the two | 100 // Appends |append_this| to the end of the current vector. Lets the two |
84 // vectors overlap by |fade_length| samples, and cross-fade linearly in this | 101 // vectors overlap by |fade_length| samples, and cross-fade linearly in this |
85 // region. | 102 // region. |
86 virtual void CrossFade(const AudioVector& append_this, size_t fade_length); | 103 virtual void CrossFade(const AudioVector& append_this, size_t fade_length); |
87 | 104 |
88 // Returns the number of elements in this AudioVector. | 105 // Returns the number of elements in this AudioVector. |
89 virtual size_t Size() const; | 106 virtual size_t Size() const; |
90 | 107 |
91 // Returns true if this AudioVector is empty. | 108 // Returns true if this AudioVector is empty. |
92 virtual bool Empty() const; | 109 virtual bool Empty() const; |
93 | 110 |
94 // Accesses and modifies an element of AudioVector. | 111 // Accesses and modifies an element of AudioVector. |
95 const int16_t& operator[](size_t index) const; | 112 const int16_t& operator[](size_t index) const; |
96 int16_t& operator[](size_t index); | 113 int16_t& operator[](size_t index); |
97 | 114 |
98 private: | 115 private: |
99 static const size_t kDefaultInitialSize = 10; | 116 static const size_t kDefaultInitialSize = 10; |
100 | 117 |
101 void Reserve(size_t n); | 118 void Reserve(size_t n); |
102 | 119 |
| 120 void InsertByPushBack(const int16_t* insert_this, size_t length, |
| 121 size_t position); |
| 122 |
| 123 void InsertByPushFront(const int16_t* insert_this, size_t length, |
| 124 size_t position); |
| 125 |
| 126 void InsertZerosByPushBack(size_t length, size_t position); |
| 127 |
| 128 void InsertZerosByPushFront(size_t length, size_t position); |
| 129 |
103 std::unique_ptr<int16_t[]> array_; | 130 std::unique_ptr<int16_t[]> array_; |
104 size_t first_free_ix_; // The first index after the last sample in array_. | 131 |
105 // Note that this index may point outside of array_. | |
106 size_t capacity_; // Allocated number of samples in the array. | 132 size_t capacity_; // Allocated number of samples in the array. |
107 | 133 |
| 134 // The index of the first sample in |array_|, except when |
| 135 // |begin_index_ == end_index_|, which indicates an empty buffer. |
| 136 size_t begin_index_; |
| 137 |
| 138 // The index of the sample after the last sample in |array_|. |
| 139 size_t end_index_; |
| 140 |
108 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); | 141 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); |
109 }; | 142 }; |
110 | 143 |
111 } // namespace webrtc | 144 } // namespace webrtc |
112 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ | 145 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ |
OLD | NEW |