@@ -60,9 +60,12 @@ For example, converting a file from 44.1 kHz to 48 kHz.
6060The ratio, 48 kHz / 44.1 kHz (equivalent to 160 / 147),
6161is fixed and constant throughout the process.
6262
63- Synchronous resampling is implemented via FFT. The data is FFT: ed , the spectrum modified,
64- and then inverse FFT: ed to get the resampled data.
65- This type of resampler is considerably faster but doesn't support changing the resampling ratio.
63+ Synchronous resampling is implemented via FFT (Fast Fourier Transform).
64+ The audio data is transformed into the frequency domain,
65+ the spectrum is scaled to match the target sample rate,
66+ and then transformed back to produce the resampled output.
67+ This type of resampler is considerably faster than sinc-based approaches
68+ but doesn't support changing the resampling ratio.
6669
6770## Usage
6871The resamplers provided by this library are intended to support processing streams of audio.
@@ -74,21 +77,28 @@ This gives a good compromise between efficiency and memory usage.
7477### Chunk size and fixed size options
7578
7679Rubato processes audio in chunks.
77- The size of these chunks is determined by the chunk size parameter given to the resampler constructor.
78- Depending on the configuration, this parameter determines
79- the number of frames in the input or output chunk, or both .
80+ The ` chunk_size ` parameter given to the resampler constructor sets the target size
81+ for the ** fixed side ** — the side that always has the same number of frames per call.
82+ The other side is variable and will differ from call to call .
8083
8184The resamplers allow specifying which side should have a fixed size.
8285
83- * ** Fixed input** : The input chunk size is fixed to the given value.
84- The output chunk size will vary depending on how many samples can be calculated using the available input data.
85- This is convenient to use for resampling data from a source that delivers data in fixed size chunks.
86- * ** Fixed output** : The output chunk size is fixed to the given value.
87- The input chunk size will vary depending on how many new samples the resampler needs to calculate the output.
88- This is meant to be used for resampling data that will be sent to some target that requires fixed size chunks.
89- * ** Both input and output fixed** : Both input and output chunk sizes are fixed.
86+ * ** Fixed input** (` FixedAsync::Input ` / ` FixedSync::Input ` ):
87+ The input chunk size is fixed to ` chunk_size ` frames per call.
88+ The output chunk size varies depending on how many samples can be calculated
89+ from the available input data.
90+ This is convenient when the audio source delivers data in fixed-size chunks
91+ (e.g. a hardware capture callback).
92+ * ** Fixed output** (` FixedAsync::Output ` / ` FixedSync::Output ` ):
93+ The output chunk size is fixed to ` chunk_size ` frames per call.
94+ The input chunk size varies depending on how many new samples the resampler
95+ needs to fill the output.
96+ This is useful when the audio destination consumes fixed-size chunks
97+ (e.g. a hardware playback callback).
98+ * ** Both input and output fixed** (` FixedSync::Both ` ):
99+ Both input and output chunk sizes are fixed.
90100 This mode is only available for the synchronous resampler.
91- In this mode, the chunk size parameter is used as a hint,
101+ In this mode, the ` chunk_size ` parameter is used as a hint,
92102 and the actual chunk sizes are calculated to fit the resampling ratio exactly.
93103 For example, a 44.1 kHz to 48 kHz resampler must use an input chunk size that is a multiple of 147,
94104 and an output chunk size that is a multiple of 160, in order to maintain the correct resampling ratio.
@@ -99,6 +109,24 @@ The resamplers allow specifying which side should have a fixed size.
99109 For asynchronous resamplers, fixing both input and output chunk sizes is not possible
100110 since the resampling ratio can change, requiring at least one side to be variable.
101111
112+ ### Input and output sizes per call
113+
114+ The ` chunk_size ` constructor parameter is only the * target* size for the fixed side.
115+ Always call ` input_frames_next() ` before providing data to ` process_into_buffer `
116+ to find out the exact number of input frames required for that call.
117+ Similarly, call ` output_frames_next() ` to find the exact number of output frames that will be written.
118+
119+ * With fixed input, ` input_frames_next() ` always returns ` chunk_size ` .
120+ ` output_frames_next() ` varies and must be checked each call.
121+ * With fixed output, ` output_frames_next() ` always returns ` chunk_size ` .
122+ ` input_frames_next() ` varies and must be checked each call.
123+ * With ` FixedSync::Both ` , both values are fixed, but they may differ from ` chunk_size `
124+ because they are rounded to fit the exact sample-rate ratio.
125+
126+ The input and output buffers must be large enough to hold at least the number of frames
127+ reported by ` input_frames_next() ` and ` output_frames_next() ` respectively.
128+ Both buffers may be larger than required — only the needed frames are read or written.
129+
102130### Resampling quality
103131The synchronous resampler has no quality settings, it always delivers the best quality.
104132
0 commit comments