#include "jl_mem.h" #include "jl_test.h" #include "sample.h" static void test_load_free() { JL_TEST_FUNC; Sample s; sample_load(&s, "test-files/sound.flac", 1.0, 8); // Check length. int len = 71750 + 8; len -= len % 8; JL_FAIL_IF(s.len != len, "Incorrect length."); // Check that data is normalized. float max = 0; for(int i = 0; i < s.len; ++i) { if(s.L[i] > max) { max = s.L[i]; } else if(-s.L[i] > max) { max = -s.L[i]; } if(s.R[i] > max) { max = s.R[i]; } else if(-s.R[i] > max) { max = -s.R[i]; } } JL_FAIL_IF(max != 1.0, "Data not normalized."); sample_free(&s); } static void test_playback_speed() { JL_TEST_FUNC; Sample s1; Sample s2; sample_load(&s1, "test-files/sound.flac", 1.0, 0); sample_load(&s2, "test-files/sound.flac", 0.5, 0); JL_FAIL_IF(2 * s1.len != s2.len, "Incorrect lengths."); for(int i = 0; i < s1.len; ++i) { JL_FAIL_IF(s1.L[i] != s2.L[2*i], "Incorrect data."); JL_FAIL_IF(s1.R[i] != s2.R[2*i], "Incorrect data."); } sample_free(&s1); sample_free(&s2); } int main(int argc, char **argv) { JL_LEAK_CHECK_INIT; test_load_free(); test_playback_speed(); return 0; }