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

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

Issue 10702050: Add SincResampler ported from WebKit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Decrease precision tests. Created 8 years, 5 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') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_BASE_SINC_RESAMPLER_H_
6 #define MEDIA_BASE_SINC_RESAMPLER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/media_export.h"
11
12 namespace media {
13
14 // SincResampler is a high-quality single-channel sample-rate converter.
15 class MEDIA_EXPORT SincResampler {
16 public:
17 // 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
19 // are available to satisfy the request.
20 typedef base::Callback<void(float* destination, int frames)> ReadCB;
21
22 // 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
24 // input / output sample rates.
25 SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb);
26 virtual ~SincResampler();
27
28 // Resample |frames| of data from |read_cb_| into |destination|.
29 void Resample(float* destination, int frames);
30
31 // The maximum size in frames that guarantees Resample() will only make a
32 // single call to |read_cb_| for more data.
33 int ChunkSize();
34
35 private:
36 void InitializeKernel();
37
38 // The ratio of input / output sample rates.
39 double io_sample_rate_ratio_;
40
41 // An index on the source input buffer with sub-sample precision. It must be
42 // double precision to avoid drift.
43 double virtual_source_idx_;
44
45 // The buffer is primed once at the very beginning of processing.
46 bool buffer_primed_;
47
48 // Source of data for resampling.
49 ReadCB read_cb_;
50
51 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
52 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from
53 // 0.0 to 1.0 sample.
54 scoped_array<float> kernel_storage_;
55
56 // Data from the source is copied into this buffer for each processing pass.
57 scoped_array<float> input_buffer_;
58
59 // Pointers to the various regions inside |input_buffer_|. See the diagram at
60 // the top of the .cc file for more information.
61 float* const r0_;
62 float* const r1_;
63 float* const r2_;
64 float* const r3_;
65 float* const r4_;
66 float* const r5_;
67 };
68
69 } // namespace media
70
71 #endif // MEDIA_BASE_SINC_RESAMPLER_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/sinc_resampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698