From cbd19fdeac44a52d0636a2722f3b4811cb0fcc9a Mon Sep 17 00:00:00 2001 From: micsthepick <11528421+micsthepick@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:06:25 +1100 Subject: [PATCH] actually fix some bugs? --- test_eel.sh | 25 ++++++++++--------- testing_defines.eel2 | 52 +++++++++++++++++++++++++++------------- vocalrediso-jamesdsp.eel | 44 +++++++++++++++++++++------------- vocalrediso.jsfx | 35 +++++++++++++++++---------- 4 files changed, 99 insertions(+), 57 deletions(-) diff --git a/test_eel.sh b/test_eel.sh index 923c73f..dde23af 100755 --- a/test_eel.sh +++ b/test_eel.sh @@ -5,17 +5,20 @@ sed -r -e 's/^(desc|slider[0-9]+):.*|^@(init|slider|block|serialize|sample)//' \ -e 's/\*IFNTEST\*|IFNTEST\{\*|\*\}IFNTEST//' \ vocalrediso-jamesdsp.eel >> vocalrediso.test.eel2 -# Run the command, capturing stderr -{ output=$(./WDL/WDL/eel2/loose_eel ./vocalrediso.test.eel2 2>&1 1>&3-); } 3>&1 - -# Check if there is any output in stderr -if [ ! -z "$output" ]; then - # Print the stderr output in red - echo -e "\e[31m$output\e[0m" - # Exit with -1 - exit -1 -else - exit 0 +# Initialize a flag to indicate stderr output +stderr_output=0 + +output=$(./WDL/WDL/eel2/loose_eel ./vocalrediso.test.eel2 2>&1) + +echo "$output" + +# Get the last line of the output +last_line=$(echo "$output" | tail -n 1) + +# Check if the last line starts with 'FAILURE' +if echo "$last_line" | grep -q "^FAILURE"; then + echo "Failed Test Cases, will return -1!" + exit -1 fi ##//DEBUGPRINT("HI"); diff --git a/testing_defines.eel2 b/testing_defines.eel2 index fcabb4f..698b10d 100644 --- a/testing_defines.eel2 +++ b/testing_defines.eel2 @@ -3,36 +3,44 @@ function is_pos_inf(x) (x == 1/0); function is_neg_inf(x) (x == -1/0); function is_nan(x) (x != x;); -function assert_equal_exact(expected, actual, message) global() ( - is_nan(expected) && is_nan(actual) ? 0 : - (is_pos_inf(expected) && is_pos_inf(actual)) || (is_neg_inf(expected) && is_neg_inf(actual)) ? 0 : +function assert_equal_exact(expected, actual, message) global(failed_asserts, successful_asserts) ( + is_nan(expected) && is_nan(actual) ? successful_asserts += 1 : + (is_pos_inf(expected) && is_pos_inf(actual)) || (is_neg_inf(expected) && is_neg_inf(actual)) ? successful_asserts += 1 : expected !== actual ? ( - fprintf(3, "expected: %g, was: %g. %s\n", expected, actual, message) - ) : 0; + fprintf(3, "\033[0;31mexpected: %g, was: %g. %s\033[0m\n", expected, actual, message); + failed_asserts += 1; + ) : successful_asserts += 1; ); function assert_equal_exact(expected, actual) global() ( assert_equal_exact(expected, actual, "values differ!") ); -function assert_near_equal(expected, tolerance, actual, message) global() ( - is_nan(expected) || is_nan(actual) || is_nan(tolerance) ? 0 : - (is_pos_inf(expected) || is_neg_inf(expected)) && (is_pos_inf(actual) || is_neg_inf(actual)) ? 0 : - abs(expected - actual) > tolerance ? ( - fprintf(3, "expected: %g (±%g), was: %g. %s\n", expected, tolerance, actual, message) - ) : 0; +function assert_near_equal(expected, tolerance, actual, message) global(failed_asserts, successful_asserts) ( + is_nan(expected) || is_nan(actual) || is_nan(tolerance) ? successful_asserts += 1 : + (is_pos_inf(expected) || is_neg_inf(expected)) && (is_pos_inf(actual) || is_neg_inf(actual)) ? successful_asserts += 1 : + abs(expected - actual) > tolerance ? ( + fprintf(3, "\033[0;31mexpected: %g (±%g), was: %g. %s\033[0m\n", expected, tolerance, actual, message); + failed_asserts += 1; + ) : successful_asserts += 1; ); -function assert_near_equal(expected, tolerance, actual) ( - assert_near_equal(expected, tolerance, actual, "values are not equal within tolerance!"); +function assert_near_equal(expected, tolerance, actual) global() ( + assert_near_equal(expected, tolerance, actual, "values are not equal within tolerance!") ); -function assert_true(boolean, message) global() ( - (!boolean) ? fprintf(3, "expected: true, was: false. %s\n", message) +function assert_true(boolean, message) global(failed_asserts, successful_asserts) ( + (!boolean) ? ( + fprintf(3, "\033[0;31mexpected: true, was: false. %s\033[0m\n", message); + failed_asserts += 1; + ) : successful_asserts += 1; ); -function assert_false(boolean, message) global() ( - boolean ? fprintf(3, "expected: false, was: true. %s\n", message) +function assert_false(boolean, message) global(failed_asserts, successful_asserts) ( + boolean ? ( + fprintf(3, "\033[0;31mexpected: false, was: true. %s\033[0m\n", message); + failed_asserts += 1; + ) : successful_asserts += 1; ); function assert_true(boolean) global() ( @@ -42,3 +50,13 @@ function assert_true(boolean) global() ( function assert_false(boolean) global() ( assert_false(boolean, ""); ); + +function test_summary() global(failed_asserts successful_asserts) local(total) ( + total = failed_asserts + successful_asserts; + failed_asserts === 0 ? fprintf(3, "\033[0;32mAll %d asserts succeeded.\033[0m\n", total) : ( + successful_asserts > 0 ? printf("\033[0;34m%d of %d asserts succeeded.\033[0m\n", successful_asserts, total); + failed_asserts > 0 ? ( + printf("\033[0;31m%d of %d asserts failed.\nFAILURE, see above!\033[0m\n", failed_asserts, total); + ) + ) +); diff --git a/vocalrediso-jamesdsp.eel b/vocalrediso-jamesdsp.eel index 39100b6..bb5362a 100644 --- a/vocalrediso-jamesdsp.eel +++ b/vocalrediso-jamesdsp.eel @@ -54,10 +54,15 @@ prev_fft_size = 0; function setup_stft_state(fft_size, first_time) ( //////////////////////// Setup block // This is called when playback starts, or when the FFT size is changed - memset(fft_buffer, 0, MAX_FFT_SIZE*2); + //memset(fft_buffer, 0, MAX_FFT_SIZE*2); memset(output_buffer, 0, buffer_length*2); memset(input_buffer, 0, buffer_length*2); + // reset indexes and counters buffer_index = 0; + output_index = 0; + fft_counter = 0; + // force silence for first overlaps where fft not yet run + silence = overlap_factor; //////////////////////// ); @@ -88,8 +93,7 @@ function process_stft_segment(fft_buffer, fft_size) local(fft_bin, left_real, le //////////////////////// Main STFT block // The 'meat' of the algorithm, the code in this block will most resemble the code from vocalrediso.ny - - // first, apply vocal reduction algorithm only in the right bands + // first, apply vocal reduction algorithm only in the right bands fft_bin >= low_bin && fft_bin <= high_bin ? ( // get constants for this bin strength = strength_buffer[fft_bin]; @@ -250,6 +254,19 @@ loop(fft_size, input_buffer[buffer_index*2] = spl0; input_buffer[buffer_index*2 + 1] = spl1; +output_index = buffer_index - fft_size; +output_index < 0 ? output_index += buffer_length; +silence > 0 ? ( + spl0 = spl1 = 0; + // silence for fft init +) : ( + spl0 = output_buffer[output_index*2]; + spl1 = output_buffer[output_index*2 + 1]; +); +output_buffer[output_index*2] = 0; // clear the sample we just read +output_buffer[output_index*2 + 1] = 0; + + fft_counter += 1; fft_counter >= fft_interval ? ( fft_counter = 0; @@ -288,16 +305,9 @@ fft_counter >= fft_interval ? ( i += 1; ); + silence > 0 ? silence -= 1; ); -output_index = buffer_index - fft_size; -output_index < 0 ? output_index += buffer_length; -spl0 = output_buffer[output_index*2]; -spl1 = output_buffer[output_index*2 + 1]; - -output_buffer[output_index*2] = 0; // clear the sample we just read -output_buffer[output_index*2 + 1] = 0; - buffer_index = (buffer_index + 1)%buffer_length; //IFTEST ); // function sample_code() ( @@ -319,10 +329,10 @@ function sum_first_pdc_samples(s0val, s1val) ( ); ); -//DEBUGPRINT("SETUP: fft range is [0, srate] dry=100 wet=100\n"); +//DEBUGPRINT("SETUP: fft range is [0, srate/2] dry=100 wet=100\n"); slider1 = slider2 = 100; slider5 = 0; -slider6 = srate; +slider6 = srate/2; slider_code(); //DEBUGPRINT("SAMPLE_0_0_TEST\n"); @@ -394,15 +404,15 @@ assert_near_equal(200, 0.001, spl1sum, "SAMPLE_1_1_TEST: spl1sum was not as expe //DEBUGPRINT("spl0sum=%g, spl1sum=%g\n", spl0sum, spl1sum); -//DEBUGPRINT("SETUP: fft range is [srate/2, srate] dry=100 wet=100\n"); +//DEBUGPRINT("SETUP: fft range is [srate/4, srate/2] dry=100 wet=100\n"); slider1 = slider2 = 100; -slider5 = srate/2; -slider6 = srate; +slider5 = srate/4; +slider6 = srate/2; //DEBUGPRINT("PDC_SILENCE_ON_PARTIAL_RANGE_TEST\n"); slider_code(); sum_first_pdc_samples(1, 1); assert_equal_exact(0, spl0sum, "PDC_SILENCE_ON_PARTIAL_RANGE_TEST failed on spl0"); assert_equal_exact(0, spl1sum, "PDC_SILENCE_ON_PARTIAL_RANGE_TEST failed on spl1"); -//DEBUGPRINT("Testing Completed Without Crashing!\n"); +test_summary(); //*}IFTEST*/ // main test block diff --git a/vocalrediso.jsfx b/vocalrediso.jsfx index 5d63e4b..1d2e118 100644 --- a/vocalrediso.jsfx +++ b/vocalrediso.jsfx @@ -44,9 +44,15 @@ prev_fft_size = 0; function setup_stft_state(fft_size, first_time) ( //////////////////////// Setup block // This is called when playback starts, or when the FFT size is changed - memset(fft_buffer, 0, MAX_FFT_SIZE*2); + //memset(fft_buffer, 0, MAX_FFT_SIZE*2); memset(output_buffer, 0, buffer_length*2); memset(input_buffer, 0, buffer_length*2); + // reset indexes and counters + buffer_index = 0; + output_index = 0; + fft_counter = 0; + // force silence for first overlaps where fft not yet run + silence = overlap_factor; //////////////////////// ); @@ -92,8 +98,8 @@ function process_stft_segment(fft_buffer, fft_size) local(fft_bin, left_real, le // calculate weight: truncate w1 to [0, 1] and apply strength, then take 1 - the result, and multiply // by 1 - the square of the difference between the two norm values divided by the sum of the two, moderated by strength * slider10 weight = (1 - min(1, max(0, w1)) ^ strength) * ( - 1 - (sqr(norm_left - norm_right)/sqr(norm_left + norm_right)) - ) ^ (slider10 / strength) / 2; + 1 - sqr(norm_left - norm_right)/sqr(norm_left + norm_right) + ) ^ (slider10 / strength) * 0.5; // find the c channel, the sum of the two complex numbers c_real = l_real_rotated + r_real_rotated; @@ -161,7 +167,7 @@ buffer_index = 0; input_buffer = simple_alloc(buffer_length*2); output_buffer = simple_alloc(buffer_length*2); -function window(r) local(s, s2, gaussian_width, x) ( +function window(r) ( // When squared, the Hann window adds up perfectly for overlap >= 4, so it's suitable for perfect reconstruction //(0.5 - 0.5*cos(r*2*$pi))/sqrt(0.375); // the MLT sine window also appears to add up correctly, with sigma = sqrt(2). @@ -232,10 +238,22 @@ loop(fft_size, @sample - input_buffer[buffer_index*2] = spl0; input_buffer[buffer_index*2 + 1] = spl1; +output_index = buffer_index - fft_size; +output_index < 0 ? output_index += buffer_length; +silence > 0 ? ( + spl0 = spl1 = 0; + // silence for fft init +) : ( + spl0 = output_buffer[output_index*2]; + spl1 = output_buffer[output_index*2 + 1]; +); +output_buffer[output_index*2] = 0; // clear the sample we just read +output_buffer[output_index*2 + 1] = 0; + + fft_counter += 1; fft_counter >= fft_interval ? ( fft_counter = 0; @@ -276,13 +294,6 @@ fft_counter >= fft_interval ? ( ); ); -output_index = buffer_index - fft_size; -output_index < 0 ? output_index += buffer_length; -spl0 = output_buffer[output_index*2]; -spl1 = output_buffer[output_index*2 + 1]; -output_buffer[output_index*2] = 0; // clear the sample we just read -output_buffer[output_index*2 + 1] = 0; - buffer_index = (buffer_index + 1)%buffer_length; @serialize