liamappelbe / wav

Dart package for reading and writing wav files
Apache License 2.0
18 stars 5 forks source link

float64 write tests fail on arm #12

Closed liamappelbe closed 1 year ago

liamappelbe commented 1 year ago

The float64 bits of wav_write_test and raw_write_test produce different results on arm vs intel. Might be better to use a noise generator like this:

// Random number generator based on 32-bit FNV hash.
//
// We can't use Dart's built in random number generator because we're saving the
// values to a file, and their implementation may change in future.
class Rand {
  static const _prime = 0x1000193;
  static const _mask = (1 << 32) - 1;

  int _x = 0x811c9dc5;

  Rand() {}

  double next() {
    final x = _x;
    _x *= _prime;
    _x &= _mask;
    print(2 * (x.toDouble() / _mask.toDouble()) - 1);
    return 2 * (x.toDouble() / _mask.toDouble()) - 1;
  }
}
liamappelbe commented 1 year ago

See https://github.com/liamappelbe/wav/pull/11

liamappelbe commented 1 year ago

The nice thing about using those sine waves as tests was they were generated by audacity. So it was verification that my implementation matched an external source.

The simplest way to switch from the sine waves to the noise generator would be to change the write tests first, which would fail, then take the generated file and replace the goldens so that the write tests pass, then migrate the read tests. But this would essentially be duplicating the bijective tests. So instead I'll generate a golden for the raw float64 test, then open that in audacity, manually verify a few of the sample values, then save it to all the other formats.