Use scoped_ptr<T[]> in SincResampler to avoid .get()[] weirdness.

R=aluebs@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/9139004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5613 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2014-02-26 18:14:54 +00:00
parent c0e9aebe8f
commit 2038920a2b
2 changed files with 12 additions and 12 deletions

View File

@ -223,20 +223,20 @@ void SincResampler::InitializeKernel() {
for (int i = 0; i < kKernelSize; ++i) {
const int idx = i + offset_idx * kKernelSize;
const float pre_sinc = M_PI * (i - kKernelSize / 2 - subsample_offset);
kernel_pre_sinc_storage_.get()[idx] = pre_sinc;
kernel_pre_sinc_storage_[idx] = pre_sinc;
// Compute Blackman window, matching the offset of the sinc().
const float x = (i - subsample_offset) / kKernelSize;
const float window = kA0 - kA1 * cos(2.0 * M_PI * x) + kA2
* cos(4.0 * M_PI * x);
kernel_window_storage_.get()[idx] = window;
kernel_window_storage_[idx] = window;
// Compute the sinc with offset, then window the sinc() function and store
// at the correct offset.
if (pre_sinc == 0) {
kernel_storage_.get()[idx] = sinc_scale_factor * window;
kernel_storage_[idx] = sinc_scale_factor * window;
} else {
kernel_storage_.get()[idx] =
kernel_storage_[idx] =
window * sin(sinc_scale_factor * pre_sinc) / pre_sinc;
}
}
@ -257,13 +257,13 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) {
for (int offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
for (int i = 0; i < kKernelSize; ++i) {
const int idx = i + offset_idx * kKernelSize;
const float window = kernel_window_storage_.get()[idx];
const float pre_sinc = kernel_pre_sinc_storage_.get()[idx];
const float window = kernel_window_storage_[idx];
const float pre_sinc = kernel_pre_sinc_storage_[idx];
if (pre_sinc == 0) {
kernel_storage_.get()[idx] = sinc_scale_factor * window;
kernel_storage_[idx] = sinc_scale_factor * window;
} else {
kernel_storage_.get()[idx] =
kernel_storage_[idx] =
window * sin(sinc_scale_factor * pre_sinc) / pre_sinc;
}
}

View File

@ -146,12 +146,12 @@ class SincResampler {
// Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
// The kernel offsets are sub-sample shifts of a windowed sinc shifted from
// 0.0 to 1.0 sample.
scoped_ptr<float, AlignedFreeDeleter> kernel_storage_;
scoped_ptr<float, AlignedFreeDeleter> kernel_pre_sinc_storage_;
scoped_ptr<float, AlignedFreeDeleter> kernel_window_storage_;
scoped_ptr<float[], AlignedFreeDeleter> kernel_storage_;
scoped_ptr<float[], AlignedFreeDeleter> kernel_pre_sinc_storage_;
scoped_ptr<float[], AlignedFreeDeleter> kernel_window_storage_;
// Data from the source is copied into this buffer for each processing pass.
scoped_ptr<float, AlignedFreeDeleter> input_buffer_;
scoped_ptr<float[], AlignedFreeDeleter> input_buffer_;
// Stores the runtime selection of which Convolve function to use.
// TODO(ajm): Move to using a global static which must only be initialized