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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 void AudioMultiVector::PushBackFromIndex(const AudioMultiVector& append_this, | 101 void AudioMultiVector::PushBackFromIndex(const AudioMultiVector& append_this, |
102 size_t index) { | 102 size_t index) { |
103 assert(index < append_this.Size()); | 103 assert(index < append_this.Size()); |
104 index = std::min(index, append_this.Size() - 1); | 104 index = std::min(index, append_this.Size() - 1); |
105 size_t length = append_this.Size() - index; | 105 size_t length = append_this.Size() - index; |
106 assert(num_channels_ == append_this.num_channels_); | 106 assert(num_channels_ == append_this.num_channels_); |
107 if (num_channels_ == append_this.num_channels_) { | 107 if (num_channels_ == append_this.num_channels_) { |
108 for (size_t i = 0; i < num_channels_; ++i) { | 108 for (size_t i = 0; i < num_channels_; ++i) { |
109 channels_[i]->PushBack(&append_this[i][index], length); | 109 channels_[i]->PushBack(append_this[i], length, index); |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void AudioMultiVector::PopFront(size_t length) { | 114 void AudioMultiVector::PopFront(size_t length) { |
115 for (size_t i = 0; i < num_channels_; ++i) { | 115 for (size_t i = 0; i < num_channels_; ++i) { |
116 channels_[i]->PopFront(length); | 116 channels_[i]->PopFront(length); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 void AudioMultiVector::PopBack(size_t length) { | 120 void AudioMultiVector::PopBack(size_t length) { |
121 for (size_t i = 0; i < num_channels_; ++i) { | 121 for (size_t i = 0; i < num_channels_; ++i) { |
122 channels_[i]->PopBack(length); | 122 channels_[i]->PopBack(length); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 size_t AudioMultiVector::ReadInterleaved(size_t length, | 126 size_t AudioMultiVector::ReadInterleaved(size_t length, |
127 int16_t* destination) const { | 127 int16_t* destination) const { |
128 return ReadInterleavedFromIndex(0, length, destination); | 128 return ReadInterleavedFromIndex(0, length, destination); |
129 } | 129 } |
130 | 130 |
131 size_t AudioMultiVector::ReadInterleavedFromIndex(size_t start_index, | 131 size_t AudioMultiVector::ReadInterleavedFromIndex(size_t start_index, |
132 size_t length, | 132 size_t length, |
133 int16_t* destination) const { | 133 int16_t* destination) const { |
134 RTC_DCHECK(destination); | 134 RTC_DCHECK(destination); |
135 size_t index = 0; // Number of elements written to |destination| so far. | 135 size_t index = 0; // Number of elements written to |destination| so far. |
136 assert(start_index <= Size()); | 136 RTC_DCHECK_LE(start_index, Size()); |
137 start_index = std::min(start_index, Size()); | 137 start_index = std::min(start_index, Size()); |
138 if (length + start_index > Size()) { | 138 if (length + start_index > Size()) { |
139 length = Size() - start_index; | 139 length = Size() - start_index; |
140 } | 140 } |
141 if (num_channels_ == 1) { | 141 if (num_channels_ == 1) { |
142 // Special case to avoid the nested for loop below. | 142 // Special case to avoid the nested for loop below. |
143 memcpy(destination, &(*this)[0][start_index], length * sizeof(int16_t)); | 143 (*this)[0].CopyTo(length, start_index, destination); |
144 return length; | 144 return length; |
145 } | 145 } |
146 for (size_t i = 0; i < length; ++i) { | 146 for (size_t i = 0; i < length; ++i) { |
147 for (size_t channel = 0; channel < num_channels_; ++channel) { | 147 for (size_t channel = 0; channel < num_channels_; ++channel) { |
148 destination[index] = (*this)[channel][i + start_index]; | 148 destination[index] = (*this)[channel][i + start_index]; |
149 ++index; | 149 ++index; |
150 } | 150 } |
151 } | 151 } |
152 return index; | 152 return index; |
153 } | 153 } |
154 | 154 |
155 size_t AudioMultiVector::ReadInterleavedFromEnd(size_t length, | 155 size_t AudioMultiVector::ReadInterleavedFromEnd(size_t length, |
156 int16_t* destination) const { | 156 int16_t* destination) const { |
157 length = std::min(length, Size()); // Cannot read more than Size() elements. | 157 length = std::min(length, Size()); // Cannot read more than Size() elements. |
158 return ReadInterleavedFromIndex(Size() - length, length, destination); | 158 return ReadInterleavedFromIndex(Size() - length, length, destination); |
159 } | 159 } |
160 | 160 |
161 void AudioMultiVector::OverwriteAt(const AudioMultiVector& insert_this, | 161 void AudioMultiVector::OverwriteAt(const AudioMultiVector& insert_this, |
162 size_t length, | 162 size_t length, |
163 size_t position) { | 163 size_t position) { |
164 assert(num_channels_ == insert_this.num_channels_); | 164 assert(num_channels_ == insert_this.num_channels_); |
165 // Cap |length| at the length of |insert_this|. | 165 // Cap |length| at the length of |insert_this|. |
166 assert(length <= insert_this.Size()); | 166 assert(length <= insert_this.Size()); |
167 length = std::min(length, insert_this.Size()); | 167 length = std::min(length, insert_this.Size()); |
168 if (num_channels_ == insert_this.num_channels_) { | 168 if (num_channels_ == insert_this.num_channels_) { |
169 for (size_t i = 0; i < num_channels_; ++i) { | 169 for (size_t i = 0; i < num_channels_; ++i) { |
170 channels_[i]->OverwriteAt(&insert_this[i][0], length, position); | 170 channels_[i]->OverwriteAt(insert_this[i], length, position); |
171 } | 171 } |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 void AudioMultiVector::CrossFade(const AudioMultiVector& append_this, | 175 void AudioMultiVector::CrossFade(const AudioMultiVector& append_this, |
176 size_t fade_length) { | 176 size_t fade_length) { |
177 assert(num_channels_ == append_this.num_channels_); | 177 assert(num_channels_ == append_this.num_channels_); |
178 if (num_channels_ == append_this.num_channels_) { | 178 if (num_channels_ == append_this.num_channels_) { |
179 for (size_t i = 0; i < num_channels_; ++i) { | 179 for (size_t i = 0; i < num_channels_; ++i) { |
180 channels_[i]->CrossFade(append_this[i], fade_length); | 180 channels_[i]->CrossFade(append_this[i], fade_length); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 const AudioVector& AudioMultiVector::operator[](size_t index) const { | 214 const AudioVector& AudioMultiVector::operator[](size_t index) const { |
215 return *(channels_[index]); | 215 return *(channels_[index]); |
216 } | 216 } |
217 | 217 |
218 AudioVector& AudioMultiVector::operator[](size_t index) { | 218 AudioVector& AudioMultiVector::operator[](size_t index) { |
219 return *(channels_[index]); | 219 return *(channels_[index]); |
220 } | 220 } |
221 | 221 |
222 } // namespace webrtc | 222 } // namespace webrtc |
OLD | NEW |