diff options
| -rw-r--r-- | unittest/CMakeLists.txt | 29 | ||||
| -rw-r--r-- | unittest/fdmdv_mem.c | 63 | ||||
| -rw-r--r-- | unittest/function_trace.c | 36 | ||||
| -rw-r--r-- | unittest/ofdm_mem.c | 107 | ||||
| -rw-r--r-- | unittest/ofdm_stack.c | 229 | ||||
| -rw-r--r-- | unittest/sd.c | 84 | ||||
| -rw-r--r-- | unittest/t_helpers.c | 38 | ||||
| -rw-r--r-- | unittest/t_helpers.h | 41 | ||||
| -rw-r--r-- | unittest/tcontphase.c | 186 | ||||
| -rw-r--r-- | unittest/tdeframer.c | 148 | ||||
| -rw-r--r-- | unittest/tesno_est.c | 31 | ||||
| -rw-r--r-- | unittest/test_phi0.c | 78 | ||||
| -rw-r--r-- | unittest/tprede.c | 53 | ||||
| -rw-r--r-- | unittest/tst_codec2_fft_init.c | 97 |
14 files changed, 0 insertions, 1220 deletions
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 5ddc5a7..48a4eb8 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -15,9 +15,6 @@ add_executable(tfreedv_data_channel tfreedv_data_channel.c ../src/freedv_data_ch add_executable(tfmfsk tfmfsk.c ../src/octave.c ../src/modem_probe.c) target_link_libraries(tfmfsk m) -add_executable(tdeframer tdeframer.c) -target_link_libraries(tdeframer m codec2) - add_definitions(-DMODEMPROBE_ENABLE -DXXXXX) add_executable(tofdm tofdm.c ../src/octave.c) @@ -26,44 +23,18 @@ target_link_libraries(tofdm m codec2) add_executable(tofdm_acq tofdm_acq.c ../src/octave.c) target_link_libraries(tofdm_acq m codec2) -add_executable(tesno_est tesno_est.c) -target_link_libraries(tesno_est m codec2) - if(UNIX) # Uses pthreads add_executable(tfifo tfifo.c ../src/codec2_fifo.c) target_link_libraries(tfifo codec2 ${CMAKE_THREAD_LIBS_INIT}) endif() -add_executable(fdmdv_mem fdmdv_mem.c) - -add_executable(ofdm_mem ofdm_mem.c ../src/ofdm.c ../src/octave.c ../src/kiss_fft.c ../src/modem_probe.c ../src/mpdecode_core.c ../src/phi0.c ../src/filter.c) -target_link_libraries(ofdm_mem m) - -add_library(function_trace STATIC ../unittest/function_trace.c) - -add_executable(ofdm_stack ofdm_stack.c ../src/ofdm.c ../src/octave.c ../src/kiss_fft.c ../src/modem_probe.c ../src/mpdecode_core.c ../src/phi0.c ../src/filter.c) -if (CMAKE_C_COMPILER MATCHES "gcc$") - target_link_libraries(ofdm_stack function_trace m -no-pie "-Wl,-Map=ofdm_stack.map") - target_compile_options(ofdm_stack PUBLIC -fstack-usage -finstrument-functions) -else() - target_link_libraries(ofdm_stack function_trace m -no-pie) - target_compile_options(ofdm_stack PUBLIC -finstrument-functions) -endif() add_definitions(-D__UNITTEST__) add_executable(tnewamp1 tnewamp1.c ../src/quantise.c ../src/newamp1.c ../src/mbest.c ../src/kiss_fft.c ../src/sine.c ../src/nlp.c ../src/dump.c ../src/octave.c ${CODEBOOKS}) target_link_libraries(tnewamp1 codec2) add_executable(compare_ints compare_ints.c) - add_executable(compare_floats compare_floats.c) - -add_executable(test_phi0 test_phi0.c ../src/phi0.c) -target_link_libraries(test_phi0 m) - -add_executable(tst_codec2_fft_init tst_codec2_fft_init.c) -target_link_libraries(tst_codec2_fft_init m codec2) - add_executable(tvq_mbest tvq_mbest.c) add_executable(tfreedv_800XA_rawdata tfreedv_800XA_rawdata.c) diff --git a/unittest/fdmdv_mem.c b/unittest/fdmdv_mem.c deleted file mode 100644 index 6bcc6bc..0000000 --- a/unittest/fdmdv_mem.c +++ /dev/null @@ -1,63 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: fdmdv_mem.c - AUTHOR......: David Rowe - DATE CREATED: 25 June 2014 - - Prints out the memory used by the FDMDV modem states. Used to optimise - memory use for the STM32F4 port. - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2014 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> - -#include "fdmdv_internal.h" - -extern float pilot_coeff[]; - -int main(int argc, char *argv[]) -{ - struct FDMDV *fdmdv; - - printf("struct FDMDV..........: %ld\n", sizeof(struct FDMDV)); - printf("prev_tx_symbols.......: %ld\n", sizeof(fdmdv->prev_tx_symbols)); - printf("tx_filter_memory......: %ld\n", sizeof(fdmdv->tx_filter_memory)); - printf("phase_tx..............: %ld\n", sizeof(fdmdv->phase_tx)); - printf("freq..................: %ld\n", sizeof(fdmdv->freq)); - printf("pilot_lut.............: %ld\n", sizeof(fdmdv->pilot_lut)); - printf("pilot_baseband1.......: %ld\n", sizeof(fdmdv->pilot_baseband1)); - printf("pilot_baseband2.......: %ld\n", sizeof(fdmdv->pilot_baseband2)); - printf("pilot_lpf1............: %ld\n", sizeof(fdmdv->pilot_lpf1)); - printf("pilot_lpf2............: %ld\n", sizeof(fdmdv->pilot_lpf2)); - printf("S1....................: %ld\n", sizeof(fdmdv->S1)); - printf("S2....................: %ld\n", sizeof(fdmdv->S2)); - printf("phase_rx..............: %ld\n", sizeof(fdmdv->phase_rx)); - printf("rx_fdm_mem............: %ld\n", sizeof(fdmdv->rx_fdm_mem)); - printf("rx_filter_mem_timing..: %ld\n", sizeof(fdmdv->rx_filter_mem_timing)); - printf("phase_difference......: %ld\n", sizeof(fdmdv->phase_difference)); - printf("prev_rx_symbols.......: %ld\n", sizeof(fdmdv->prev_rx_symbols)); - - return 0; -} - diff --git a/unittest/function_trace.c b/unittest/function_trace.c deleted file mode 100644 index 5ed47a9..0000000 --- a/unittest/function_trace.c +++ /dev/null @@ -1,36 +0,0 @@ -#include <stdio.h> - -static FILE *fp_trace; - -void -__attribute__ ((constructor)) -trace_begin (void) -{ - fp_trace = fopen("function_trace.out", "w"); -} - -void -__attribute__ ((destructor)) -trace_end (void) -{ - if(fp_trace != NULL) { - fclose(fp_trace); - } -} - - -void -__cyg_profile_func_enter (void *func, void *caller) -{ - if(fp_trace != NULL) { - fprintf(fp_trace, "e %p %p\n", func, caller); - } -} - -void -__cyg_profile_func_exit (void *func, void *caller) -{ - if(fp_trace != NULL) { - fprintf(fp_trace, "x %p %p\n", func, caller); - } -} diff --git a/unittest/ofdm_mem.c b/unittest/ofdm_mem.c deleted file mode 100644 index c87f067..0000000 --- a/unittest/ofdm_mem.c +++ /dev/null @@ -1,107 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: ofdm_mem.c - AUTHOR......: Don Reid - DATE CREATED: 11 June 2018 - - Prints out the memory used by the OFDM modem states. Used to optimise - memory use for the STM32F4 port. - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2018 Don Reid - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <complex.h> - -#include "codec2_ofdm.h" -#include "ofdm_internal.h" - -int main() -{ - struct OFDM_CONFIG *ofdm_config; - struct OFDM *ofdm; - - ofdm = ofdm_create(NULL); - assert(ofdm != NULL); - - /* Get a copy of the actual modem config */ - ofdm_config = ofdm_get_config_param(ofdm); - - int ofdm_m = (int) (ofdm_config->fs / ofdm_config->rs); /* 144 */ - int ofdm_ncp = (int) (ofdm_config->tcp * ofdm_config->fs); /* 16 */ - int ofdm_bitsperframe = (ofdm_config->ns - 1) * (ofdm_config->nc * ofdm_config->bps); - int ofdm_rowsperframe = ofdm_bitsperframe / (ofdm_config->nc * ofdm_config->bps); - int ofdm_samplesperframe = ofdm_config->ns * (ofdm_m + ofdm_ncp); - int ofdm_rxbuf = 3 * ofdm_samplesperframe + 3 * (ofdm_m + ofdm_ncp); - int ofdm_nuwbits = (ofdm_config->ns - 1) * ofdm_config->bps - ofdm_config->txtbits; - - int used = 0; - - printf("struct OFDM.................: %zd\n", sizeof(struct OFDM)); - printf("config......................: %zd\n", sizeof(struct OFDM_CONFIG)); - used += sizeof(struct OFDM_CONFIG); - printf("pilot_samples...............: %zd\n", sizeof (complex float) * (ofdm_m + ofdm_ncp)); - used += sizeof (complex float) * (ofdm_m + ofdm_ncp); - printf("rxbuf.......................: %zd\n", sizeof (complex float) * ofdm_rxbuf); - used += sizeof (complex float) * ofdm_rxbuf; - printf("pilots......................: %zd\n", sizeof (complex float) * (ofdm_config->nc + 2)); - used += sizeof (complex float) * (ofdm_config->nc + 2); - - size_t rxsym_size = sizeof (complex float) * (ofdm_config->ns + 3) * (ofdm_config->nc + 2); - - printf("rx_sym......................: %zd\n", rxsym_size); - used += rxsym_size; - printf("rx_np.......................: %zd\n", sizeof (complex float) * (ofdm_rowsperframe * ofdm_config->nc)); - used += sizeof (complex float) * (ofdm_rowsperframe * ofdm_config->nc); - printf("rx_amp......................: %zd\n", sizeof (float) * (ofdm_rowsperframe * ofdm_config->nc)); - used += sizeof (float) * (ofdm_rowsperframe * ofdm_config->nc); - printf("aphase_est_pilot_log........: %zd\n", sizeof (float) * (ofdm_rowsperframe * ofdm_config->nc)); - used += sizeof (float) * (ofdm_rowsperframe * ofdm_config->nc); - printf("tx_uw.......................: %zd\n", sizeof (int) * ofdm_nuwbits); - used += sizeof (int) * ofdm_nuwbits; - printf("sync_state..................: %zd\n", sizeof (State)); - used += sizeof (State); - printf("last_sync_state.............: %zd\n", sizeof (State)); - used += sizeof (State); - printf("sync_state_interleaver......: %zd\n", sizeof (State)); - used += sizeof (State); - printf("last_sync_state_interleaver.: %zd\n", sizeof (State)); - used += sizeof (State); - - // add in non-array sizes - int single = 0; - single += 8 * sizeof(int); - single += 13 * sizeof(float); - single += 1 * sizeof(complex float); - single += 1 * sizeof(float *); - single += 4 * sizeof(bool); - printf("single values...............: %d\n", single); - used += single; - - printf("Total used .................: %zd\n", (size_t) used); - - ofdm_destroy(ofdm); - - return 0; -} - diff --git a/unittest/ofdm_stack.c b/unittest/ofdm_stack.c deleted file mode 100644 index aef6f42..0000000 --- a/unittest/ofdm_stack.c +++ /dev/null @@ -1,229 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <complex.h> -#include <unistd.h> -#include <assert.h> - -#include "comp.h" -#include "ofdm_internal.h" -#include "codec2_ofdm.h" -#include "test_bits_ofdm.h" /* payload_data_bits */ -#include "mpdecode_core.h" - -#define MAX_ERRORS 32 - -static int ofdm_bitsperframe; -static int ofdm_rowsperframe; -static int ofdm_nuwbits; -static int ofdm_ntxtbits; -static int ofdm_rx_offset; -static int ofdm_data_bitsperframe; -static int ofdm_samplesperframe; -static int ofdm_max_samplesperframe; -static int ofdm_rxbuf; -static int ofdm_m; -static int ofdm_ncp; - -// Forwards -void run_modem(struct OFDM *ofdm, int tx_bits[], int rx_bits[], COMP tx_rx[]); -void dummy_code(); - -///////////////////////////////////////////////////////////// -/// MAIN() -int main(int argc, char *argv[]) { - // Options - int f, i, opt; - int dummy = 0; // flag to use dummy code - int frames = 1; // how many frames - int print = 0; // flag to print all bits - struct OFDM *ofdm; - struct OFDM_CONFIG *ofdm_config; - - ofdm = ofdm_create(NULL); - assert(ofdm != NULL); - - /* Get a copy of the actual modem config */ - - ofdm_config = ofdm_get_config_param(ofdm); - - ofdm_m = (int) (ofdm_config->fs / ofdm_config->rs); - ofdm_ncp = (int) (ofdm_config->tcp * ofdm_config->fs); - ofdm_bitsperframe = ofdm_get_bits_per_frame(ofdm); - ofdm_rowsperframe = ofdm_bitsperframe / (ofdm_config->nc * ofdm_config->bps); - ofdm_samplesperframe = ofdm_get_samples_per_frame(ofdm); - ofdm_max_samplesperframe = ofdm_get_max_samples_per_frame(ofdm); - ofdm_rxbuf = 3 * ofdm_samplesperframe + 3 * (ofdm_m + ofdm_ncp); - ofdm_nuwbits = (ofdm_config->ns - 1) * ofdm_config->bps - ofdm_config->txtbits; - ofdm_ntxtbits = ofdm_config->txtbits; - ofdm_rx_offset = (ofdm_nuwbits + ofdm_ntxtbits); - ofdm_data_bitsperframe = (ofdm_bitsperframe - ofdm_rx_offset); - - int tx_bits[ofdm_data_bitsperframe]; - int rx_bits[ofdm_data_bitsperframe]; - COMP tx_rx[ofdm_samplesperframe]; - - while ((opt = getopt(argc, argv, "df:p")) != -1) { - switch (opt) { - case 'd': - dummy = 1; - break; - case 'f': - frames = atoi(optarg); - break; - case 'p': - print = 1; - break; - default: - fprintf(stderr, "Usage: %s [-e] [-f <frames>] [-p]\n", argv[0]); - } - } - - for (f = 0; f < frames; f++) { - //////// - // Prep inputs - - for(i=0; i<ofdm_data_bitsperframe; i++) { - tx_bits[i] = payload_data_bits[(i % (sizeof(payload_data_bits)/sizeof(payload_data_bits[0])))]; - } - - //////// - // Modem (or dummy) - - if (dummy) { - dummy_code(tx_bits, rx_bits); - } else { - run_modem(ofdm, tx_bits, rx_bits, tx_rx); - } - - //////// - // Compare results (or print) - int errors = 0; - - if (print) { - for(i=0; i<ofdm_data_bitsperframe; i++) { - fprintf(stderr, "bit %3d: tx = %1d, rx = %1d", - i, tx_bits[i], rx_bits[i + ofdm_rx_offset]); - - if (tx_bits[i] != rx_bits[i + ofdm_rx_offset]) { - fprintf(stderr, " Error"); - errors ++; - } - - fprintf(stderr, "\n"); - } - } else { - for(i=0; i<ofdm_data_bitsperframe; i++) { - if (tx_bits[i] != rx_bits[i + ofdm_rx_offset]) { - if (errors < MAX_ERRORS) { - fprintf(stderr, "Error in bit %3d: tx = %1d, rx = %1d\n", - i, tx_bits[i], rx_bits[i + ofdm_rx_offset]); - } - - errors++; - } - } - } - - fprintf(stderr, "%d Errors\n", errors); - - } // for (f<frames - - ofdm_destroy(ofdm); - -} // end main() - - -////////////////////////////////// -void run_modem(struct OFDM *ofdm, int tx_bits[], int rx_bits[], COMP tx_rx[]) { - int mod_bits[ofdm_samplesperframe]; - int i, j; - - /////////// - // Mod - /////////// - - for(i=0; i<ofdm_nuwbits; i++) { - mod_bits[i] = ofdm->tx_uw[i]; - } - - for(i=ofdm_nuwbits; i<ofdm_nuwbits+ofdm_ntxtbits; i++) { - mod_bits[i] = 0; - } - - for(j=0, i=ofdm_nuwbits+ofdm_ntxtbits; j<ofdm_data_bitsperframe; i++,j++) { - mod_bits[i] = tx_bits[j]; - } - - for(j=0; j<ofdm_data_bitsperframe; i++,j++) { - mod_bits[i] = tx_bits[j]; - } - - ofdm_mod(ofdm, tx_rx, mod_bits); - - /////////// - // DeMod - /////////// - - int Nsam = ofdm_samplesperframe; - int prx = 0; - int nin = ofdm_samplesperframe + 2 * (ofdm_m + ofdm_ncp); - - int lnew; - COMP rxbuf_in[ofdm_max_samplesperframe]; - - for (i=0; i<ofdm_samplesperframe ; i++,prx++) { - ofdm->rxbuf[ofdm_rxbuf-nin+i] = tx_rx[prx].real + tx_rx[prx].imag * I; - } - - for (i=ofdm_samplesperframe ; i<nin; i++) { - ofdm->rxbuf[ofdm_rxbuf-nin+i] = 0.0 + 0.0 * I; - } - - /* disable estimators for initial testing */ - ofdm_set_verbose(ofdm, false); - ofdm_set_timing_enable(ofdm, true); - ofdm_set_foff_est_enable(ofdm, true); - ofdm_set_phase_est_enable(ofdm, true); - - ofdm->mean_amp = 1.0; - - nin = ofdm_get_nin(ofdm); - - /* Insert samples at end of buffer, set to zero if no samples - available to disable phase estimation on future pilots on - last frame of simulation. */ - - if ((Nsam-prx) < nin) { - lnew = Nsam-prx; - } else { - lnew = nin; - } - for(i=0; i<nin; i++) { - rxbuf_in[i].real = 0.0; - rxbuf_in[i].imag = 0.0; - } - - if (lnew) { - for(i=0; i<lnew; i++, prx++) { - rxbuf_in[i] = tx_rx[prx]; - } - } - - ofdm_demod(ofdm, rx_bits, rxbuf_in); - - -} // end run_modem() - - -////////////////////////////////// -void dummy_code(int tx_bits[], int rx_bits[]) { - int i; - - for(i=0; i<ofdm_data_bitsperframe; i++) { - rx_bits[i] = tx_bits[i]; - } - -} // end dummy_code() - -/* vi:set ts=4 sts=4 et: */ diff --git a/unittest/sd.c b/unittest/sd.c deleted file mode 100644 index 1d1a628..0000000 --- a/unittest/sd.c +++ /dev/null @@ -1,84 +0,0 @@ -/*--------------------------------------------------------------------------*\ - - FILE........: sd.c - AUTHOR......: David Rowe - DATE CREATED: 20/7/93 - - Function to determine spectral distortion between two sets of LPCs. - -\*--------------------------------------------------------------------------*/ - -/* - Copyright (C) 2009 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#define MAX_N 2048 /* maximum DFT size */ - -#include <math.h> -#include "four1.h" -#include "comp.h" -#include "sd.h" - -/*---------------------------------------------------------------------------*\ - - FUNCTION....: spectral_dist() - - AUTHOR......: David Rowe - DATE CREATED: 20/7/93 - - This function returns the soectral distoertion between two - sets of LPCs. - -\*---------------------------------------------------------------------------*/ - -float spectral_dist(float ak1[], float ak2[], int p, int n) -/* float ak1[]; unquantised set of p+1 LPCs */ -/* float ak2[]; quantised set of p+1 LPCs */ -/* int p; LP order */ -/* int n; DFT size to use for SD calculations (power of 2) */ -{ - COMP A1[MAX_N]; /* DFT of ak1[] */ - COMP A2[MAX_N]; /* DFT of ak2[] */ - float P1,P2; /* power of current bin */ - float sd; - int i; - - for(i=0; i<n; i++) { - A1[i].real = 0.0; - A1[i].imag = 0.0; - A2[i].real = 0.0; - A2[i].imag = 0.0; - } - - for(i=0; i<p+1; i++) { - A1[i].real = ak1[i]; - A2[i].real = ak2[i]; - } - - #warn Array index -1 is out of bounds - four1(&A1[-1].imag,n,-1); - four1(&A2[-1].imag,n,-1); - - sd = 0.0; - for(i=0; i<n; i++) { - P1 = A1[i].real*A1[i].real + A1[i].imag*A1[i].imag; - P2 = A2[i].real*A2[i].real + A2[i].imag*A2[i].imag; - sd += pow(log10(P2/P1),2.0); - } - sd = 10.0*sqrt(sd/n); /* sd in dB */ - - return(sd); -} diff --git a/unittest/t_helpers.c b/unittest/t_helpers.c deleted file mode 100644 index 4f20743..0000000 --- a/unittest/t_helpers.c +++ /dev/null @@ -1,38 +0,0 @@ -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "t_helpers.h" - -void test(char * tfn) -{ - fn = tfn; - printf("========================================\n"); - printf("test function: %s\n", fn); - printf("========================================\n"); -} - -void test_failed() -{ - printf("Failed to calculate %s.\n", fn); - exit(1); -} - -void test_failed_s(char * expected, char * res) -{ - - printf("Failed to calculate %s.\n", fn); - - printf("expected: %s\ngot: %s\n", expected, res); - exit(1); -} - -void test_failed_f(float expected, float res) -{ - - printf("Failed to calculate %s.\n", fn); - printf("expected: %f\ngot: %f\n", expected, res); - exit(1); -} - diff --git a/unittest/t_helpers.h b/unittest/t_helpers.h deleted file mode 100644 index 2dfcbef..0000000 --- a/unittest/t_helpers.h +++ /dev/null @@ -1,41 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: t_helpers.c - AUTHOR......: Phil Ayres - DATE CREATED: July 2017 - - * Simple helper functions for unit tests - * -\*---------------------------------------------------------------------------*/ - -/* - Copyright David Rowe 2017 - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - */ - -#ifndef T_HELPERS_H -#define T_HELPERS_H - -void test(char * tfn); -void test_failed(); -void test_failed_s(char * expected, char * res); -void test_failed_f(float expected, float res); - -char *fn; - - -#endif /* T_HELPERS_H */ - diff --git a/unittest/tcontphase.c b/unittest/tcontphase.c deleted file mode 100644 index 02e51b2..0000000 --- a/unittest/tcontphase.c +++ /dev/null @@ -1,186 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: tcontphase.c - AUTHOR......: David Rowe - DATE CREATED: 11/9/09 - - Test program for developing continuous phase track synthesis algorithm. - However while developing this it was discovered that synthesis_mixed() - worked just as well. - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2009 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#define N 80 /* frame size */ -#define F 160 /* frames to synthesis */ -#define P 10 /* LPC order */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <math.h> -#include "sine.h" -#include "dump.h" -#include "synth.h" -#include "phase.h" - -int frames; - -float ak[] = { - 1.000000, --1.455836, - 1.361841, --0.879267, - 0.915985, --1.002202, - 0.944103, --0.743094, - 1.053356, --0.817491, - 0.431222 -}; - - -/*---------------------------------------------------------------------------*\ - - switch_present() - - Searches the command line arguments for a "switch". If the switch is - found, returns the command line argument where it ws found, else returns - NULL. - -\*---------------------------------------------------------------------------*/ - -int switch_present(sw,argc,argv) - char sw[]; /* switch in string form */ - int argc; /* number of command line arguments */ - char *argv[]; /* array of command line arguments in string form */ -{ - int i; /* loop variable */ - - for(i=1; i<argc; i++) - if (!strcmp(sw,argv[i])) - return(i); - - return 0; -} - -/*---------------------------------------------------------------------------*\ - - MAIN - -\*---------------------------------------------------------------------------*/ - -int main(argc,argv) -int argc; -char *argv[]; -{ - FILE *fout; - short buf[N]; - int i,j; - int dump; - float phi_prev[MAX_AMP]; - float Wo_prev, ex_phase, G; - //float ak[P+1]; - COMP H[MAX_AMP]; - float f0; - - if (argc < 3) { - printf("\nusage: %s OutputRawSpeechFile F0\n", argv[0]); - exit(1); - } - - /* Output file */ - - if ((fout = fopen(argv[1],"wb")) == NULL) { - printf("Error opening output speech file: %s\n",argv[1]); - exit(1); - } - - f0 = atof(argv[2]); - - dump = switch_present("--dump",argc,argv); - if (dump) - dump_on(argv[dump+1]); - - init_decoder(); - - for(i=0; i<MAX_AMP; i++) - phi_prev[i] = 0.0; - Wo_prev = 0.0; - - model.Wo = PI*(f0/4000.0); - G = 1000.0; - model.L = floor(PI/model.Wo); - - //aks_to_H(&model, ak, G , H, P); - //for(i=1; i<=model.L; i++) - model.A[i] = sqrt(H[i].real*H[i].real + H[i].imag*H[i].imag); - //printf("L = %d\n", model.L); - //model.L = 10; - for(i=1; i<=model.L; i++) { - model.A[i] = 1000/model.L; - model.phi[i] = 0; - H[i].real = 1.0; H[i].imag = 0.0; - } - - //ak[0] = 1.0; - //for(i=1; i<=P; i++) - // ak[i] = 0.0; - - frames = 0; - for(j=0; j<F; j++) { - frames++; - - #ifdef SWAP - /* lets make phases bounce around from frame to frame. This - could happen if H[m] is varying, for example due to frame - to frame Wo variations, or non-stationary speech. - Continuous model generally results in smooth phase track - under these circumstances. */ - if (j%2){ - H[1].real = 1.0; H[1].imag = 0.0; - model.phi[1] = 0.0; - } - else { - H[1].real = 0.0; H[1].imag = 1.0; - model.phi[1] = PI/2; - } - #endif - - //#define CONT - #ifdef CONT - synthesise_continuous_phase(Pn, &model, Sn_, 1, &Wo_prev, phi_prev); - #else - phase_synth_zero_order(5.0, H, &Wo_prev, &ex_phase); - synthesise_mixed(Pn,&model,Sn_,1); - #endif - - for(i=0; i<N; i++) - buf[i] = Sn_[i]; - fwrite(buf,sizeof(short),N,fout); - } - - fclose(fout); - if (dump) dump_off(); - - return 0; -} - - diff --git a/unittest/tdeframer.c b/unittest/tdeframer.c deleted file mode 100644 index 03e8bb1..0000000 --- a/unittest/tdeframer.c +++ /dev/null @@ -1,148 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: tdeframer.c - AUTHOR......: Brady O'Brien - DATE CREATED: 8 April 2016 - - C unit test for the VHF framer/deframer used by modes 2400A and 2400B. - The deframer should sync up within one frame at a BER of 10e-3 -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2016 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -/* BER of test */ -#define TESTBER 0.01 - -/* Frame count */ -#define FRCNT 1500 - -/* Random bits leading frame */ -#define LRCNT 44 - -#include <stdio.h> -#include <math.h> -#include <stdint.h> -#include <freedv_vhf_framing.h> -#include <golay23.h> -#include <string.h> - -/* The main loop of the test driver */ -int main(int argc,char *argv[]){ - uint8_t * bit_buffer; - uint8_t c2_buffer[10]; - struct freedv_vhf_deframer * fvd; - int i,p,k; - int bitbufferlen; - int fsize; - int ftype; - int first_tol; - - if(argc<2){ - fprintf(stderr,"Usage: %s [A|B]\n",argv[0]); - exit(1); - } - - if(strcmp(argv[1],"A")==0){ - ftype = FREEDV_VHF_FRAME_A; - first_tol = 2; - }else if(strcmp(argv[1],"B")==0){ - ftype = FREEDV_HF_FRAME_B; - first_tol = 5; - }else{ - fprintf(stderr,"Usage: %s [A|B]\n",argv[0]); - exit(1); - } - - srand(1); - golay23_init(); - - /* Set up the deframer */ - fvd = fvhff_create_deframer(ftype,1); - - fsize = fvhff_get_frame_size(fvd); - bitbufferlen = (LRCNT+fsize*FRCNT); - - /* Allocate bit buffer */ - bit_buffer = (uint8_t *) malloc(sizeof(uint8_t)*bitbufferlen); - p = 0; - - /* Fill out front of buffer */ - for(i=0; i<LRCNT; i++){ - bit_buffer[p++] = rand()&0x1; - } - - /* Place frames */ - for(i=0; i<FRCNT; i++){ - /* Encode frame index into golay codeword to protect from test BER*/ - k = golay23_encode((i+1)&0x0FFF); - c2_buffer[5] = (k )&0xFF; - c2_buffer[1] = (k>>8 )&0xFF; - c2_buffer[0] = (k>>16)&0x7F; - /* Frame the bits */ - fvhff_frame_bits(ftype, &bit_buffer[p+(i*fsize)], c2_buffer,NULL,NULL); - } - - /* Flip bits */ - for(i=0; i<bitbufferlen; i++){ - if( (rand()&0xFFFFFF) < (int)(TESTBER*0xFFFFFF)){ - bit_buffer[i] = bit_buffer[i]?0:1; - } - } - - p=0; - int first_extract = 0; - int total_extract = 0; - int err_count = 0; - printf("\n"); - /* Deframe some bits */ - for(i=0; i<bitbufferlen; i+=fsize){ - if( fvhff_deframe_bits(fvd, c2_buffer, NULL, NULL, &bit_buffer[i])){ - /* Extract golay23 codeword */ - k = ((int)c2_buffer[5]) ; - k |= ((int)c2_buffer[1])<<8 ; - k |= ((int)c2_buffer[0])<<16; - k = k & 0x7FFFFF; - /* Decode frame index */ - p = golay23_decode(k); - err_count += golay23_count_errors(k,p); - p = p>>11; - - printf("%d,\t",p); - total_extract++; - if(first_extract==0) - first_extract=p; - } - } - printf("\n"); - float measured_ber = (float)err_count/(float)(23*total_extract); - - printf("First extracted frame %d\n",first_extract); - printf("Extracted %d frames of %d, %f hit rate\n",total_extract,FRCNT,((float)total_extract/(float)FRCNT)); - printf("Bit error rate %f measured from golay code\n",measured_ber); - printf("Bit error rate %f measured by deframer\n",fvd->ber_est); - printf("Bit error rate %f measured by deframer\n",(float)fvd->total_uw_err/(float)fvd->total_uw_bits); - /* Check test condition */ - if(first_extract<first_tol){ - printf("Test passed at test BER of %f!\n",TESTBER); - exit(0); - }else{ - printf("** Test failed at test BER of %f!\n",TESTBER); - exit(1); - } - fvhff_destroy_deframer(fvd); -} diff --git a/unittest/tesno_est.c b/unittest/tesno_est.c deleted file mode 100644 index e198510..0000000 --- a/unittest/tesno_est.c +++ /dev/null @@ -1,31 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: tesno_est.c - AUTHORS.....: David Rowe - DATE CREATED: Mar 2021 - - Test for C port of Es/No estimator. - -\*---------------------------------------------------------------------------*/ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <math.h> - -#include "ofdm_internal.h" - -int main(int argc, char *argv[]) -{ - FILE *fin = fopen(argv[1],"rb"); assert(fin != NULL); - size_t nsym = atoi(argv[2]); assert(nsym >= 0); - complex float rx_sym[nsym]; - size_t nread = fread(rx_sym, sizeof(complex float), nsym, fin); - assert(nread == nsym); - fclose(fin); - - float EsNodB = ofdm_esno_est_calc(rx_sym, nsym); - printf("%f\n",EsNodB); - - return 0; -} diff --git a/unittest/test_phi0.c b/unittest/test_phi0.c deleted file mode 100644 index 8063843..0000000 --- a/unittest/test_phi0.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - FILE...: test_phi0.c - AUTHOR.: Matthew C. Valenti, Rohit Iyer Seshadri, David Rowe, Don Reid - CREATED: Sep 2018 - - Compare new generated phi0 function to what was originally in mpdecode_core.c -*/ - -#include <math.h> -#include <stdlib.h> -#include <stdio.h> - -#include "phi0.h" - - -/* Original Phi function */ -static float phi0_orig( float x ) { - float z; - - if (x>10) - return( 0 ); - else if (x< 9.08e-5 ) - return( 10 ); - else if (x > 9) - return( 1.6881e-4 ); - /* return( 1.4970e-004 ); */ - else if (x > 8) - return( 4.5887e-4 ); - /* return( 4.0694e-004 ); */ - else if (x > 7) - return( 1.2473e-3 ); - /* return( 1.1062e-003 ); */ - else if (x > 6) - return( 3.3906e-3 ); - /* return( 3.0069e-003 ); */ - else if (x > 5) - return( 9.2168e-3 ); - /* return( 8.1736e-003 ); */ - else { - z = (float) exp(x); - return( (float) log( (z+1)/(z-1) ) ); - } -} - -//////////////////////////////////////////////////// -// Main -int main(void) { - - float xf; - float error; - int errsum = 0; - int errsum2 = 0; - int errcnt = 0; - - for (xf=10.5f; xf>5e-5f; xf = xf * 0.9) { - - float orig = phi0_orig(xf); - float new = phi0(xf); - - error = new - orig; - printf("%10.4f: %10.6f - %10.6f = %10.6f", xf, new, orig, error); - if ((error >= 0.001) && (error >= (orig * 0.1))) printf(" ****"); - printf("\n"); - - errsum += error; - errsum2 += error * error; - errcnt ++; - - } - - printf("Net error %f\n", (double)errsum); - printf("avg error %f\n", (double)errsum/errcnt); - printf("rms error %f\n", (double)sqrt(errsum2/errcnt)); - - return(0); -} - -/* vi:set ts=4 et sts=4: */ diff --git a/unittest/tprede.c b/unittest/tprede.c deleted file mode 100644 index 4d3d09c..0000000 --- a/unittest/tprede.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - tpre_de.c - David Rowe - Sep 24 2012 - - Unit test to generate the combined impulse response of pre & de-emphasis filters. - - pl("../unittest/out48.raw",1,3000) - pl("../unittest/out8.raw",1,3000) - - Listening to it also shows up anything nasty: - - $ play -s -2 -r 48000 out48.raw - $ play -s -2 -r 8000 out8.raw - - */ - -#include <assert.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#include "lpc.h" - -#define N 10 -#define F 10 - -int main() { - FILE *fprede; - float Sn[N], Sn_pre[N], Sn_de[N]; - float pre_mem = 0.0, de_mem = 0.0; - int i, f; - - fprede = fopen("prede.txt", "wt"); - assert(fprede != NULL); - - for(i=0; i<N; i++) - Sn[i] = 0.0; - - Sn[0]= 1.0; - - for(f=0; f<F; f++) { - pre_emp(Sn_pre, Sn, &pre_mem, N); - de_emp(Sn_de, Sn_pre, &de_mem, N); - for(i=0; i<N; i++) { - fprintf(fprede, "%f\n", Sn_de[i]); - } - Sn[0] = 0.0; - } - - fclose(fprede); - - return 0; -} diff --git a/unittest/tst_codec2_fft_init.c b/unittest/tst_codec2_fft_init.c deleted file mode 100644 index 71ddc38..0000000 --- a/unittest/tst_codec2_fft_init.c +++ /dev/null @@ -1,97 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: tst_codec2_fft_init.c, - AUTHOR......: David Rowe, Don Reid - DATE CREATED: 30 May 2013, Oct 2018, Feb 2018 - - Test FFT Window initialization in Codec2_create - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2014 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program is - distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <math.h> - -#include "codec2.h" -#include "codec2_internal.h" -#include "defines.h" - -#include "machdep.h" - -static const float expect_w[] = { - 0.004293, 0.004301, 0.004309, 0.004315, - 0.004320, 0.004323, 0.004326, 0.004328, - 0.004328, 0.004328, 0.004326, 0.004323, - 0.004320, 0.004315, 0.004309, 0.004301}; - - -static const float expect_W[] = { - -0.002176, 0.002195, 0.004429, -0.008645, - -0.012196, 0.065359, 0.262390, 0.495616, - 0.601647, 0.495616, 0.262390, 0.065359, - -0.012196, -0.008645, 0.004429, 0.002195}; - - -int float_cmp(float a, float b) { - if ( fabsf(a - b) < 1e-6f ) return 1; - else return 0; - } - -int main(int argc, char *argv[]) { - - struct CODEC2 *codec2; - int i, j; - - //////// - codec2 = codec2_create(CODEC2_MODE_700C); - - j = (codec2->c2const.m_pitch / 2) - 8; - for (i=0; i<16; i++) { - printf("w[%d] = %f", j+i, - (double)codec2->w[j+i]); - if (!float_cmp(codec2->w[j+i], expect_w[i])) { - printf(" Error, expected %f", (double)expect_w[i]); - } - printf("\n"); - } - - printf("\n"); - - j = (FFT_ENC / 2) - 8; - for (i=0; i<16; i++) { - printf("W[%d] = %f", j+i, - (double)codec2->W[j+i]); - if (!float_cmp(codec2->W[j+i], expect_W[i])) { - printf(" Error, expected %f", (double)expect_W[i]); - } - printf("\n"); - } - - codec2_destroy(codec2); - - printf("\nEnd of Test\n"); - fclose(stdout); - fclose(stderr); - - return(0); -} - -/* vi:set ts=4 et sts=4: */ |
