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

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: 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
« no previous file with comments | « no previous file | media/base/sinc_resampler.cc » ('j') | media/base/sinc_resampler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // of data to be rendered into |destination|; zero padded if not enough frames 46 // of data to be rendered into |destination|; zero padded if not enough frames
47 // are available to satisfy the request. 47 // are available to satisfy the request.
48 typedef base::Callback<void(float* destination, int frames)> ReadCB; 48 typedef base::Callback<void(float* destination, int frames)> ReadCB;
49 49
50 // Constructs a SincResampler with the specified |read_cb|, which is used to 50 // Constructs a SincResampler with the specified |read_cb|, which is used to
51 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of 51 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of
52 // input / output sample rates. 52 // input / output sample rates.
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|.
henrika (OOO until Aug 14) 2013/04/11 18:27:20 nit, remove trailing _
DaleCurtis 2013/04/15 20:27:31 read_cb_ is correct here since it's referring to t
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.
henrika (OOO until Aug 14) 2013/04/11 18:27:20 same here
DaleCurtis 2013/04/15 20:27:31 Ditto.
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.
64 void Flush(); 64 void Flush();
65 65
66 void UpdateSampleRateRatio(double io_sample_rate_ratio_);
Chris Rogers 2013/04/08 19:38:11 nit: method param should not have "_" at end Also
henrika (OOO until Aug 14) 2013/04/11 18:27:20 Would it make any sense to add sanity checks here
DaleCurtis 2013/04/15 20:27:31 Removed _. Changed to SetRatio().
DaleCurtis 2013/04/15 20:27:31 Any value is okay.
67
66 private: 68 private:
67 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve); 69 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve);
68 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark); 70 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark);
69 71
70 void InitializeKernel(); 72 void InitializeKernel(bool first_run);
Chris Rogers 2013/04/08 19:38:11 Can't we avoid having to pass this in as a param a
DaleCurtis 2013/04/15 20:27:31 Done.
71 73
72 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are 74 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are
73 // linearly interpolated using |kernel_interpolation_factor|. On x86, the 75 // linearly interpolated using |kernel_interpolation_factor|. On x86, the
74 // underlying implementation is chosen at run time based on SSE support. On 76 // 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. 77 // ARM, NEON support is chosen at compile time based on compilation flags.
76 static float Convolve_C(const float* input_ptr, const float* k1, 78 static float Convolve_C(const float* input_ptr, const float* k1,
77 const float* k2, double kernel_interpolation_factor); 79 const float* k2, double kernel_interpolation_factor);
78 #if defined(ARCH_CPU_X86_FAMILY) 80 #if defined(ARCH_CPU_X86_FAMILY)
79 static float Convolve_SSE(const float* input_ptr, const float* k1, 81 static float Convolve_SSE(const float* input_ptr, const float* k1,
80 const float* k2, 82 const float* k2,
81 double kernel_interpolation_factor); 83 double kernel_interpolation_factor);
82 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) 84 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
83 static float Convolve_NEON(const float* input_ptr, const float* k1, 85 static float Convolve_NEON(const float* input_ptr, const float* k1,
84 const float* k2, 86 const float* k2,
85 double kernel_interpolation_factor); 87 double kernel_interpolation_factor);
86 #endif 88 #endif
87 89
88 // The ratio of input / output sample rates. 90 // The ratio of input / output sample rates.
89 const double io_sample_rate_ratio_; 91 double io_sample_rate_ratio_;
90 92
91 // An index on the source input buffer with sub-sample precision. It must be 93 // An index on the source input buffer with sub-sample precision. It must be
92 // double precision to avoid drift. 94 // double precision to avoid drift.
93 double virtual_source_idx_; 95 double virtual_source_idx_;
94 96
95 // The buffer is primed once at the very beginning of processing. 97 // The buffer is primed once at the very beginning of processing.
96 bool buffer_primed_; 98 bool buffer_primed_;
97 99
98 // Source of data for resampling. 100 // Source of data for resampling.
99 ReadCB read_cb_; 101 ReadCB read_cb_;
100 102
101 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. 103 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
102 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from 104 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from
103 // 0.0 to 1.0 sample. 105 // 0.0 to 1.0 sample.
104 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> kernel_storage_; 106 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_storage_;
107 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_pre_sinc_storage_;
108 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_window_storage_;
105 109
106 // Data from the source is copied into this buffer for each processing pass. 110 // Data from the source is copied into this buffer for each processing pass.
107 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> input_buffer_; 111 scoped_ptr<float[], base::ScopedPtrAlignedFree> input_buffer_;
108 112
109 // Stores the runtime selection of which Convolve function to use. 113 // Stores the runtime selection of which Convolve function to use.
110 #if defined(ARCH_CPU_X86_FAMILY) && !defined(__SSE__) 114 #if defined(ARCH_CPU_X86_FAMILY) && !defined(__SSE__)
111 typedef float (*ConvolveProc)(const float*, const float*, const float*, 115 typedef float (*ConvolveProc)(const float*, const float*, const float*,
112 double); 116 double);
113 const ConvolveProc convolve_proc_; 117 const ConvolveProc convolve_proc_;
114 #endif 118 #endif
115 119
116 // Pointers to the various regions inside |input_buffer_|. See the diagram at 120 // Pointers to the various regions inside |input_buffer_|. See the diagram at
117 // the top of the .cc file for more information. 121 // the top of the .cc file for more information.
118 float* const r0_; 122 float* const r0_;
119 float* const r1_; 123 float* const r1_;
120 float* const r2_; 124 float* const r2_;
121 float* const r3_; 125 float* const r3_;
122 float* const r4_; 126 float* const r4_;
123 float* const r5_; 127 float* const r5_;
124 128
125 DISALLOW_COPY_AND_ASSIGN(SincResampler); 129 DISALLOW_COPY_AND_ASSIGN(SincResampler);
126 }; 130 };
127 131
128 } // namespace media 132 } // namespace media
129 133
130 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ 134 #endif // MEDIA_BASE_SINC_RESAMPLER_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/sinc_resampler.cc » ('j') | media/base/sinc_resampler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698