| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_SINC_RESAMPLER_H_ | 5 #ifndef MEDIA_BASE_SINC_RESAMPLER_H_ |
| 6 #define MEDIA_BASE_SINC_RESAMPLER_H_ | 6 #define MEDIA_BASE_SINC_RESAMPLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // are available to satisfy the request. | 43 // are available to satisfy the request. |
| 44 typedef base::Callback<void(int frames, float* destination)> ReadCB; | 44 typedef base::Callback<void(int frames, float* destination)> ReadCB; |
| 45 | 45 |
| 46 // Constructs a SincResampler with the specified |read_cb|, which is used to | 46 // Constructs a SincResampler with the specified |read_cb|, which is used to |
| 47 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio | 47 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio |
| 48 // of input / output sample rates. |request_frames| controls the size in | 48 // of input / output sample rates. |request_frames| controls the size in |
| 49 // frames of the buffer requested by each |read_cb| call. The value must be | 49 // frames of the buffer requested by each |read_cb| call. The value must be |
| 50 // greater than kKernelSize. Specify kDefaultRequestSize if there are no | 50 // greater than kKernelSize. Specify kDefaultRequestSize if there are no |
| 51 // request size constraints. | 51 // request size constraints. |
| 52 SincResampler(double io_sample_rate_ratio, | 52 SincResampler(double io_sample_rate_ratio, |
| 53 size_t request_frames, | 53 int request_frames, |
| 54 const ReadCB& read_cb); | 54 const ReadCB& read_cb); |
| 55 virtual ~SincResampler(); | 55 virtual ~SincResampler(); |
| 56 | 56 |
| 57 // Resample |frames| of data from |read_cb_| into |destination|. | 57 // Resample |frames| of data from |read_cb_| into |destination|. |
| 58 void Resample(int frames, float* destination); | 58 void Resample(int frames, float* destination); |
| 59 | 59 |
| 60 // The maximum size in frames that guarantees Resample() will only make a | 60 // The maximum size in frames that guarantees Resample() will only make a |
| 61 // single call to |read_cb_| for more data. | 61 // single call to |read_cb_| for more data. |
| 62 int ChunkSize() const; | 62 int ChunkSize() const; |
| 63 | 63 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // double precision to avoid drift. | 102 // double precision to avoid drift. |
| 103 double virtual_source_idx_; | 103 double virtual_source_idx_; |
| 104 | 104 |
| 105 // The buffer is primed once at the very beginning of processing. | 105 // The buffer is primed once at the very beginning of processing. |
| 106 bool buffer_primed_; | 106 bool buffer_primed_; |
| 107 | 107 |
| 108 // Source of data for resampling. | 108 // Source of data for resampling. |
| 109 const ReadCB read_cb_; | 109 const ReadCB read_cb_; |
| 110 | 110 |
| 111 // The size (in samples) to request from each |read_cb_| execution. | 111 // The size (in samples) to request from each |read_cb_| execution. |
| 112 const size_t request_frames_; | 112 const int request_frames_; |
| 113 | 113 |
| 114 // The number of source frames processed per pass. | 114 // The number of source frames processed per pass. |
| 115 size_t block_size_; | 115 int block_size_; |
| 116 | 116 |
| 117 // The size (in samples) of the internal buffer used by the resampler. | 117 // The size (in samples) of the internal buffer used by the resampler. |
| 118 const size_t input_buffer_size_; | 118 const int input_buffer_size_; |
| 119 | 119 |
| 120 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. | 120 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. |
| 121 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from | 121 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from |
| 122 // 0.0 to 1.0 sample. | 122 // 0.0 to 1.0 sample. |
| 123 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_storage_; | 123 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_storage_; |
| 124 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_pre_sinc_storage_; | 124 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_pre_sinc_storage_; |
| 125 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_window_storage_; | 125 scoped_ptr<float[], base::ScopedPtrAlignedFree> kernel_window_storage_; |
| 126 | 126 |
| 127 // Data from the source is copied into this buffer for each processing pass. | 127 // Data from the source is copied into this buffer for each processing pass. |
| 128 scoped_ptr<float[], base::ScopedPtrAlignedFree> input_buffer_; | 128 scoped_ptr<float[], base::ScopedPtrAlignedFree> input_buffer_; |
| 129 | 129 |
| 130 // Pointers to the various regions inside |input_buffer_|. See the diagram at | 130 // Pointers to the various regions inside |input_buffer_|. See the diagram at |
| 131 // the top of the .cc file for more information. | 131 // the top of the .cc file for more information. |
| 132 float* r0_; | 132 float* r0_; |
| 133 float* const r1_; | 133 float* const r1_; |
| 134 float* const r2_; | 134 float* const r2_; |
| 135 float* r3_; | 135 float* r3_; |
| 136 float* r4_; | 136 float* r4_; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(SincResampler); | 138 DISALLOW_COPY_AND_ASSIGN(SincResampler); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 } // namespace media | 141 } // namespace media |
| 142 | 142 |
| 143 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ | 143 #endif // MEDIA_BASE_SINC_RESAMPLER_H_ |
| OLD | NEW |