[openal] Questions about OpenAL Soft's Resampler
Chris Robinson
chris.kcat at gmail.com
Fri Nov 10 01:59:11 EST 2017
On 11/09/2017 03:54 PM, Ethan Lee wrote:
> I think all that's left before this works is padding. How are padding
> sizes calculated, and how is padding adjusted for changing pitches? For
> now I just have an arbitrary block of memory to store padding...
>
> https://github.com/flibitijibibo/FACT/blob/a55aaace54f91e0ba22738c0274c823b4c6c8216/src/FACT_platform_sdl2.c#L111
Hmm. Normally padding is actually dependent on the resampler used,
rather than the stepping ratio. For a given destination sample, you only
need a certain number of source samples (two for linear, the current
sample and the next one). The stepping ratio won't influence this
because the source offset will remain in the source data range as long
as the destination offset is within the destination data range (the
number of destination samples will obviously need to be limited given
the number of available source samples).
Looking over your code though, I see it streams in samples from a
decoder rather than using predefined blocks. That can complicate things
a bit since you don't have free random access to the source samples in
the processing loop. I'd need to take a bit of time to work out how to
best deal with that.
> (Right now I'm being lazy and getting data lengths by converting the
> step size to a float64, once my brain figures out how to do it without
> getting floats involved that should be fixed too... but I figured I may
> as well do that after padding is done.)
Just be careful with that. Floating-point is notorious for rounding
errors as a result of variable precision, so if you're not careful the
calculated length could unexpectedly overshoot or undershoot by 1.
> Lastly, and this is probably super picky, but when converting from float
> to fixed is it better to round or ceil? Right now this helper is just
> used to calculate the stepping size, and plain rounding seems to work
> fine...
>
> https://github.com/flibitijibibo/FACT/blob/a55aaace54f91e0ba22738c0274c823b4c6c8216/src/FACT_platform_sdl2.c#L73
It probably doesn't matter too much given that this is dealing with step
scales around 1/4096th of a sample, but I use rounding to make the
stepping value closest to the original calculated value.
An important safety step is to ensure the resulting fixed-point stepping
value doesn't end up as 0 due to really low pitch values (maybe the XACT
API already limits this?). Clamp it to 1 to avoid a potential
divide-by-zero. You may also want to clamp the maximum stepping value to
avoid overflowing or taking too much time (high stepping values will
need more source samples for the same number of output samples).
More information about the openal
mailing list