Chromium Code Reviews| 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..4fcc021eaba7e7c09215cd907b0b000b0efb72df |
| --- /dev/null |
| +++ b/media/base/sinc_resampler.h |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Ami GONE FROM CHROMIUM
2012/06/30 20:29:30
Visual plot link should include a bit of explanati
DaleCurtis
2012/07/03 00:36:34
Moved to imgur and updated description.
|
| +// 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 "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +// SincResampler is a high-quality single-channel sample-rate converter. |
| +class MEDIA_EXPORT SincResampler { |
| + public: |
| + // The number of destination frames generated per processing pass. |
| + static const int kBlockSize; |
|
Ami GONE FROM CHROMIUM
2012/06/30 20:29:30
enum turns this into a compile-time constant, avoi
DaleCurtis
2012/07/03 00:36:34
With the changes to multichannel resampler, these
DaleCurtis
2012/07/03 01:53:07
Actually this is more complicated than I thought,
|
| + |
| + // The size of the internal buffer used by the resampler. |
| + static const int kBufferSize; |
|
Ami GONE FROM CHROMIUM
2012/06/30 20:29:30
ditto
DaleCurtis
2012/07/03 00:36:34
Ditto.
|
| + |
| + // Abstract base-class for a pulling data into SincResampler. |
|
Ami GONE FROM CHROMIUM
2012/06/30 20:29:30
Ditto to comment from other CL; make this a typede
DaleCurtis
2012/07/03 00:36:34
Done.
|
| + class AudioSourceProvider { |
| + public: |
| + // ProvideInput() is called repeatedly to render time-slices of a continuous |
| + // audio stream. |
| + virtual void ProvideInput(float* destination, int number_of_frames) = 0; |
| + |
| + protected: |
| + virtual ~AudioSourceProvider() {} |
| + }; |
| + |
| + // Constructs a SincResampler with the specified |provider|, which is used to |
| + // acquire audio data for resampling. |scale_factor| is input_sample_rate / |
| + // output_sample_rate. |
| + // TODO(dalecurtis): Should provider be a const ref? Need to make ProvideInput |
| + // const if so... Following the RenderCallback model currently. |
| + SincResampler(AudioSourceProvider* provider, double scale_factor); |
| + virtual ~SincResampler(); |
| + |
| + // Resample |number_of_frames| of data from |provider_| into |destination|. |
| + // If |number_of_frames| < kBlockSize AudioSourceProvider::ProvideInput() will |
| + // be called at most once depending on if data remains in the internal buffer. |
| + void Resample(float* destination, int number_of_frames); |
| + |
| + private: |
| + double scale_factor_; |
| + |
| + // |virtual_source_idx_| is 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_; |
| + |
| + // |provider_| is used to provide the audio input stream to the resampler. |
| + AudioSourceProvider* provider_; |
| + |
| + // |kernel_storage_| has 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. |
| + float* kernel_storage_; |
|
Ami GONE FROM CHROMIUM
2012/06/30 20:29:30
scoped
DaleCurtis
2012/07/03 00:36:34
Done.
|
| + |
| + // Data from the source is copied into this buffer for each processing pass. |
| + float* input_buffer_; |
|
Ami GONE FROM CHROMIUM
2012/06/30 20:29:30
scoped
DaleCurtis
2012/07/03 00:36:34
Done.
|
| + |
| + void InitializeKernel(); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_SINC_RESAMPLER_H_ |