| OLD | NEW |
| 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 #ifndef MEDIA_BASE_SINC_RESAMPLER_H_ | 5 #ifndef MEDIA_BASE_SINC_RESAMPLER_H_ |
| 6 #define MEDIA_BASE_SINC_RESAMPLER_H_ | 6 #define MEDIA_BASE_SINC_RESAMPLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/aligned_memory.h" | 13 #include "base/memory/aligned_memory.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 16 #include "media/base/vector_math.h" |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 | 19 |
| 19 // SincResampler is a high-quality single-channel sample-rate converter. | 20 // SincResampler is a high-quality single-channel sample-rate converter. |
| 20 class MEDIA_EXPORT SincResampler { | 21 class MEDIA_EXPORT SincResampler { |
| 21 public: | 22 public: |
| 22 enum { | 23 enum { |
| 23 // The kernel size can be adjusted for quality (higher is better) at the | 24 // The kernel size can be adjusted for quality (higher is better) at the |
| 24 // expense of performance. Must be a multiple of 32. | 25 // expense of performance. For performance we use the same kernel size |
| 25 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+. | 26 // as the SIMD optimized Convolve() operation. |
| 26 kKernelSize = 32, | 27 kKernelSize = vector_math::kKernelSize, |
| 27 | 28 |
| 28 // Default request size. Affects how often and for how much SincResampler | 29 // Default request size. Affects how often and for how much SincResampler |
| 29 // calls back for input. Must be greater than kKernelSize. | 30 // calls back for input. Must be greater than kKernelSize. |
| 30 kDefaultRequestSize = 512, | 31 kDefaultRequestSize = 512, |
| 31 | 32 |
| 32 // The kernel offset count is used for interpolation and is the number of | 33 // The kernel offset count is used for interpolation and is the number of |
| 33 // sub-sample kernel shifts. Can be adjusted for quality (higher is better) | 34 // sub-sample kernel shifts. Can be adjusted for quality (higher is better) |
| 34 // at the expense of allocating more memory. | 35 // at the expense of allocating more memory. |
| 35 kKernelOffsetCount = 32, | 36 kKernelOffsetCount = 32, |
| 36 kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), | 37 kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 void SetRatio(double io_sample_rate_ratio); | 78 void SetRatio(double io_sample_rate_ratio); |
| 78 | 79 |
| 79 float* get_kernel_for_testing() { return kernel_storage_.get(); } | 80 float* get_kernel_for_testing() { return kernel_storage_.get(); } |
| 80 | 81 |
| 81 // Return number of input frames consumed by a callback but not yet processed. | 82 // Return number of input frames consumed by a callback but not yet processed. |
| 82 // Since input/output ratio can be fractional, so can this value. | 83 // Since input/output ratio can be fractional, so can this value. |
| 83 // Zero before first call to Resample(). | 84 // Zero before first call to Resample(). |
| 84 double BufferedFrames() const; | 85 double BufferedFrames() const; |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve); | |
| 88 FRIEND_TEST_ALL_PREFIXES(SincResamplerPerfTest, Convolve); | |
| 89 | |
| 90 void InitializeKernel(); | 88 void InitializeKernel(); |
| 91 void UpdateRegions(bool second_load); | 89 void UpdateRegions(bool second_load); |
| 92 | 90 |
| 93 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are | |
| 94 // linearly interpolated using |kernel_interpolation_factor|. On x86, the | |
| 95 // underlying implementation is chosen at run time based on SSE support. On | |
| 96 // ARM, NEON support is chosen at compile time based on compilation flags. | |
| 97 static float Convolve_C(const float* input_ptr, const float* k1, | |
| 98 const float* k2, double kernel_interpolation_factor); | |
| 99 #if defined(ARCH_CPU_X86_FAMILY) | |
| 100 static float Convolve_SSE(const float* input_ptr, const float* k1, | |
| 101 const float* k2, | |
| 102 double kernel_interpolation_factor); | |
| 103 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) | |
| 104 static float Convolve_NEON(const float* input_ptr, const float* k1, | |
| 105 const float* k2, | |
| 106 double kernel_interpolation_factor); | |
| 107 #endif | |
| 108 | |
| 109 // The ratio of input / output sample rates. | 91 // The ratio of input / output sample rates. |
| 110 double io_sample_rate_ratio_; | 92 double io_sample_rate_ratio_; |
| 111 | 93 |
| 112 // An index on the source input buffer with sub-sample precision. It must be | 94 // An index on the source input buffer with sub-sample precision. It must be |
| 113 // double precision to avoid drift. | 95 // double precision to avoid drift. |
| 114 double virtual_source_idx_; | 96 double virtual_source_idx_; |
| 115 | 97 |
| 116 // The buffer is primed once at the very beginning of processing. | 98 // The buffer is primed once at the very beginning of processing. |
| 117 bool buffer_primed_; | 99 bool buffer_primed_; |
| 118 | 100 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 149 float* const r2_; | 131 float* const r2_; |
| 150 float* r3_; | 132 float* r3_; |
| 151 float* r4_; | 133 float* r4_; |
| 152 | 134 |
| 153 DISALLOW_COPY_AND_ASSIGN(SincResampler); | 135 DISALLOW_COPY_AND_ASSIGN(SincResampler); |
| 154 }; | 136 }; |
| 155 | 137 |
| 156 } // namespace media | 138 } // namespace media |
| 157 | 139 |
| 158 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ | 140 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ |
| OLD | NEW |