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

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

Issue 12478002: Break out SSE functions into new media_sse target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix presubmit. Created 7 years, 9 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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 // SincResampler is a high-quality single-channel sample-rate converter. 16 // SincResampler is a high-quality single-channel sample-rate converter.
17 class MEDIA_EXPORT SincResampler { 17 class MEDIA_EXPORT SincResampler {
18 public: 18 public:
19 // The maximum number of samples that may be requested from the callback ahead 19 enum {
20 // of the current position in the stream. 20 // The kernel size can be adjusted for quality (higher is better) at the
21 static const int kMaximumLookAheadSize; 21 // expense of performance. Must be a multiple of 32.
22 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
23 kKernelSize = 32,
24
25 // The number of destination frames generated per processing pass. Affects
26 // how often and for how much SincResampler calls back for input. Must be
27 // greater than kKernelSize.
28 kBlockSize = 512,
29
30 // The kernel offset count is used for interpolation and is the number of
31 // sub-sample kernel shifts. Can be adjusted for quality (higher is better)
32 // at the expense of allocating more memory.
33 kKernelOffsetCount = 32,
34 kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1),
35
36 // The size (in samples) of the internal buffer used by the resampler.
37 kBufferSize = kBlockSize + kKernelSize,
38
39 // The maximum number of samples that may be requested from the callback
40 // ahead of the current position in the stream.
41 kMaximumLookAheadSize = kBufferSize
42 };
22 43
23 // Callback type for providing more data into the resampler. Expects |frames| 44 // Callback type for providing more data into the resampler. Expects |frames|
24 // of data to be rendered into |destination|; zero padded if not enough frames 45 // of data to be rendered into |destination|; zero padded if not enough frames
25 // are available to satisfy the request. 46 // are available to satisfy the request.
26 typedef base::Callback<void(float* destination, int frames)> ReadCB; 47 typedef base::Callback<void(float* destination, int frames)> ReadCB;
27 48
28 // Constructs a SincResampler with the specified |read_cb|, which is used to 49 // Constructs a SincResampler with the specified |read_cb|, which is used to
29 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of 50 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of
30 // input / output sample rates. 51 // input / output sample rates.
31 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb); 52 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb);
32 virtual ~SincResampler(); 53 virtual ~SincResampler();
33 54
34 // Resample |frames| of data from |read_cb_| into |destination|. 55 // Resample |frames| of data from |read_cb_| into |destination|.
35 void Resample(float* destination, int frames); 56 void Resample(float* destination, int frames);
36 57
37 // The maximum size in frames that guarantees Resample() will only make a 58 // The maximum size in frames that guarantees Resample() will only make a
38 // single call to |read_cb_| for more data. 59 // single call to |read_cb_| for more data.
39 int ChunkSize(); 60 int ChunkSize() const;
40 61
41 // Flush all buffered data and reset internal indices. 62 // Flush all buffered data and reset internal indices.
42 void Flush(); 63 void Flush();
43 64
44 private: 65 private:
45 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve); 66 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve);
46 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark); 67 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark);
47 68
48 void InitializeKernel(); 69 void InitializeKernel();
49 70
50 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are 71 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are
51 // linearly interpolated using |kernel_interpolation_factor|. On x86, the 72 // linearly interpolated using |kernel_interpolation_factor|. On x86, the
52 // underlying implementation is chosen at run time based on SSE support. On 73 // underlying implementation is chosen at run time based on SSE support. On
53 // ARM, NEON support is chosen at compile time based on compilation flags. 74 // ARM, NEON support is chosen at compile time based on compilation flags.
54 static float Convolve(const float* input_ptr, const float* k1, 75 static float Convolve(const float* input_ptr, const float* k1,
55 const float* k2, double kernel_interpolation_factor); 76 const float* k2, double kernel_interpolation_factor);
56 static float Convolve_C(const float* input_ptr, const float* k1, 77 static float Convolve_C(const float* input_ptr, const float* k1,
57 const float* k2, double kernel_interpolation_factor); 78 const float* k2, double kernel_interpolation_factor);
58 static float Convolve_SSE(const float* input_ptr, const float* k1, 79 static float Convolve_SSE(const float* input_ptr, const float* k1,
Mark Mentovai 2013/03/05 21:32:31 Can you wrap Convolve_SSE and Convolve_NEON in the
DaleCurtis 2013/03/05 21:51:37 Done.
59 const float* k2, 80 const float* k2,
60 double kernel_interpolation_factor); 81 double kernel_interpolation_factor);
61 static float Convolve_NEON(const float* input_ptr, const float* k1, 82 static float Convolve_NEON(const float* input_ptr, const float* k1,
62 const float* k2, 83 const float* k2,
63 double kernel_interpolation_factor); 84 double kernel_interpolation_factor);
64 85
65 // The ratio of input / output sample rates. 86 // The ratio of input / output sample rates.
66 double io_sample_rate_ratio_; 87 const double io_sample_rate_ratio_;
67 88
68 // An index on the source input buffer with sub-sample precision. It must be 89 // An index on the source input buffer with sub-sample precision. It must be
69 // double precision to avoid drift. 90 // double precision to avoid drift.
70 double virtual_source_idx_; 91 double virtual_source_idx_;
71 92
72 // The buffer is primed once at the very beginning of processing. 93 // The buffer is primed once at the very beginning of processing.
73 bool buffer_primed_; 94 bool buffer_primed_;
74 95
75 // Source of data for resampling. 96 // Source of data for resampling.
76 ReadCB read_cb_; 97 ReadCB read_cb_;
(...skipping 14 matching lines...) Expand all
91 float* const r3_; 112 float* const r3_;
92 float* const r4_; 113 float* const r4_;
93 float* const r5_; 114 float* const r5_;
94 115
95 DISALLOW_COPY_AND_ASSIGN(SincResampler); 116 DISALLOW_COPY_AND_ASSIGN(SincResampler);
96 }; 117 };
97 118
98 } // namespace media 119 } // namespace media
99 120
100 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ 121 #endif // MEDIA_BASE_SINC_RESAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698