soxr icon indicating copy to clipboard operation
soxr copied to clipboard

16 bit clipping results in values being destroyed due to fe_test_invalid() check

Open TomArrow opened this issue 2 years ago • 0 comments

This took me hours to debug and I'm not even sure what I'm looking at.

This code here destroys values at the start of a variable rate resample with small increments (11-12 samples).

static void RINT_CLIP(RINT_T * const dest, FLOATX const * const src,
    unsigned stride, size_t i, size_t const n, size_t * const clips SEED_ARG)
{
  COPY_SEED
  DITHER_VARS;
  for (; i < n; ++i) {
    FLOATD const d = src[i] DITHERING;
    RINT(dest[stride * i], d);
    if (fe_test_invalid()) {
      fe_clear_invalid();
      dest[stride * i] = d > 0? RINT_MAX : -RINT_MAX - 1;
      ++*clips;
    }
  }
  SAVE_SEED;
}

I am not sure what causes this to happen. The src[i] value is a perfectly fine float value but the fe_test_invalid() returns true for some reason and the code consequently destroys the values.

Sometimes it happens, sometimes it doesn't. It seems in particular small increments for resampling seem to cause it. My code uses variable rate but this happened in cases where it was just a fixed rate of 1.000 throughout. The IO values I did sox create with were 1,1 but I also tried 1,10 and 10,1 to make sure.

TomArrow avatar Nov 14 '23 04:11 TomArrow