Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: media/base/audio_buffer_converter.cc

Issue 217923002: Make sure AudioBufferConverter uses aligned AudioBus channels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/audio_buffer_converter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_buffer_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698