OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/audio_buffer_converter.h" | 5 #include "media/base/audio_buffer_converter.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/audio_buffer.h" | 10 #include "media/base/audio_buffer.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 output_params_.sample_rate(), | 191 output_params_.sample_rate(), |
192 request_frames); | 192 request_frames); |
193 scoped_ptr<AudioBus> output_bus = | 193 scoped_ptr<AudioBus> output_bus = |
194 AudioBus::CreateWrapper(output_buffer->channel_count()); | 194 AudioBus::CreateWrapper(output_buffer->channel_count()); |
195 | 195 |
196 int frames_remaining = request_frames; | 196 int frames_remaining = request_frames; |
197 | 197 |
198 // The AudioConverter wants requests of a fixed size, so we'll slide an | 198 // The AudioConverter wants requests of a fixed size, so we'll slide an |
199 // AudioBus of that size across the |output_buffer|. | 199 // AudioBus of that size across the |output_buffer|. |
200 while (frames_remaining != 0) { | 200 while (frames_remaining != 0) { |
201 int frames_this_iteration = | 201 // It's important that this is a multiple of AudioBus::kChannelAlignment in |
202 std::min(output_params_.frames_per_buffer(), frames_remaining); | 202 // all requests except for the last, otherwise downstream SIMD optimizations |
203 | 203 // will crash on unaligned data. |
204 int offset_into_buffer = output_buffer->frame_count() - frames_remaining; | 204 const int frames_this_iteration = std::min( |
| 205 static_cast<int>(SincResampler::kDefaultRequestSize), frames_remaining); |
| 206 const int offset_into_buffer = |
| 207 output_buffer->frame_count() - frames_remaining; |
205 | 208 |
206 // Wrap the portion of the AudioBuffer in an AudioBus so the AudioConverter | 209 // Wrap the portion of the AudioBuffer in an AudioBus so the AudioConverter |
207 // can fill it. | 210 // can fill it. |
208 output_bus->set_frames(frames_this_iteration); | 211 output_bus->set_frames(frames_this_iteration); |
209 for (int ch = 0; ch < output_buffer->channel_count(); ++ch) { | 212 for (int ch = 0; ch < output_buffer->channel_count(); ++ch) { |
210 output_bus->SetChannelData( | 213 output_bus->SetChannelData( |
211 ch, | 214 ch, |
212 reinterpret_cast<float*>(output_buffer->channel_data()[ch]) + | 215 reinterpret_cast<float*>(output_buffer->channel_data()[ch]) + |
213 offset_into_buffer); | 216 offset_into_buffer); |
214 } | 217 } |
(...skipping 21 matching lines...) Expand all Loading... |
236 is_flushing_ = false; | 239 is_flushing_ = false; |
237 audio_converter_->Reset(); | 240 audio_converter_->Reset(); |
238 DCHECK_EQ(input_frames_, 0); | 241 DCHECK_EQ(input_frames_, 0); |
239 DCHECK_EQ(last_input_buffer_offset_, 0); | 242 DCHECK_EQ(last_input_buffer_offset_, 0); |
240 DCHECK_LT(buffered_input_frames_, 1.0); | 243 DCHECK_LT(buffered_input_frames_, 1.0); |
241 DCHECK(queued_inputs_.empty()); | 244 DCHECK(queued_inputs_.empty()); |
242 buffered_input_frames_ = 0.0; | 245 buffered_input_frames_ = 0.0; |
243 } | 246 } |
244 | 247 |
245 } // namespace media | 248 } // namespace media |
OLD | NEW |