mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 00:34:03 +02:00
SRC/Speex: Add support for querying required input frame counts.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#define RANDOM_PREFIX ma_speex
|
||||
#include "thirdparty/speex_resampler.h"
|
||||
|
||||
int ma_speex_resampler_get_required_input_frame_count(SpeexResamplerState* st, spx_uint32_t out_len, spx_uint32_t* in_len);
|
||||
|
||||
#endif /* ma_speex_resampler_h */
|
||||
|
||||
#if defined(MINIAUDIO_SPEEX_RESAMPLER_IMPLEMENTATION)
|
||||
@@ -23,4 +25,31 @@
|
||||
#else
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
EXPORT int ma_speex_resampler_get_required_input_frame_count(SpeexResamplerState* st, spx_uint32_t out_len, spx_uint32_t* in_len)
|
||||
{
|
||||
spx_uint32_t count;
|
||||
|
||||
if (st == NULL || in_len == NULL) {
|
||||
return RESAMPLER_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
*in_len = 0;
|
||||
|
||||
if (out_len == 0) {
|
||||
return RESAMPLER_ERR_SUCCESS; /* Nothing to do. */
|
||||
}
|
||||
|
||||
/* miniaudio only uses interleaved APIs so we can safely just use channel index 0 for the calculations. */
|
||||
if (st->nb_channels == 0) {
|
||||
return RESAMPLER_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
count = out_len * st->int_advance;
|
||||
count += (st->samp_frac_num[0] + (out_len * st->frac_advance)) / st->den_rate;
|
||||
|
||||
*in_len = count;
|
||||
|
||||
return RESAMPLER_ERR_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user