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..517e0df4c8cb281a1cc56e3b12064e8a9543a62a |
--- /dev/null |
+++ b/media/base/sinc_resampler.h |
@@ -0,0 +1,75 @@ |
+// 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: |
+ enum { |
+ // The kernel size can be adjusted for quality (higher is better). |
Ami GONE FROM CHROMIUM
2012/07/03 20:54:42
For each of these magic constants you should state
DaleCurtis
2012/07/10 01:00:25
Done.
|
+ // 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. |
+ kBlockSize = 512, |
+ |
+ // The kernel offset count is used for interpolation and is the number of |
+ // sub-sample kernel shifts. |
+ kKernelOffsetCount = 32, |
+ kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), |
+ |
+ // The size of the internal buffer used by the resampler. |
Ami GONE FROM CHROMIUM
2012/07/03 20:54:42
If this is the only thing that needs to be public
Ami GONE FROM CHROMIUM
2012/07/03 20:54:42
"size" here means frame count, right? Clarify her
DaleCurtis
2012/07/09 20:35:34
Not quite. WDYT about adding a method like:
// Re
DaleCurtis
2012/07/10 01:00:25
After discussion with Chris, added a ChunkSize() m
|
+ kBufferSize = kBlockSize + kKernelSize |
+ }; |
+ |
+ // Callback type for providing more data into the resampler. Expects |frames| |
+ // of data for all channels to be rendered into |destination|; zero padded if |
Ami GONE FROM CHROMIUM
2012/07/03 20:54:42
de-multi-channel this comment
DaleCurtis
2012/07/10 01:00:25
Done.
|
+ // 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(const ReadCB& read_cb, double io_sample_rate_ratio); |
Ami GONE FROM CHROMIUM
2012/07/03 20:54:42
I'd put the ratio before the CB.
DaleCurtis
2012/07/10 01:00:25
Done.
|
+ virtual ~SincResampler(); |
+ |
+ // Resample |frames| of data from |read_cb_| into |destination|. |
+ void Resample(float* destination, int frames); |
+ |
+ private: |
+ // 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. |
+ 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(); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_SINC_RESAMPLER_H_ |