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

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

Issue 13741004: Varispeed support for SincResampler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Skip equivalent ratios. Created 7 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
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 #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/gtest_prod_util.h"
10 #include "base/memory/aligned_memory.h" 10 #include "base/memory/aligned_memory.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb); 53 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb);
54 virtual ~SincResampler(); 54 virtual ~SincResampler();
55 55
56 // Resample |frames| of data from |read_cb_| into |destination|. 56 // Resample |frames| of data from |read_cb_| into |destination|.
57 void Resample(float* destination, int frames); 57 void Resample(float* destination, int frames);
58 58
59 // The maximum size in frames that guarantees Resample() will only make a 59 // The maximum size in frames that guarantees Resample() will only make a
60 // single call to |read_cb_| for more data. 60 // single call to |read_cb_| for more data.
61 int ChunkSize() const; 61 int ChunkSize() const;
62 62
63 // Flush all buffered data and reset internal indices. 63 // Flush all buffered data and reset internal indices. Not thread safe, do
64 // not call while Resample() is in progress.
64 void Flush(); 65 void Flush();
65 66
67 // Update |io_sample_rate_ratio_|. SetRatio() will cause a reconstruction of
68 // the kernels used for resampling. Not thread safe, do not call while
69 // Resample() is in progress.
70 void SetRatio(double io_sample_rate_ratio);
71
72 float* get_kernel_for_testing() { return kernel_storage_.get(); }
73
66 private: 74 private:
67 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve); 75 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve);
68 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark); 76 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark);
69 77
70 void InitializeKernel(); 78 void InitializeKernel();
71 79
72 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are 80 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are
73 // linearly interpolated using |kernel_interpolation_factor|. On x86, the 81 // linearly interpolated using |kernel_interpolation_factor|. On x86, the
74 // underlying implementation is chosen at run time based on SSE support. On 82 // underlying implementation is chosen at run time based on SSE support. On
75 // ARM, NEON support is chosen at compile time based on compilation flags. 83 // ARM, NEON support is chosen at compile time based on compilation flags.
76 static float Convolve_C(const float* input_ptr, const float* k1, 84 static float Convolve_C(const float* input_ptr, const float* k1,
77 const float* k2, double kernel_interpolation_factor); 85 const float* k2, double kernel_interpolation_factor);
78 #if defined(ARCH_CPU_X86_FAMILY) 86 #if defined(ARCH_CPU_X86_FAMILY)
79 static float Convolve_SSE(const float* input_ptr, const float* k1, 87 static float Convolve_SSE(const float* input_ptr, const float* k1,
80 const float* k2, 88 const float* k2,
81 double kernel_interpolation_factor); 89 double kernel_interpolation_factor);
82 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) 90 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
83 static float Convolve_NEON(const float* input_ptr, const float* k1, 91 static float Convolve_NEON(const float* input_ptr, const float* k1,
84 const float* k2, 92 const float* k2,
85 double kernel_interpolation_factor); 93 double kernel_interpolation_factor);
86 #endif 94 #endif
87 95
88 // The ratio of input / output sample rates. 96 // The ratio of input / output sample rates.
89 const double io_sample_rate_ratio_; 97 double io_sample_rate_ratio_;
90 98
91 // An index on the source input buffer with sub-sample precision. It must be 99 // An index on the source input buffer with sub-sample precision. It must be
92 // double precision to avoid drift. 100 // double precision to avoid drift.
93 double virtual_source_idx_; 101 double virtual_source_idx_;
94 102
95 // The buffer is primed once at the very beginning of processing. 103 // The buffer is primed once at the very beginning of processing.
96 bool buffer_primed_; 104 bool buffer_primed_;
97 105
98 // Source of data for resampling. 106 // Source of data for resampling.
99 ReadCB read_cb_; 107 ReadCB read_cb_;
100 108
101 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. 109 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
102 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from 110 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from
103 // 0.0 to 1.0 sample. 111 // 0.0 to 1.0 sample.
104 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> kernel_storage_; 112 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_storage_;
113 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_pre_sinc_storage_;
114 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_window_storage_;
105 115
106 // Data from the source is copied into this buffer for each processing pass. 116 // Data from the source is copied into this buffer for each processing pass.
107 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> input_buffer_; 117 scoped_ptr<float[], base::ScopedPtrAlignedFree> input_buffer_;
108 118
109 // Stores the runtime selection of which Convolve function to use. 119 // Stores the runtime selection of which Convolve function to use.
110 #if defined(ARCH_CPU_X86_FAMILY) && !defined(__SSE__) 120 #if defined(ARCH_CPU_X86_FAMILY) && !defined(__SSE__)
111 typedef float (*ConvolveProc)(const float*, const float*, const float*, 121 typedef float (*ConvolveProc)(const float*, const float*, const float*,
112 double); 122 double);
113 const ConvolveProc convolve_proc_; 123 const ConvolveProc convolve_proc_;
114 #endif 124 #endif
115 125
116 // Pointers to the various regions inside |input_buffer_|. See the diagram at 126 // Pointers to the various regions inside |input_buffer_|. See the diagram at
117 // the top of the .cc file for more information. 127 // the top of the .cc file for more information.
118 float* const r0_; 128 float* const r0_;
119 float* const r1_; 129 float* const r1_;
120 float* const r2_; 130 float* const r2_;
121 float* const r3_; 131 float* const r3_;
122 float* const r4_; 132 float* const r4_;
123 float* const r5_; 133 float* const r5_;
124 134
125 DISALLOW_COPY_AND_ASSIGN(SincResampler); 135 DISALLOW_COPY_AND_ASSIGN(SincResampler);
126 }; 136 };
127 137
128 } // namespace media 138 } // namespace media
129 139
130 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ 140 #endif // MEDIA_BASE_SINC_RESAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698