Draft: dsound: Speed up resampling.

This implements a number of optimizations, in particular:

  • Swapping around the resampling loops in case of downsampling, allowing the FIR step to stay fixed regardless of the resampling ratio.
  • Rearranging the FIR array elements to make the access sequential.
  • Adding SSE versions of the resampling functions.

Together, these amount to more than a 5x reduction of cp_fields_resample execution time. The quality of the resampling should be the same, or even improve slightly, due to a more precise rem calculation and removal of the FIR step rounding, although I haven't yet conducted any measurements.

UPDATE

Added some more optimizations:

  • Using fixed point math inside the resampling functions.
  • Optimizing the SSE versions by hand.
  • Adding AVX+FMA3 versions of the resampling functions.
  • Getting and putting all channel samples in one go.

Combined with the previous ones, these bring the total speedup to 15x for upsampling and 13x for downsampling compared to the upstream.

UPDATE 2

Added even more optimizations:

  • Mixing and applying the volume in the put functions.
  • Directly resampling interleaved stereo.
  • Adding SSE2 version of getsamples16.
  • Adding SSE version of putsamples_stereo and putsamples_mono2stereo.

With these changes the speed of the Wine resampler gets very close to the current native DirectSound resampler. It's only about 15% slower on my Zen+ laptop CPU and on my Zen 4 desktop CPU it's actually faster than native.

Edited by Anton Baskanov

Merge request reports

Loading