From 097d4e8097b5cd5858060caec71880ad4e6ae719 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Grondin?= Date: Mon, 3 Jul 2017 15:18:42 -0400 Subject: [PATCH] Add files via upload --- src/module/mod_istft.c | 89 ++++ src/module/mod_istft.h | 42 ++ src/module/mod_mapping.c | 97 ++++ src/module/mod_mapping.h | 42 ++ src/module/mod_resample.c | 428 +++++++++++++++++ src/module/mod_resample.h | 85 ++++ src/module/mod_ssl.c | 308 ++++++++++++ src/module/mod_ssl.h | 90 ++++ src/module/mod_sspf.c | 145 ++++++ src/module/mod_sspf.h | 69 +++ src/module/mod_sss.c | 169 +++++++ src/module/mod_sss.h | 76 +++ src/module/mod_sst.c | 988 ++++++++++++++++++++++++++++++++++++++ src/module/mod_sst.h | 129 +++++ src/module/mod_stft.c | 90 ++++ src/module/mod_stft.h | 41 ++ 16 files changed, 2888 insertions(+) create mode 100644 src/module/mod_istft.c create mode 100644 src/module/mod_istft.h create mode 100644 src/module/mod_mapping.c create mode 100644 src/module/mod_mapping.h create mode 100644 src/module/mod_resample.c create mode 100644 src/module/mod_resample.h create mode 100644 src/module/mod_ssl.c create mode 100644 src/module/mod_ssl.h create mode 100644 src/module/mod_sspf.c create mode 100644 src/module/mod_sspf.h create mode 100644 src/module/mod_sss.c create mode 100644 src/module/mod_sss.h create mode 100644 src/module/mod_sst.c create mode 100644 src/module/mod_sst.h create mode 100644 src/module/mod_stft.c create mode 100644 src/module/mod_stft.h diff --git a/src/module/mod_istft.c b/src/module/mod_istft.c new file mode 100644 index 0000000..e7411a7 --- /dev/null +++ b/src/module/mod_istft.c @@ -0,0 +1,89 @@ + + #include "mod_istft.h" + + mod_istft_obj * mod_istft_construct(const mod_istft_cfg * mod_istft_config, const msg_spectra_cfg * msg_spectra_config, const msg_hops_cfg * msg_hops_config) { + + mod_istft_obj * obj; + + obj = (mod_istft_obj *) malloc(sizeof(mod_istft_obj)); + + obj->freq2frame = freq2frame_construct_zero(2*(msg_spectra_config->halfFrameSize-1), msg_spectra_config->halfFrameSize); + obj->frames = frames_construct_zero(msg_hops_config->nChannels,2*(msg_spectra_config->halfFrameSize-1)); + obj->frame2hop = frame2hop_construct_zero(msg_hops_config->hopSize, 2*(msg_spectra_config->halfFrameSize-1), msg_hops_config->nChannels); + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void mod_istft_destroy(mod_istft_obj * obj) { + + freq2frame_destroy(obj->freq2frame); + frames_destroy(obj->frames); + frame2hop_destroy(obj->frame2hop); + + free((void *) obj); + + } + + int mod_istft_process(mod_istft_obj * obj) { + + int rtnValue; + + if (msg_spectra_isZero(obj->in) == 0) { + + freq2frame_process(obj->freq2frame, obj->in->freqs, obj->frames); + frame2hop_process(obj->frame2hop, obj->frames, obj->out->hops); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_hops_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_istft_connect(mod_istft_obj * obj, msg_spectra_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_istft_disconnect(mod_istft_obj * obj) { + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_istft_cfg * mod_istft_cfg_construct(void) { + + mod_istft_cfg * cfg; + + cfg = (mod_istft_cfg *) malloc(sizeof(mod_istft_cfg)); + + return cfg; + + } + + void mod_istft_cfg_destroy(mod_istft_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_istft_cfg_printf(const mod_istft_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_istft.h b/src/module/mod_istft.h new file mode 100644 index 0000000..fd0d9b0 --- /dev/null +++ b/src/module/mod_istft.h @@ -0,0 +1,42 @@ +#ifndef __ODAS_MODULE_ISTFT +#define __ODAS_MODULE_ISTFT + + #include "../system/freq2frame.h" + #include "../signal/frame.h" + #include "../system/frame2hop.h" + + #include "../message/msg_hops.h" + #include "../message/msg_spectra.h" + + typedef struct mod_istft_obj { + + freq2frame_obj * freq2frame; + frames_obj * frames; + frame2hop_obj * frame2hop; + + msg_spectra_obj * in; + msg_hops_obj * out; + + } mod_istft_obj; + + typedef struct mod_istft_cfg { + + } mod_istft_cfg; + + mod_istft_obj * mod_istft_construct(const mod_istft_cfg * mod_istft_config, const msg_spectra_cfg * msg_spectra_config, const msg_hops_cfg * msg_hops_config); + + void mod_istft_destroy(mod_istft_obj * obj); + + int mod_istft_process(mod_istft_obj * obj); + + void mod_istft_connect(mod_istft_obj * obj, msg_spectra_obj * in, msg_hops_obj * out); + + void mod_istft_disconnect(mod_istft_obj * obj); + + mod_istft_cfg * mod_istft_cfg_construct(void); + + void mod_istft_cfg_destroy(mod_istft_cfg * cfg); + + void mod_istft_cfg_printf(const mod_istft_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_mapping.c b/src/module/mod_mapping.c new file mode 100644 index 0000000..42e5d61 --- /dev/null +++ b/src/module/mod_mapping.c @@ -0,0 +1,97 @@ + + #include "mod_mapping.h" + + mod_mapping_obj * mod_mapping_construct(const mod_mapping_cfg * mod_mapping_config, const msg_hops_cfg * msg_hops_config) { + + mod_mapping_obj * obj; + unsigned int iLink; + + obj = (mod_mapping_obj *) malloc(sizeof(mod_mapping_obj)); + + obj->hop2hop_multiplex = hop2hop_multiplex_construct_zero(msg_hops_config->hopSize); + obj->links = links_clone(mod_mapping_config->links); + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void mod_mapping_destroy(mod_mapping_obj * obj) { + + links_destroy(obj->links); + hop2hop_multiplex_destroy(obj->hop2hop_multiplex); + free((void *) obj); + + } + + int mod_mapping_process(mod_mapping_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + hop2hop_multiplex_process(obj->hop2hop_multiplex, + obj->links, + obj->in->hops, + obj->out->hops); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_hops_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_mapping_connect(mod_mapping_obj * obj, msg_hops_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_mapping_disconnect(mod_mapping_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_mapping_cfg * mod_mapping_cfg_construct(void) { + + mod_mapping_cfg * cfg; + + cfg = (mod_mapping_cfg *) malloc(sizeof(mod_mapping_cfg)); + + cfg->links = (links_obj *) NULL; + + return cfg; + + } + + void mod_mapping_cfg_destroy(mod_mapping_cfg * cfg) { + + if (cfg->links != NULL) { + links_destroy(cfg->links); + } + + free((void *) cfg); + + } + + void mod_mapping_cfg_printf(const mod_mapping_cfg * cfg) { + + printf("links:"); links_printf(cfg->links); + + } \ No newline at end of file diff --git a/src/module/mod_mapping.h b/src/module/mod_mapping.h new file mode 100644 index 0000000..76c3abb --- /dev/null +++ b/src/module/mod_mapping.h @@ -0,0 +1,42 @@ +#ifndef __ODAS_MODULE_MAPPING +#define __ODAS_MODULE_MAPPING + + #include "../message/msg_hops.h" + #include "../message/msg_spectra.h" + + #include "../general/link.h" + #include "../system/hop2hop.h" + + typedef struct mod_mapping_obj { + + hop2hop_multiplex_obj * hop2hop_multiplex; + links_obj * links; + + msg_hops_obj * in; + msg_hops_obj * out; + + } mod_mapping_obj; + + typedef struct mod_mapping_cfg { + + links_obj * links; + + } mod_mapping_cfg; + + mod_mapping_obj * mod_mapping_construct(const mod_mapping_cfg * mod_mapping_config, const msg_hops_cfg * msg_hops_config); + + void mod_mapping_destroy(mod_mapping_obj * obj); + + int mod_mapping_process(mod_mapping_obj * obj); + + void mod_mapping_connect(mod_mapping_obj * obj, msg_hops_obj * in, msg_hops_obj * out); + + void mod_mapping_disconnect(mod_mapping_obj * obj); + + mod_mapping_cfg * mod_mapping_cfg_construct(void); + + void mod_mapping_cfg_destroy(mod_mapping_cfg * cfg); + + void mod_mapping_cfg_printf(const mod_mapping_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_resample.c b/src/module/mod_resample.c new file mode 100644 index 0000000..0034ca9 --- /dev/null +++ b/src/module/mod_resample.c @@ -0,0 +1,428 @@ + + #include "mod_resample.h" + + mod_resample_obj * mod_resample_construct(const mod_resample_cfg * mod_resample_config, const msg_hops_cfg * msg_hops_in_config, const msg_hops_cfg * msg_hops_out_config) { + + mod_resample_obj * obj; + + obj = (mod_resample_obj *) malloc(sizeof(mod_resample_obj)); + + obj->timeStamp = 0; + + if (mod_resample_config->fSin == mod_resample_config->fSout) { + obj->type = 's'; + } + if (mod_resample_config->fSin > mod_resample_config->fSout) { + obj->type = 'd'; + } + if (mod_resample_config->fSin < mod_resample_config->fSout) { + obj->type = 'u'; + } + + obj->nChannels = msg_hops_in_config->nChannels; + obj->fSin = mod_resample_config->fSin; + obj->fSout = mod_resample_config->fSout; + obj->hopSizeIn = msg_hops_in_config->hopSize; + obj->hopSizeOut = msg_hops_out_config->hopSize; + obj->ratio = ((float) obj->fSout) / ((float) obj->fSin); + + switch (obj->type) { + + case 'd': + + obj->frameSize = obj->hopSizeIn * 2; + obj->halfFrameSize = obj->frameSize / 2 + 1; + obj->lowPassCut = (unsigned int) floorf(((float) (obj->frameSize/2)) * obj->ratio); + + obj->hop2hop = hop2hop_buffer_construct_zero(obj->nChannels, obj->hopSizeIn, obj->hopSizeOut, obj->ratio); + + obj->hop2frame = hop2frame_construct_zero(obj->hopSizeIn, obj->frameSize, obj->nChannels); + obj->framesAnalysis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2freq = frame2freq_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->freqsAnalysis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, obj-> lowPassCut, 0.0f); + obj->freqsSynthesis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2frame = freq2frame_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->framesSynthesis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2hop = frame2hop_construct_zero(obj->hopSizeIn, obj->frameSize, obj->nChannels); + obj->hops = hops_construct_zero(obj->nChannels, obj->hopSizeIn); + + break; + + case 'u': + + obj->frameSize = obj->hopSizeOut * 2; + obj->halfFrameSize = obj->frameSize / 2 + 1; + obj->lowPassCut = (unsigned int) floorf(((float) (obj->frameSize/2)) / obj->ratio); + + obj->hop2hop = hop2hop_buffer_construct_zero(obj->nChannels, obj->hopSizeIn, obj->hopSizeOut, obj->ratio); + + obj->hop2frame = hop2frame_construct_zero(obj->hopSizeOut, obj->frameSize, obj->nChannels); + obj->framesAnalysis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2freq = frame2freq_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->freqsAnalysis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, obj-> lowPassCut, 0.0f); + obj->freqsSynthesis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2frame = freq2frame_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->framesSynthesis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2hop = frame2hop_construct_zero(obj->hopSizeOut, obj->frameSize, obj->nChannels); + obj->hops = hops_construct_zero(obj->nChannels, obj->hopSizeOut); + + break; + + case 's': + + obj->frameSize = 0; + obj->halfFrameSize = 0; + obj->lowPassCut = 0; + + obj->hop2hop = hop2hop_buffer_construct_zero(obj->nChannels, obj->hopSizeIn, obj->hopSizeOut, obj->ratio); + + obj->hop2frame = (hop2frame_obj *) NULL; + obj->framesAnalysis = (frames_obj *) NULL; + obj->frame2freq = (frame2freq_obj *) NULL; + obj->freqsAnalysis = (freqs_obj *) NULL; + obj->freq2freq = (freq2freq_obj *) NULL; + obj->freqsSynthesis = (freqs_obj *) NULL; + obj->freq2frame = (freq2frame_obj *) NULL; + obj->framesSynthesis = (frames_obj *) NULL; + obj->frame2hop = (frame2hop_obj *) NULL; + obj->hops = (hops_obj *) NULL; + + break; + + } + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void mod_resample_destroy(mod_resample_obj * obj) { + + if (obj->hop2hop != NULL) { + hop2hop_buffer_destroy(obj->hop2hop); + } + + if (obj->hop2frame != NULL) { + hop2frame_destroy(obj->hop2frame); + } + + if (obj->framesAnalysis != NULL) { + frames_destroy(obj->framesAnalysis); + } + + if (obj->frame2freq != NULL) { + frame2freq_destroy(obj->frame2freq); + } + + if (obj->freqsAnalysis != NULL) { + freqs_destroy(obj->freqsAnalysis); + } + + if (obj->freq2freq != NULL) { + freq2freq_destroy(obj->freq2freq); + } + + if (obj->freqsSynthesis != NULL) { + freqs_destroy(obj->freqsSynthesis); + } + + if (obj->freq2frame != NULL) { + freq2frame_destroy(obj->freq2frame); + } + + if (obj->framesSynthesis != NULL) { + frames_destroy(obj->framesSynthesis); + } + + if (obj->frame2hop != NULL) { + frame2hop_destroy(obj->frame2hop); + } + + if (obj->hops != NULL) { + hops_destroy(obj->hops); + } + + free((void *) obj); + + } + + int mod_resample_process(mod_resample_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + switch(obj->type) { + + case 'd': + + rtnValue = mod_resample_process_down(obj); + + break; + + case 'u': + + rtnValue = mod_resample_process_up(obj); + + break; + + case 's': + + rtnValue = mod_resample_process_same(obj); + + break; + + } + + obj->timeStamp++; + obj->out->timeStamp = obj->timeStamp; + + } + else { + + msg_hops_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_resample_process_down(mod_resample_obj * obj) { + + int rtnValue; + char pushDone; + char popDone; + + if (hop2hop_buffer_isFull(obj->hop2hop) == 0) { + + hop2frame_process(obj->hop2frame, + obj->in->hops, + obj->framesAnalysis); + + frame2freq_process(obj->frame2freq, + obj->framesAnalysis, + obj->freqsAnalysis); + + freq2freq_process_lowpass(obj->freq2freq, + obj->freqsAnalysis, + obj->freqsSynthesis); + + freq2frame_process(obj->freq2frame, + obj->freqsSynthesis, + obj->framesSynthesis); + + frame2hop_process(obj->frame2hop, + obj->framesSynthesis, + obj->hops); + + hop2hop_buffer_push(obj->hop2hop, + obj->hops); + + pushDone = 1; + + } + else { + + pushDone = 0; + + } + + if (hop2hop_buffer_isEmpty(obj->hop2hop) == 0) { + + hop2hop_buffer_pop(obj->hop2hop, + obj->out->hops); + + popDone = 1; + + } + else { + + popDone = 0; + + } + + if ((pushDone == 0) && (popDone == 0)) { + rtnValue = 1; + } + if ((pushDone == 0) && (popDone == 1)) { + rtnValue = 2; + } + if ((pushDone == 1) && (popDone == 0)) { + rtnValue = 3; + } + if ((pushDone == 1) && (popDone == 1)) { + rtnValue = 4; + } + + return rtnValue; + + } + + int mod_resample_process_up(mod_resample_obj * obj) { + + int rtnValue; + char pushDone; + char popDone; + + if (hop2hop_buffer_isFull(obj->hop2hop) == 0) { + + hop2hop_buffer_push(obj->hop2hop, + obj->in->hops); + + pushDone = 1; + + } + else { + + pushDone = 0; + + } + + if (hop2hop_buffer_isEmpty(obj->hop2hop) == 0) { + + hop2hop_buffer_pop(obj->hop2hop, + obj->hops); + + hop2frame_process(obj->hop2frame, + obj->hops, + obj->framesAnalysis); + + frame2freq_process(obj->frame2freq, + obj->framesAnalysis, + obj->freqsAnalysis); + + freq2freq_process_lowpass(obj->freq2freq, + obj->freqsAnalysis, + obj->freqsSynthesis); + + freq2frame_process(obj->freq2frame, + obj->freqsSynthesis, + obj->framesSynthesis); + + frame2hop_process(obj->frame2hop, + obj->framesSynthesis, + obj->out->hops); + + popDone = 1; + + } + else { + + popDone = 0; + + } + + if ((pushDone == 0) && (popDone == 0)) { + rtnValue = 1; + } + if ((pushDone == 0) && (popDone == 1)) { + rtnValue = 2; + } + if ((pushDone == 1) && (popDone == 0)) { + rtnValue = 3; + } + if ((pushDone == 1) && (popDone == 1)) { + rtnValue = 4; + } + + return rtnValue; + + } + + int mod_resample_process_same(mod_resample_obj * obj) { + + int rtnValue; + char pushDone; + char popDone; + + if (hop2hop_buffer_isFull(obj->hop2hop) == 0) { + + hop2hop_buffer_push(obj->hop2hop, + obj->in->hops); + + pushDone = 1; + + } + else { + + pushDone = 0; + + } + + if (hop2hop_buffer_isEmpty(obj->hop2hop) == 0) { + + hop2hop_buffer_pop(obj->hop2hop, + obj->out->hops); + + popDone = 1; + + } + else { + + popDone = 0; + + } + + if ((pushDone == 0) && (popDone == 0)) { + rtnValue = 1; + } + if ((pushDone == 0) && (popDone == 1)) { + rtnValue = 2; + } + if ((pushDone == 1) && (popDone == 0)) { + rtnValue = 3; + } + if ((pushDone == 1) && (popDone == 1)) { + rtnValue = 4; + } + + return rtnValue; + + } + + void mod_resample_connect(mod_resample_obj * obj, msg_hops_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_resample_disconnect(mod_resample_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_resample_cfg * mod_resample_cfg_construct(void) { + + mod_resample_cfg * cfg; + + cfg = (mod_resample_cfg *) malloc(sizeof(mod_resample_cfg)); + + cfg->fSin = 0; + cfg->fSout = 0; + + return cfg; + + } + + void mod_resample_cfg_destroy(mod_resample_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_resample_cfg_printf(const mod_resample_cfg * cfg) { + + printf("fSin = %u\n", cfg->fSin); + printf("fSout = %u\n", cfg->fSout); + + } diff --git a/src/module/mod_resample.h b/src/module/mod_resample.h new file mode 100644 index 0000000..65a6322 --- /dev/null +++ b/src/module/mod_resample.h @@ -0,0 +1,85 @@ +#ifndef __ODAS_MODULE_RS +#define __ODAS_MODULE_RS + + #include "../message/msg_hops.h" + + #include "../signal/hop.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + + #include "../system/hop2frame.h" + #include "../system/hop2hop.h" + #include "../system/frame2freq.h" + #include "../system/freq2freq.h" + #include "../system/freq2frame.h" + #include "../system/frame2hop.h" + + #include + #include + #include + + typedef struct mod_resample_obj { + + unsigned long long timeStamp; + + char type; + + unsigned int nChannels; + unsigned int fSin; + unsigned int fSout; + unsigned int hopSizeIn; + unsigned int hopSizeOut; + float ratio; + + unsigned int frameSize; + unsigned int halfFrameSize; + unsigned int lowPassCut; + + hop2hop_buffer_obj * hop2hop; + + hop2frame_obj * hop2frame; + frames_obj * framesAnalysis; + frame2freq_obj * frame2freq; + freqs_obj * freqsAnalysis; + freq2freq_obj * freq2freq; + freqs_obj * freqsSynthesis; + freq2frame_obj * freq2frame; + frames_obj * framesSynthesis; + frame2hop_obj * frame2hop; + hops_obj * hops; + + msg_hops_obj * in; + msg_hops_obj * out; + + } mod_resample_obj; + + typedef struct mod_resample_cfg { + + unsigned int fSin; + unsigned int fSout; + + } mod_resample_cfg; + + mod_resample_obj * mod_resample_construct(const mod_resample_cfg * mod_resample_config, const msg_hops_cfg * msg_hops_in_config, const msg_hops_cfg * msg_hops_out_config); + + void mod_resample_destroy(mod_resample_obj * obj); + + int mod_resample_process(mod_resample_obj * obj); + + int mod_resample_process_down(mod_resample_obj * obj); + + int mod_resample_process_up(mod_resample_obj * obj); + + int mod_resample_process_same(mod_resample_obj * obj); + + void mod_resample_connect(mod_resample_obj * obj, msg_hops_obj * in, msg_hops_obj * out); + + void mod_resample_disconnect(mod_resample_obj * obj); + + mod_resample_cfg * mod_resample_cfg_construct(void); + + void mod_resample_cfg_destroy(mod_resample_cfg * cfg); + + void mod_resample_cfg_printf(const mod_resample_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_ssl.c b/src/module/mod_ssl.c new file mode 100644 index 0000000..fc770e1 --- /dev/null +++ b/src/module/mod_ssl.c @@ -0,0 +1,308 @@ + + #include "mod_ssl.h" + + // +----------------------------------------------------------+ + // | Object - Constructor | + // +----------------------------------------------------------+ + + mod_ssl_obj * mod_ssl_construct(const mod_ssl_cfg * mod_ssl_config, const msg_spectra_cfg * msg_spectra_config, const msg_pots_cfg * msg_pots_config) { + + mod_ssl_obj * obj; + unsigned int iLevel; + unsigned int iPot; + + points_obj * points; + + obj = (mod_ssl_obj *) malloc(sizeof(mod_ssl_obj)); + + obj->nChannels = mod_ssl_config->mics->nChannels; + obj->nPairs = obj->nChannels * (obj->nChannels - 1) / 2; + obj->nPots = msg_pots_config->nPots; + obj->nLevels = mod_ssl_config->nLevels; + obj->frameSize = 2 * (msg_spectra_config->halfFrameSize - 1); + obj->halfFrameSize = msg_spectra_config->halfFrameSize; + + obj->scans = scanning_init_scans(mod_ssl_config->mics, + mod_ssl_config->nLevels, + mod_ssl_config->levels, + mod_ssl_config->samplerate->mu, + mod_ssl_config->soundspeed, + mod_ssl_config->nMatches, + 2 * (msg_spectra_config->halfFrameSize - 1), + mod_ssl_config->deltas, + mod_ssl_config->probMin, + mod_ssl_config->nRefinedLevels, + mod_ssl_config->nThetas, + mod_ssl_config->gainMin); + + obj->freq2freq = freq2freq_construct_zero(msg_spectra_config->halfFrameSize, + 0, + mod_ssl_config->epsilon); + + obj->phasors = freqs_construct_zero(mod_ssl_config->mics->nChannels, + msg_spectra_config->halfFrameSize); + + obj->products = freqs_construct_zero(mod_ssl_config->mics->nPairs, + msg_spectra_config->halfFrameSize); + + obj->freq2xcorr = freq2xcorr_construct_zero(2 * (msg_spectra_config->halfFrameSize - 1), + msg_spectra_config->halfFrameSize); + + obj->xcorrs = xcorrs_construct_zero(mod_ssl_config->mics->nPairs, + 2 * (msg_spectra_config->halfFrameSize - 1)); + + obj->xcorrsMax = xcorrs_construct_zero(mod_ssl_config->mics->nPairs, + 2 * (msg_spectra_config->halfFrameSize - 1)); + + obj->aimgs = (aimg_obj **) malloc(sizeof(aimg_obj *) * msg_pots_config->nPots); + + for (iLevel = 0; iLevel < mod_ssl_config->nLevels; iLevel++) { + + obj->aimgs[iLevel] = aimg_construct_zero(obj->scans->points[iLevel]->nPoints); + + } + + obj->xcorr2xcorr = xcorr2xcorr_construct_zero(2 * (msg_spectra_config->halfFrameSize - 1)); + + obj->xcorr2aimg = (xcorr2aimg_obj **) malloc(sizeof(xcorr2aimg_obj *) * mod_ssl_config->nLevels); + + for (iLevel = 0; iLevel < mod_ssl_config->nLevels; iLevel++) { + + obj->xcorr2aimg[iLevel] = xcorr2aimg_construct_zero(obj->scans->points[iLevel]->nPoints); + + } + + obj->pots = pots_construct_zero(msg_pots_config->nPots); + + return obj; + + } + + void mod_ssl_destroy(mod_ssl_obj * obj) { + + unsigned int iLevel; + unsigned int iPot; + + scans_destroy(obj->scans); + + freq2freq_destroy(obj->freq2freq); + freqs_destroy(obj->phasors); + freqs_destroy(obj->products); + freq2xcorr_destroy(obj->freq2xcorr); + xcorrs_destroy(obj->xcorrs); + xcorrs_destroy(obj->xcorrsMax); + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + aimg_destroy(obj->aimgs[iLevel]); + } + + free((void *) obj->aimgs); + + xcorr2xcorr_destroy(obj->xcorr2xcorr); + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + xcorr2aimg_destroy(obj->xcorr2aimg[iLevel]); + } + + free((void *) obj->xcorr2aimg); + + pots_destroy(obj->pots); + + free((void *) obj); + + } + + int mod_ssl_process(mod_ssl_obj * obj) { + + int rtnValue; + unsigned int iPot; + unsigned int iLevel; + unsigned int iPoint; + + float maxValue; + unsigned int maxIndex; + + if (msg_spectra_isZero(obj->in) == 0) { + + freq2freq_process_phasor(obj->freq2freq, + obj->in->freqs, + obj->phasors); + + freq2freq_process_product(obj->freq2freq, + obj->phasors, + obj->phasors, + obj->scans->pairs, + obj->products); + + freq2xcorr_process(obj->freq2xcorr, + obj->products, + obj->scans->pairs, + obj->xcorrs); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + if (iPot > 0) { + + xcorr2xcorr_process_reset(obj->xcorr2xcorr, + obj->scans->tdoas[obj->nLevels-1], + obj->scans->deltas[obj->nLevels-1], + obj->scans->pairs, + maxIndex, + obj->xcorrs); + + } + + maxIndex = 0; + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + + xcorr2xcorr_process_max(obj->xcorr2xcorr, + obj->xcorrs, + obj->scans->tdoas[iLevel], + obj->scans->deltas[iLevel], + obj->scans->pairs, + obj->xcorrsMax); + + xcorr2aimg_process(obj->xcorr2aimg[iLevel], + obj->scans->tdoas[iLevel], + obj->scans->indexes[iLevel], + obj->scans->spatialindexes[iLevel], + maxIndex, + obj->xcorrsMax, + obj->aimgs[iLevel]); + + maxValue = obj->aimgs[iLevel]->array[0]; + + for (iPoint = 0; iPoint < obj->aimgs[iLevel]->aimgSize; iPoint++) { + + if (obj->aimgs[iLevel]->array[iPoint] > maxValue) { + + maxValue = obj->aimgs[iLevel]->array[iPoint]; + maxIndex = iPoint; + + } + + } + + } + + obj->pots->array[iPot * 4 + 0] = obj->scans->points[obj->nLevels-1]->array[maxIndex * 3 + 0]; + obj->pots->array[iPot * 4 + 1] = obj->scans->points[obj->nLevels-1]->array[maxIndex * 3 + 1]; + obj->pots->array[iPot * 4 + 2] = obj->scans->points[obj->nLevels-1]->array[maxIndex * 3 + 2]; + obj->pots->array[iPot * 4 + 3] = maxValue; + + } + + memcpy(obj->out->pots->array, obj->pots->array, sizeof(float) * obj->pots->nPots * 4); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_pots_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_ssl_connect(mod_ssl_obj * obj, msg_spectra_obj * in, msg_pots_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_ssl_disconnect(mod_ssl_obj * obj) { + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_pots_obj *) NULL; + + } + + mod_ssl_cfg * mod_ssl_cfg_construct(void) { + + mod_ssl_cfg * cfg; + + cfg = (mod_ssl_cfg *) malloc(sizeof(mod_ssl_cfg)); + + cfg->mics = (mics_obj *) NULL; + cfg->samplerate = (samplerate_obj *) NULL; + cfg->soundspeed = (soundspeed_obj *) NULL; + + cfg->nLevels = 0;; + cfg->levels = (unsigned int *) NULL; + cfg->deltas = (unsigned int *) NULL; + cfg->nMatches = 0; + cfg->probMin = 0.0f; + cfg->nRefinedLevels = 0; + cfg->nThetas = 0; + cfg->gainMin = 0.0f; + + return cfg; + + } + + void mod_ssl_cfg_destroy(mod_ssl_cfg * cfg) { + + if (cfg->mics != NULL) { + mics_destroy(cfg->mics); + } + + if (cfg->samplerate != NULL) { + samplerate_destroy(cfg->samplerate); + } + + if (cfg->soundspeed != NULL) { + soundspeed_destroy(cfg->soundspeed); + } + + if (cfg->levels != NULL) { + free((void *) cfg->levels); + } + + if (cfg->deltas != NULL) { + free((void *) cfg->deltas); + } + + free((void *) cfg); + + } + + void mod_ssl_cfg_printf(const mod_ssl_cfg * cfg) { + + unsigned int iLevel; + + mics_printf(cfg->mics); + samplerate_printf(cfg->samplerate); + soundspeed_printf(cfg->soundspeed); + + for (iLevel = 0; iLevel < cfg->nLevels; iLevel++) { + + if (iLevel == 0) { + + printf("levels = (%u): level = %u, delta = %d\n", iLevel, cfg->levels[iLevel], cfg->deltas[iLevel]); + + } + else { + + printf(" (%u): level = %u, delta = %d\n", iLevel, cfg->levels[iLevel], cfg->deltas[iLevel]); + + } + + + } + + printf("nMatches = %u\n", cfg->nMatches); + printf("probMin = %f\n", cfg->probMin); + printf("nRefinedLevels = %u\n", cfg->nRefinedLevels); + printf("nThetas = %u\n", cfg->nThetas); + printf("gainMin = %f\n", cfg->gainMin); + + } \ No newline at end of file diff --git a/src/module/mod_ssl.h b/src/module/mod_ssl.h new file mode 100644 index 0000000..53f5697 --- /dev/null +++ b/src/module/mod_ssl.h @@ -0,0 +1,90 @@ +#ifndef __ODAS_MODULE_SSL +#define __ODAS_MODULE_SSL + + #include + #include + + #include "../general/mic.h" + #include "../general/samplerate.h" + #include "../general/soundspeed.h" + + #include "../signal/aimg.h" + #include "../signal/freq.h" + #include "../signal/xcorr.h" + + #include "../system/freq2freq.h" + #include "../system/freq2xcorr.h" + #include "../system/xcorr2aimg.h" + #include "../system/xcorr2xcorr.h" + + #include "../init/scanning.h" + + #include "../message/msg_spectra.h" + #include "../message/msg_pots.h" + + + typedef struct mod_ssl_obj { + + unsigned int nChannels; + unsigned int nPairs; + unsigned int nPots; + unsigned int nLevels; + unsigned int frameSize; + unsigned int halfFrameSize; + + scans_obj * scans; + + freqs_obj * phasors; + freqs_obj * products; + xcorrs_obj * xcorrs; + xcorrs_obj * xcorrsMax; + + freq2freq_obj * freq2freq; + freq2xcorr_obj * freq2xcorr; + xcorr2xcorr_obj * xcorr2xcorr; + + aimg_obj ** aimgs; + xcorr2aimg_obj ** xcorr2aimg; + + pots_obj * pots; + + msg_spectra_obj * in; + msg_pots_obj * out; + + } mod_ssl_obj; + + typedef struct mod_ssl_cfg { + + mics_obj * mics; + samplerate_obj * samplerate; + soundspeed_obj * soundspeed; + + float epsilon; + unsigned int nLevels; + unsigned int * levels; + signed int * deltas; + unsigned int nMatches; + float probMin; + unsigned int nRefinedLevels; + unsigned int nThetas; + float gainMin; + + } mod_ssl_cfg; + + mod_ssl_obj * mod_ssl_construct(const mod_ssl_cfg * mod_ssl_config, const msg_spectra_cfg * msg_spectra_config, const msg_pots_cfg * msg_pots_config); + + void mod_ssl_destroy(mod_ssl_obj * obj); + + int mod_ssl_process(mod_ssl_obj * obj); + + void mod_ssl_connect(mod_ssl_obj * obj, msg_spectra_obj * in, msg_pots_obj * out); + + void mod_ssl_disconnect(mod_ssl_obj * obj); + + mod_ssl_cfg * mod_ssl_cfg_construct(void); + + void mod_ssl_cfg_destroy(mod_ssl_cfg * cfg); + + void mod_ssl_cfg_printf(const mod_ssl_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_sspf.c b/src/module/mod_sspf.c new file mode 100644 index 0000000..82b3fb2 --- /dev/null +++ b/src/module/mod_sspf.c @@ -0,0 +1,145 @@ + + #include "mod_sspf.h" + + mod_sspf_obj * mod_sspf_construct(const mod_sspf_cfg * mod_sspf_config, const msg_spectra_cfg * msg_spectra_config, const msg_tracks_cfg * msg_tracks_config) { + + mod_sspf_obj * obj; + + obj = (mod_sspf_obj *) malloc(sizeof(mod_sspf_obj)); + + obj->nChannels = mod_sspf_config->mics->nChannels; + obj->nSeps = msg_tracks_config->nTracks; + + obj->beampatterns = directivity_beampattern(mod_sspf_config->mics, mod_sspf_config->nThetas); + + obj->track2gain = track2gain_construct_zero(obj->nSeps, + obj->nChannels, + mod_sspf_config->mics->direction); + + obj->gains = gains_construct_zero(obj->nSeps, + obj->nChannels); + + obj->gain2mask = gain2mask_construct_zero(obj->nSeps, + obj->nChannels, + mod_sspf_config->gainMin); + + obj->masks = masks_construct_zero(obj->nSeps, + obj->nChannels); + + obj->freq2freq = freq2freq_construct_zero(msg_spectra_config->halfFrameSize, + 0, + 0.0f); + + obj->in1 = (msg_spectra_obj *) NULL; + obj->in2 = (msg_spectra_obj *) NULL; + obj->in3 = (msg_tracks_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + return obj; + + } + + void mod_sspf_destroy(mod_sspf_obj * obj) { + + beampatterns_destroy(obj->beampatterns); + + track2gain_destroy(obj->track2gain); + gains_destroy(obj->gains); + gain2mask_destroy(obj->gain2mask); + masks_destroy(obj->masks); + freq2freq_destroy(obj->freq2freq); + + free((void *) obj); + + } + + int mod_sspf_process(mod_sspf_obj * obj) { + + int rtnValue; + + if ((msg_spectra_isZero(obj->in1) == 0) && (msg_spectra_isZero(obj->in2) == 0) && (msg_tracks_isZero(obj->in3) == 0)) { + + if ((obj->in1->timeStamp != obj->in2->timeStamp) || (obj->in1->timeStamp != obj->in3->timeStamp)) { + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + } + + track2gain_process(obj->track2gain, + obj->beampatterns, + obj->in3->tracks, + obj->gains); + + gain2mask_process(obj->gain2mask, + obj->gains, + obj->masks); + + freq2freq_process_postfilter(obj->freq2freq, + obj->in1->freqs, + obj->in2->freqs, + obj->gains, + obj->masks, + obj->out->freqs); + + obj->out->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_sspf_connect(mod_sspf_obj * obj, msg_spectra_obj * in1, msg_spectra_obj * in2, msg_tracks_obj * in3, msg_spectra_obj * out) { + + obj->in1 = in1; + obj->in2 = in2; + obj->in3 = in3; + obj->out = out; + + } + + void mod_sspf_disconnect(mod_sspf_obj * obj) { + + obj->in1 = (msg_spectra_obj *) NULL; + obj->in2 = (msg_spectra_obj *) NULL; + obj->in3 = (msg_tracks_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + } + + mod_sspf_cfg * mod_sspf_cfg_construct(void) { + + mod_sspf_cfg * cfg; + + cfg = (mod_sspf_cfg *) malloc(sizeof(mod_sspf_cfg)); + + cfg->mics = (mics_obj *) NULL; + + cfg->nThetas = 0; + cfg->gainMin = 0.0f; + + return cfg; + + } + + void mod_sspf_cfg_destroy(mod_sspf_cfg * cfg) { + + if (cfg->mics != NULL) { + mics_destroy(cfg->mics); + } + + free((void *) cfg); + + } + + void mod_sspf_cfg_printf(const mod_sspf_cfg * cfg) { + + } diff --git a/src/module/mod_sspf.h b/src/module/mod_sspf.h new file mode 100644 index 0000000..467c333 --- /dev/null +++ b/src/module/mod_sspf.h @@ -0,0 +1,69 @@ +#ifndef __ODAS_MODULE_SSPF +#define __ODAS_MODULE_SSPF + + #include "../signal/beampattern.h" + #include "../signal/freq.h" + #include "../signal/gain.h" + #include "../signal/mask.h" + + #include "../system/gain2mask.h" + #include "../system/track2gain.h" + #include "../system/freq2freq.h" + + #include "../general/mic.h" + #include "../general/samplerate.h" + #include "../general/soundspeed.h" + + #include "../init/directivity.h" + + #include "../message/msg_spectra.h" + #include "../message/msg_tracks.h" + + #include + + typedef struct mod_sspf_obj { + + unsigned int nChannels; + unsigned int nSeps; + + beampatterns_obj * beampatterns; + + track2gain_obj * track2gain; + gains_obj * gains; + gain2mask_obj * gain2mask; + masks_obj * masks; + freq2freq_obj * freq2freq; + + msg_spectra_obj * in1; + msg_spectra_obj * in2; + msg_tracks_obj * in3; + msg_spectra_obj * out; + + } mod_sspf_obj; + + typedef struct mod_sspf_cfg { + + mics_obj * mics; + + unsigned int nThetas; + float gainMin; + + } mod_sspf_cfg; + + mod_sspf_obj * mod_sspf_construct(const mod_sspf_cfg * mod_sspf_config, const msg_spectra_cfg * msg_spectra_config, const msg_tracks_cfg * msg_tracks_config); + + void mod_sspf_destroy(mod_sspf_obj * obj); + + int mod_sspf_process(mod_sspf_obj * obj); + + void mod_sspf_connect(mod_sspf_obj * obj, msg_spectra_obj * in1, msg_spectra_obj * in2, msg_tracks_obj * in3, msg_spectra_obj * out); + + void mod_sspf_disconnect(mod_sspf_obj * obj); + + mod_sspf_cfg * mod_sspf_cfg_construct(void); + + void mod_sspf_cfg_destroy(mod_sspf_cfg * cfg); + + void mod_sspf_cfg_printf(const mod_sspf_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_sss.c b/src/module/mod_sss.c new file mode 100644 index 0000000..d51ec37 --- /dev/null +++ b/src/module/mod_sss.c @@ -0,0 +1,169 @@ + + #include "mod_sss.h" + + mod_sss_obj * mod_sss_construct(const mod_sss_cfg * mod_sss_config, const msg_spectra_cfg * msg_spectra_config, const msg_tracks_cfg * msg_tracks_config) { + + mod_sss_obj * obj; + + obj = (mod_sss_obj *) malloc(sizeof(mod_sss_obj)); + + obj->nChannels = mod_sss_config->mics->nChannels; + obj->nSeps = msg_tracks_config->nTracks; + + obj->beampatterns = directivity_beampattern(mod_sss_config->mics, mod_sss_config->nThetas); + + obj->track2shift = track2shift_construct_zero(obj->nSeps, + obj->nChannels, + mod_sss_config->samplerate->mu, + mod_sss_config->soundspeed->mu, + mod_sss_config->mics->mu); + + obj->shifts = shifts_construct_zero(obj->nSeps, + obj->nChannels); + + obj->track2gain = track2gain_construct_zero(obj->nSeps, + obj->nChannels, + mod_sss_config->mics->direction); + + obj->gains = gains_construct_zero(obj->nSeps, + obj->nChannels); + + obj->gain2mask = gain2mask_construct_zero(obj->nSeps, + obj->nChannels, + mod_sss_config->gainMin); + + obj->masks = masks_construct_zero(obj->nSeps, + obj->nChannels); + + obj->freq2freq = freq2freq_construct_zero(msg_spectra_config->halfFrameSize, + 0, + mod_sss_config->epsilon); + + obj->in1 = (msg_spectra_obj *) NULL; + obj->in2 = (msg_tracks_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + return obj; + + } + + void mod_sss_destroy(mod_sss_obj * obj) { + + beampatterns_destroy(obj->beampatterns); + + track2shift_destroy(obj->track2shift); + shifts_destroy(obj->shifts); + track2gain_destroy(obj->track2gain); + gains_destroy(obj->gains); + gain2mask_destroy(obj->gain2mask); + masks_destroy(obj->masks); + freq2freq_destroy(obj->freq2freq); + + free((void *) obj); + + } + + int mod_sss_process(mod_sss_obj * obj) { + + int rtnValue; + + if ((msg_spectra_isZero(obj->in1) == 0) && (msg_tracks_isZero(obj->in2) == 0)) { + + if (obj->in1->timeStamp != obj->in2->timeStamp) { + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + } + + track2shift_process(obj->track2shift, + obj->in2->tracks, + obj->shifts); + + track2gain_process(obj->track2gain, + obj->beampatterns, + obj->in2->tracks, + obj->gains); + + gain2mask_process(obj->gain2mask, + obj->gains, + obj->masks); + + freq2freq_process_delaysum(obj->freq2freq, + obj->in1->freqs, + obj->shifts, + obj->gains, + obj->masks, + obj->out->freqs); + + obj->out->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_sss_connect(mod_sss_obj * obj, msg_spectra_obj * in1, msg_tracks_obj * in2, msg_spectra_obj * out) { + + obj->in1 = in1; + obj->in2 = in2; + obj->out = out; + + } + + void mod_sss_disconnect(mod_sss_obj * obj) { + + obj->in1 = (msg_spectra_obj *) NULL; + obj->in2 = (msg_tracks_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + } + + mod_sss_cfg * mod_sss_cfg_construct(void) { + + mod_sss_cfg * cfg; + + cfg = (mod_sss_cfg *) malloc(sizeof(mod_sss_cfg)); + + cfg->mics = (mics_obj *) NULL; + cfg->samplerate = (samplerate_obj *) NULL; + cfg->soundspeed = (soundspeed_obj *) NULL; + + cfg->epsilon = 0.0f; + + cfg->nThetas = 0; + cfg->gainMin = 0.0f; + + return cfg; + + } + + void mod_sss_cfg_destroy(mod_sss_cfg * cfg) { + + if (cfg->mics != NULL) { + mics_destroy(cfg->mics); + } + + if (cfg->samplerate != NULL) { + samplerate_destroy(cfg->samplerate); + } + + if (cfg->soundspeed != NULL) { + soundspeed_destroy(cfg->soundspeed); + } + + free((void *) cfg); + + } + + void mod_sss_cfg_printf(const mod_sss_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_sss.h b/src/module/mod_sss.h new file mode 100644 index 0000000..646766a --- /dev/null +++ b/src/module/mod_sss.h @@ -0,0 +1,76 @@ +#ifndef __ODAS_MODULE_SSS +#define __ODAS_MODULE_SSS + + #include "../signal/beampattern.h" + #include "../signal/freq.h" + #include "../signal/gain.h" + #include "../signal/mask.h" + #include "../signal/shift.h" + + #include "../system/gain2mask.h" + #include "../system/track2gain.h" + #include "../system/track2shift.h" + #include "../system/freq2freq.h" + + #include "../general/mic.h" + #include "../general/samplerate.h" + #include "../general/soundspeed.h" + + #include "../init/directivity.h" + + #include "../message/msg_spectra.h" + #include "../message/msg_tracks.h" + + #include + + typedef struct mod_sss_obj { + + unsigned int nChannels; + unsigned int nSeps; + + beampatterns_obj * beampatterns; + + track2shift_obj * track2shift; + shifts_obj * shifts; + track2gain_obj * track2gain; + gains_obj * gains; + gain2mask_obj * gain2mask; + masks_obj * masks; + freq2freq_obj * freq2freq; + + msg_spectra_obj * in1; + msg_tracks_obj * in2; + msg_spectra_obj * out; + + } mod_sss_obj; + + typedef struct mod_sss_cfg { + + mics_obj * mics; + samplerate_obj * samplerate; + soundspeed_obj * soundspeed; + + float epsilon; + + unsigned int nThetas; + float gainMin; + + } mod_sss_cfg; + + mod_sss_obj * mod_sss_construct(const mod_sss_cfg * mod_sss_config, const msg_spectra_cfg * msg_spectra_config, const msg_tracks_cfg * msg_tracks_config); + + void mod_sss_destroy(mod_sss_obj * obj); + + int mod_sss_process(mod_sss_obj * obj); + + void mod_sss_connect(mod_sss_obj * obj, msg_spectra_obj * in1, msg_tracks_obj * in2, msg_spectra_obj * out); + + void mod_sss_disconnect(mod_sss_obj * obj); + + mod_sss_cfg * mod_sss_cfg_construct(void); + + void mod_sss_cfg_destroy(mod_sss_cfg * cfg); + + void mod_sss_cfg_printf(const mod_sss_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_sst.c b/src/module/mod_sst.c new file mode 100644 index 0000000..6f479ab --- /dev/null +++ b/src/module/mod_sst.c @@ -0,0 +1,988 @@ + + #include "mod_sst.h" + + mod_sst_obj * mod_sst_construct(const mod_sst_cfg * mod_sst_config, const mod_ssl_cfg * mod_ssl_config, const msg_pots_cfg * msg_pots_config, const msg_tracks_cfg * msg_tracks_config) { + + mod_sst_obj * obj; + + unsigned int iTrackMax; + points_obj * points; + beampatterns_obj * beampatterns; + spatialgains_obj * spatialgains; + spatialmasks_obj * spatialmasks; + spatialindexes_obj * spatialindexes; + unsigned int iPoint; + unsigned int nPointsActive; + float diffuse_cst; + float deltaT; + + obj = (mod_sst_obj *) malloc(sizeof(mod_sst_obj)); + + obj->nPots = msg_pots_config->nPots; + obj->nTracksMax = msg_tracks_config->nTracks; + obj->nTracks = 0; + + obj->mode = mod_sst_config->mode; + + obj->mixtures = (mixture_obj **) malloc(sizeof(mixture_obj *) * (obj->nTracksMax+1)); + obj->coherences = (coherences_obj **) malloc(sizeof(coherences_obj *) * (obj->nTracksMax+1)); + obj->postprobs = (postprobs_obj **) malloc(sizeof(postprobs_obj *) * (obj->nTracksMax+1)); + + for (iTrackMax = 0; iTrackMax <= obj->nTracksMax; iTrackMax++) { + + obj->mixtures[iTrackMax] = mixture_construct_zero(obj->nPots, iTrackMax); + obj->coherences[iTrackMax] = coherences_construct_zero(obj->nPots, iTrackMax); + obj->postprobs[iTrackMax] = postprobs_construct_zero(obj->nPots, iTrackMax); + + } + + obj->ids = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracksMax); + obj->idsAdded = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracksMax); + obj->idsRemoved = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracksMax); + + obj->type = (char *) malloc(sizeof(char) * obj->nTracksMax); + + obj->kalmans = (kalman_obj **) malloc(sizeof(kalman_obj *) * obj->nTracksMax); + memset(obj->kalmans, 0x00, sizeof(kalman_obj *) * obj->nTracksMax); + obj->particles = (particles_obj **) malloc(sizeof(particles_obj *) * obj->nTracksMax); + memset(obj->particles, 0x00, sizeof(particles_obj *) * obj->nTracksMax); + + obj->theta_new = mod_sst_config->theta_new; + obj->N_prob = mod_sst_config->N_prob; + obj->theta_prob = mod_sst_config->theta_prob; + obj->N_inactive = (unsigned int *) malloc(sizeof(unsigned int) * obj->nTracksMax); + + obj->theta_inactive = mod_sst_config->theta_inactive; + + obj->n_prob = (unsigned int *) malloc(sizeof(unsigned int) * obj->nTracksMax); + obj->mean_prob = (float *) malloc(sizeof(float) * obj->nTracksMax); + obj->n_inactive = (unsigned int *) malloc(sizeof(unsigned int) * obj->nTracksMax); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->ids[iTrackMax] = 0; + obj->idsAdded[iTrackMax] = 0; + obj->idsRemoved[iTrackMax] = 0; + + obj->type[iTrackMax] = 'I'; + + switch(obj->mode) { + + case 'k': + + obj->kalmans[iTrackMax] = kalman_construct_zero(); + + break; + + case 'p': + + obj->particles[iTrackMax] = particles_construct_zero(mod_sst_config->nParticles); + + break; + + default: + + printf("Invalid type of filter\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->N_inactive[iTrackMax] = mod_sst_config->N_inactive[iTrackMax]; + + obj->n_prob[iTrackMax] = 0; + obj->mean_prob[iTrackMax] = 0.0f; + obj->n_inactive[iTrackMax] = 0; + + } + + points = space_sphere(mod_ssl_config->levels[mod_ssl_config->nLevels-1]); + beampatterns = directivity_beampattern(mod_ssl_config->mics, mod_ssl_config->nThetas); + spatialgains = directivity_spatialgains(mod_ssl_config->mics, beampatterns, points); + spatialmasks = directivity_spatialmasks(spatialgains, mod_ssl_config->gainMin); + spatialindexes = directivity_spatialindexes(spatialmasks); + + nPointsActive = 0; + + for (iPoint = 0; iPoint < spatialindexes->nPoints; iPoint++) { + + if (spatialindexes->count[iPoint] > 0) { + nPointsActive++; + } + + } + + diffuse_cst = 1.0f / (4.0f * M_PI * ((float) nPointsActive) / ((float) spatialindexes->nPoints)); + + points_destroy(points); + beampatterns_destroy(beampatterns); + spatialgains_destroy(spatialgains); + spatialmasks_destroy(spatialmasks); + spatialindexes_destroy(spatialindexes); + + deltaT = ((float) mod_sst_config->hopSize) / ((float) msg_pots_config->fS); + + switch(obj->mode) { + + case 'k': + + obj->kalman2kalman_prob = kalman2kalman_construct(deltaT, + mod_sst_config->sigmaQ, + mod_sst_config->sigmaR_prob, + mod_sst_config->epsilon); + + obj->kalman2kalman_active = kalman2kalman_construct(deltaT, + mod_sst_config->sigmaQ, + mod_sst_config->sigmaR_active, + mod_sst_config->epsilon); + + obj->kalman2coherence_prob = kalman2coherence_construct(mod_sst_config->epsilon, + mod_sst_config->sigmaR_prob); + + obj->kalman2coherence_active = kalman2coherence_construct(mod_sst_config->epsilon, + mod_sst_config->sigmaR_active); + + obj->particle2particle_prob = NULL; + obj->particle2particle_active = NULL; + obj->particle2coherence_prob = NULL; + obj->particle2coherence_active = NULL; + + break; + + case 'p': + + obj->kalman2kalman_prob = NULL; + obj->kalman2kalman_active = NULL; + obj->kalman2coherence_prob = NULL; + obj->kalman2coherence_active = NULL; + + obj->particle2particle_prob = particle2particle_construct(mod_sst_config->nParticles, + deltaT, + mod_sst_config->st_alpha, + mod_sst_config->st_beta, + mod_sst_config->st_ratio, + mod_sst_config->ve_alpha, + mod_sst_config->ve_beta, + mod_sst_config->ve_ratio, + mod_sst_config->ac_alpha, + mod_sst_config->ac_beta, + mod_sst_config->ac_ratio, + (double) mod_sst_config->epsilon, + mod_sst_config->sigmaR_prob, + mod_sst_config->Nmin); + + obj->particle2particle_active = particle2particle_construct(mod_sst_config->nParticles, + deltaT, + mod_sst_config->st_alpha, + mod_sst_config->st_beta, + mod_sst_config->st_ratio, + mod_sst_config->ve_alpha, + mod_sst_config->ve_beta, + mod_sst_config->ve_ratio, + mod_sst_config->ac_alpha, + mod_sst_config->ac_beta, + mod_sst_config->ac_ratio, + (double) mod_sst_config->epsilon, + mod_sst_config->sigmaR_active, + mod_sst_config->Nmin); + + obj->particle2coherence_prob = particle2coherence_construct(mod_sst_config->sigmaR_prob); + + obj->particle2coherence_active = particle2coherence_construct(mod_sst_config->sigmaR_active); + + break; + + default: + + break; + + } + + obj->mixture2mixture = mixture2mixture_construct(mod_sst_config->active_gmm, + mod_sst_config->inactive_gmm, + diffuse_cst, + mod_sst_config->Pfalse, + mod_sst_config->Pnew, + mod_sst_config->Ptrack, + mod_sst_config->epsilon); + + obj->id = 0; + + return obj; + + } + + void mod_sst_destroy(mod_sst_obj * obj) { + + unsigned int iTrackMax; + + for (iTrackMax = 0; iTrackMax <= obj->nTracksMax; iTrackMax++) { + + mixture_destroy(obj->mixtures[iTrackMax]); + coherences_destroy(obj->coherences[iTrackMax]); + postprobs_destroy(obj->postprobs[iTrackMax]); + + } + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->kalmans[iTrackMax] != NULL) { + + kalman_destroy(obj->kalmans[iTrackMax]); + + } + + if (obj->particles[iTrackMax] != NULL) { + + particles_destroy(obj->particles[iTrackMax]); + + } + + } + + free((void *) obj->mixtures); + free((void *) obj->coherences); + free((void *) obj->postprobs); + + free((void *) obj->ids); + free((void *) obj->idsAdded); + free((void *) obj->idsRemoved); + free((void *) obj->type); + + free((void *) obj->kalmans); + free((void *) obj->particles); + + free((void *) obj->N_inactive); + free((void *) obj->n_prob); + free((void *) obj->mean_prob); + free((void *) obj->n_inactive); + + if (obj->kalman2kalman_prob != NULL) { + kalman2kalman_destroy(obj->kalman2kalman_prob); + } + if (obj->kalman2kalman_active != NULL) { + kalman2kalman_destroy(obj->kalman2kalman_active); + } + if (obj->kalman2coherence_prob != NULL) { + kalman2coherence_destroy(obj->kalman2coherence_prob); + } + if (obj->kalman2coherence_active != NULL) { + kalman2coherence_destroy(obj->kalman2coherence_active); + } + if (obj->particle2particle_prob != NULL) { + particle2particle_destroy(obj->particle2particle_prob); + } + if (obj->particle2particle_active != NULL) { + particle2particle_destroy(obj->particle2particle_active); + } + if (obj->particle2coherence_prob != NULL) { + particle2coherence_destroy(obj->particle2coherence_prob); + } + if (obj->particle2coherence_active != NULL) { + particle2coherence_destroy(obj->particle2coherence_active); + } + + mixture2mixture_destroy(obj->mixture2mixture); + + free((void *) obj); + + } + + int mod_sst_process(mod_sst_obj * obj) { + + unsigned int iPot; + unsigned int iTrackMax; + unsigned int iTrack; + float x,y,z; + float sourceActivity; + int rtnValue; + + if (msg_pots_isZero(obj->in) == 0) { + + // Count + + obj->nTracks = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + obj->nTracks++; + + } + + } + + // Predict + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + switch(obj->mode) { + + case 'k': + + switch (obj->type[iTrackMax]) { + + case 'P': + + kalman2kalman_predict(obj->kalman2kalman_prob, + obj->kalmans[iTrackMax]); + + break; + + case 'A': + + kalman2kalman_predict(obj->kalman2kalman_active, + obj->kalmans[iTrackMax]); + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + case 'p': + + switch (obj->type[iTrackMax]) { + + case 'P': + + particle2particle_predict(obj->particle2particle_prob, + obj->particles[iTrackMax]); + + break; + + case 'A': + + particle2particle_predict(obj->particle2particle_active, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + } + + // Coherence + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + switch(obj->mode) { + + case 'k': + + switch (obj->type[iTrackMax]) { + + case 'P': + + kalman2coherence_process(obj->kalman2coherence_prob, + obj->kalmans[iTrackMax], + obj->in->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + case 'A': + + kalman2coherence_process(obj->kalman2coherence_active, + obj->kalmans[iTrackMax], + obj->in->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + case 'p': + + switch (obj->type[iTrackMax]) { + + case 'P': + + particle2coherence_process(obj->particle2coherence_prob, + obj->particles[iTrackMax], + obj->in->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + case 'A': + + particle2coherence_process(obj->particle2coherence_active, + obj->particles[iTrackMax], + obj->in->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + iTrack++; + + } + + } + + // Mixture + + mixture2mixture_process(obj->mixture2mixture, + obj->mixtures[obj->nTracks], + obj->in->pots, + obj->coherences[obj->nTracks], + obj->postprobs[obj->nTracks]); + + // Update + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + switch(obj->mode) { + + case 'k': + + switch (obj->type[iTrackMax]) { + + case 'P': + + kalman2kalman_update(obj->kalman2kalman_prob, + obj->postprobs[obj->nTracks], + iTrack, + obj->in->pots, + obj->kalmans[iTrackMax]); + + break; + + case 'A': + + kalman2kalman_update(obj->kalman2kalman_active, + obj->postprobs[obj->nTracks], + iTrack, + obj->in->pots, + obj->kalmans[iTrackMax]); + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + case 'p': + + switch (obj->type[iTrackMax]) { + + case 'P': + + particle2particle_update(obj->particle2particle_prob, + obj->postprobs[obj->nTracks], + iTrack, + obj->in->pots, + obj->particles[iTrackMax]); + + break; + + case 'A': + + particle2particle_update(obj->particle2particle_active, + obj->postprobs[obj->nTracks], + iTrack, + obj->in->pots, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + iTrack++; + + } + + } + + // Activity + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + sourceActivity = obj->postprobs[obj->nTracks]->arrayTrackTotal[iTrack]; + + // Update counters + + switch (obj->type[iTrackMax]) { + + case 'P': + + obj->n_prob[iTrackMax]++; + obj->mean_prob[iTrackMax] += sourceActivity; + + break; + + case 'A': + + if (sourceActivity >= obj->theta_inactive) { + obj->n_inactive[iTrackMax] = 0; + } + else { + obj->n_inactive[iTrackMax]++; + } + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + iTrack++; + + } + + } + + // Transitions + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + if ((obj->type[iTrackMax] == 'P') && + (obj->n_prob[iTrackMax] == obj->N_prob) && + (obj->mean_prob[iTrackMax]/((float) obj->N_prob) >= obj->theta_prob)) { + + obj->type[iTrackMax] = 'A'; + obj->n_inactive[iTrackMax] = 0; + + } + + iTrack++; + + } + + } + + // Add source + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->idsAdded[iTrackMax] = 0; + + } + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + if (obj->postprobs[obj->nTracks]->arrayNew[iPot] > obj->theta_new) { + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] == 0) { + + obj->id++; + obj->idsAdded[iTrackMax] = obj->id; + + switch(obj->mode) { + + case 'k': + + kalman2kalman_init(obj->kalman2kalman_prob, + obj->in->pots, + iPot, + obj->kalmans[iTrackMax]); + + break; + + case 'p': + + particle2particle_init(obj->particle2particle_prob, + obj->in->pots, + iPot, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->type[iTrackMax] = 'P'; + obj->n_prob[iTrackMax] = 0; + obj->mean_prob[iTrackMax] = 0.0f; + + break; + + } + + } + + } + + } + + // Remove source + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->idsRemoved[iTrackMax] = 0; + + } + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + if ((obj->type[iTrackMax] == 'P') && + (obj->n_prob[iTrackMax] == obj->N_prob) && + (obj->mean_prob[iTrackMax]/((float) obj->N_prob) < obj->theta_prob)) { + + obj->idsRemoved[iTrackMax] = obj->ids[iTrackMax]; + + } + + if ((obj->type[iTrackMax] == 'A') && + (obj->n_inactive[iTrackMax] >= obj->N_inactive[obj->nTracks-1])) { + + obj->idsRemoved[iTrackMax] = obj->ids[iTrackMax]; + + } + + iTrack++; + + } + + } + + // Update IDs + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->idsAdded[iTrackMax] != 0) { + + obj->ids[iTrackMax] = obj->idsAdded[iTrackMax]; + + } + + if (obj->idsRemoved[iTrackMax] != 0) { + + obj->ids[iTrackMax] = 0; + + } + + } + + // Count + + obj->nTracks = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + obj->nTracks++; + + } + + } + + + // Copy in tracking + + memset(obj->out->tracks->array, 0x00, sizeof(float) * obj->out->tracks->nTracks * 3); + memset(obj->out->tracks->ids, 0x00, sizeof(unsigned long long) * obj->out->tracks->nTracks); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + if (obj->type[iTrackMax] == 'A') { + + switch(obj->mode) { + + case 'k': + + kalman2kalman_estimate(obj->kalman2kalman_active, + obj->kalmans[iTrackMax], + &x, + &y, + &z); + + break; + + case 'p': + + particle2particle_estimate(obj->particle2particle_active, + obj->particles[iTrackMax], + &x, + &y, + &z); + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->out->tracks->array[iTrackMax * 3 + 0] = x; + obj->out->tracks->array[iTrackMax * 3 + 1] = y; + obj->out->tracks->array[iTrackMax * 3 + 2] = z; + obj->out->tracks->ids[iTrackMax] = obj->ids[iTrackMax]; + + } + + } + + } + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_tracks_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_sst_connect(mod_sst_obj * obj, msg_pots_obj * in, msg_tracks_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_sst_disconnect(mod_sst_obj * obj) { + + obj->in = (msg_pots_obj *) NULL; + obj->out = (msg_tracks_obj *) NULL; + + } + + mod_sst_cfg * mod_sst_cfg_construct(void) { + + mod_sst_cfg * cfg; + + cfg = (mod_sst_cfg *) malloc(sizeof(mod_sst_cfg)); + + cfg->mode = 0x00; + + cfg->hopSize = 0; + cfg->sigmaQ = 0.0f; + + cfg->nParticles = 0; + cfg->st_alpha = 0.0f; + cfg->st_beta = 0.0f; + cfg->st_ratio = 0.0f; + cfg->ve_alpha = 0.0f; + cfg->ve_beta = 0.0f; + cfg->ve_ratio = 0.0f; + cfg->ac_alpha = 0.0f; + cfg->ac_beta = 0.0f; + cfg->ac_ratio = 0.0f; + cfg->Nmin = 0.0f; + + cfg->epsilon = 0.0f; + cfg->sigmaR_prob = 0.0f; + cfg->sigmaR_active = 0.0f; + cfg->active_gmm = (gaussians_1d_obj *) NULL; + cfg->inactive_gmm = (gaussians_1d_obj *) NULL; + cfg->Pfalse = 0.0f; + cfg->Pnew = 0.0f; + cfg->Ptrack = 0.0f; + + cfg->theta_new = 0.0f; + cfg->N_prob = 0; + cfg->theta_prob = 0.0f; + cfg->N_inactive = (unsigned int *) NULL; + cfg->theta_inactive = 0.0f; + + return cfg; + + } + + void mod_sst_cfg_destroy(mod_sst_cfg * cfg) { + + if (cfg->active_gmm != NULL) { + gaussians_1d_destroy(cfg->active_gmm); + } + + if (cfg->inactive_gmm != NULL) { + gaussians_1d_destroy(cfg->inactive_gmm); + } + + if (cfg->N_inactive != NULL) { + free((void *) cfg->N_inactive); + } + + free((void *) cfg); + + } + + void mod_sst_cfg_printf(const mod_sst_cfg * cfg) { + + unsigned int iTrackMax; + + printf("mode = %c\n", cfg->mode); + printf("nTracksMax = %u\n", cfg->nTracksMax); + printf("hopSize = %u\n", cfg->hopSize); + printf("sigmaQ = %f\n", cfg->sigmaQ); + printf("nParticles = %u\n", cfg->nParticles); + printf("st_alpha = %f\n", cfg->st_alpha); + printf("st_beta = %f\n", cfg->st_beta); + printf("st_ratio = %f\n", cfg->st_ratio); + printf("ve_alpha = %f\n", cfg->ve_alpha); + printf("ve_beta = %f\n", cfg->ve_beta); + printf("ve_ratio = %f\n", cfg->ve_ratio); + printf("ac_alpha = %f\n", cfg->ac_alpha); + printf("ac_beta = %f\n", cfg->ac_beta); + printf("ac_ratio = %f\n", cfg->ac_ratio); + printf("Nmin = %f\n", cfg->Nmin); + printf("epsilon = %f\n", cfg->epsilon); + printf("sigmaR_prob = %f\n", cfg->sigmaR_prob); + printf("sigmaR_active = %f\n", cfg->sigmaR_active); + + printf("active_gmm:\n"); + gaussians_1d_printf(cfg->active_gmm); + + printf("inactive_gmm:\n"); + gaussians_1d_printf(cfg->inactive_gmm); + + printf("Pfalse = %f\n", cfg->Pfalse); + printf("Pnew = %f\n", cfg->Pnew); + printf("Ptrack = %f\n", cfg->Ptrack); + printf("theta_new = %f\n", cfg->theta_new); + printf("N_prob = %u\n", cfg->N_prob); + printf("theta_prob = %f\n", cfg->theta_prob); + + printf("N_inactive = ("); + for (iTrackMax = 0; iTrackMax < cfg->nTracksMax; iTrackMax++) { + + printf("%u",cfg->N_inactive[iTrackMax]); + + if (iTrackMax != (cfg->nTracksMax-1)) { + printf(", "); + } + + } + printf(")\n"); + + printf("theta_inactive = %f\n", cfg->theta_inactive); + + } \ No newline at end of file diff --git a/src/module/mod_sst.h b/src/module/mod_sst.h new file mode 100644 index 0000000..b0c6e48 --- /dev/null +++ b/src/module/mod_sst.h @@ -0,0 +1,129 @@ +#ifndef __ODAS_MODULE_SST +#define __ODAS_MODULE_SST + + #include + #include + #include + #include + + #include "../general/mic.h" + + #include "../signal/coherence.h" + #include "../signal/kalman.h" + #include "../signal/mixture.h" + #include "../signal/particle.h" + + #include "../system/kalman2kalman.h" + #include "../system/particle2particle.h" + #include "../system/kalman2coherence.h" + #include "../system/particle2coherence.h" + #include "../system/mixture2mixture.h" + + #include "../message/msg_pots.h" + #include "../message/msg_tracks.h" + #include "../module/mod_ssl.h" + + typedef struct mod_sst_obj { + + unsigned int nPots; + unsigned int nTracksMax; + unsigned int nTracks; + + char mode; + + mixture_obj ** mixtures; + coherences_obj ** coherences; + postprobs_obj ** postprobs; + + unsigned long long * ids; + unsigned long long * idsAdded; + unsigned long long * idsRemoved; + + char * type; + + kalman_obj ** kalmans; + kalman2kalman_obj * kalman2kalman_prob; + kalman2kalman_obj * kalman2kalman_active; + kalman2coherence_obj * kalman2coherence_prob; + kalman2coherence_obj * kalman2coherence_active; + + particles_obj ** particles; + particle2particle_obj * particle2particle_prob; + particle2particle_obj * particle2particle_active; + particle2coherence_obj * particle2coherence_prob; + particle2coherence_obj * particle2coherence_active; + + mixture2mixture_obj * mixture2mixture; + + float theta_new; + unsigned int N_prob; + float theta_prob; + unsigned int * N_inactive; + float theta_inactive; + + unsigned int * n_prob; + float * mean_prob; + unsigned int * n_inactive; + + unsigned long long id; + + msg_pots_obj * in; + msg_tracks_obj * out; + + } mod_sst_obj; + + typedef struct mod_sst_cfg { + + char mode; + + unsigned int nTracksMax; + unsigned int hopSize; + + float sigmaQ; + + unsigned int nParticles; + float st_alpha; + float st_beta; + float st_ratio; + float ve_alpha; + float ve_beta; + float ve_ratio; + float ac_alpha; + float ac_beta; + float ac_ratio; + float Nmin; + + float epsilon; + float sigmaR_active; + float sigmaR_prob; + gaussians_1d_obj * active_gmm; + gaussians_1d_obj * inactive_gmm; + float Pfalse; + float Pnew; + float Ptrack; + + float theta_new; + unsigned int N_prob; + float theta_prob; + unsigned int * N_inactive; + float theta_inactive; + + } mod_sst_cfg; + + mod_sst_obj * mod_sst_construct(const mod_sst_cfg * mod_sst_config, const mod_ssl_cfg * mod_ssl_config, const msg_pots_cfg * msg_pots_config, const msg_tracks_cfg * msg_tracks_config); + + void mod_sst_destroy(mod_sst_obj * obj); + + int mod_sst_process(mod_sst_obj * obj); + + void mod_sst_connect(mod_sst_obj * obj, msg_pots_obj * in, msg_tracks_obj * out); + + void mod_sst_disconnect(mod_sst_obj * obj); + + mod_sst_cfg * mod_sst_cfg_construct(void); + + void mod_sst_cfg_destroy(mod_sst_cfg * cfg); + + void mod_sst_cfg_printf(const mod_sst_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_stft.c b/src/module/mod_stft.c new file mode 100644 index 0000000..9916c8d --- /dev/null +++ b/src/module/mod_stft.c @@ -0,0 +1,90 @@ + + #include "mod_stft.h" + + mod_stft_obj * mod_stft_construct(const mod_stft_cfg * mod_stft_config, const msg_hops_cfg * msg_hops_config, const msg_spectra_cfg * msg_spectra_config) { + + mod_stft_obj * obj; + + obj = (mod_stft_obj *) malloc(sizeof(mod_stft_obj)); + + obj->hop2frame = hop2frame_construct_zero(msg_hops_config->hopSize, 2*(msg_spectra_config->halfFrameSize-1),msg_hops_config->nChannels); + obj->frames = frames_construct_zero(msg_hops_config->nChannels,2*(msg_spectra_config->halfFrameSize-1)); + obj->frame2freq = frame2freq_construct_zero(2*(msg_spectra_config->halfFrameSize-1), msg_spectra_config->halfFrameSize); + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + return obj; + + } + + void mod_stft_destroy(mod_stft_obj * obj) { + + hop2frame_destroy(obj->hop2frame); + frames_destroy(obj->frames); + frame2freq_destroy(obj->frame2freq); + + free((void *) obj); + + } + + int mod_stft_process(mod_stft_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + hop2frame_process(obj->hop2frame, obj->in->hops, obj->frames); + frame2freq_process(obj->frame2freq, obj->frames, obj->out->freqs); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_stft_connect(mod_stft_obj * obj, msg_hops_obj * in, msg_spectra_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_stft_disconnect(mod_stft_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + } + + mod_stft_cfg * mod_stft_cfg_construct(void) { + + mod_stft_cfg * cfg; + + cfg = (mod_stft_cfg *) malloc(sizeof(mod_stft_cfg)); + + return cfg; + + } + + void mod_stft_cfg_destroy(mod_stft_cfg * cfg) { + + free((void *) cfg); + + } + + + void mod_stft_cfg_printf(const mod_stft_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_stft.h b/src/module/mod_stft.h new file mode 100644 index 0000000..1e3822a --- /dev/null +++ b/src/module/mod_stft.h @@ -0,0 +1,41 @@ +#ifndef __ODAS_MODULE_STFT +#define __ODAS_MODULE_STFT + + #include "../system/hop2frame.h" + #include "../signal/frame.h" + #include "../system/frame2freq.h" + #include "../message/msg_hops.h" + #include "../message/msg_spectra.h" + + typedef struct mod_stft_obj { + + hop2frame_obj * hop2frame; + frames_obj * frames; + frame2freq_obj * frame2freq; + + msg_hops_obj * in; + msg_spectra_obj * out; + + } mod_stft_obj; + + typedef struct mod_stft_cfg { + + } mod_stft_cfg; + + mod_stft_obj * mod_stft_construct(const mod_stft_cfg * mod_stft_config, const msg_hops_cfg * msg_hops_config, const msg_spectra_cfg * msg_spectra_config); + + void mod_stft_destroy(mod_stft_obj * obj); + + int mod_stft_process(mod_stft_obj * obj); + + void mod_stft_connect(mod_stft_obj * obj, msg_hops_obj * in, msg_spectra_obj * out); + + void mod_stft_disconnect(mod_stft_obj * obj); + + mod_stft_cfg * mod_stft_cfg_construct(void); + + void mod_stft_cfg_destroy(mod_stft_cfg * cfg); + + void mod_stft_cfg_printf(const mod_stft_cfg * cfg); + +#endif \ No newline at end of file -- 2.34.1