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...) Expand all 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. 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 |
51 // Same as PushFront but will append to the end of this object. | 60 // Same as PushFront but will append to the end of this object. |
52 virtual void PushBack(const int16_t* append_this, size_t length); | 61 virtual void PushBack(const int16_t* append_this, size_t length); |
53 | 62 |
54 // Removes |length| elements from the beginning of this object. | 63 // Removes |length| elements from the beginning of this object. |
55 virtual void PopFront(size_t length); | 64 virtual void PopFront(size_t length); |
56 | 65 |
57 // Removes |length| elements from the end of this object. | 66 // Removes |length| elements from the end of this object. |
58 virtual void PopBack(size_t length); | 67 virtual void PopBack(size_t length); |
59 | 68 |
60 // Extends this object with |extra_length| elements at the end. The new | 69 // Extends this object with |extra_length| elements at the end. The new |
61 // elements are initialized to zero. | 70 // elements are initialized to zero. |
62 virtual void Extend(size_t extra_length); | 71 virtual void Extend(size_t extra_length); |
63 | 72 |
64 // Inserts |length| elements taken from the array |insert_this| and insert | 73 // Inserts |length| elements taken from the array |insert_this| and insert |
65 // them at |position|. The length of the AudioVector is increased by |length|. | 74 // 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. | 75 // |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. | 76 // |position| = Size() means that the new values are appended to the vector. |
68 virtual void InsertAt(const int16_t* insert_this, size_t length, | 77 virtual void InsertAt(const int16_t* insert_this, size_t length, |
69 size_t position); | 78 size_t position); |
70 | 79 |
71 // Like InsertAt, but inserts |length| zero elements at |position|. | 80 // Like InsertAt, but inserts |length| zero elements at |position|. |
72 virtual void InsertZerosAt(size_t length, size_t position); | 81 virtual void InsertZerosAt(size_t length, size_t position); |
73 | 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 |
74 // Overwrites |length| elements of this AudioVector with values taken from the | 92 // Overwrites |length| elements of this AudioVector with values taken from the |
75 // array |insert_this|, starting at |position|. The definition of |position| | 93 // array |insert_this|, starting at |position|. The definition of |position| |
76 // is the same as for InsertAt(). If |length| and |position| are selected | 94 // 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, | 95 // such that the new data extends beyond the end of the current AudioVector, |
78 // the vector is extended to accommodate the new data. | 96 // the vector is extended to accommodate the new data. |
79 virtual void OverwriteAt(const int16_t* insert_this, | 97 virtual void OverwriteAt(const int16_t* insert_this, |
80 size_t length, | 98 size_t length, |
81 size_t position); | 99 size_t position); |
82 | 100 |
83 // Appends |append_this| to the end of the current vector. Lets the two | 101 // 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 | 102 // vectors overlap by |fade_length| samples, and cross-fade linearly in this |
85 // region. | 103 // region. |
86 virtual void CrossFade(const AudioVector& append_this, size_t fade_length); | 104 virtual void CrossFade(const AudioVector& append_this, size_t fade_length); |
87 | 105 |
88 // Returns the number of elements in this AudioVector. | 106 // Returns the number of elements in this AudioVector. |
89 virtual size_t Size() const; | 107 virtual size_t Size() const; |
90 | 108 |
91 // Returns true if this AudioVector is empty. | 109 // Returns true if this AudioVector is empty. |
92 virtual bool Empty() const; | 110 virtual bool Empty() const; |
93 | 111 |
94 // Accesses and modifies an element of AudioVector. | 112 // Accesses and modifies an element of AudioVector. |
95 const int16_t& operator[](size_t index) const; | 113 const int16_t& operator[](size_t index) const; |
96 int16_t& operator[](size_t index); | 114 int16_t& operator[](size_t index); |
97 | 115 |
98 private: | 116 private: |
99 static const size_t kDefaultInitialSize = 10; | 117 static const size_t kDefaultInitialSize = 10; |
100 | 118 |
101 void Reserve(size_t n); | 119 void Reserve(size_t n); |
102 | 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 |
103 std::unique_ptr<int16_t[]> array_; | 131 std::unique_ptr<int16_t[]> array_; |
104 size_t first_free_ix_; // The first index after the last sample in array_. | 132 |
105 // Note that this index may point outside of array_. | |
106 size_t capacity_; // Allocated number of samples in the array. | 133 size_t capacity_; // Allocated number of samples in the array. |
107 | 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 |
108 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); | 142 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); |
109 }; | 143 }; |
110 | 144 |
111 } // namespace webrtc | 145 } // namespace webrtc |
112 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ | 146 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ |
OLD | NEW |