- Need to be able to query the number of output PCM frames that can be generated from the currently cached input. The
returned value must be fractional. Likewise, must be able to query the number of cached input PCM frames and must
also be fractional.
- Need to be able to query exactly how many output PCM frames the user would get if they requested a certain number
input frames. Likewise, need to be able to query how many input PCM frames are required for a certain number of
output frames.
- Must support dynamic changing of the sample rate, both by input/output rate and by ratio
- Each read and seek function for each algorithm must handle a ratio of 1 in a fast path
- Must have different modes on how to handle the last of the input samples. Certain situations (streaming) requires
the last input samples to be cached in the internal structure for the windowing algorithm. Other situations require
all of the input samples to be consumed in order to output the correct total sample count.
- Pointers passed into the onRead() callback must be guaranteed to be aligned to MAL_SIMD_ALIGNMENT.
Other Notes:
- I've had a bug in the past where a single call to read() returns too many samples. It essentially computes more
samples than the input data would allow. The input data would get consumed, but output samples would continue to
get computed up to the requested frame count, filling in the end with zeroes. This is completely wrong because
the return value needs to be used to know whether or not the end of the input has been reached.
Random Notes:
- You cannot change the algorithm after initialization.
*/
#ifndef mal_resampler_h
#define mal_resampler_h
#define MAL_RESAMPLER_SEEK_SILENT_INPUT (1 << 0) /* When set, does not read anything from the client when seeking. This does _not_ call onRead(). */
#define MAL_RESAMPLER_SEEK_INPUT_RATE (1 << 1) /* When set, treats the specified frame count based on the input sample rate rather than the output sample rate. */
mal_resample_algorithm_passthrough/* No resampling. */
}mal_resample_algorithm;
typedefenum
{
mal_resampler_end_of_input_mode_consume=0,/* When the end of the input stream is reached, consume the last input PCM frames (do not leave them in the internal cache). Default. */
mal_resampler_end_of_input_mode_no_consume/* When the end of the input stream is reached, do _not_ consume the last input PCM frames (leave them in the internal cache). Use this in streaming situations. */
mal_uint64framesToReadNow=(pResampler->config.format==mal_format_f32)?ppRunningFramesFrameCount:ppRunningFramesFrameCount*2;/* x2 for the s16 frame count because ppRunningFramesFrameCount is based on f32. */