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

Unified 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: Remove unused variable. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/sinc_resampler.cc » ('j') | media/base/sinc_resampler.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/sinc_resampler.h
diff --git a/media/base/sinc_resampler.h b/media/base/sinc_resampler.h
new file mode 100644
index 0000000000000000000000000000000000000000..626478f7205f9756bbcdcae7c9bfbad8ce56b17b
--- /dev/null
+++ b/media/base/sinc_resampler.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_SINC_RESAMPLER_H_
+#define MEDIA_BASE_SINC_RESAMPLER_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// SincResampler is a high-quality single-channel sample-rate converter.
+class MEDIA_EXPORT SincResampler {
+ public:
+ // Callback type for providing more data into the resampler. Expects |frames|
+ // of data to be rendered into |destination|; zero padded if not enough frames
+ // are available to satisfy the request.
+ typedef base::Callback<void(float* destination, int frames)> ReadCB;
+
+ // Constructs a SincResampler with the specified |read_cb|, which is used to
+ // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of
+ // input / output sample rates.
+ SincResampler(double io_sample_rate_ratio, const ReadCB& read_cb);
+ virtual ~SincResampler();
+
+ // Resample |frames| of data from |read_cb_| into |destination|.
+ void Resample(float* destination, int frames);
+
+ // The maximum size in frames that guarantees Resample() will only make a
+ // single call to |read_cb_| for more data.
+ int ChunkSize();
+
+ private:
+ enum {
Ami GONE FROM CHROMIUM 2012/07/10 03:23:00 This entire enum can move to the top of the .cc fi
DaleCurtis 2012/07/10 21:38:55 Done.
+ // The kernel size can be adjusted for quality (higher is better) at the
+ // expense of performance. Must be an even number.
+ // TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
+ kKernelSize = 32,
+
+ // The number of destination frames generated per processing pass. Affects
+ // how often and for how much SincResampler calls back for input. Must be
+ // greater than kKernelSize.
+ kBlockSize = 512,
+
+ // The kernel offset count is used for interpolation and is the number of
+ // sub-sample kernel shifts. Can be adjusted for quality (higher is better)
+ // at the expense of allocating more memory.
+ kKernelOffsetCount = 32,
+ kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1),
+
+ // The size (in samples) of the internal buffer used by the resampler.
+ kBufferSize = kBlockSize + kKernelSize
+ };
+
+ // The ratio of input / output sample rates.
+ double io_sample_rate_ratio_;
+
+ // An index on the source input buffer with sub-sample precision. It must be
+ // double precision to avoid drift.
Ami GONE FROM CHROMIUM 2012/07/10 03:23:00 This gives me the heebie-jeebies. Skimming the .c
DaleCurtis 2012/07/10 05:24:48 Not quite, it moves forward by io_sample_rate_rati
Ami GONE FROM CHROMIUM 2012/07/10 16:48:50 int64 virtual_source_thingy_; while (...) { int
DaleCurtis 2012/07/10 21:38:55 So I experimented with this a couple different way
+ double virtual_source_idx_;
+
+ // The buffer is primed once at the very beginning of processing.
+ bool buffer_primed_;
+
+ // Source of data for resampling.
+ ReadCB read_cb_;
+
+ // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
+ // The kernel offsets are sub-sample shifts of a windowed sinc shifted from
+ // 0.0 to 1.0 sample.
+ scoped_array<float> kernel_storage_;
+
+ // Data from the source is copied into this buffer for each processing pass.
+ scoped_array<float> input_buffer_;
+
+ void InitializeKernel();
Ami GONE FROM CHROMIUM 2012/07/10 03:23:00 Methods go above members.
DaleCurtis 2012/07/10 21:38:55 Done.
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_SINC_RESAMPLER_H_
« 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