Chromium Code Reviews| 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 "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/gtest_prod_util.h" | |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "build/build_config.h" | |
| 10 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
| 11 | 13 |
| 12 namespace media { | 14 namespace media { |
| 13 | 15 |
| 14 // SincResampler is a high-quality single-channel sample-rate converter. | 16 // SincResampler is a high-quality single-channel sample-rate converter. |
| 15 class MEDIA_EXPORT SincResampler { | 17 class MEDIA_EXPORT SincResampler { |
| 16 public: | 18 public: |
| 17 // Callback type for providing more data into the resampler. Expects |frames| | 19 // Callback type for providing more data into the resampler. Expects |frames| |
| 18 // of data to be rendered into |destination|; zero padded if not enough frames | 20 // of data to be rendered into |destination|; zero padded if not enough frames |
| 19 // are available to satisfy the request. | 21 // are available to satisfy the request. |
| 20 typedef base::Callback<void(float* destination, int frames)> ReadCB; | 22 typedef base::Callback<void(float* destination, int frames)> ReadCB; |
| 21 | 23 |
| 22 // Constructs a SincResampler with the specified |read_cb|, which is used to | 24 // Constructs a SincResampler with the specified |read_cb|, which is used to |
| 23 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of | 25 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of |
| 24 // input / output sample rates. | 26 // input / output sample rates. |
| 25 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb); | 27 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb); |
| 26 virtual ~SincResampler(); | 28 virtual ~SincResampler(); |
| 27 | 29 |
| 28 // Resample |frames| of data from |read_cb_| into |destination|. | 30 // Resample |frames| of data from |read_cb_| into |destination|. |
| 29 void Resample(float* destination, int frames); | 31 void Resample(float* destination, int frames); |
| 30 | 32 |
| 31 // The maximum size in frames that guarantees Resample() will only make a | 33 // The maximum size in frames that guarantees Resample() will only make a |
| 32 // single call to |read_cb_| for more data. | 34 // single call to |read_cb_| for more data. |
| 33 int ChunkSize(); | 35 int ChunkSize(); |
| 34 | 36 |
| 35 private: | 37 private: |
| 38 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve); | |
| 39 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark); | |
| 40 | |
| 36 void InitializeKernel(); | 41 void InitializeKernel(); |
| 37 | 42 |
| 43 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are | |
| 44 // linearly interpolated using |kernel_interpolation_factor|. The underlying | |
| 45 // implementation is chosen at run time based on SSE support. | |
| 46 static float Convolve(const float* input_ptr, const float* k1, | |
| 47 const float* k2, double kernel_interpolation_factor); | |
| 48 static float Convolve_C(const float* input_ptr, const float* k1, | |
| 49 const float* k2, double kernel_interpolation_factor); | |
| 50 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) | |
|
Ami GONE FROM CHROMIUM
2012/07/21 17:25:10
#if unnecessary (fine to leave methods undefined a
DaleCurtis
2012/07/24 00:13:07
Done.
| |
| 51 static float Convolve_SSE(const float* input_ptr, const float* k1, | |
| 52 const float* k2, | |
| 53 double kernel_interpolation_factor); | |
| 54 #endif | |
| 55 | |
| 38 // The ratio of input / output sample rates. | 56 // The ratio of input / output sample rates. |
| 39 double io_sample_rate_ratio_; | 57 double io_sample_rate_ratio_; |
| 40 | 58 |
| 41 // An index on the source input buffer with sub-sample precision. It must be | 59 // An index on the source input buffer with sub-sample precision. It must be |
| 42 // double precision to avoid drift. | 60 // double precision to avoid drift. |
| 43 double virtual_source_idx_; | 61 double virtual_source_idx_; |
| 44 | 62 |
| 45 // The buffer is primed once at the very beginning of processing. | 63 // The buffer is primed once at the very beginning of processing. |
| 46 bool buffer_primed_; | 64 bool buffer_primed_; |
| 47 | 65 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 62 float* const r1_; | 80 float* const r1_; |
| 63 float* const r2_; | 81 float* const r2_; |
| 64 float* const r3_; | 82 float* const r3_; |
| 65 float* const r4_; | 83 float* const r4_; |
| 66 float* const r5_; | 84 float* const r5_; |
| 67 }; | 85 }; |
| 68 | 86 |
| 69 } // namespace media | 87 } // namespace media |
| 70 | 88 |
| 71 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ | 89 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ |
| OLD | NEW |