diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5758d85..08b98ca 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -25,6 +25,9 @@ jobs: mkdir -p build_linux && cd build_linux cmake .. make - # simple test to make sure the code runs - cd src && sox ../../wav/wia.wav -t raw -r 16000 - | ./lpcnet_enc -s | ./lpcnet_dec -s > /dev/null + - name: Run ctests + shell: bash + run: | + cd build_linux + ctest -V --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index ba2339b..c52d830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,16 +178,26 @@ add_subdirectory(src) include(CTest) enable_testing() -add_test(NAME core_synthesis_default - COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/unittest; SYNTH=1 ./test_core_nn.sh") -add_test(NAME core_synthesis_load_20h - COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/unittest; SYNTH_20h=1 ./test_core_nn.sh") -add_test(NAME core_synthesis_mag - COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/unittest; SYNTH_mag=1 ./test_core_nn.sh") +# some basic tests - unfortunately the core NN synthsis is hard to test reliably as we get +# different results on different runs due to numerical/precision issues +add_test(NAME feature_extraction + COMMAND sh -c "PATH=$PATH:${CMAKE_CURRENT_BINARY_DIR}/src:${CMAKE_CURRENT_BINARY_DIR}/unittest; + cd ${CMAKE_CURRENT_SOURCE_DIR}/unittest; + pwd; + dump_data --test --c2pitch ${CMAKE_CURRENT_SOURCE_DIR}/wav/birch.wav birch.f32; + md5sum birch.f32; + md5sum birch_targ.f32; + diff32 --cont birch_targ.f32 birch.f32") add_test(NAME nnet2f32 COMMAND sh -c "cd ${CMAKE_CURRENT_BINARY_DIR}; ./src/nnet2f32 t.f32") add_test(NAME SIMD_functions COMMAND sh -c "cd ${CMAKE_CURRENT_BINARY_DIR}; ./src/test_vec") +add_test(NAME lpcnet_enc_dec + COMMAND sh -c "PATH=$PATH:${CMAKE_CURRENT_BINARY_DIR}/src; + cd ${CMAKE_CURRENT_SOURCE_DIR}; + sox wav/wia.wav -t raw -r 16000 - | + lpcnet_enc -s | + lpcnet_dec -s > /dev/null") # Packaging set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Next-Generation Digital Voice for Two-Way Radio") diff --git a/src/diff32.c b/src/diff32.c index b0b95e5..a84bf9e 100644 --- a/src/diff32.c +++ b/src/diff32.c @@ -1,4 +1,8 @@ -/* test tool to diffs two .f32 files */ +/* Test tool to diff two float (.f32) files that hold LPCNet + "features". Each file can be seen as a matrix, where each row has + "stride" columns. We calculate the "SNR" of each col measured + between the two files, as each col represents a specific feature + that will have it's own scaling. */ #include #include @@ -6,10 +10,11 @@ #include #include -#define NB_FEATURES 55 +#define NB_FEATURES 55 +#define FDIFF_THRESH 0.001 +#define SNR_THRESH 1000.0 int main(int argc, char *argv[]) { - float fdiff, fdiff_tot=0.0; int f=0; unsigned int ret, i, stride = NB_FEATURES, cont = 0; @@ -56,21 +61,39 @@ int main(int argc, char *argv[]) { exit(1); } - float f1[stride],f2[stride]; + float fdiff; + float f1[stride], f2[stride], s[stride], n[stride]; + for(i=0; i 1E-3)) { - printf("f: %d i: %d %f %f %f\n", f, i, f1[i], f2[i], fdiff); - if (cont == 0) exit(0); + n[i] += fdiff*fdiff; + + /* flag any gross errors straight away */ + if (isnan(fdiff) || (fdiff > FDIFF_THRESH)) { + fprintf(stderr, "f: %d i: %d %f %f %f\n", f, i, f1[i], f2[i], fdiff); + if (cont == 0) exit(1); } } f++; } - fprintf(stderr,"stride: %d f: %d fdiff_tot: %f\n", stride, f, fdiff_tot); + fclose(file1); fclose(file2); + + /* calculate per col SNRs, as each feature might have a different scaling */ + float snr_min = 1E32; + for(i=0; i SNR_THRESH) + exit(0); + else + exit(1); } diff --git a/src/dump_data.c b/src/dump_data.c index 4e8d3c4..2a76f41 100644 --- a/src/dump_data.c +++ b/src/dump_data.c @@ -438,7 +438,9 @@ int main(int argc, char **argv) { g = f*speech_gain + (1-f)*old_speech_gain; x[i] *= g; } - for (i=0;i