xiph / opus-tools

A set of tools to encode, inspect, and decode audio in the Opus format.
https://opus-codec.org/
Other
214 stars 78 forks source link

Resampler stride #29

Closed AndrewBelt closed 6 years ago

AndrewBelt commented 6 years ago

How does speex_resampler_set_input_stride and speex_resampler_set_output_stride work? Is the stride intended to be the number of bytes or samples until the next frame in speex_resampler_process_interleaved_float? It doesn't look like it, since its default value is 1. I would expect it to be nb_channels * sizeof(float).

AndrewBelt commented 6 years ago

Answered by mark4o on IRC. Summary:

I refer to a "frame" as N adjacent samples representing a moment in time for all N channels. in_len and out_len are in units of frames. speex_resampler_process_interleaved_*() assumes that your interleaved samples have a stride of channels samples, i.e. tightly packed frames. To process interleaved samples with a certain stride, simply call speex_resampler_process_*() for each channel, as such.

spx_uint32_t in_len_bak = *in_len;
spx_uint32_t out_len_bak = *out_len;
for (int i = 0; i < st->nb_channels; i++) {
    *in_len = in_len_bak;
    *out_len = out_len_bak;
    speex_resampler_process_float(st, i, in + i, in_len, out + i, out_len);
}