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 |
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ |
13 | 13 |
14 #include <string.h> // Access to size_t. | 14 #include <string.h> // Access to size_t. |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/base/checks.h" | |
17 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
18 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 class AudioVector { | 23 class AudioVector { |
23 public: | 24 public: |
24 // Creates an empty AudioVector. | 25 // Creates an empty AudioVector. |
25 AudioVector(); | 26 AudioVector(); |
26 | 27 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 // region. | 104 // region. |
104 virtual void CrossFade(const AudioVector& append_this, size_t fade_length); | 105 virtual void CrossFade(const AudioVector& append_this, size_t fade_length); |
105 | 106 |
106 // Returns the number of elements in this AudioVector. | 107 // Returns the number of elements in this AudioVector. |
107 virtual size_t Size() const; | 108 virtual size_t Size() const; |
108 | 109 |
109 // Returns true if this AudioVector is empty. | 110 // Returns true if this AudioVector is empty. |
110 virtual bool Empty() const; | 111 virtual bool Empty() const; |
111 | 112 |
112 // Accesses and modifies an element of AudioVector. | 113 // Accesses and modifies an element of AudioVector. |
113 const int16_t& operator[](size_t index) const; | 114 inline const int16_t& operator[](size_t index) const { |
kwiberg-webrtc
2017/02/13 14:44:08
You should also DCHECK that begin_index_ + index d
hlundin-webrtc
2017/02/14 08:49:28
Done.
| |
114 int16_t& operator[](size_t index); | 115 const size_t ix = begin_index_ + index >= capacity_ ? |
116 begin_index_ + index - capacity_ : | |
117 begin_index_ + index; | |
118 RTC_DCHECK_LT(ix, capacity_); | |
119 return array_[ix]; | |
120 } | |
121 | |
122 inline int16_t& operator[](size_t index) { | |
123 const size_t ix = begin_index_ + index >= capacity_ ? | |
124 begin_index_ + index - capacity_ : | |
125 begin_index_ + index; | |
126 RTC_DCHECK_LT(ix, capacity_); | |
kwiberg-webrtc
2017/02/13 14:44:08
Break out the index calculation to a separate func
hlundin-webrtc
2017/02/14 08:49:28
Done.
| |
127 return array_[ix]; | |
128 } | |
115 | 129 |
116 private: | 130 private: |
117 static const size_t kDefaultInitialSize = 10; | 131 static const size_t kDefaultInitialSize = 10; |
118 | 132 |
119 void Reserve(size_t n); | 133 void Reserve(size_t n); |
120 | 134 |
121 void InsertByPushBack(const int16_t* insert_this, size_t length, | 135 void InsertByPushBack(const int16_t* insert_this, size_t length, |
122 size_t position); | 136 size_t position); |
123 | 137 |
124 void InsertByPushFront(const int16_t* insert_this, size_t length, | 138 void InsertByPushFront(const int16_t* insert_this, size_t length, |
(...skipping 12 matching lines...) Expand all Loading... | |
137 size_t begin_index_; | 151 size_t begin_index_; |
138 | 152 |
139 // The index of the sample after the last sample in |array_|. | 153 // The index of the sample after the last sample in |array_|. |
140 size_t end_index_; | 154 size_t end_index_; |
141 | 155 |
142 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); | 156 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); |
143 }; | 157 }; |
144 | 158 |
145 } // namespace webrtc | 159 } // namespace webrtc |
146 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ | 160 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ |
OLD | NEW |