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

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

Issue 231623005: Remove obsolete atomic debugging checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | « media/base/sinc_resampler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Initial input buffer layout, dividing into regions r0_ to r4_ (note: r0_, r3_ 5 // Initial input buffer layout, dividing into regions r0_ to r4_ (note: r0_, r3_
6 // and r4_ will move after the first load): 6 // and r4_ will move after the first load):
7 // 7 //
8 // |----------------|-----------------------------------------|----------------| 8 // |----------------|-----------------------------------------|----------------|
9 // 9 //
10 // request_frames_ 10 // request_frames_
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Create input buffers with a 16-byte alignment for SSE optimizations. 146 // Create input buffers with a 16-byte alignment for SSE optimizations.
147 kernel_storage_(static_cast<float*>( 147 kernel_storage_(static_cast<float*>(
148 base::AlignedAlloc(sizeof(float) * kKernelStorageSize, 16))), 148 base::AlignedAlloc(sizeof(float) * kKernelStorageSize, 16))),
149 kernel_pre_sinc_storage_(static_cast<float*>( 149 kernel_pre_sinc_storage_(static_cast<float*>(
150 base::AlignedAlloc(sizeof(float) * kKernelStorageSize, 16))), 150 base::AlignedAlloc(sizeof(float) * kKernelStorageSize, 16))),
151 kernel_window_storage_(static_cast<float*>( 151 kernel_window_storage_(static_cast<float*>(
152 base::AlignedAlloc(sizeof(float) * kKernelStorageSize, 16))), 152 base::AlignedAlloc(sizeof(float) * kKernelStorageSize, 16))),
153 input_buffer_(static_cast<float*>( 153 input_buffer_(static_cast<float*>(
154 base::AlignedAlloc(sizeof(float) * input_buffer_size_, 16))), 154 base::AlignedAlloc(sizeof(float) * input_buffer_size_, 16))),
155 r1_(input_buffer_.get()), 155 r1_(input_buffer_.get()),
156 r2_(input_buffer_.get() + kKernelSize / 2), 156 r2_(input_buffer_.get() + kKernelSize / 2) {
157 not_currently_resampling_(1) {
158 CHECK_GT(request_frames_, 0); 157 CHECK_GT(request_frames_, 0);
159 Flush(); 158 Flush();
160 CHECK_GT(block_size_, kKernelSize) 159 CHECK_GT(block_size_, kKernelSize)
161 << "block_size must be greater than kKernelSize!"; 160 << "block_size must be greater than kKernelSize!";
162 161
163 memset(kernel_storage_.get(), 0, 162 memset(kernel_storage_.get(), 0,
164 sizeof(*kernel_storage_.get()) * kKernelStorageSize); 163 sizeof(*kernel_storage_.get()) * kKernelStorageSize);
165 memset(kernel_pre_sinc_storage_.get(), 0, 164 memset(kernel_pre_sinc_storage_.get(), 0,
166 sizeof(*kernel_pre_sinc_storage_.get()) * kKernelStorageSize); 165 sizeof(*kernel_pre_sinc_storage_.get()) * kKernelStorageSize);
167 memset(kernel_window_storage_.get(), 0, 166 memset(kernel_window_storage_.get(), 0,
168 sizeof(*kernel_window_storage_.get()) * kKernelStorageSize); 167 sizeof(*kernel_window_storage_.get()) * kKernelStorageSize);
169 168
170 InitializeKernel(); 169 InitializeKernel();
171 } 170 }
172 171
173 SincResampler::~SincResampler() { 172 SincResampler::~SincResampler() {}
174 // TODO(dalecurtis): Remove debugging for http://crbug.com/295278
175 CHECK(!base::AtomicRefCountDec(&not_currently_resampling_));
176 }
177 173
178 void SincResampler::UpdateRegions(bool second_load) { 174 void SincResampler::UpdateRegions(bool second_load) {
179 // Setup various region pointers in the buffer (see diagram above). If we're 175 // Setup various region pointers in the buffer (see diagram above). If we're
180 // on the second load we need to slide r0_ to the right by kKernelSize / 2. 176 // on the second load we need to slide r0_ to the right by kKernelSize / 2.
181 r0_ = input_buffer_.get() + (second_load ? kKernelSize : kKernelSize / 2); 177 r0_ = input_buffer_.get() + (second_load ? kKernelSize : kKernelSize / 2);
182 r3_ = r0_ + request_frames_ - kKernelSize; 178 r3_ = r0_ + request_frames_ - kKernelSize;
183 r4_ = r0_ + request_frames_ - kKernelSize / 2; 179 r4_ = r0_ + request_frames_ - kKernelSize / 2;
184 block_size_ = r4_ - r2_; 180 block_size_ = r4_ - r2_;
185 181
186 // r1_ at the beginning of the buffer. 182 // r1_ at the beginning of the buffer.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 kernel_storage_[idx] = sinc_scale_factor * window; 245 kernel_storage_[idx] = sinc_scale_factor * window;
250 } else { 246 } else {
251 kernel_storage_[idx] = 247 kernel_storage_[idx] =
252 window * sin(sinc_scale_factor * pre_sinc) / pre_sinc; 248 window * sin(sinc_scale_factor * pre_sinc) / pre_sinc;
253 } 249 }
254 } 250 }
255 } 251 }
256 } 252 }
257 253
258 void SincResampler::Resample(int frames, float* destination) { 254 void SincResampler::Resample(int frames, float* destination) {
259 CHECK(!base::AtomicRefCountDec(&not_currently_resampling_));
260
261 int remaining_frames = frames; 255 int remaining_frames = frames;
262 256
263 // Step (1) -- Prime the input buffer at the start of the input stream. 257 // Step (1) -- Prime the input buffer at the start of the input stream.
264 if (!buffer_primed_ && remaining_frames) { 258 if (!buffer_primed_ && remaining_frames) {
265 read_cb_.Run(request_frames_, r0_); 259 read_cb_.Run(request_frames_, r0_);
266 buffer_primed_ = true; 260 buffer_primed_ = true;
267 } 261 }
268 262
269 // Step (2) -- Resample! const what we can outside of the loop for speed. It 263 // Step (2) -- Resample! const what we can outside of the loop for speed. It
270 // actually has an impact on ARM performance. See inner loop comment below. 264 // actually has an impact on ARM performance. See inner loop comment below.
(...skipping 28 matching lines...) Expand all
299 // Figure out how much to weight each kernel's "convolution". 293 // Figure out how much to weight each kernel's "convolution".
300 const double kernel_interpolation_factor = 294 const double kernel_interpolation_factor =
301 virtual_offset_idx - offset_idx; 295 virtual_offset_idx - offset_idx;
302 *destination++ = CONVOLVE_FUNC( 296 *destination++ = CONVOLVE_FUNC(
303 input_ptr, k1, k2, kernel_interpolation_factor); 297 input_ptr, k1, k2, kernel_interpolation_factor);
304 298
305 // Advance the virtual index. 299 // Advance the virtual index.
306 virtual_source_idx_ += current_io_ratio; 300 virtual_source_idx_ += current_io_ratio;
307 source_idx = virtual_source_idx_; 301 source_idx = virtual_source_idx_;
308 302
309 if (!--remaining_frames) { 303 if (!--remaining_frames)
310 base::AtomicRefCountInc(&not_currently_resampling_);
311 return; 304 return;
312 }
313 } 305 }
314 306
315 // Wrap back around to the start. 307 // Wrap back around to the start.
316 DCHECK_GE(virtual_source_idx_, block_size_); 308 DCHECK_GE(virtual_source_idx_, block_size_);
317 virtual_source_idx_ -= block_size_; 309 virtual_source_idx_ -= block_size_;
318 310
319 // Step (3) -- Copy r3_, r4_ to r1_, r2_. 311 // Step (3) -- Copy r3_, r4_ to r1_, r2_.
320 // This wraps the last input frames back to the start of the buffer. 312 // This wraps the last input frames back to the start of the buffer.
321 memcpy(r1_, r3_, sizeof(*input_buffer_.get()) * kKernelSize); 313 memcpy(r1_, r3_, sizeof(*input_buffer_.get()) * kKernelSize);
322 314
323 // Step (4) -- Reinitialize regions if necessary. 315 // Step (4) -- Reinitialize regions if necessary.
324 if (r0_ == r2_) 316 if (r0_ == r2_)
325 UpdateRegions(true); 317 UpdateRegions(true);
326 318
327 // Step (5) -- Refresh the buffer with more input. 319 // Step (5) -- Refresh the buffer with more input.
328 read_cb_.Run(request_frames_, r0_); 320 read_cb_.Run(request_frames_, r0_);
329 } 321 }
330
331 base::AtomicRefCountInc(&not_currently_resampling_);
332 } 322 }
333 323
334 #undef CONVOLVE_FUNC 324 #undef CONVOLVE_FUNC
335 325
336 int SincResampler::ChunkSize() const { 326 int SincResampler::ChunkSize() const {
337 return block_size_ / io_sample_rate_ratio_; 327 return block_size_ / io_sample_rate_ratio_;
338 } 328 }
339 329
340 void SincResampler::Flush() { 330 void SincResampler::Flush() {
341 CHECK(base::AtomicRefCountIsOne(&not_currently_resampling_));
342 virtual_source_idx_ = 0; 331 virtual_source_idx_ = 0;
343 buffer_primed_ = false; 332 buffer_primed_ = false;
344 memset(input_buffer_.get(), 0, 333 memset(input_buffer_.get(), 0,
345 sizeof(*input_buffer_.get()) * input_buffer_size_); 334 sizeof(*input_buffer_.get()) * input_buffer_size_);
346 UpdateRegions(false); 335 UpdateRegions(false);
347 } 336 }
348 337
349 float SincResampler::Convolve_C(const float* input_ptr, const float* k1, 338 float SincResampler::Convolve_C(const float* input_ptr, const float* k1,
350 const float* k2, 339 const float* k2,
351 double kernel_interpolation_factor) { 340 double kernel_interpolation_factor) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 vmulq_f32(m_sums1, vmovq_n_f32(1.0 - kernel_interpolation_factor)), 377 vmulq_f32(m_sums1, vmovq_n_f32(1.0 - kernel_interpolation_factor)),
389 m_sums2, vmovq_n_f32(kernel_interpolation_factor)); 378 m_sums2, vmovq_n_f32(kernel_interpolation_factor));
390 379
391 // Sum components together. 380 // Sum components together.
392 float32x2_t m_half = vadd_f32(vget_high_f32(m_sums1), vget_low_f32(m_sums1)); 381 float32x2_t m_half = vadd_f32(vget_high_f32(m_sums1), vget_low_f32(m_sums1));
393 return vget_lane_f32(vpadd_f32(m_half, m_half), 0); 382 return vget_lane_f32(vpadd_f32(m_half, m_half), 0);
394 } 383 }
395 #endif 384 #endif
396 385
397 } // namespace media 386 } // namespace media
OLDNEW
« no previous file with comments | « media/base/sinc_resampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698