Initial Commit
This commit is contained in:
36 files changed
+4431
No files matched your search
@@ -0,0 +1,74 @@
|
||||
#! Contains the tests of Ogg Vorbis: streams the tests make decoded to the
|
||||
#! frames the spec defines, coupled channels and single, short blocks and long,
|
||||
#! cut where their granule positions say; read in pieces and from the start
|
||||
#! again; and broken streams refused.
|
||||
#!
|
||||
#! Real encoders' files were checked apart from these: 63 of them, from 1 KB to
|
||||
#! 9 MB, decoded as libvorbis decodes them, every sample within 5e-7.
|
||||
|
||||
import std::testing;
|
||||
import malunal::audio;
|
||||
|
||||
@test def decodes_two_coupled_channels_as_the_spec_defines(t: &mut tester): void {
|
||||
val made := made_vorbis(2, 0);
|
||||
val read := audio::decode(made.bytes.view()) else (e) { t.expects(false); return; };
|
||||
t.expects(read.rate == 48000 && read.channels == 2);
|
||||
t.expects(read.frames == made.expected.length / 2);
|
||||
t.expects(apart(read.samples.view(), made.expected.view()) < 1e-4);
|
||||
}
|
||||
|
||||
@test def decodes_one_channel_as_the_spec_defines(t: &mut tester): void {
|
||||
val made := made_vorbis(1, 0);
|
||||
val read := audio::decode(made.bytes.view()) else (e) { t.expects(false); return; };
|
||||
t.expects(read.channels == 1 && read.frames == made.expected.length);
|
||||
t.expects(apart(read.samples.view(), made.expected.view()) < 1e-4);
|
||||
}
|
||||
|
||||
@test def cuts_the_frames_its_last_granule_position_leaves_out(t: &mut tester): void {
|
||||
val made := made_vorbis(2, 37);
|
||||
val read := audio::decode(made.bytes.view()) else (e) { t.expects(false); return; };
|
||||
t.expects(read.frames == made.expected.length / 2);
|
||||
t.expects(apart(read.samples.view(), made.expected.view()) < 1e-4);
|
||||
val opened := audio::vorbis::decoder::open(made.bytes.view()) else (e) { t.expects(false); return; };
|
||||
t.expects(opened.frames == read.frames && opened.rate == 48000 && opened.channels == 2);
|
||||
}
|
||||
|
||||
@test def reads_in_any_pieces_and_from_the_start_again(t: &mut tester): void {
|
||||
val made := made_vorbis(2, 5);
|
||||
var reading := audio::vorbis::decoder::open(made.bytes.view()) else (e) { t.expects(false); return; };
|
||||
for _ in 0..2 {
|
||||
var all := vector::<f32>::new();
|
||||
var piece := vector::<f32>::new();
|
||||
piece.resize(2 * 13);
|
||||
while true {
|
||||
val count := reading.read(piece.slice()) else (e) { t.expects(false); return; };
|
||||
break if count == 0;
|
||||
for i in 0..count * 2 {
|
||||
all.append(piece[i]);
|
||||
}
|
||||
}
|
||||
t.expects(apart(all.view(), made.expected.view()) < 1e-4);
|
||||
reading.rewind();
|
||||
}
|
||||
}
|
||||
|
||||
@test def refuses_broken_streams(t: &mut tester): void {
|
||||
# A byte of a page changed, so its CRC is wrong.
|
||||
var changed := made_vorbis(1, 0);
|
||||
changed.bytes[changed.bytes.length - 3] ^= 0x10;
|
||||
t.expects(fails(audio::decode(changed.bytes.view()), audio_error::malformed));
|
||||
|
||||
# Cut short, partway through its last page.
|
||||
var cut := made_vorbis(1, 0);
|
||||
cut.bytes.truncate();
|
||||
t.expects(fails(audio::decode(cut.bytes.view()), audio_error::malformed));
|
||||
|
||||
# A floor of type 0.
|
||||
val old := made_vorbis(1, 0, true);
|
||||
t.expects(fails(audio::decode(old.bytes.view()), audio_error::unsupported));
|
||||
|
||||
# An Ogg file of something besides Vorbis.
|
||||
var other := vector::<u8>::new();
|
||||
page_of(&mut other, 2, 0, 0, "\x80theora", span::<u8>::empty());
|
||||
t.expects(fails(audio::decode(other.view()), audio_error::unrecognized));
|
||||
}
|
||||
Reference in new issue
Block a user