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

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: Really fix iOS. 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
« no previous file with comments | « media/base/simd/vector_math_sse.cc ('k') | media/base/sinc_resampler.cc » ('j') | no next file with comments »
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "build/build_config.h"
12 #include "media/base/media_export.h" 13 #include "media/base/media_export.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 // SincResampler is a high-quality single-channel sample-rate converter. 17 // SincResampler is a high-quality single-channel sample-rate converter.
17 class MEDIA_EXPORT SincResampler { 18 class MEDIA_EXPORT SincResampler {
18 public: 19 public:
19 // The maximum number of samples that may be requested from the callback ahead 20 enum {
20 // of the current position in the stream. 21 // The kernel size can be adjusted for quality (higher is better) at the
21 static const int kMaximumLookAheadSize; 22 // expense of performance. Must be a multiple of 32.
23 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
24 kKernelSize = 32,
25
26 // The number of destination frames generated per processing pass. Affects
27 // how often and for how much SincResampler calls back for input. Must be
28 // greater than kKernelSize.
29 kBlockSize = 512,
30
31 // The kernel offset count is used for interpolation and is the number of
32 // sub-sample kernel shifts. Can be adjusted for quality (higher is better)
33 // at the expense of allocating more memory.
34 kKernelOffsetCount = 32,
35 kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1),
36
37 // The size (in samples) of the internal buffer used by the resampler.
38 kBufferSize = kBlockSize + kKernelSize,
39
40 // The maximum number of samples that may be requested from the callback
41 // ahead of the current position in the stream.
42 kMaximumLookAheadSize = kBufferSize
43 };
22 44
23 // Callback type for providing more data into the resampler. Expects |frames| 45 // 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 46 // of data to be rendered into |destination|; zero padded if not enough frames
25 // are available to satisfy the request. 47 // are available to satisfy the request.
26 typedef base::Callback<void(float* destination, int frames)> ReadCB; 48 typedef base::Callback<void(float* destination, int frames)> ReadCB;
27 49
28 // 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
29 // 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
30 // input / output sample rates. 52 // input / output sample rates.
31 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb); 53 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb);
32 virtual ~SincResampler(); 54 virtual ~SincResampler();
33 55
34 // Resample |frames| of data from |read_cb_| into |destination|. 56 // Resample |frames| of data from |read_cb_| into |destination|.
35 void Resample(float* destination, int frames); 57 void Resample(float* destination, int frames);
36 58
37 // 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
38 // single call to |read_cb_| for more data. 60 // single call to |read_cb_| for more data.
39 int ChunkSize(); 61 int ChunkSize() const;
40 62
41 // Flush all buffered data and reset internal indices. 63 // Flush all buffered data and reset internal indices.
42 void Flush(); 64 void Flush();
43 65
44 private: 66 private:
45 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve); 67 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, Convolve);
46 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark); 68 FRIEND_TEST_ALL_PREFIXES(SincResamplerTest, ConvolveBenchmark);
47 69
48 void InitializeKernel(); 70 void InitializeKernel();
49 71
50 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are 72 // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are
51 // linearly interpolated using |kernel_interpolation_factor|. On x86, the 73 // linearly interpolated using |kernel_interpolation_factor|. On x86, the
52 // underlying implementation is chosen at run time based on SSE support. On 74 // 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. 75 // ARM, NEON support is chosen at compile time based on compilation flags.
54 static float Convolve(const float* input_ptr, const float* k1, 76 static float Convolve(const float* input_ptr, const float* k1,
55 const float* k2, double kernel_interpolation_factor); 77 const float* k2, double kernel_interpolation_factor);
56 static float Convolve_C(const float* input_ptr, const float* k1, 78 static float Convolve_C(const float* input_ptr, const float* k1,
57 const float* k2, double kernel_interpolation_factor); 79 const float* k2, double kernel_interpolation_factor);
80 #if defined(ARCH_CPU_X86_FAMILY)
58 static float Convolve_SSE(const float* input_ptr, const float* k1, 81 static float Convolve_SSE(const float* input_ptr, const float* k1,
59 const float* k2, 82 const float* k2,
60 double kernel_interpolation_factor); 83 double kernel_interpolation_factor);
84 #elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)
61 static float Convolve_NEON(const float* input_ptr, const float* k1, 85 static float Convolve_NEON(const float* input_ptr, const float* k1,
62 const float* k2, 86 const float* k2,
63 double kernel_interpolation_factor); 87 double kernel_interpolation_factor);
88 #endif
64 89
65 // The ratio of input / output sample rates. 90 // The ratio of input / output sample rates.
66 double io_sample_rate_ratio_; 91 const double io_sample_rate_ratio_;
67 92
68 // 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
69 // double precision to avoid drift. 94 // double precision to avoid drift.
70 double virtual_source_idx_; 95 double virtual_source_idx_;
71 96
72 // The buffer is primed once at the very beginning of processing. 97 // The buffer is primed once at the very beginning of processing.
73 bool buffer_primed_; 98 bool buffer_primed_;
74 99
75 // Source of data for resampling. 100 // Source of data for resampling.
76 ReadCB read_cb_; 101 ReadCB read_cb_;
(...skipping 14 matching lines...) Expand all
91 float* const r3_; 116 float* const r3_;
92 float* const r4_; 117 float* const r4_;
93 float* const r5_; 118 float* const r5_;
94 119
95 DISALLOW_COPY_AND_ASSIGN(SincResampler); 120 DISALLOW_COPY_AND_ASSIGN(SincResampler);
96 }; 121 };
97 122
98 } // namespace media 123 } // namespace media
99 124
100 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ 125 #endif // MEDIA_BASE_SINC_RESAMPLER_H_
OLDNEW
« no previous file with comments | « media/base/simd/vector_math_sse.cc ('k') | media/base/sinc_resampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698