From 098f94dba5502067d5ec20765457317fc4d73b76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Grondin?= Date: Mon, 3 Jul 2017 15:24:11 -0400 Subject: [PATCH] Add files via upload --- demo/configs.c | 438 +++++++++++ demo/configs.h | 57 ++ demo/main.c | 159 ++++ demo/objects.c | 694 ++++++++++++++++++ demo/objects.h | 67 ++ demo/parameters.c | 1778 +++++++++++++++++++++++++++++++++++++++++++++ demo/parameters.h | 88 +++ demo/threads.c | 416 +++++++++++ demo/threads.h | 14 + 9 files changed, 3711 insertions(+) create mode 100644 demo/configs.c create mode 100644 demo/configs.h create mode 100644 demo/main.c create mode 100644 demo/objects.c create mode 100644 demo/objects.h create mode 100644 demo/parameters.c create mode 100644 demo/parameters.h create mode 100644 demo/threads.c create mode 100644 demo/threads.h diff --git a/demo/configs.c b/demo/configs.c new file mode 100644 index 0000000..87ec20c --- /dev/null +++ b/demo/configs.c @@ -0,0 +1,438 @@ + + #include "configs.h" + + configs * configs_construct(const char * file_config, const char * file_ios) { + + configs * cfgs; + unsigned int iSink; + + cfgs = (configs *) malloc(sizeof(configs)); + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + cfgs->src_hops_raw_config = parameters_src_hops_raw_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_raw_config = parameters_msg_hops_raw_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_hops_raw_config_count = parameters_snk_hops_raw_count(file_config, file_ios); + cfgs->snk_hops_raw_configs = (snk_hops_cfg **) malloc(sizeof(snk_hops_cfg *) * cfgs->snk_hops_raw_config_count); + + for (iSink = 0; iSink < cfgs->snk_hops_raw_config_count; iSink++) { + cfgs->snk_hops_raw_configs[iSink] = parameters_snk_hops_raw_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_mapping_config = parameters_mod_mapping_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_mapping_config = parameters_msg_hops_mapping_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_hops_mapping_config_count = parameters_snk_hops_mapping_count(file_config, file_ios); + cfgs->snk_hops_mapping_configs = (snk_hops_cfg **) malloc(sizeof(snk_hops_cfg *) * cfgs->snk_hops_mapping_config_count); + + for (iSink = 0; iSink < cfgs->snk_hops_mapping_config_count; iSink++) { + cfgs->snk_hops_mapping_configs[iSink] = parameters_snk_hops_mapping_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_resample_config = parameters_mod_resample_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_resample_config = parameters_msg_hops_resample_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_hops_resample_config_count = parameters_snk_hops_resample_count(file_config, file_ios); + cfgs->snk_hops_resample_configs = (snk_hops_cfg **) malloc(sizeof(snk_hops_cfg *) * cfgs->snk_hops_resample_config_count); + + for (iSink = 0; iSink < cfgs->snk_hops_resample_config_count; iSink++) { + cfgs->snk_hops_resample_configs[iSink] = parameters_snk_hops_resample_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_stft_config = parameters_mod_stft_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_spectra_stft_config = parameters_msg_spectra_stft_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_spectra_stft_config_count = parameters_snk_spectra_stft_count(file_config, file_ios); + cfgs->snk_spectra_stft_configs = (snk_spectra_cfg **) malloc(sizeof(snk_spectra_cfg *) * cfgs->snk_spectra_stft_config_count); + + for (iSink = 0; iSink < cfgs->snk_spectra_stft_config_count; iSink++) { + cfgs->snk_spectra_stft_configs[iSink] = parameters_snk_spectra_stft_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_ssl_config = parameters_mod_ssl_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_pots_ssl_config = parameters_msg_pots_ssl_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_pots_ssl_config_count = parameters_snk_pots_ssl_count(file_config, file_ios); + cfgs->snk_pots_ssl_configs = (snk_pots_cfg **) malloc(sizeof(snk_pots_cfg *) * cfgs->snk_pots_ssl_config_count); + + for (iSink = 0; iSink < cfgs->snk_pots_ssl_config_count; iSink++) { + cfgs->snk_pots_ssl_configs[iSink] = parameters_snk_pots_ssl_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_sst_config = parameters_mod_sst_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_tracks_sst_config = parameters_msg_tracks_sst_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_tracks_sst_config_count = parameters_snk_tracks_sst_count(file_config, file_ios); + cfgs->snk_tracks_sst_configs = (snk_tracks_cfg **) malloc(sizeof(snk_tracks_cfg *) * cfgs->snk_tracks_sst_config_count); + + for (iSink = 0; iSink < cfgs->snk_tracks_sst_config_count; iSink++) { + cfgs->snk_tracks_sst_configs[iSink] = parameters_snk_tracks_sst_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_sss_config = parameters_mod_sss_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_spectra_sss_config = parameters_msg_spectra_sss_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_spectra_sss_config_count = parameters_snk_spectra_sss_count(file_config, file_ios); + cfgs->snk_spectra_sss_configs = (snk_spectra_cfg **) malloc(sizeof(snk_spectra_cfg *) * cfgs->snk_spectra_sss_config_count); + + for (iSink = 0; iSink < cfgs->snk_spectra_sss_config_count; iSink++) { + cfgs->snk_spectra_sss_configs[iSink] = parameters_snk_spectra_sss_config(file_config, file_ios, iSink); + } + + // +----------------------------------------------------------+ + // | SSPF | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_sspf_config = parameters_mod_sspf_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_spectra_sspf_config = parameters_msg_spectra_sspf_config(file_config, file_ios); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_spectra_sspf_config_count = parameters_snk_spectra_sspf_count(file_config, file_ios); + cfgs->snk_spectra_sspf_configs = (snk_spectra_cfg **) malloc(sizeof(snk_spectra_cfg *) * cfgs->snk_spectra_sspf_config_count); + + for (iSink = 0; iSink < cfgs->snk_spectra_sspf_config_count; iSink++) { + cfgs->snk_spectra_sspf_configs[iSink] = parameters_snk_spectra_sspf_config(file_config, file_ios, iSink); + } + + + return cfgs; + + } + + void configs_destroy(configs * cfgs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + src_hops_cfg_destroy(cfgs->src_hops_raw_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_raw_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_hops_raw_config_count; iSink++) { + snk_hops_cfg_destroy(cfgs->snk_hops_raw_configs[iSink]); + } + free((void *) cfgs->snk_hops_raw_configs); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_mapping_cfg_destroy(cfgs->mod_mapping_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_mapping_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_hops_mapping_config_count; iSink++) { + snk_hops_cfg_destroy(cfgs->snk_hops_mapping_configs[iSink]); + } + free((void *) cfgs->snk_hops_mapping_configs); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_resample_cfg_destroy(cfgs->mod_resample_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_resample_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_hops_resample_config_count; iSink++) { + snk_hops_cfg_destroy(cfgs->snk_hops_resample_configs[iSink]); + } + free((void *) cfgs->snk_hops_resample_configs); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_stft_cfg_destroy(cfgs->mod_stft_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_spectra_cfg_destroy(cfgs->msg_spectra_stft_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_spectra_stft_config_count; iSink++) { + snk_spectra_cfg_destroy(cfgs->snk_spectra_stft_configs[iSink]); + } + free((void *) cfgs->snk_spectra_stft_configs); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_ssl_cfg_destroy(cfgs->mod_ssl_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_pots_cfg_destroy(cfgs->msg_pots_ssl_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_pots_ssl_config_count; iSink++) { + snk_pots_cfg_destroy(cfgs->snk_pots_ssl_configs[iSink]); + } + free((void *) cfgs->snk_pots_ssl_configs); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_sst_cfg_destroy(cfgs->mod_sst_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_tracks_cfg_destroy(cfgs->msg_tracks_sst_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_tracks_sst_config_count; iSink++) { + snk_tracks_cfg_destroy(cfgs->snk_tracks_sst_configs[iSink]); + } + free((void *) cfgs->snk_tracks_sst_configs); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_sss_cfg_destroy(cfgs->mod_sss_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_spectra_cfg_destroy(cfgs->msg_spectra_sss_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_spectra_sss_config_count; iSink++) { + snk_spectra_cfg_destroy(cfgs->snk_spectra_sss_configs[iSink]); + } + free((void *) cfgs->snk_spectra_sss_configs); + + // +----------------------------------------------------------+ + // | SSPF | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_sspf_cfg_destroy(cfgs->mod_sspf_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_spectra_cfg_destroy(cfgs->msg_spectra_sspf_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < cfgs->snk_spectra_sspf_config_count; iSink++) { + snk_spectra_cfg_destroy(cfgs->snk_spectra_sspf_configs[iSink]); + } + free((void *) cfgs->snk_spectra_sspf_configs); + + free((void *) cfgs); + + } diff --git a/demo/configs.h b/demo/configs.h new file mode 100644 index 0000000..35d29da --- /dev/null +++ b/demo/configs.h @@ -0,0 +1,57 @@ +#ifndef __DEMO_CONFIGS +#define __DEMO_CONFIGS + + #include "parameters.h" + + #include + #include + + typedef struct configs { + + src_hops_cfg * src_hops_raw_config; + msg_hops_cfg * msg_hops_raw_config; + unsigned int snk_hops_raw_config_count; + snk_hops_cfg ** snk_hops_raw_configs; + + mod_mapping_cfg * mod_mapping_config; + msg_hops_cfg * msg_hops_mapping_config; + unsigned int snk_hops_mapping_config_count; + snk_hops_cfg ** snk_hops_mapping_configs; + + mod_resample_cfg * mod_resample_config; + msg_hops_cfg * msg_hops_resample_config; + unsigned int snk_hops_resample_config_count; + snk_hops_cfg ** snk_hops_resample_configs; + + mod_stft_cfg * mod_stft_config; + msg_spectra_cfg * msg_spectra_stft_config; + unsigned int snk_spectra_stft_config_count; + snk_spectra_cfg ** snk_spectra_stft_configs; + + mod_ssl_cfg * mod_ssl_config; + msg_pots_cfg * msg_pots_ssl_config; + unsigned int snk_pots_ssl_config_count; + snk_pots_cfg ** snk_pots_ssl_configs; + + mod_sst_cfg * mod_sst_config; + msg_tracks_cfg * msg_tracks_sst_config; + unsigned int snk_tracks_sst_config_count; + snk_tracks_cfg ** snk_tracks_sst_configs; + + mod_sss_cfg * mod_sss_config; + msg_spectra_cfg * msg_spectra_sss_config; + unsigned int snk_spectra_sss_config_count; + snk_spectra_cfg ** snk_spectra_sss_configs; + + mod_sspf_cfg * mod_sspf_config; + msg_spectra_cfg * msg_spectra_sspf_config; + unsigned int snk_spectra_sspf_config_count; + snk_spectra_cfg ** snk_spectra_sspf_configs; + + } configs; + + configs * configs_construct(const char * file_config, const char * file_ios); + + void configs_destroy(configs * cfgs); + +#endif \ No newline at end of file diff --git a/demo/main.c b/demo/main.c new file mode 100644 index 0000000..db8ac89 --- /dev/null +++ b/demo/main.c @@ -0,0 +1,159 @@ + + #include + + #include "parameters.h" + #include "configs.h" + #include "objects.h" + #include "threads.h" + + #include + #include + + int main(int argc, char * argv[]) { + + // +----------------------------------------------------------+ + // | Getopt | + // +----------------------------------------------------------+ + + int c; + char * file_config; + char * file_ios; + + // +----------------------------------------------------------+ + // | Timer | + // +----------------------------------------------------------+ + + struct timespec ts; + + // +----------------------------------------------------------+ + // | Flag | + // +----------------------------------------------------------+ + + char isRunning; + + // +----------------------------------------------------------+ + // | Configurations | + // +----------------------------------------------------------+ + + configs * cfgs; + + // +----------------------------------------------------------+ + // | Objects | + // +----------------------------------------------------------+ + + objects * objs; + + // +----------------------------------------------------------+ + // | Arguments | + // +----------------------------------------------------------+ + + file_config = (char *) NULL; + file_ios = (char *) NULL; + + while ((c = getopt(argc,argv, "hc:i:")) != -1) { + + switch(c) { + + case 'h': + + exit(EXIT_SUCCESS); + + break; + + case 'c': + + file_config = (char *) malloc(sizeof(char) * (strlen(optarg)+1)); + strcpy(file_config, optarg); + + break; + + case 'i': + + file_ios = (char *) malloc(sizeof(char) * (strlen(optarg)+1)); + strcpy(file_ios, optarg); + + break; + + } + + } + + if (file_config == NULL) { + printf("Missing configuration file.\n"); + exit(EXIT_FAILURE); + } + if (file_ios == NULL) { + printf("Missing ios file.\n"); + exit(EXIT_FAILURE); + } + + // +----------------------------------------------------------+ + // | Copyright | + // +----------------------------------------------------------+ + + printf("+--------------------------------------------+\n"); + printf("| ODAS (Open embeddeD Audition System) |\n"); + printf("+--------------------------------------------+\n"); + printf("| Author: Francois Grondin |\n"); + printf("| Email: francois.grondin2@usherbrooke.ca |\n"); + printf("| Website: introlab.3it.usherbrooke.ca |\n"); + printf("| Version: 1.0 |\n"); + printf("+--------------------------------------------+\n"); + + // +----------------------------------------------------------+ + // | Configure | + // +----------------------------------------------------------+ + + printf(" + Initializing configurations...... "); fflush(stdout); + + cfgs = configs_construct(file_config, file_ios); + + printf("[Done]\n"); + + // +----------------------------------------------------------+ + // | Construct | + // +----------------------------------------------------------+ + + printf(" + Initializing objects............. "); fflush(stdout); + + objs = objects_construct(cfgs); + + printf("[Done]\n"); + + // +----------------------------------------------------------+ + // | Launch threads | + // +----------------------------------------------------------+ + + printf(" + Launch threads................... "); fflush(stdout); + + threads_start(objs); + + printf("[Done]\n"); + + + // +----------------------------------------------------------+ + // | Wait | + // +----------------------------------------------------------+ + + printf(" + Threads running.................. "); fflush(stdout); + + threads_join(objs); + + printf("[Done]\n"); + + // +----------------------------------------------------------+ + // | Free memory | + // +----------------------------------------------------------+ + + printf(" + Free memory...................... "); fflush(stdout); + + objects_destroy(objs); + configs_destroy(cfgs); + free((void *) file_config); + free((void *) file_ios); + + printf("[Done]\n"); + + return 0; + + } diff --git a/demo/objects.c b/demo/objects.c new file mode 100644 index 0000000..865b74d --- /dev/null +++ b/demo/objects.c @@ -0,0 +1,694 @@ + + #include "objects.h" + + objects * objects_construct(const configs * cfgs) { + + objects * objs; + unsigned int iSink; + + objs = (objects *) malloc(sizeof(objects)); + + objs->nMessages = 10; + + // +----------------------------------------------------------+ + // | Construct | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + objs->asrc_hops_raw_object = asrc_hops_construct(cfgs->src_hops_raw_config, cfgs->msg_hops_raw_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_hops_raw_object = amsg_hops_construct(objs->nMessages, cfgs->msg_hops_raw_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_hops_raw_object_count = cfgs->snk_hops_raw_config_count; + objs->asnk_hops_raw_objects = (asnk_hops_obj **) malloc(sizeof(asnk_hops_obj *) * cfgs->snk_hops_raw_config_count); + + for (iSink = 0; iSink < objs->asnk_hops_raw_object_count; iSink++) { + objs->asnk_hops_raw_objects[iSink] = asnk_hops_construct(cfgs->snk_hops_raw_configs[iSink], cfgs->msg_hops_raw_config); + } + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_mapping_object = amod_mapping_construct(cfgs->mod_mapping_config, cfgs->msg_hops_mapping_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_hops_mapping_object = amsg_hops_construct(objs->nMessages, cfgs->msg_hops_mapping_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_hops_mapping_object_count = cfgs->snk_hops_mapping_config_count; + objs->asnk_hops_mapping_objects = (asnk_hops_obj **) malloc(sizeof(asnk_hops_obj *) * cfgs->snk_hops_mapping_config_count); + + for (iSink = 0; iSink < objs->asnk_hops_mapping_object_count; iSink++) { + objs->asnk_hops_mapping_objects[iSink] = asnk_hops_construct(cfgs->snk_hops_mapping_configs[iSink], cfgs->msg_hops_mapping_config); + } + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_resample_object = amod_resample_construct(cfgs->mod_resample_config, cfgs->msg_hops_mapping_config, cfgs->msg_hops_resample_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_hops_resample_object = amsg_hops_construct(objs->nMessages, cfgs->msg_hops_resample_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_hops_resample_object_count = cfgs->snk_hops_resample_config_count; + objs->asnk_hops_resample_objects = (asnk_hops_obj **) malloc(sizeof(asnk_hops_obj *) * cfgs->snk_hops_resample_config_count); + + for (iSink = 0; iSink < objs->asnk_hops_resample_object_count; iSink++) { + objs->asnk_hops_resample_objects[iSink] = asnk_hops_construct(cfgs->snk_hops_resample_configs[iSink], cfgs->msg_hops_resample_config); + } + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_stft_object = amod_stft_construct(cfgs->mod_stft_config, cfgs->msg_hops_resample_config, cfgs->msg_spectra_stft_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_spectra_stft_object = amsg_spectra_construct(objs->nMessages, cfgs->msg_spectra_stft_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_spectra_stft_object_count = cfgs->snk_spectra_stft_config_count; + objs->asnk_spectra_stft_objects = (asnk_spectra_obj **) malloc(sizeof(asnk_spectra_obj *) * cfgs->snk_spectra_stft_config_count); + + for (iSink = 0; iSink < objs->asnk_spectra_stft_object_count; iSink++) { + objs->asnk_spectra_stft_objects[iSink] = asnk_spectra_construct(cfgs->snk_spectra_stft_configs[iSink], cfgs->msg_spectra_stft_config); + } + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_ssl_object = amod_ssl_construct(cfgs->mod_ssl_config, cfgs->msg_spectra_stft_config, cfgs->msg_pots_ssl_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_pots_ssl_object = amsg_pots_construct(objs->nMessages, cfgs->msg_pots_ssl_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_pots_ssl_object_count = cfgs->snk_pots_ssl_config_count; + objs->asnk_pots_ssl_objects = (asnk_pots_obj **) malloc(sizeof(asnk_pots_obj *) * cfgs->snk_pots_ssl_config_count); + + for (iSink = 0; iSink < objs->asnk_pots_ssl_object_count; iSink++) { + objs->asnk_pots_ssl_objects[iSink] = asnk_pots_construct(cfgs->snk_pots_ssl_configs[iSink], cfgs->msg_pots_ssl_config); + } + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_sst_object = amod_sst_construct(cfgs->mod_sst_config, cfgs->mod_ssl_config, cfgs->msg_pots_ssl_config, cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_tracks_sst_object = amsg_tracks_construct(objs->nMessages, cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_tracks_sst_object_count = cfgs->snk_tracks_sst_config_count; + objs->asnk_tracks_sst_objects = (asnk_tracks_obj **) malloc(sizeof(asnk_tracks_obj *) * cfgs->snk_tracks_sst_config_count); + + for (iSink = 0; iSink < objs->asnk_tracks_sst_object_count; iSink++) { + objs->asnk_tracks_sst_objects[iSink] = asnk_tracks_construct(cfgs->snk_tracks_sst_configs[iSink], cfgs->msg_tracks_sst_config); + } + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_sss_object = amod_sss_construct(cfgs->mod_sss_config, cfgs->msg_spectra_sss_config, cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_spectra_sss_object = amsg_spectra_construct(objs->nMessages, cfgs->msg_spectra_sss_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_spectra_sss_object_count = cfgs->snk_spectra_sss_config_count; + objs->asnk_spectra_sss_objects = (asnk_spectra_obj **) malloc(sizeof(asnk_spectra_obj *) * cfgs->snk_spectra_sss_config_count); + + for (iSink = 0; iSink < objs->asnk_spectra_sss_object_count; iSink++) { + objs->asnk_spectra_sss_objects[iSink] = asnk_spectra_construct(cfgs->snk_spectra_sss_configs[iSink], cfgs->msg_spectra_sss_config); + } + + // +------------------------------------------------------+ + // | SSPF | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_sspf_object = amod_sspf_construct(cfgs->mod_sspf_config, cfgs->msg_spectra_sspf_config, cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + objs->amsg_spectra_sspf_object = amsg_spectra_construct(objs->nMessages, cfgs->msg_spectra_sspf_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_spectra_sspf_object_count = cfgs->snk_spectra_sspf_config_count; + objs->asnk_spectra_sspf_objects = (asnk_spectra_obj **) malloc(sizeof(asnk_spectra_obj *) * cfgs->snk_spectra_sspf_config_count); + + for (iSink = 0; iSink < objs->asnk_spectra_sspf_object_count; iSink++) { + objs->asnk_spectra_sspf_objects[iSink] = asnk_spectra_construct(cfgs->snk_spectra_sspf_configs[iSink], cfgs->msg_spectra_sspf_config); + } + + // +----------------------------------------------------------+ + // | Connect | + // +----------------------------------------------------------+ + + objs->acon_hops_raw_object = acon_hops_construct(objs->asnk_hops_raw_object_count+1, objs->nMessages, cfgs->msg_hops_raw_config); + objs->acon_hops_mapping_object = acon_hops_construct(objs->asnk_hops_mapping_object_count+1, objs->nMessages, cfgs->msg_hops_mapping_config); + objs->acon_hops_resample_object = acon_hops_construct(objs->asnk_hops_resample_object_count+1, objs->nMessages, cfgs->msg_hops_resample_config); + objs->acon_spectra_stft_object = acon_spectra_construct(objs->asnk_spectra_stft_object_count+3, objs->nMessages, cfgs->msg_spectra_stft_config); + objs->acon_pots_ssl_object = acon_pots_construct(objs->asnk_pots_ssl_object_count+1, objs->nMessages, cfgs->msg_pots_ssl_config); + objs->acon_tracks_sst_object = acon_tracks_construct(objs->asnk_tracks_sst_object_count+2, objs->nMessages, cfgs->msg_tracks_sst_config); + objs->acon_spectra_sss_object = acon_spectra_construct(objs->asnk_spectra_sss_object_count+1, objs->nMessages, cfgs->msg_spectra_sss_config); + objs->acon_spectra_sspf_object = acon_spectra_construct(objs->asnk_spectra_sspf_object_count, objs->nMessages, cfgs->msg_spectra_sspf_config); + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + asrc_hops_connect(objs->asrc_hops_raw_object, + objs->acon_hops_raw_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_raw_object_count; iSink++) { + + asnk_hops_connect(objs->asnk_hops_raw_objects[iSink], + objs->acon_hops_raw_object->outs[iSink+1]); + + } + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_mapping_connect(objs->amod_mapping_object, + objs->acon_hops_raw_object->outs[0], + objs->acon_hops_mapping_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_mapping_object_count; iSink++) { + + asnk_hops_connect(objs->asnk_hops_mapping_objects[iSink], + objs->acon_hops_mapping_object->outs[iSink+1]); + + } + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_resample_connect(objs->amod_resample_object, + objs->acon_hops_mapping_object->outs[0], + objs->acon_hops_resample_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_resample_object_count; iSink++) { + + asnk_hops_connect(objs->asnk_hops_resample_objects[iSink], + objs->acon_hops_resample_object->outs[iSink+1]); + + } + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_stft_connect(objs->amod_stft_object, + objs->acon_hops_resample_object->outs[0], + objs->acon_spectra_stft_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_stft_object_count; iSink++) { + + asnk_spectra_connect(objs->asnk_spectra_stft_objects[iSink], + objs->acon_spectra_stft_object->outs[iSink+3]); + + } + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_ssl_connect(objs->amod_ssl_object, + objs->acon_spectra_stft_object->outs[0], + objs->acon_pots_ssl_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_pots_ssl_object_count; iSink++) { + + asnk_pots_connect(objs->asnk_pots_ssl_objects[iSink], + objs->acon_pots_ssl_object->outs[iSink+1]); + + } + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sst_connect(objs->amod_sst_object, + objs->acon_pots_ssl_object->outs[0], + objs->acon_tracks_sst_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_tracks_sst_object_count; iSink++) { + + asnk_tracks_connect(objs->asnk_tracks_sst_objects[iSink], + objs->acon_tracks_sst_object->outs[iSink+2]); + + } + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sss_connect(objs->amod_sss_object, + objs->acon_spectra_stft_object->outs[1], + objs->acon_tracks_sst_object->outs[0], + objs->acon_spectra_sss_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sss_object_count; iSink++) { + + asnk_spectra_connect(objs->asnk_spectra_sss_objects[iSink], + objs->acon_spectra_sss_object->outs[iSink+1]); + + } + + // +------------------------------------------------------+ + // | SSPF | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sspf_connect(objs->amod_sspf_object, + objs->acon_spectra_stft_object->outs[2], + objs->acon_spectra_sss_object->outs[0], + objs->acon_tracks_sst_object->outs[1], + objs->acon_spectra_sspf_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sspf_object_count; iSink++) { + + asnk_spectra_connect(objs->asnk_spectra_sspf_objects[iSink], + objs->acon_spectra_sspf_object->outs[iSink]); + + } + + return objs; + + } + + void objects_destroy(objects * objs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Destroy | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + asrc_hops_destroy(objs->asrc_hops_raw_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_hops_destroy(objs->amsg_hops_raw_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_raw_object_count; iSink++) { + asnk_hops_destroy(objs->asnk_hops_raw_objects[iSink]); + } + free((void *) objs->asnk_hops_raw_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_raw_object); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_mapping_destroy(objs->amod_mapping_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_hops_destroy(objs->amsg_hops_mapping_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_mapping_object_count; iSink++) { + asnk_hops_destroy(objs->asnk_hops_mapping_objects[iSink]); + } + free((void *) objs->asnk_hops_mapping_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_mapping_object); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_resample_destroy(objs->amod_resample_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_hops_destroy(objs->amsg_hops_resample_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_resample_object_count; iSink++) { + asnk_hops_destroy(objs->asnk_hops_resample_objects[iSink]); + } + free((void *) objs->asnk_hops_resample_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_resample_object); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_stft_destroy(objs->amod_stft_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_spectra_destroy(objs->amsg_spectra_stft_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_stft_object_count; iSink++) { + asnk_spectra_destroy(objs->asnk_spectra_stft_objects[iSink]); + } + free((void *) objs->asnk_spectra_stft_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_spectra_destroy(objs->acon_spectra_stft_object); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_ssl_destroy(objs->amod_ssl_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_pots_destroy(objs->amsg_pots_ssl_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_pots_ssl_object_count; iSink++) { + asnk_pots_destroy(objs->asnk_pots_ssl_objects[iSink]); + } + free((void *) objs->asnk_pots_ssl_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_pots_destroy(objs->acon_pots_ssl_object); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sst_destroy(objs->amod_sst_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_tracks_destroy(objs->amsg_tracks_sst_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_tracks_sst_object_count; iSink++) { + asnk_tracks_destroy(objs->asnk_tracks_sst_objects[iSink]); + } + free((void *) objs->asnk_tracks_sst_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_tracks_destroy(objs->acon_tracks_sst_object); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sss_destroy(objs->amod_sss_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_spectra_destroy(objs->amsg_spectra_sss_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sss_object_count; iSink++) { + asnk_spectra_destroy(objs->asnk_spectra_sss_objects[iSink]); + } + free((void *) objs->asnk_spectra_sss_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_spectra_destroy(objs->acon_spectra_sss_object); + + // +------------------------------------------------------+ + // | SSPF | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sspf_destroy(objs->amod_sspf_object); + + // +--------------------------------------------------+ + // | Message | + // +--------------------------------------------------+ + + amsg_spectra_destroy(objs->amsg_spectra_sspf_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sspf_object_count; iSink++) { + asnk_spectra_destroy(objs->asnk_spectra_sspf_objects[iSink]); + } + free((void *) objs->asnk_spectra_sspf_objects); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_spectra_destroy(objs->acon_spectra_sspf_object); + + free((void *) objs); + + } \ No newline at end of file diff --git a/demo/objects.h b/demo/objects.h new file mode 100644 index 0000000..e76bab9 --- /dev/null +++ b/demo/objects.h @@ -0,0 +1,67 @@ +#ifndef __DEMO_OBJECTS +#define __DEMO_OBJECTS + + #include "configs.h" + + #include + #include + + typedef struct objects { + + unsigned int nMessages; + + asrc_hops_obj * asrc_hops_raw_object; + amsg_hops_obj * amsg_hops_raw_object; + unsigned int asnk_hops_raw_object_count; + asnk_hops_obj ** asnk_hops_raw_objects; + acon_hops_obj * acon_hops_raw_object; + + amod_mapping_obj * amod_mapping_object; + amsg_hops_obj * amsg_hops_mapping_object; + unsigned int asnk_hops_mapping_object_count; + asnk_hops_obj ** asnk_hops_mapping_objects; + acon_hops_obj * acon_hops_mapping_object; + + amod_resample_obj * amod_resample_object; + amsg_hops_obj * amsg_hops_resample_object; + unsigned int asnk_hops_resample_object_count; + asnk_hops_obj ** asnk_hops_resample_objects; + acon_hops_obj * acon_hops_resample_object; + + amod_stft_obj * amod_stft_object; + amsg_spectra_obj * amsg_spectra_stft_object; + unsigned int asnk_spectra_stft_object_count; + asnk_spectra_obj ** asnk_spectra_stft_objects; + acon_spectra_obj * acon_spectra_stft_object; + + amod_ssl_obj * amod_ssl_object; + amsg_pots_obj * amsg_pots_ssl_object; + unsigned int asnk_pots_ssl_object_count; + asnk_pots_obj ** asnk_pots_ssl_objects; + acon_pots_obj * acon_pots_ssl_object; + + amod_sst_obj * amod_sst_object; + amsg_tracks_obj * amsg_tracks_sst_object; + unsigned int asnk_tracks_sst_object_count; + asnk_tracks_obj ** asnk_tracks_sst_objects; + acon_tracks_obj * acon_tracks_sst_object; + + amod_sss_obj * amod_sss_object; + amsg_spectra_obj * amsg_spectra_sss_object; + unsigned int asnk_spectra_sss_object_count; + asnk_spectra_obj ** asnk_spectra_sss_objects; + acon_spectra_obj * acon_spectra_sss_object; + + amod_sspf_obj * amod_sspf_object; + amsg_spectra_obj * amsg_spectra_sspf_object; + unsigned int asnk_spectra_sspf_object_count; + asnk_spectra_obj ** asnk_spectra_sspf_objects; + acon_spectra_obj * acon_spectra_sspf_object; + + } objects; + + objects * objects_construct(const configs * cfgs); + + void objects_destroy(objects * objs); + +#endif \ No newline at end of file diff --git a/demo/parameters.c b/demo/parameters.c new file mode 100644 index 0000000..528cd8c --- /dev/null +++ b/demo/parameters.c @@ -0,0 +1,1778 @@ + + #include "parameters.h" + + int parameters_lookup_int(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + int rtnValue; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + rtnValue = config_setting_get_int(setting); + + config_destroy(&cfg); + + return rtnValue; + + } + + float parameters_lookup_float(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + float rtnValue; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + rtnValue = (float) config_setting_get_float(setting); + + config_destroy(&cfg); + + return rtnValue; + + } + + char * parameters_lookup_string(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + const char * tmpStr; + char * rtnStr; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + tmpStr = config_setting_get_string(setting); + + rtnStr = (char *) malloc(sizeof(char) * (strlen(tmpStr)+1)); + strcpy(rtnStr, tmpStr); + + config_destroy(&cfg); + + return rtnStr; + + } + + unsigned int parameters_count(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + unsigned int rtnValue; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + rtnValue = config_setting_length(setting); + + config_destroy(&cfg); + + return rtnValue; + + } + + src_hops_cfg * parameters_src_hops_raw_config(const char * fileConfig, const char * fileIOs) { + + src_hops_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = src_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileIOs, "input.raw.format"); + + if (strcmp(tmpStr1, "bin08") == 0) { cfg->format = format_construct_bin(8); } + else if (strcmp(tmpStr1, "bin16") == 0) { cfg->format = format_construct_bin(16); } + else if (strcmp(tmpStr1, "bin24") == 0) { cfg->format = format_construct_bin(24); } + else if (strcmp(tmpStr1, "bin32") == 0) { cfg->format = format_construct_bin(32); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileIOs, "input.raw.type"); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileIOs, "input.raw.path"); + + cfg->interface = interface_construct_file(tmpStr2); + + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileIOs, "input.raw.ip"); + tmpInt1 = parameters_lookup_int(fileIOs, "input.raw.port"); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "soundcard") == 0) { + + tmpInt1 = parameters_lookup_int(fileIOs, "input.raw.device"); + tmpInt2 = parameters_lookup_int(fileIOs, "input.raw.subdevice"); + + cfg->interface = interface_construct_soundcard(tmpInt1, tmpInt2); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_raw_config(const char * fileConfig, const char * fileIOs) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "raw.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_lookup_int(fileConfig, "raw.nChannels"); + + return cfg; + + } + + unsigned int parameters_snk_hops_raw_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.raw"); + + } + + snk_hops_cfg * parameters_snk_hops_raw_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_hops_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_hops_cfg_construct(); + + // +------------------------------------------------------+ + // | Sample rate | + // +------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +------------------------------------------------------+ + // | Format | + // +------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "bin08") == 0) { cfg->format = format_construct_bin(8); } + else if (strcmp(tmpStr1, "bin16") == 0) { cfg->format = format_construct_bin(16); } + else if (strcmp(tmpStr1, "bin24") == 0) { cfg->format = format_construct_bin(24); } + else if (strcmp(tmpStr1, "bin32") == 0) { cfg->format = format_construct_bin(32); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +------------------------------------------------------+ + // | Type | + // +------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "soundcard") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].device", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.raw.[%u].subdevice", iSink); + tmpInt2 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_soundcard(tmpInt1, tmpInt2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + mod_mapping_cfg * parameters_mod_mapping_config(const char * fileConfig, const char * fileIOs) { + + mod_mapping_cfg * cfg; + unsigned int nLinks; + unsigned int iLink; + char * tmpStr1; + + cfg = mod_mapping_cfg_construct(); + + // +----------------------------------------------------------+ + // | Links | + // +----------------------------------------------------------+ + + nLinks = parameters_count(fileConfig, "mapping.map"); + cfg->links = links_construct_zero(nLinks); + + for (iLink = 0; iLink < nLinks; iLink++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "mapping.map.[%u]", iLink); + cfg->links->array[iLink] = parameters_lookup_int(fileConfig, tmpStr1); + free((void *) tmpStr1); + + } + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_mapping_config(const char * fileConfig, const char * fileIOs) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "raw.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + unsigned int parameters_snk_hops_mapping_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.mapping"); + + } + + snk_hops_cfg * parameters_snk_hops_mapping_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_hops_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_hops_cfg_construct(); + + // +------------------------------------------------------+ + // | Sample rate | + // +------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +------------------------------------------------------+ + // | Format | + // +------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "bin08") == 0) { cfg->format = format_construct_bin(8); } + else if (strcmp(tmpStr1, "bin16") == 0) { cfg->format = format_construct_bin(16); } + else if (strcmp(tmpStr1, "bin24") == 0) { cfg->format = format_construct_bin(24); } + else if (strcmp(tmpStr1, "bin32") == 0) { cfg->format = format_construct_bin(32); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +------------------------------------------------------+ + // | Type | + // +------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "soundcard") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].device", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.mapping.[%u].subdevice", iSink); + tmpInt2 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_soundcard(tmpInt1, tmpInt2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + mod_resample_cfg * parameters_mod_resample_config(const char * fileConfig, const char * fileIOs) { + + mod_resample_cfg * cfg; + + cfg = mod_resample_cfg_construct(); + + unsigned int fSin; + unsigned int fSout; + + // +----------------------------------------------------------+ + // | Sample rates | + // +----------------------------------------------------------+ + + cfg->fSin = parameters_lookup_int(fileConfig, "raw.fS"); + cfg->fSout = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_resample_config(const char * fileConfig, const char * fileIOs) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "general.size.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + unsigned int parameters_snk_hops_resample_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.resample"); + + } + + snk_hops_cfg * parameters_snk_hops_resample_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_hops_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_hops_cfg_construct(); + + // +------------------------------------------------------+ + // | Sample rate | + // +------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +------------------------------------------------------+ + // | Format | + // +------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "bin08") == 0) { cfg->format = format_construct_bin(8); } + else if (strcmp(tmpStr1, "bin16") == 0) { cfg->format = format_construct_bin(16); } + else if (strcmp(tmpStr1, "bin24") == 0) { cfg->format = format_construct_bin(24); } + else if (strcmp(tmpStr1, "bin32") == 0) { cfg->format = format_construct_bin(32); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +------------------------------------------------------+ + // | Type | + // +------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "soundcard") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].device", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.resample.[%u].subdevice", iSink); + tmpInt2 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_soundcard(tmpInt1, tmpInt2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + mod_stft_cfg * parameters_mod_stft_config(const char * fileConfig, const char * fileIOs) { + + mod_stft_cfg * cfg; + + cfg = mod_stft_cfg_construct(); + + return cfg; + + } + + msg_spectra_cfg * parameters_msg_spectra_stft_config(const char * fileConfig, const char * fileIOs) { + + msg_spectra_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + unsigned int parameters_snk_spectra_stft_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.stft"); + + } + + snk_spectra_cfg * parameters_snk_spectra_stft_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_spectra_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.stft.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "float") == 0) { cfg->format = format_construct_float(); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.stft.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.stft.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.stft.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.stft.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + mod_ssl_cfg * parameters_mod_ssl_config(const char * fileConfig, const char * fileIOs) { + + mod_ssl_cfg * cfg; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int iSample; + unsigned int iLevel; + + char * tmpLabel; + + cfg = mod_ssl_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + nChannels = parameters_count(fileConfig, "general.mics"); + + cfg->mics = mics_construct_zero(nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + // +--------------------------------------------------+ + // | Mu | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].mu.[%u]", iChannel, iSample); + cfg->mics->mu[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Sigma2 | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 9; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].sigma2.[%u]", iChannel, iSample); + cfg->mics->sigma2[iChannel * 9 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Direction | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].direction.[%u]", iChannel, iSample); + cfg->mics->direction[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Angle | + // +--------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 0); + cfg->mics->thetaAllPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 1); + cfg->mics->thetaNoPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->samplerate = samplerate_construct_zero(); + + cfg->samplerate->mu = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + cfg->samplerate->sigma2 = parameters_lookup_float(fileConfig, "general.samplerate.sigma2"); + + // +----------------------------------------------------------+ + // | Sound speed | + // +----------------------------------------------------------+ + + cfg->soundspeed = soundspeed_construct_zero(); + + cfg->soundspeed->mu = parameters_lookup_float(fileConfig, "general.speedofsound.mu"); + cfg->soundspeed->sigma2 = parameters_lookup_float(fileConfig, "general.speedofsound.sigma2"); + + // +----------------------------------------------------------+ + // | Epsilon | + // +----------------------------------------------------------+ + + cfg->epsilon = parameters_lookup_float(fileConfig, "general.epsilon"); + + // +----------------------------------------------------------+ + // | Levels | + // +----------------------------------------------------------+ + + cfg->nLevels = parameters_count(fileConfig, "ssl.scans"); + + cfg->levels = (unsigned int *) malloc(sizeof(unsigned int) * cfg->nLevels); + cfg->deltas = (signed int *) malloc(sizeof(signed int) * cfg->nLevels); + + for (iLevel = 0; iLevel < cfg->nLevels; iLevel++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "ssl.scans.[%u].level", iLevel); + cfg->levels[iLevel] = parameters_lookup_int(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "ssl.scans.[%u].delta", iLevel); + cfg->deltas[iLevel] = parameters_lookup_int(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Matches | + // +----------------------------------------------------------+ + + cfg->nMatches = parameters_lookup_int(fileConfig, "ssl.nMatches"); + + // +----------------------------------------------------------+ + // | Minimum probability | + // +----------------------------------------------------------+ + + cfg->probMin = parameters_lookup_float(fileConfig, "ssl.probMin"); + + // +----------------------------------------------------------+ + // | Number of refined levels | + // +----------------------------------------------------------+ + + cfg->nRefinedLevels = parameters_lookup_int(fileConfig, "ssl.nRefinedLevels"); + + // +----------------------------------------------------------+ + // | Number of thetas | + // +----------------------------------------------------------+ + + cfg->nThetas = parameters_lookup_int(fileConfig, "ssl.nThetas"); + + // +----------------------------------------------------------+ + // | Number of thetas | + // +----------------------------------------------------------+ + + cfg->gainMin = parameters_lookup_float(fileConfig, "ssl.gainMin"); + + return cfg; + + } + + msg_pots_cfg * parameters_msg_pots_ssl_config(const char * fileConfig, const char * fileIOs) { + + msg_pots_cfg * cfg; + + cfg = msg_pots_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Number of potential sources | + // +----------------------------------------------------------+ + + cfg->nPots = parameters_lookup_int(fileConfig, "ssl.nPots"); + + return cfg; + + } + + unsigned int parameters_snk_pots_ssl_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.ssl"); + + } + + snk_pots_cfg * parameters_snk_pots_ssl_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_pots_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_pots_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.ssl.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "float") == 0) { cfg->format = format_construct_float(); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.ssl.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.ssl.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.ssl.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.ssl.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + mod_sst_cfg * parameters_mod_sst_config(const char * fileConfig, const char * fileIOs) { + + mod_sst_cfg * cfg; + + unsigned int nGaussians; + unsigned int iGaussian; + float weight; + float mu; + float sigma; + unsigned int iTrack; + + char * tmpStr1; + + cfg = mod_sst_cfg_construct(); + + // +----------------------------------------------------------+ + // | Mode | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sst.mode"); + + if (strcmp(tmpStr1, "kalman") == 0) { + cfg->mode = 'k'; + } + else if (strcmp(tmpStr1, "particle") == 0) { + cfg->mode = 'p'; + } + else { + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | nTracksMax | + // +----------------------------------------------------------+ + + cfg->nTracksMax = parameters_count(fileConfig, "sst.N_inactive"); + + // +----------------------------------------------------------+ + // | hopSize | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "general.size.hopSize"); + + // +----------------------------------------------------------+ + // | Kalman | + // +----------------------------------------------------------+ + + cfg->sigmaQ = parameters_lookup_float(fileConfig, "sst.kalman.sigmaQ"); + + // +----------------------------------------------------------+ + // | Particles | + // +----------------------------------------------------------+ + + cfg->nParticles = parameters_lookup_int(fileConfig, "sst.particle.nParticles"); + cfg->st_alpha = parameters_lookup_float(fileConfig, "sst.particle.st_alpha"); + cfg->st_beta = parameters_lookup_float(fileConfig, "sst.particle.st_beta"); + cfg->st_ratio = parameters_lookup_float(fileConfig, "sst.particle.st_ratio"); + cfg->ve_alpha = parameters_lookup_float(fileConfig, "sst.particle.ve_alpha"); + cfg->ve_beta = parameters_lookup_float(fileConfig, "sst.particle.ve_beta"); + cfg->ve_ratio = parameters_lookup_float(fileConfig, "sst.particle.ve_ratio"); + cfg->ac_alpha = parameters_lookup_float(fileConfig, "sst.particle.ac_alpha"); + cfg->ac_beta = parameters_lookup_float(fileConfig, "sst.particle.ac_beta"); + cfg->ac_ratio = parameters_lookup_float(fileConfig, "sst.particle.ac_ratio"); + cfg->Nmin = parameters_lookup_float(fileConfig, "sst.particle.Nmin"); + + // +----------------------------------------------------------+ + // | Epsilon | + // +----------------------------------------------------------+ + + cfg->epsilon = parameters_lookup_float(fileConfig, "general.epsilon"); + + // +----------------------------------------------------------+ + // | SigmaR | + // +----------------------------------------------------------+ + + cfg->sigmaR_active = sqrtf(parameters_lookup_float(fileConfig, "sst.sigmaR2_active")); + cfg->sigmaR_prob = sqrtf(parameters_lookup_float(fileConfig, "sst.sigmaR2_prob")); + + // +----------------------------------------------------------+ + // | GMM Active | + // +----------------------------------------------------------+ + + nGaussians = parameters_count(fileConfig, "sst.active"); + + cfg->active_gmm = gaussians_1d_construct_null(nGaussians); + + for (iGaussian = 0; iGaussian < nGaussians; iGaussian++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.active.[%u].weight",iGaussian); + weight = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.active.[%u].mu",iGaussian); + mu = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.active.[%u].sigma2",iGaussian); + sigma = sqrtf(parameters_lookup_float(fileConfig, tmpStr1)); + free((void *) tmpStr1); + + cfg->active_gmm->array[iGaussian] = gaussian_1d_construct_weightmusigma(weight, mu, sigma); + } + + // +----------------------------------------------------------+ + // | GMM Inactive | + // +----------------------------------------------------------+ + + nGaussians = parameters_count(fileConfig, "sst.inactive"); + + cfg->inactive_gmm = gaussians_1d_construct_null(nGaussians); + + for (iGaussian = 0; iGaussian < nGaussians; iGaussian++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.inactive.[%u].weight",iGaussian); + weight = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.inactive.[%u].mu",iGaussian); + mu = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.inactive.[%u].sigma2",iGaussian); + sigma = sqrtf(parameters_lookup_float(fileConfig, tmpStr1)); + free((void *) tmpStr1); + + cfg->inactive_gmm->array[iGaussian] = gaussian_1d_construct_weightmusigma(weight, mu, sigma); + } + + // +----------------------------------------------------------+ + // | Pfalse, Pnew and Ptrack | + // +----------------------------------------------------------+ + + cfg->Pfalse = parameters_lookup_float(fileConfig, "sst.Pfalse"); + cfg->Pnew = parameters_lookup_float(fileConfig, "sst.Pnew"); + cfg->Ptrack = parameters_lookup_float(fileConfig, "sst.Ptrack"); + + // +----------------------------------------------------------+ + // | New | + // +----------------------------------------------------------+ + + cfg->theta_new = parameters_lookup_float(fileConfig, "sst.theta_new"); + + // +----------------------------------------------------------+ + // | Prob | + // +----------------------------------------------------------+ + + cfg->theta_prob = parameters_lookup_float(fileConfig, "sst.theta_prob"); + cfg->N_prob = parameters_lookup_int(fileConfig, "sst.N_prob"); + + // +----------------------------------------------------------+ + // | Inactive | + // +----------------------------------------------------------+ + + cfg->theta_inactive = parameters_lookup_float(fileConfig, "sst.theta_inactive"); + cfg->N_inactive = (unsigned int *) malloc(sizeof(unsigned int) * cfg->nTracksMax); + + for (iTrack = 0; iTrack < cfg->nTracksMax; iTrack++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.N_inactive.[%u]", iTrack); + cfg->N_inactive[iTrack] = parameters_lookup_int(fileConfig, tmpStr1); + free((void *) tmpStr1); + + } + + return cfg; + + } + + msg_tracks_cfg * parameters_msg_tracks_sst_config(const char * fileConfig, const char * fileIOs) { + + msg_tracks_cfg * cfg; + + cfg = msg_tracks_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Number of tracked sources | + // +----------------------------------------------------------+ + + cfg->nTracks = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + unsigned int parameters_snk_tracks_sst_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.sst"); + + } + + snk_tracks_cfg * parameters_snk_tracks_sst_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_tracks_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_tracks_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sst.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "float") == 0) { cfg->format = format_construct_float(); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sst.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sst.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sst.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sst.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + + } + + mod_sss_cfg * parameters_mod_sss_config(const char * fileConfig, const char * fileIOs) { + + mod_sss_cfg * cfg; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int iSample; + unsigned int iLevel; + + char * tmpLabel; + + cfg = mod_sss_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + nChannels = parameters_count(fileConfig, "general.mics"); + + cfg->mics = mics_construct_zero(nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + // +--------------------------------------------------+ + // | Mu | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].mu.[%u]", iChannel, iSample); + cfg->mics->mu[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Sigma2 | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 9; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].sigma2.[%u]", iChannel, iSample); + cfg->mics->sigma2[iChannel * 9 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Direction | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].direction.[%u]", iChannel, iSample); + cfg->mics->direction[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Angle | + // +--------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 0); + cfg->mics->thetaAllPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 1); + cfg->mics->thetaNoPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->samplerate = samplerate_construct_zero(); + + cfg->samplerate->mu = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + cfg->samplerate->sigma2 = parameters_lookup_float(fileConfig, "general.samplerate.sigma2"); + + // +----------------------------------------------------------+ + // | Sound speed | + // +----------------------------------------------------------+ + + cfg->soundspeed = soundspeed_construct_zero(); + + cfg->soundspeed->mu = parameters_lookup_float(fileConfig, "general.speedofsound.mu"); + cfg->soundspeed->sigma2 = parameters_lookup_float(fileConfig, "general.speedofsound.sigma2"); + + // +----------------------------------------------------------+ + // | Epsilon | + // +----------------------------------------------------------+ + + cfg->epsilon = parameters_lookup_float(fileConfig, "general.epsilon"); + + // +----------------------------------------------------------+ + // | Directivity | + // +----------------------------------------------------------+ + + cfg->nThetas = parameters_lookup_int(fileConfig, "sss.nThetas"); + cfg->gainMin = parameters_lookup_float(fileConfig, "sss.gainMin"); + + return cfg; + + } + + msg_spectra_cfg * parameters_msg_spectra_sss_config(const char * fileConfig, const char * fileIOs) { + + msg_spectra_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + + } + + unsigned int parameters_snk_spectra_sss_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.sss"); + + } + + snk_spectra_cfg * parameters_snk_spectra_sss_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_spectra_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sss.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "float") == 0) { cfg->format = format_construct_float(); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sss.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sss.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sss.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sss.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + mod_sspf_cfg * parameters_mod_sspf_config(const char * fileConfig, const char * fileIOs) { + + mod_sspf_cfg * cfg; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int iSample; + unsigned int iLevel; + + char * tmpLabel; + + cfg = mod_sspf_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + nChannels = parameters_count(fileConfig, "general.mics"); + + cfg->mics = mics_construct_zero(nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + // +--------------------------------------------------+ + // | Mu | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].mu.[%u]", iChannel, iSample); + cfg->mics->mu[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Sigma2 | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 9; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].sigma2.[%u]", iChannel, iSample); + cfg->mics->sigma2[iChannel * 9 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Direction | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].direction.[%u]", iChannel, iSample); + cfg->mics->direction[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Angle | + // +--------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 0); + cfg->mics->thetaAllPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 1); + cfg->mics->thetaNoPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Directivity | + // +----------------------------------------------------------+ + + cfg->nThetas = parameters_lookup_int(fileConfig, "sspf.nThetas"); + cfg->gainMin = parameters_lookup_float(fileConfig, "sspf.gainMin"); + + return cfg; + + } + + msg_spectra_cfg * parameters_msg_spectra_sspf_config(const char * fileConfig, const char * fileIOs) { + + msg_spectra_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + unsigned int parameters_snk_spectra_sspf_count(const char * fileConfig, const char * fileIOs) { + + return parameters_count(fileIOs, "output.sspf"); + + } + + snk_spectra_cfg * parameters_snk_spectra_sspf_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink) { + + snk_spectra_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sspf.[%u].format", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "float") == 0) { cfg->format = format_construct_float(); } + else { printf("Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sspf.[%u].type", iSink); + tmpStr1 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sspf.[%u].path", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sspf.[%u].ip", iSink); + tmpStr2 = parameters_lookup_string(fileIOs, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "output.sspf.[%u].port", iSink); + tmpInt1 = parameters_lookup_int(fileIOs, tmpLabel); + free((void *) tmpLabel); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else { + + printf("Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } \ No newline at end of file diff --git a/demo/parameters.h b/demo/parameters.h new file mode 100644 index 0000000..827d665 --- /dev/null +++ b/demo/parameters.h @@ -0,0 +1,88 @@ +#ifndef __DEMO_PARAMETERS +#define __DEMO_PARAMETERS + + #include + #include + + int parameters_lookup_int(const char * file, const char * path); + + float parameters_lookup_float(const char * file, const char * path); + + char * parameters_lookup_string(const char * file, const char * path); + + unsigned int parameters_count(const char * file, const char * path); + + + src_hops_cfg * parameters_src_hops_raw_config(const char * fileConfig, const char * fileIOs); + + msg_hops_cfg * parameters_msg_hops_raw_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_hops_raw_count(const char * fileConfig, const char * fileIOs); + + snk_hops_cfg * parameters_snk_hops_raw_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_mapping_cfg * parameters_mod_mapping_config(const char * fileConfig, const char * fileIOs); + + msg_hops_cfg * parameters_msg_hops_mapping_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_hops_mapping_count(const char * fileConfig, const char * fileIOs); + + snk_hops_cfg * parameters_snk_hops_mapping_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_resample_cfg * parameters_mod_resample_config(const char * fileConfig, const char * fileIOs); + + msg_hops_cfg * parameters_msg_hops_resample_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_hops_resample_count(const char * fileConfig, const char * fileIOs); + + snk_hops_cfg * parameters_snk_hops_resample_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_stft_cfg * parameters_mod_stft_config(const char * fileConfig, const char * fileIOs); + + msg_spectra_cfg * parameters_msg_spectra_stft_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_spectra_stft_count(const char * fileConfig, const char * fileIOs); + + snk_spectra_cfg * parameters_snk_spectra_stft_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_ssl_cfg * parameters_mod_ssl_config(const char * fileConfig, const char * fileIOs); + + msg_pots_cfg * parameters_msg_pots_ssl_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_pots_ssl_count(const char * fileConfig, const char * fileIOs); + + snk_pots_cfg * parameters_snk_pots_ssl_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_sst_cfg * parameters_mod_sst_config(const char * fileConfig, const char * fileIOs); + + msg_tracks_cfg * parameters_msg_tracks_sst_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_tracks_sst_count(const char * fileConfig, const char * fileIOs); + + snk_tracks_cfg * parameters_snk_tracks_sst_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_sss_cfg * parameters_mod_sss_config(const char * fileConfig, const char * fileIOs); + + msg_spectra_cfg * parameters_msg_spectra_sss_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_spectra_sss_count(const char * fileConfig, const char * fileIOs); + + snk_spectra_cfg * parameters_snk_spectra_sss_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + + mod_sspf_cfg * parameters_mod_sspf_config(const char * fileConfig, const char * fileIOs); + + msg_spectra_cfg * parameters_msg_spectra_sspf_config(const char * fileConfig, const char * fileIOs); + + unsigned int parameters_snk_spectra_sspf_count(const char * fileConfig, const char * fileIOs); + + snk_spectra_cfg * parameters_snk_spectra_sspf_config(const char * fileConfig, const char * fileIOs, const unsigned int iSink); + + +#endif \ No newline at end of file diff --git a/demo/threads.c b/demo/threads.c new file mode 100644 index 0000000..b4c0144 --- /dev/null +++ b/demo/threads.c @@ -0,0 +1,416 @@ + + #include "threads.h" + + void threads_start(objects * objs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + thread_start(objs->asrc_hops_raw_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_raw_object_count; iSink++) { + thread_start(objs->asnk_hops_raw_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_hops_raw_object->thread); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_mapping_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_mapping_object_count; iSink++) { + thread_start(objs->asnk_hops_mapping_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_hops_mapping_object->thread); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_resample_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_resample_object_count; iSink++) { + thread_start(objs->asnk_hops_resample_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_hops_resample_object->thread); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_stft_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_stft_object_count; iSink++) { + thread_start(objs->asnk_spectra_stft_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_spectra_stft_object->thread); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_ssl_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_pots_ssl_object_count; iSink++) { + thread_start(objs->asnk_pots_ssl_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_pots_ssl_object->thread); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_sst_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_tracks_sst_object_count; iSink++) { + thread_start(objs->asnk_tracks_sst_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_tracks_sst_object->thread); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_sss_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sss_object_count; iSink++) { + thread_start(objs->asnk_spectra_sss_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_spectra_sss_object->thread); + + // +----------------------------------------------------------+ + // | SSPF | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(objs->amod_sspf_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sspf_object_count; iSink++) { + thread_start(objs->asnk_spectra_sspf_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(objs->acon_spectra_sspf_object->thread); + + } + + void threads_stop(objects * objs) { + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + thread_stop(objs->asrc_hops_raw_object->thread); + + // Stops the source that generate frames to process. + // This will generate a "zero" message that will stop + // all following threads. + + } + + void threads_join(objects * objs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + thread_join(objs->asrc_hops_raw_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_raw_object_count; iSink++) { + thread_join(objs->asnk_hops_raw_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_hops_raw_object->thread); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_mapping_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_mapping_object_count; iSink++) { + thread_join(objs->asnk_hops_mapping_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_hops_mapping_object->thread); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_resample_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_hops_resample_object_count; iSink++) { + thread_join(objs->asnk_hops_resample_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_hops_resample_object->thread); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_stft_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_stft_object_count; iSink++) { + thread_join(objs->asnk_spectra_stft_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_spectra_stft_object->thread); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_ssl_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_pots_ssl_object_count; iSink++) { + thread_join(objs->asnk_pots_ssl_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_pots_ssl_object->thread); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_sst_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_tracks_sst_object_count; iSink++) { + thread_join(objs->asnk_tracks_sst_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_tracks_sst_object->thread); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_sss_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sss_object_count; iSink++) { + thread_join(objs->asnk_spectra_sss_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_spectra_sss_object->thread); + + // +----------------------------------------------------------+ + // | SSPF | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(objs->amod_sspf_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + for (iSink = 0; iSink < objs->asnk_spectra_sspf_object_count; iSink++) { + thread_join(objs->asnk_spectra_sspf_objects[iSink]->thread); + } + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(objs->acon_spectra_sspf_object->thread); + + } \ No newline at end of file diff --git a/demo/threads.h b/demo/threads.h new file mode 100644 index 0000000..f245a18 --- /dev/null +++ b/demo/threads.h @@ -0,0 +1,14 @@ +#ifndef __DEMO_THREADS +#define __DEMO_THREADS + + #include "objects.h" + + #include + + void threads_start(objects * objs); + + void threads_stop(objects * objs); + + void threads_join(objects * objs); + +#endif \ No newline at end of file -- 2.34.1