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 // 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 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.
| |
| 37 // The kernel size can be adjusted for quality (higher is better) at the | |
| 38 // expense of performance. Must be an even number. | |
| 39 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+. | |
| 40 kKernelSize = 32, | |
| 41 | |
| 42 // The number of destination frames generated per processing pass. Affects | |
| 43 // how often and for how much SincResampler calls back for input. Must be | |
| 44 // greater than kKernelSize. | |
| 45 kBlockSize = 512, | |
| 46 | |
| 47 // The kernel offset count is used for interpolation and is the number of | |
| 48 // sub-sample kernel shifts. Can be adjusted for quality (higher is better) | |
| 49 // at the expense of allocating more memory. | |
| 50 kKernelOffsetCount = 32, | |
| 51 kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), | |
| 52 | |
| 53 // The size (in samples) of the internal buffer used by the resampler. | |
| 54 kBufferSize = kBlockSize + kKernelSize | |
| 55 }; | |
| 56 | |
| 57 // The ratio of input / output sample rates. | |
| 58 double io_sample_rate_ratio_; | |
| 59 | |
| 60 // An index on the source input buffer with sub-sample precision. It must be | |
| 61 // 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
| |
| 62 double virtual_source_idx_; | |
| 63 | |
| 64 // The buffer is primed once at the very beginning of processing. | |
| 65 bool buffer_primed_; | |
| 66 | |
| 67 // Source of data for resampling. | |
| 68 ReadCB read_cb_; | |
| 69 | |
| 70 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. | |
| 71 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from | |
| 72 // 0.0 to 1.0 sample. | |
| 73 scoped_array<float> kernel_storage_; | |
| 74 | |
| 75 // Data from the source is copied into this buffer for each processing pass. | |
| 76 scoped_array<float> input_buffer_; | |
| 77 | |
| 78 void InitializeKernel(); | |
|
Ami GONE FROM CHROMIUM
2012/07/10 03:23:00
Methods go above members.
DaleCurtis
2012/07/10 21:38:55
Done.
| |
| 79 }; | |
| 80 | |
| 81 } // namespace media | |
| 82 | |
| 83 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ | |
| OLD | NEW |