Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 enum { | |
| 18 // 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.
| |
| 19 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+. | |
| 20 kKernelSize = 32, | |
| 21 | |
| 22 // The number of destination frames generated per processing pass. | |
| 23 kBlockSize = 512, | |
| 24 | |
| 25 // The kernel offset count is used for interpolation and is the number of | |
| 26 // sub-sample kernel shifts. | |
| 27 kKernelOffsetCount = 32, | |
| 28 kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), | |
| 29 | |
| 30 // 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
| |
| 31 kBufferSize = kBlockSize + kKernelSize | |
| 32 }; | |
| 33 | |
| 34 // Callback type for providing more data into the resampler. Expects |frames| | |
| 35 // 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.
| |
| 36 // not enough frames are available to satisfy the request. | |
| 37 typedef base::Callback<void(float* destination, int frames)> ReadCB; | |
| 38 | |
| 39 // Constructs a SincResampler with the specified |read_cb|, which is used to | |
| 40 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio of | |
| 41 // input / output sample rates. | |
| 42 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.
| |
| 43 virtual ~SincResampler(); | |
| 44 | |
| 45 // Resample |frames| of data from |read_cb_| into |destination|. | |
| 46 void Resample(float* destination, int frames); | |
| 47 | |
| 48 private: | |
| 49 // The ratio of input / output sample rates. | |
| 50 double io_sample_rate_ratio_; | |
| 51 | |
| 52 // An index on the source input buffer with sub-sample precision. It must be | |
| 53 // double precision to avoid drift. | |
| 54 double virtual_source_idx_; | |
| 55 | |
| 56 // The buffer is primed once at the very beginning of processing. | |
| 57 bool buffer_primed_; | |
| 58 | |
| 59 // Source of data for resampling. | |
| 60 ReadCB read_cb_; | |
| 61 | |
| 62 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. | |
| 63 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from | |
| 64 // 0.0 to 1.0 sample. | |
| 65 scoped_array<float> kernel_storage_; | |
| 66 | |
| 67 // Data from the source is copied into this buffer for each processing pass. | |
| 68 scoped_array<float> input_buffer_; | |
| 69 | |
| 70 void InitializeKernel(); | |
| 71 }; | |
| 72 | |
| 73 } // namespace media | |
| 74 | |
| 75 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ | |
| OLD | NEW |