diff --git a/REAPERDenoiser b/REAPERDenoiser index aaea6a4..f98458a 100644 --- a/REAPERDenoiser +++ b/REAPERDenoiser @@ -114,7 +114,7 @@ function store_noise_profile(buffer) global(SIZE, noiseBuffer) local(index, norm // calculate an attenuation given the yNorm, and nNorm, and kSquared to approximate sNorm function denoise(yNorm, nNorm, kSquared) ( - yNorm / (yNorm + kSquared * nNorm); + yNorm > 0 ? yNorm / (yNorm + kSquared * nNorm); ); // helpful functions to get/set the right sample given an index @@ -306,6 +306,15 @@ function sum_first_pdc_samples(s0val, s1val) ( ); ); +//DEBUGPRINT("TEST_denoise_0_yNorm\n"); +assert_equal_exact(0, denoise(0, 0, 0)); + +//DEBUGPRINT("TEST_denoise_really_small_yNorm\n"); +assert_equal_exact(1, denoise(2^-140, 0, 0)); + +//DEBUGPRINT("TEST_denoise_really_small_yNorm_and_nNorm\n"); +assert_equal_exact(0.5, denoise(2^-140, 2^-140, 1)); + //DEBUGPRINT("SAMPLE_1_1_STRESS_TEST\n"); // spl0=1 spl1=1 for many samples sum_first_pdc_samples(1, 1); diff --git a/testing_defines.eel2 b/testing_defines.eel2 index cb0e252..1e0b7b9 100644 --- a/testing_defines.eel2 +++ b/testing_defines.eel2 @@ -1,8 +1,16 @@ // Helper functions to check for positive infinity, negative infinity, and nan -function is_pos_inf(x) (x == 1/0); -function is_neg_inf(x) (x == -1/0); -function is_nan(x) (x != x;); +function is_pos_inf(x) ( + (x * 2 == x) && x > 0; +); +function is_neg_inf(x) ( + is_pos_inf(-x); +); +function is_nan(x) local(z1, z2) ( + z2 = x; + z1 = x + 1; + z2 == 0 && z1 == 0; +); function assert_equal_exact(expected, actual, message) global(failed_asserts, successful_asserts) ( is_nan(expected) && is_nan(actual) ? successful_asserts += 1 : @@ -62,6 +70,35 @@ function test_summary() global(failed_asserts successful_asserts) local(total) ( ) ); +/* +pif = 0; +pif = 1/pif; +nif = 0; +nif = -1/nif; +lg = 2^64; + +printf("z/z=%g, pif=%g, nif=%g\n", z/z, pif, nif); + +assert_true( is_pos_inf(pif), " +1/0 is +inf"); +assert_false(is_neg_inf(pif), " +1/0 is -inf"); +assert_false( is_nan(pif), " +1/0 is nan"); +assert_false(is_pos_inf(nif), " -1/0 is +inf"); +assert_true( is_neg_inf(nif), " -1/0 is -inf"); +assert_false( is_nan(nif), " -1/0 is nan"); +assert_false(is_pos_inf(z/z), " z/z is +inf"); +assert_false(is_neg_inf(z/z), " z/z is -inf"); +assert_true( is_nan(z/z), " z/z is nan"); +assert_false(is_pos_inf( 0), " 0 is +inf"); +assert_false(is_neg_inf( 0), " 0 is -inf"); +assert_false( is_nan( 0), " 0 is nan"); +assert_false(is_pos_inf( lg), " 2^64 is +inf"); +assert_false(is_neg_inf( lg), " 2^64 is -inf"); +assert_false( is_nan( lg), " 2^64 is nan"); +assert_false(is_pos_inf(-lg), "-2^64 is +inf"); +assert_false(is_neg_inf(-lg), "-2^64 is -inf"); +assert_false( is_nan(-lg), "-2^64 is nan"); +*/ + // drop in for spl(channel) // function spl(channel) ( // 0 == channel ? spl0 :