24 lines
729 B
Plaintext
24 lines
729 B
Plaintext
#! Contains what the tests of `audio` share: whether a result failed as it
|
|||
|
|
#! should, and how far one run of samples strays from another. The Ogg Vorbis
|
||
|
|
#! streams they decode are made in `streams.sakura`.
|
||
|
|
|
||
|
|
import std::math;
|
||
|
|
import malunal::audio;
|
||
|
|
|
||
|
|
# Whether a result failed with an error.
|
||
|
|
def fails<T>(made: result<T, audio_error>, why: audio_error): bool {
|
||
|
|
if made is error(e) {
|
||
|
|
return e == why;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
# How far one run of samples strays from another at most, or 1000 where they're
|
||
|
|
# of other lengths.
|
||
|
|
def apart(a: span<f32>, b: span<f32>): f32 {
|
||
|
|
return 1000 if a.length != b.length;
|
||
|
|
var most: f32 = 0;
|
||
|
|
for i in 0..a.length {
|
||
|
|
most = math::max(most, math::abs(a[i] - b[i]));
|
||
|
|
}
|
||
|
|
return most;
|
||
|
|
}
|