Index: media/base/sinc_resampler.h |
diff --git a/media/base/sinc_resampler.h b/media/base/sinc_resampler.h |
index facd1a106df27b7d3a2cdc6165f358177958f46e..60abd6128f9306171b744eec8be3a729224d3294 100644 |
--- a/media/base/sinc_resampler.h |
+++ b/media/base/sinc_resampler.h |
@@ -1,21 +1,45 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-#ifndef MEDIA_BASE_SINC_RESAMPLER_H_ |
-#define MEDIA_BASE_SINC_RESAMPLER_H_ |
+/* |
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+// Modified from the Chromium original here: |
+// src/media/base/sinc_resampler.h |
+ |
+#ifndef WEBRTC_COMMON_AUDIO_RESAMPLER_SINC_RESAMPLER_H_ |
+#define WEBRTC_COMMON_AUDIO_RESAMPLER_SINC_RESAMPLER_H_ |
+ |
+#include "webrtc/system_wrappers/interface/aligned_malloc.h" |
+#include "webrtc/system_wrappers/interface/constructor_magic.h" |
+#include "webrtc/system_wrappers/interface/scoped_ptr.h" |
+#include "webrtc/test/testsupport/gtest_prod_util.h" |
+#include "webrtc/typedefs.h" |
+ |
+#if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(WEBRTC_IOS) && \ |
+ !defined(__SSE__)) || \ |
+ (defined(WEBRTC_ARCH_ARM_V7) && !defined(WEBRTC_ARCH_ARM_NEON)) |
+// Convenience define. |
+#define WEBRTC_RESAMPLER_CPU_DETECTION |
+#endif |
-#include "base/callback.h" |
-#include "base/gtest_prod_util.h" |
-#include "base/memory/aligned_memory.h" |
-#include "base/memory/scoped_ptr.h" |
-#include "build/build_config.h" |
-#include "media/base/media_export.h" |
+namespace webrtc { |
-namespace media { |
+// Callback class for providing more data into the resampler. Expects |frames| |
+// of data to be rendered into |destination|; zero padded if not enough frames |
+// are available to satisfy the request. |
+class SincResamplerCallback { |
+ public: |
+ virtual ~SincResamplerCallback() {} |
+ virtual void Run(int frames, float* destination) = 0; |
+}; |
// SincResampler is a high-quality single-channel sample-rate converter. |
-class MEDIA_EXPORT SincResampler { |
+class SincResampler { |
public: |
enum { |
// The kernel size can be adjusted for quality (higher is better) at the |
@@ -34,15 +58,6 @@ class MEDIA_EXPORT SincResampler { |
kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), |
}; |
- // Selects runtime specific CPU features like SSE. Must be called before |
- // using SincResampler. |
- static void InitializeCPUSpecificFeatures(); |
- |
- // Callback type for providing more data into the resampler. Expects |frames| |
- // of data to be rendered into |destination|; zero padded if not enough frames |
- // are available to satisfy the request. |
- typedef base::Callback<void(int frames, float* destination)> ReadCB; |
- |
// Constructs a SincResampler with the specified |read_cb|, which is used to |
// acquire audio data for resampling. |io_sample_rate_ratio| is the ratio |
// of input / output sample rates. |request_frames| controls the size in |
@@ -51,7 +66,7 @@ class MEDIA_EXPORT SincResampler { |
// request size constraints. |
SincResampler(double io_sample_rate_ratio, |
int request_frames, |
- const ReadCB& read_cb); |
+ SincResamplerCallback* read_cb); |
virtual ~SincResampler(); |
// Resample |frames| of data from |read_cb_| into |destination|. |
@@ -61,6 +76,8 @@ class MEDIA_EXPORT SincResampler { |
// single call to |read_cb_| for more data. |
int ChunkSize() const; |
+ int request_frames() const { return request_frames_; } |
+ |
// Flush all buffered data and reset internal indices. Not thread safe, do |
// not call while Resample() is in progress. |
void Flush(); |
@@ -68,6 +85,9 @@ class MEDIA_EXPORT SincResampler { |
// Update |io_sample_rate_ratio_|. SetRatio() will cause a reconstruction of |
// the kernels used for resampling. Not thread safe, do not call while |
// Resample() is in progress. |
+ // |
+ // TODO(ajm): Use this in PushSincResampler rather than reconstructing |
+ // SincResampler. We would also need a way to update |request_frames_|. |
void SetRatio(double io_sample_rate_ratio); |
float* get_kernel_for_testing() { return kernel_storage_.get(); } |
@@ -79,17 +99,23 @@ class MEDIA_EXPORT SincResampler { |
void InitializeKernel(); |
void UpdateRegions(bool second_load); |
+ // Selects runtime specific CPU features like SSE. Must be called before |
+ // using SincResampler. |
+ // TODO(ajm): Currently managed by the class internally. See the note with |
+ // |convolve_proc_| below. |
+ void InitializeCPUSpecificFeatures(); |
+ |
// Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are |
// linearly interpolated using |kernel_interpolation_factor|. On x86, the |
// underlying implementation is chosen at run time based on SSE support. On |
// ARM, NEON support is chosen at compile time based on compilation flags. |
static float Convolve_C(const float* input_ptr, const float* k1, |
const float* k2, double kernel_interpolation_factor); |
-#if defined(ARCH_CPU_X86_FAMILY) |
+#if defined(WEBRTC_ARCH_X86_FAMILY) |
static float Convolve_SSE(const float* input_ptr, const float* k1, |
const float* k2, |
double kernel_interpolation_factor); |
-#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) |
+#elif defined(WEBRTC_ARCH_ARM_V7) |
static float Convolve_NEON(const float* input_ptr, const float* k1, |
const float* k2, |
double kernel_interpolation_factor); |
@@ -106,7 +132,7 @@ class MEDIA_EXPORT SincResampler { |
bool buffer_primed_; |
// Source of data for resampling. |
- const ReadCB read_cb_; |
+ SincResamplerCallback* read_cb_; |
// The size (in samples) to request from each |read_cb_| execution. |
const int request_frames_; |
@@ -120,12 +146,22 @@ class MEDIA_EXPORT 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[], base::ScopedPtrAlignedFree> kernel_storage_; |
- scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_pre_sinc_storage_; |
- scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_window_storage_; |
+ scoped_ptr_malloc<float, AlignedFree> kernel_storage_; |
+ scoped_ptr_malloc<float, AlignedFree> kernel_pre_sinc_storage_; |
+ scoped_ptr_malloc<float, AlignedFree> kernel_window_storage_; |
// Data from the source is copied into this buffer for each processing pass. |
- scoped_ptr<float[], base::ScopedPtrAlignedFree> input_buffer_; |
+ scoped_ptr_malloc<float, AlignedFree> 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 |
+ // once by the user. We're not doing this initially, because we don't have |
+ // e.g. a LazyInstance helper in webrtc. |
+#if defined(WEBRTC_RESAMPLER_CPU_DETECTION) |
+ typedef float (*ConvolveProc)(const float*, const float*, const float*, |
+ double); |
+ ConvolveProc convolve_proc_; |
+#endif |
// Pointers to the various regions inside |input_buffer_|. See the diagram at |
// the top of the .cc file for more information. |
@@ -138,6 +174,6 @@ class MEDIA_EXPORT SincResampler { |
DISALLOW_COPY_AND_ASSIGN(SincResampler); |
}; |
-} // namespace media |
+} // namespace webrtc |
-#endif // MEDIA_BASE_SINC_RESAMPLER_H_ |
+#endif // WEBRTC_COMMON_AUDIO_RESAMPLER_SINC_RESAMPLER_H_ |