From: FrancoisGrondin Date: Thu, 19 Oct 2017 18:43:02 +0000 (-0400) Subject: Sound classification completed. X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=5f31f6af93b6313f937d60e62c0013a58a224e12;p=yn%2Fyn-odas.git Sound classification completed. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c235b6d..adf7e5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ set(SRC src/amessage/amsg_pots.c src/amessage/amsg_spectra.c src/amessage/amsg_tracks.c + src/amodule/amod_classify.c src/amodule/amod_istft.c src/amodule/amod_mapping.c src/amodule/amod_resample.c @@ -139,6 +140,7 @@ set(SRC src/message/msg_pots.c src/message/msg_spectra.c src/message/msg_tracks.c + src/module/mod_classify.c src/module/mod_istft.c src/module/mod_mapping.c src/module/mod_resample.c diff --git a/config/azimut_cma.cfg b/config/azimut_cma.cfg index 4c7c640..3206bad 100644 --- a/config/azimut_cma.cfg +++ b/config/azimut_cma.cfg @@ -353,3 +353,27 @@ sss: }; } + +classify: +{ + + frameSize = 1024; + winSize = 3; + tauMin = 32; + tauMax = 200; + deltaTauMax = 7; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.15; + + category: { + + format = "json"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/azimut_oma.cfg b/config/azimut_oma.cfg index bd73698..d4f02c6 100644 --- a/config/azimut_oma.cfg +++ b/config/azimut_oma.cfg @@ -15,7 +15,7 @@ raw: # Input with raw signal from microphones interface: { type = "file"; - path = "input_oma.raw"; + path = "noise_030.raw"; } } @@ -353,3 +353,27 @@ sss: }; } + +classify: +{ + + frameSize = 1024; + winSize = 3; + tauMin = 32; + tauMax = 200; + deltaTauMax = 7; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.15; + + category: { + + format = "json"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/respeaker.cfg b/config/respeaker.cfg index aee32f0..17fe52f 100644 --- a/config/respeaker.cfg +++ b/config/respeaker.cfg @@ -281,4 +281,28 @@ sss: }; -} \ No newline at end of file +} + +classify: +{ + + frameSize = 1024; + winSize = 3; + tauMin = 32; + tauMax = 200; + deltaTauMax = 7; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.15; + + category: { + + format = "json"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/xmos.cfg b/config/xmos.cfg index 5a53091..1348aa2 100644 --- a/config/xmos.cfg +++ b/config/xmos.cfg @@ -280,4 +280,28 @@ sss: }; -} \ No newline at end of file +} + +classify: +{ + + frameSize = 4096; + winSize = 3; + tauMin = 88; + tauMax = 551; + deltaTauMax = 20; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.5; + + category: { + + format = "json"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/demo/configs.c b/demo/configs.c index bf38676..ef1d8d1 100644 --- a/demo/configs.c +++ b/demo/configs.c @@ -177,6 +177,28 @@ cfgs->snk_hops_seps_rs_config = parameters_snk_hops_seps_rs_config(file_config); cfgs->snk_hops_pfs_rs_config = parameters_snk_hops_pfs_rs_config(file_config); + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_classify_config = parameters_mod_classify_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_categories_config = parameters_msg_categories_config(file_config); + + // +------------------------------------------------------+ + // | Sink | + // +------------------------------------------------------+ + + cfgs->snk_categories_config = parameters_snk_categories_config(file_config); + return cfgs; } @@ -353,6 +375,22 @@ snk_hops_cfg_destroy(cfgs->snk_hops_seps_rs_config); snk_hops_cfg_destroy(cfgs->snk_hops_pfs_rs_config); + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_classify_cfg_destroy(cfgs->mod_classify_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_categories_cfg_destroy(cfgs->msg_categories_config); + free((void *) cfgs); } diff --git a/demo/configs.h b/demo/configs.h index cbcef4c..dcc9e8c 100644 --- a/demo/configs.h +++ b/demo/configs.h @@ -44,6 +44,10 @@ snk_hops_cfg * snk_hops_seps_rs_config; snk_hops_cfg * snk_hops_pfs_rs_config; + mod_classify_cfg * mod_classify_config; + msg_categories_cfg * msg_categories_config; + snk_categories_cfg * snk_categories_config; + } configs; configs * configs_construct(const char * file_config); diff --git a/demo/objects.c b/demo/objects.c index b53ecd7..2044b01 100644 --- a/demo/objects.c +++ b/demo/objects.c @@ -172,7 +172,7 @@ // | Connector | // +--------------------------------------------------+ - objs->con_hops_seps_object = con_hops_construct(1, cfgs->msg_hops_seps_config); + objs->con_hops_seps_object = con_hops_construct(2, cfgs->msg_hops_seps_config); objs->con_hops_pfs_object = con_hops_construct(1, cfgs->msg_hops_pfs_config); // +------------------------------------------------------+ @@ -209,6 +209,30 @@ objs->snk_hops_pfs_rs_object = snk_hops_construct(cfgs->snk_hops_pfs_rs_config, cfgs->msg_hops_pfs_rs_config); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_classify_object = mod_classify_construct(cfgs->mod_classify_config, + cfgs->msg_hops_seps_config, + cfgs->msg_categories_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_categories_object = con_categories_construct(1, cfgs->msg_categories_config); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + objs->snk_categories_object = snk_categories_construct(cfgs->snk_categories_config, + cfgs->msg_categories_config); // +----------------------------------------------------------+ // | Connect | @@ -355,6 +379,25 @@ snk_hops_connect(objs->snk_hops_pfs_rs_object, objs->con_hops_pfs_rs_object->outs[0]); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_classify_connect(objs->mod_classify_object, + objs->con_hops_seps_object->outs[1], + objs->con_categories_object->in); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + snk_categories_connect(objs->snk_categories_object, + objs->con_categories_object->outs[0]); + return objs; } @@ -535,6 +578,28 @@ snk_hops_destroy(objs->snk_hops_seps_rs_object); snk_hops_destroy(objs->snk_hops_pfs_rs_object); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_classify_destroy(objs->mod_classify_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_categories_destroy(objs->con_categories_object); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + snk_categories_destroy(objs->snk_categories_object); + free((void *) objs); } @@ -712,7 +777,7 @@ // | Connector | // +--------------------------------------------------+ - objs->acon_hops_seps_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_seps_config); + objs->acon_hops_seps_object = acon_hops_construct(2, objs->nMessages, cfgs->msg_hops_seps_config); objs->acon_hops_pfs_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_pfs_config); // +------------------------------------------------------+ @@ -749,6 +814,31 @@ objs->asnk_hops_pfs_rs_object = asnk_hops_construct(cfgs->snk_hops_pfs_rs_config, cfgs->msg_hops_pfs_rs_config); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_classify_object = amod_classify_construct(cfgs->mod_classify_config, + cfgs->msg_hops_seps_config, + cfgs->msg_categories_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_categories_object = acon_categories_construct(1, objs->nMessages, cfgs->msg_categories_config); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + objs->asnk_categories_object = asnk_categories_construct(cfgs->snk_categories_config, + cfgs->msg_categories_config); + // +----------------------------------------------------------+ // | Connect | // +----------------------------------------------------------+ @@ -894,6 +984,25 @@ asnk_hops_connect(objs->asnk_hops_pfs_rs_object, objs->acon_hops_pfs_rs_object->outs[0]); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_classify_connect(objs->amod_classify_object, + objs->acon_hops_seps_object->outs[1], + objs->acon_categories_object->in); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + asnk_categories_connect(objs->asnk_categories_object, + objs->acon_categories_object->outs[0]); + return objs; } @@ -1074,6 +1183,28 @@ asnk_hops_destroy(objs->asnk_hops_seps_rs_object); asnk_hops_destroy(objs->asnk_hops_pfs_rs_object); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_classify_destroy(objs->amod_classify_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_categories_destroy(objs->acon_categories_object); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + asnk_categories_destroy(objs->asnk_categories_object); + free((void *) objs); } \ No newline at end of file diff --git a/demo/objects.h b/demo/objects.h index 5210bec..d38da5d 100644 --- a/demo/objects.h +++ b/demo/objects.h @@ -49,6 +49,10 @@ snk_hops_obj * snk_hops_seps_rs_object; snk_hops_obj * snk_hops_pfs_rs_object; + mod_classify_obj * mod_classify_object; + con_categories_obj * con_categories_object; + snk_categories_obj * snk_categories_object; + } objects; typedef struct aobjects { @@ -95,6 +99,10 @@ asnk_hops_obj * asnk_hops_seps_rs_object; asnk_hops_obj * asnk_hops_pfs_rs_object; + amod_classify_obj * amod_classify_object; + acon_categories_obj * acon_categories_object; + asnk_categories_obj * asnk_categories_object; + } aobjects; objects * objects_construct(const configs * cfgs); diff --git a/demo/parameters.c b/demo/parameters.c index 8d0d422..d1baaea 100644 --- a/demo/parameters.c +++ b/demo/parameters.c @@ -1122,7 +1122,7 @@ cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); // +----------------------------------------------------------+ - // | Hop size | + // | Half frame size | // +----------------------------------------------------------+ cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; @@ -1154,7 +1154,7 @@ cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); // +----------------------------------------------------------+ - // | Hop size | + // | Half frame size | // +----------------------------------------------------------+ cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; @@ -1437,7 +1437,6 @@ cfg->fS = parameters_lookup_int(fileConfig, "sss.postfiltered.fS"); - // +----------------------------------------------------------+ // | Format | // +----------------------------------------------------------+ @@ -1496,3 +1495,154 @@ return cfg; } + + mod_classify_cfg * parameters_mod_classify_config(const char * fileConfig) { + + mod_classify_cfg * cfg; + + cfg = mod_classify_cfg_construct(); + + // +----------------------------------------------------------+ + // | Frame size | + // +----------------------------------------------------------+ + + cfg->frameSize = parameters_lookup_int(fileConfig, "classify.frameSize"); + + // +----------------------------------------------------------+ + // | Window size | + // +----------------------------------------------------------+ + + cfg->winSize = parameters_lookup_int(fileConfig, "classify.winSize"); + + // +----------------------------------------------------------+ + // | tauMin | + // +----------------------------------------------------------+ + + cfg->tauMin = parameters_lookup_int(fileConfig, "classify.tauMin"); + + // +----------------------------------------------------------+ + // | tauMax | + // +----------------------------------------------------------+ + + cfg->tauMax = parameters_lookup_int(fileConfig, "classify.tauMax"); + + // +----------------------------------------------------------+ + // | deltaTauMax | + // +----------------------------------------------------------+ + + cfg->deltaTauMax = parameters_lookup_int(fileConfig, "classify.deltaTauMax"); + + // +----------------------------------------------------------+ + // | alpha | + // +----------------------------------------------------------+ + + cfg->alpha = parameters_lookup_float(fileConfig, "classify.alpha"); + + // +----------------------------------------------------------+ + // | gamma | + // +----------------------------------------------------------+ + + cfg->gamma = parameters_lookup_float(fileConfig, "classify.gamma"); + + // +----------------------------------------------------------+ + // | phiMin | + // +----------------------------------------------------------+ + + cfg->phiMin = parameters_lookup_float(fileConfig, "classify.phiMin"); + + return cfg; + + } + + msg_categories_cfg * parameters_msg_categories_config(const char * fileConfig) { + + msg_categories_cfg * cfg; + + cfg = msg_categories_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + return cfg; + + } + + snk_categories_cfg * parameters_snk_categories_config(const char * fileConfig) { + + snk_categories_cfg * cfg; + unsigned int tmpInt1; + char * tmpStr1; + char * tmpStr2; + + cfg = snk_categories_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "classify.category.format"); + + if (strcmp(tmpStr1, "json") == 0) { cfg->format = format_construct_text_json(); } + else { printf("classify.category.format: Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "classify.category.interface.type"); + + if (strcmp(tmpStr1, "blackhole") == 0) { + + cfg->interface = interface_construct_blackhole(); + + } + else if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "classify.category.interface.path"); + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "classify.category.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "classify.category.interface.port"); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "terminal") == 0) { + + cfg->interface = interface_construct_terminal(); + + } + else { + + printf("classify.category.interface.type: 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 index 0598cac..694ca22 100644 --- a/demo/parameters.h +++ b/demo/parameters.h @@ -76,4 +76,10 @@ snk_hops_cfg * parameters_snk_hops_pfs_rs_config(const char * fileConfig); + mod_classify_cfg * parameters_mod_classify_config(const char * fileConfig); + + msg_categories_cfg * parameters_msg_categories_config(const char * fileConfig); + + snk_categories_cfg * parameters_snk_categories_config(const char * fileConfig); + #endif \ No newline at end of file diff --git a/demo/profiler.c b/demo/profiler.c index 096a5ab..583b6f9 100644 --- a/demo/profiler.c +++ b/demo/profiler.c @@ -45,6 +45,10 @@ prf->snk_hops_seps_rs_prf = 0.0f; prf->snk_hops_pfs_rs_prf = 0.0f; + prf->mod_classify_prf = 0.0f; + prf->con_categories_prf = 0.0f; + prf->snk_categories_prf = 0.0f; + return prf; } @@ -65,7 +69,8 @@ sink = prf->snk_pots_ssl_prf + prf->snk_tracks_sst_prf + prf->snk_hops_seps_rs_prf + - prf->snk_hops_pfs_rs_prf; + prf->snk_hops_pfs_rs_prf + + prf->snk_categories_prf; module = prf->mod_mapping_mics_prf + prf->mod_resample_mics_prf + @@ -76,7 +81,8 @@ prf->mod_istft_seps_prf + prf->mod_istft_pfs_prf + prf->mod_resample_seps_prf + - prf->mod_resample_pfs_prf; + prf->mod_resample_pfs_prf + + prf->mod_classify_prf; connector = prf->con_hops_mics_raw_prf + prf->con_hops_mics_map_prf + @@ -89,7 +95,8 @@ prf->con_hops_seps_prf + prf->con_hops_pfs_prf + prf->con_hops_seps_rs_prf + - prf->con_hops_pfs_rs_prf; + prf->con_hops_pfs_rs_prf + + prf->con_categories_prf; total = source + sink + module + connector; @@ -126,6 +133,10 @@ printf("| - Module.......... %07.3f (%06.2f%%) |\n",(prf->mod_resample_seps_prf+prf->mod_resample_pfs_prf),roundf(10000.0f * (prf->mod_resample_seps_prf+prf->mod_resample_pfs_prf) / prf->duration) / 100.0f); printf("| - Connector....... %07.3f (%06.2f%%) |\n",(prf->con_hops_seps_rs_prf+prf->con_hops_pfs_rs_prf),roundf(10000.0f * (prf->con_hops_seps_rs_prf+prf->con_hops_pfs_rs_prf) / prf->duration) / 100.0f); printf("| - Sink............ %07.3f (%06.2f%%) |\n",(prf->snk_hops_seps_rs_prf+prf->snk_hops_pfs_rs_prf),roundf(10000.0f * (prf->snk_hops_seps_rs_prf+prf->snk_hops_pfs_rs_prf) / prf->duration) / 100.0f); + printf("| + Classify |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_classify_prf,roundf(10000.0f * prf->mod_classify_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_categories_prf,roundf(10000.0f * prf->con_categories_prf / prf->duration) / 100.0f); + printf("| - Sink............ %07.3f (%06.2f%%) |\n",prf->snk_categories_prf,roundf(10000.0f * prf->snk_categories_prf / prf->duration) / 100.0f); printf("+--------------------------------------------+\n"); printf("| + TOTAL.............. %07.3f (%06.2f%%) |\n",total,roundf(10000.0f * total / prf->duration) / 100.0f); printf("| - Module.......... %07.3f (%06.2f%%) |\n",module,roundf(10000.0f * module / prf->duration) / 100.0f); diff --git a/demo/profiler.h b/demo/profiler.h index 8b3dd65..05dc808 100644 --- a/demo/profiler.h +++ b/demo/profiler.h @@ -45,6 +45,10 @@ float snk_hops_seps_rs_prf; float snk_hops_pfs_rs_prf; + float mod_classify_prf; + float con_categories_prf; + float snk_categories_prf; + } profiler; profiler * profiler_construct(void); diff --git a/demo/threads.c b/demo/threads.c index 39e5e94..b7c5a73 100644 --- a/demo/threads.c +++ b/demo/threads.c @@ -173,6 +173,28 @@ thread_start(aobjs->acon_hops_seps_rs_object->thread); thread_start(aobjs->acon_hops_pfs_rs_object->thread); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + thread_start(aobjs->amod_classify_object->thread); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + thread_start(aobjs->asnk_categories_object->thread); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + thread_start(aobjs->acon_categories_object->thread); + } void threads_multiple_stop(aobjects * aobjs) { @@ -365,6 +387,29 @@ thread_join(aobjs->acon_hops_seps_rs_object->thread); thread_join(aobjs->acon_hops_pfs_rs_object->thread); + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + thread_join(aobjs->amod_classify_object->thread); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + thread_join(aobjs->asnk_categories_object->thread); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + thread_join(aobjs->acon_categories_object->thread); + + } void threads_single_open(objects * objs) { @@ -412,6 +457,16 @@ snk_hops_open(objs->snk_hops_seps_rs_object); snk_hops_open(objs->snk_hops_pfs_rs_object); + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_categories_open(objs->snk_categories_object); + } void threads_single_close(objects * objs) { @@ -459,6 +514,16 @@ snk_hops_close(objs->snk_hops_seps_rs_object); snk_hops_close(objs->snk_hops_pfs_rs_object); + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_categories_close(objs->snk_categories_object); + } int threads_single_process(objects * objs, profiler * prf) { @@ -804,6 +869,37 @@ } + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_classify_process(objs->mod_classify_object); + end = clock(); + prf->mod_classify_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_categories_process(objs->con_categories_object); + end = clock(); + prf->con_categories_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + begin = clock(); + snk_categories_process(objs->snk_categories_object); + end = clock(); + prf->snk_categories_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + } return rtnValue; diff --git a/include/odas/odas.h b/include/odas/odas.h index 93b74a1..e9e801c 100644 --- a/include/odas/odas.h +++ b/include/odas/odas.h @@ -1,12 +1,15 @@ + #include "../../src/connector/con_categories.h" #include "../../src/connector/con_hops.h" #include "../../src/connector/con_pots.h" #include "../../src/connector/con_spectra.h" #include "../../src/connector/con_tracks.h" + #include "../../src/message/msg_categories.h" #include "../../src/message/msg_hops.h" #include "../../src/message/msg_pots.h" #include "../../src/message/msg_spectra.h" #include "../../src/message/msg_tracks.h" + #include "../../src/module/mod_classify.h" #include "../../src/module/mod_istft.h" #include "../../src/module/mod_mapping.h" #include "../../src/module/mod_resample.h" @@ -14,20 +17,24 @@ #include "../../src/module/mod_sst.h" #include "../../src/module/mod_sss.h" #include "../../src/module/mod_stft.h" + #include "../../src/sink/snk_categories.h" #include "../../src/sink/snk_hops.h" #include "../../src/sink/snk_pots.h" #include "../../src/sink/snk_spectra.h" #include "../../src/sink/snk_tracks.h" #include "../../src/source/src_hops.h" + #include "../../src/aconnector/acon_categories.h" #include "../../src/aconnector/acon_hops.h" #include "../../src/aconnector/acon_pots.h" #include "../../src/aconnector/acon_spectra.h" #include "../../src/aconnector/acon_tracks.h" + #include "../../src/amessage/amsg_categories.h" #include "../../src/amessage/amsg_hops.h" #include "../../src/amessage/amsg_pots.h" #include "../../src/amessage/amsg_spectra.h" #include "../../src/amessage/amsg_tracks.h" + #include "../../src/amodule/amod_classify.h" #include "../../src/amodule/amod_istft.h" #include "../../src/amodule/amod_mapping.h" #include "../../src/amodule/amod_resample.h" @@ -35,6 +42,7 @@ #include "../../src/amodule/amod_sst.h" #include "../../src/amodule/amod_sss.h" #include "../../src/amodule/amod_stft.h" + #include "../../src/asink/asnk_categories.h" #include "../../src/asink/asnk_hops.h" #include "../../src/asink/asnk_pots.h" #include "../../src/asink/asnk_spectra.h" diff --git a/src/amodule/amod_classify.c b/src/amodule/amod_classify.c new file mode 100644 index 0000000..01f2c68 --- /dev/null +++ b/src/amodule/amod_classify.c @@ -0,0 +1,70 @@ + + #include "amod_classify.h" + + amod_classify_obj * amod_classify_construct(const mod_classify_cfg * mod_classify_config, const msg_hops_cfg * msg_hops_config, const msg_categories_cfg * msg_categories_config) { + + amod_classify_obj * obj; + + obj = (amod_classify_obj *) malloc(sizeof(amod_classify_obj)); + + obj->mod_classify = mod_classify_construct(mod_classify_config, msg_hops_config, msg_categories_config); + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_categories_obj *) NULL; + + obj->thread = thread_construct(&amod_classify_thread, (void *) obj); + + return obj; + + } + + void amod_classify_destroy(amod_classify_obj * obj) { + + mod_classify_destroy(obj->mod_classify); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_classify_connect(amod_classify_obj * obj, amsg_hops_obj * in, amsg_categories_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_classify_disconnect(amod_classify_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_categories_obj *) NULL; + + } + + void * amod_classify_thread(void * ptr) { + + amod_classify_obj * obj; + msg_hops_obj * msg_hops_in; + msg_categories_obj * msg_categories_out; + int rtnValue; + + obj = (amod_classify_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_hops_in = amsg_hops_filled_pop(obj->in); + msg_categories_out = amsg_categories_empty_pop(obj->out); + mod_classify_connect(obj->mod_classify, msg_hops_in, msg_categories_out); + rtnValue = mod_classify_process(obj->mod_classify); + mod_classify_disconnect(obj->mod_classify); + amsg_hops_empty_push(obj->in, msg_hops_in); + amsg_categories_filled_push(obj->out, msg_categories_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } diff --git a/src/amodule/amod_classify.h b/src/amodule/amod_classify.h new file mode 100644 index 0000000..c831be9 --- /dev/null +++ b/src/amodule/amod_classify.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_AMODULE_CLASSIFY +#define __ODAS_AMODULE_CLASSIFY + + #include "../module/mod_classify.h" + #include "../amessage/amsg_hops.h" + #include "../amessage/amsg_categories.h" + #include "../general/thread.h" + + typedef struct amod_classify_obj { + + mod_classify_obj * mod_classify; + amsg_hops_obj * in; + amsg_categories_obj * out; + thread_obj * thread; + + } amod_classify_obj; + + amod_classify_obj * amod_classify_construct(const mod_classify_cfg * mod_classify_config, const msg_hops_cfg * msg_hops_config, const msg_categories_cfg * msg_categories_config); + + void amod_classify_destroy(amod_classify_obj * obj); + + void amod_classify_connect(amod_classify_obj * obj, amsg_hops_obj * in, amsg_categories_obj * out); + + void amod_classify_disconnect(amod_classify_obj * obj); + + void * amod_classify_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/connector/con_categories.c b/src/connector/con_categories.c new file mode 100644 index 0000000..05dff28 --- /dev/null +++ b/src/connector/con_categories.c @@ -0,0 +1,57 @@ + + #include "con_categories.h" + + con_categories_obj * con_categories_construct(const unsigned int nOuts, const msg_categories_cfg * msg_categories_config) { + + con_categories_obj * obj; + unsigned int iOut; + + obj = (con_categories_obj *) malloc(sizeof(con_categories_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_categories_construct(msg_categories_config); + + obj->outs = (msg_categories_obj **) malloc(sizeof(msg_categories_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_categories_construct(msg_categories_config); + } + + return obj; + + } + + void con_categories_destroy(con_categories_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_categories_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_categories_destroy(obj->in); + + free((void *) obj); + + } + + int con_categories_process(con_categories_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_categories_copy(obj->outs[iOut], obj->in); + } + + if (msg_categories_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_categories.h b/src/connector/con_categories.h new file mode 100644 index 0000000..fec8ef1 --- /dev/null +++ b/src/connector/con_categories.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_CATEGORIES +#define __ODAS_CONNECTOR_CATEGORIES + + #include "../message/msg_categories.h" + + #include + #include + + typedef struct con_categories_obj { + + msg_categories_obj * in; + msg_categories_obj ** outs; + + unsigned int nOuts; + + } con_categories_obj; + + con_categories_obj * con_categories_construct(const unsigned int nOuts, const msg_categories_cfg * msg_categories_config); + + void con_categories_destroy(con_categories_obj * obj); + + int con_categories_process(con_categories_obj * obj); + +#endif \ No newline at end of file diff --git a/src/message/msg_categories.c b/src/message/msg_categories.c new file mode 100644 index 0000000..aec6139 --- /dev/null +++ b/src/message/msg_categories.c @@ -0,0 +1,81 @@ + + #include "msg_categories.h" + + msg_categories_obj * msg_categories_construct(const msg_categories_cfg * msg_categories_config) { + + msg_categories_obj * obj; + + obj = (msg_categories_obj *) malloc(sizeof(msg_categories_obj)); + + obj->timeStamp = 0; + obj->fS = msg_categories_config->fS; + obj->categories = categories_construct_zero(msg_categories_config->nChannels); + + return obj; + + } + + void msg_categories_destroy(msg_categories_obj * obj) { + + categories_destroy(obj->categories); + free((void *) obj); + + } + + void msg_categories_copy(msg_categories_obj * dest, const msg_categories_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + + categories_copy(dest->categories, src->categories); + + } + + void msg_categories_zero(msg_categories_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + categories_zero(obj->categories); + + } + + unsigned int msg_categories_isZero(const msg_categories_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_categories_cfg * msg_categories_cfg_construct(void) { + + msg_categories_cfg * cfg; + + cfg = (msg_categories_cfg *) malloc(sizeof(msg_categories_cfg)); + + cfg->nChannels = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_categories_cfg_destroy(msg_categories_cfg * msg_categories_config) { + + free((void *) msg_categories_config); + + } + + void msg_categories_cfg_printf(const msg_categories_cfg * msg_categories_config) { + + printf("nChannels = %u\n", msg_categories_config->nChannels); + printf("fS = %u\n", msg_categories_config->fS); + + } diff --git a/src/message/msg_categories.h b/src/message/msg_categories.h new file mode 100644 index 0000000..1ef1a2c --- /dev/null +++ b/src/message/msg_categories.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_MESSAGE_CATEGORIES +#define __ODAS_MESSAGE_CATEGORIES + + #include + #include "../signal/category.h" + + typedef struct msg_categories_obj { + + unsigned long long timeStamp; + unsigned int fS; + categories_obj * categories; + + } msg_categories_obj; + + typedef struct msg_categories_cfg { + + unsigned int nChannels; + unsigned int fS; + + } msg_categories_cfg; + + msg_categories_obj * msg_categories_construct(const msg_categories_cfg * msg_categories_config); + + void msg_categories_destroy(msg_categories_obj * obj); + + void msg_categories_copy(msg_categories_obj * dest, const msg_categories_obj * src); + + void msg_categories_zero(msg_categories_obj * obj); + + unsigned int msg_categories_isZero(const msg_categories_obj * obj); + + msg_categories_cfg * msg_categories_cfg_construct(void); + + void msg_categories_cfg_destroy(msg_categories_cfg * msg_categories_config); + + void msg_categories_cfg_printf(const msg_categories_cfg * msg_categories_config); + +#endif \ No newline at end of file diff --git a/src/module/mod_classify.c b/src/module/mod_classify.c index e69de29..24cce83 100644 --- a/src/module/mod_classify.c +++ b/src/module/mod_classify.c @@ -0,0 +1,123 @@ + + #include "mod_classify.h" + + mod_classify_obj * mod_classify_construct(const mod_classify_cfg * mod_classify_config, const msg_hops_cfg * msg_hops_config, const msg_categories_cfg * msg_categories_config) { + + mod_classify_obj * obj; + + obj = (mod_classify_obj *) malloc(sizeof(mod_classify_obj)); + + obj->hop2frame = hop2frame_construct_zero(msg_hops_config->hopSize, + mod_classify_config->frameSize, + msg_hops_config->nChannels); + + obj->frames = frames_construct_zero(msg_hops_config->nChannels, + mod_classify_config->frameSize); + + obj->frame2freq = frame2freq_construct_zero(mod_classify_config->frameSize, + (mod_classify_config->frameSize)/2+1); + + obj->freqs = freqs_construct_zero(msg_hops_config->nChannels, + (mod_classify_config->frameSize)/2+1); + + obj->freq2acorr = freq2acorr_construct_zero(msg_hops_config->nChannels, + (mod_classify_config->frameSize)/2+1); + + obj->acorrs = acorrs_construct_zero(msg_hops_config->nChannels, + (mod_classify_config->frameSize)/2+1); + + obj->acorr2pitch = acorr2pitch_construct_zero(msg_hops_config->nChannels, + (mod_classify_config->frameSize)/2+1, + mod_classify_config->winSize); + + obj->pitches = pitches_construct_zero(msg_hops_config->nChannels); + + obj->pitch2category = pitch2category_construct_zero(msg_hops_config->nChannels, + mod_classify_config->tauMin, + mod_classify_config->tauMax, + mod_classify_config->deltaTauMax, + mod_classify_config->alpha, + mod_classify_config->gamma, + mod_classify_config->phiMin, + mod_classify_config->r0); + + return obj; + + } + + void mod_classify_destroy(mod_classify_obj * obj) { + + hop2frame_destroy(obj->hop2frame); + frames_destroy(obj->frames); + frame2freq_destroy(obj->frame2freq); + freqs_destroy(obj->freqs); + freq2acorr_destroy(obj->freq2acorr); + acorrs_destroy(obj->acorrs); + acorr2pitch_destroy(obj->acorr2pitch); + pitches_destroy(obj->pitches); + pitch2category_destroy(obj->pitch2category); + + } + + int mod_classify_process(mod_classify_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->freqs); + freq2acorr_process(obj->freq2acorr, obj->freqs, obj->acorrs); + acorr2pitch_process(obj->acorr2pitch, obj->acorrs, obj->pitches); + pitch2category_process(obj->pitch2category, obj->pitches, obj->out->categories); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_categories_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_classify_connect(mod_classify_obj * obj, msg_hops_obj * in, msg_categories_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_classify_disconnect(mod_classify_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_categories_obj *) NULL; + + } + + mod_classify_cfg * mod_classify_cfg_construct(void) { + + mod_classify_cfg * cfg; + + cfg = (mod_classify_cfg *) malloc(sizeof(mod_classify_cfg)); + + return cfg; + + } + + void mod_classify_cfg_destroy(mod_classify_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_classify_cfg_printf(const mod_classify_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_classify.h b/src/module/mod_classify.h index e69de29..1297ee1 100644 --- a/src/module/mod_classify.h +++ b/src/module/mod_classify.h @@ -0,0 +1,71 @@ +#ifndef __ODAS_MODULE_CLASSIFY +#define __ODAS_MODULE_CLASSIFY + + #include + + #include "../message/msg_hops.h" + #include "../message/msg_categories.h" + + #include "../signal/acorr.h" + #include "../signal/category.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/hop.h" + #include "../signal/pitch.h" + + #include "../system/acorr2pitch.h" + #include "../system/frame2freq.h" + #include "../system/freq2acorr.h" + #include "../system/hop2frame.h" + #include "../system/pitch2category.h" + + typedef struct mod_classify_obj { + + frames_obj * frames; + freqs_obj * freqs; + acorrs_obj * acorrs; + pitches_obj * pitches; + + hop2frame_obj * hop2frame; + frame2freq_obj * frame2freq; + freq2acorr_obj * freq2acorr; + acorr2pitch_obj * acorr2pitch; + pitch2category_obj * pitch2category; + + msg_hops_obj * in; + msg_categories_obj * out; + + } mod_classify_obj; + + typedef struct mod_classify_cfg { + + unsigned int frameSize; + unsigned int winSize; + + float tauMin; + float tauMax; + float deltaTauMax; + float alpha; + float gamma; + float phiMin; + float r0; + + } mod_classify_cfg; + + mod_classify_obj * mod_classify_construct(const mod_classify_cfg * mod_classify_config, const msg_hops_cfg * msg_hops_config, const msg_categories_cfg * msg_categories_config); + + void mod_classify_destroy(mod_classify_obj * obj); + + int mod_classify_process(mod_classify_obj * obj); + + void mod_classify_connect(mod_classify_obj * obj, msg_hops_obj * in, msg_categories_obj * out); + + void mod_classify_disconnect(mod_classify_obj * obj); + + mod_classify_cfg * mod_classify_cfg_construct(void); + + void mod_classify_cfg_destroy(mod_classify_cfg * cfg); + + void mod_classify_cfg_printf(const mod_classify_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/signal/category.c b/src/signal/category.c index 2ee2303..109b2ff 100644 --- a/src/signal/category.c +++ b/src/signal/category.c @@ -22,6 +22,18 @@ } + void categories_copy(categories_obj * dest, const categories_obj * src) { + + memcpy(dest->array, src->array, sizeof(char) * src->nSignals); + + } + + void categories_zero(categories_obj * obj) { + + memset(obj->array, 0x00, sizeof(char) * obj->nSignals); + + } + void categories_printf(const categories_obj * obj) { unsigned int iSignal; diff --git a/src/signal/category.h b/src/signal/category.h index 11e4013..3a86a25 100644 --- a/src/signal/category.h +++ b/src/signal/category.h @@ -16,6 +16,10 @@ void categories_destroy(categories_obj * obj); + void categories_copy(categories_obj * dest, const categories_obj * src); + + void categories_zero(categories_obj * obj); + void categories_printf(const categories_obj * obj); #endif \ No newline at end of file diff --git a/src/sink/snk_categories.c b/src/sink/snk_categories.c new file mode 100644 index 0000000..25e429c --- /dev/null +++ b/src/sink/snk_categories.c @@ -0,0 +1,246 @@ + + #include "snk_categories.h" + + snk_categories_obj * snk_categories_construct(const snk_categories_cfg * snk_categories_config, const msg_categories_cfg * msg_categories_config) { + + snk_categories_obj * obj; + + obj = (snk_categories_obj *) malloc(sizeof(snk_categories_obj)); + + obj->timeStamp = 0; + + obj->nChannels = msg_categories_config->nChannels; + obj->fS = snk_categories_config->fS; + + obj->format = format_clone(snk_categories_config->format); + obj->interface = interface_clone(snk_categories_config->interface); + + switch (obj->format->type) { + + case format_text_json: break; + default: + + printf("Invalid format.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->in = (msg_categories_obj *) NULL; + + return obj; + + } + + void snk_categories_destroy(snk_categories_obj * obj) { + + format_destroy(obj->format); + interface_destroy(obj->interface); + + free((void *) obj); + + } + + void snk_categories_connect(snk_categories_obj * obj, msg_categories_obj * in) { + + obj->in = in; + + } + + void snk_categories_disconnect(snk_categories_obj * obj) { + + obj->in = (msg_categories_obj *) NULL; + + } + + int snk_categories_open(snk_categories_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + // Empty + + break; + + case interface_file: + + printf("Not implemented yet.\n"); + exit(EXIT_FAILURE); + + break; + + case interface_socket: + + printf("Not implemented yet.\n"); + exit(EXIT_FAILURE); + + break; + + case interface_terminal: + + // Empty + + break; + + default: + + printf("Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + int snk_categories_close(snk_categories_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + // Empty + + break; + + case interface_file: + + printf("Not implemented yet.\n"); + exit(EXIT_FAILURE); + + break; + + case interface_socket: + + printf("Not implemented yet.\n"); + exit(EXIT_FAILURE); + + break; + + case interface_terminal: + + // Empty + + break; + + default: + + printf("Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + int snk_categories_process(snk_categories_obj * obj) { + + int rtnValue; + + switch(obj->interface->type) { + + case interface_blackhole: + + rtnValue = snk_categories_process_blackhole(obj); + + break; + + case interface_file: + + rtnValue = snk_categories_process_file(obj); + + break; + + case interface_socket: + + rtnValue = snk_categories_process_socket(obj); + + break; + + case interface_terminal: + + rtnValue = snk_categories_process_terminal(obj); + + break; + + default: + + printf("Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + return rtnValue; + + } + + int snk_categories_process_blackhole(snk_categories_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + int snk_categories_process_file(snk_categories_obj * obj) { + + printf("Not implemented\n"); + exit(EXIT_FAILURE); + + } + + int snk_categories_process_socket(snk_categories_obj * obj) { + + printf("Not implemented\n"); + exit(EXIT_FAILURE); + + } + + int snk_categories_process_terminal(snk_categories_obj * obj) { + + + + } + + snk_categories_cfg * snk_categories_cfg_construct(void) { + + snk_categories_cfg * cfg; + + cfg = (snk_categories_cfg *) malloc(sizeof(snk_categories_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_categories_cfg_destroy(snk_categories_cfg * snk_categories_config) { + + if (snk_categories_config->format != NULL) { + format_destroy(snk_categories_config->format); + } + if (snk_categories_config->interface != NULL) { + interface_destroy(snk_categories_config->interface); + } + + free((void *) snk_categories_config); + + } \ No newline at end of file diff --git a/src/sink/snk_categories.h b/src/sink/snk_categories.h new file mode 100644 index 0000000..6923311 --- /dev/null +++ b/src/sink/snk_categories.h @@ -0,0 +1,67 @@ +#ifndef __ODAS_SINK_CATEGORIES +#define __ODAS_SINK_CATEGORIES + + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_categories.h" + #include "../utils/pcm.h" + + typedef struct snk_categories_obj { + + unsigned long long timeStamp; + + unsigned int nChannels; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + FILE * fp; + + //struct sockaddr_in sserver; + //char * smessage; + //int sid; + + msg_categories_obj * in; + + } snk_categories_obj; + + typedef struct snk_categories_cfg { + + unsigned int fS; + format_obj * format; + interface_obj * interface; + + } snk_categories_cfg; + + snk_categories_obj * snk_categories_construct(const snk_categories_cfg * snk_categories_config, const msg_categories_cfg * msg_categories_config); + + void snk_categories_destroy(snk_categories_obj * obj); + + void snk_categories_connect(snk_categories_obj * obj, msg_categories_obj * in); + + void snk_categories_disconnect(snk_categories_obj * obj); + + int snk_categories_open(snk_categories_obj * obj); + + int snk_categories_close(snk_categories_obj * obj); + + int snk_categories_process(snk_categories_obj * obj); + + int snk_categories_process_blackhole(snk_categories_obj * obj); + + int snk_categories_process_file(snk_categories_obj * obj); + + int snk_categories_process_socket(snk_categories_obj * obj); + + int snk_categories_process_terminal(snk_categories_obj * obj); + + snk_categories_cfg * snk_categories_cfg_construct(void); + + void snk_categories_cfg_destroy(snk_categories_cfg * snk_categories_config); + +#endif \ No newline at end of file diff --git a/src/system/acorr2pitch.c b/src/system/acorr2pitch.c index d7378df..81ad2ac 100644 --- a/src/system/acorr2pitch.c +++ b/src/system/acorr2pitch.c @@ -35,6 +35,7 @@ float maxValue; unsigned int maxIndex; char isPeak; + char peakFound; unsigned int peakPrev; unsigned int peakNow; @@ -45,17 +46,20 @@ for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + maxValue = -INFINITY; + peakFound = 0x00; + for (iBin = obj->winSize; iBin < (obj->halfFrameSize - obj->winSize); iBin++) { peakValue = acorrs->array[iSignal][iBin]; isPeak = 0x01; - for (iWin = -1 * (obj->winSize); iWin <= obj->winSize; iWin++) { + for (iWin = -1 * ((signed int) (obj->winSize)); iWin <= ((signed int) (obj->winSize)); iWin++) { iSample = iBin + iWin; nextValue = acorrs->array[iSignal][iSample]; - if (peakValue <= nextValue) { + if ((iWin != 0) && (peakValue <= nextValue)) { isPeak = 0x00; break; @@ -71,20 +75,31 @@ maxValue = peakValue; maxIndex = iBin; + peakFound = 0x01; + } } } - peakPrev = maxIndex - 1; - peakNow = maxIndex; - peakNext = maxIndex + 1; - RPrev = acorrs->array[iSignal][peakPrev]; - RNow = acorrs->array[iSignal][peakNow]; - RNext = acorrs->array[iSignal][peakNext]; + if (peakFound == 0x01) { + + peakPrev = maxIndex - 1; + peakNow = maxIndex; + peakNext = maxIndex + 1; + RPrev = acorrs->array[iSignal][peakPrev]; + RNow = acorrs->array[iSignal][peakNow]; + RNext = acorrs->array[iSignal][peakNext]; + + pitches->array[iSignal] = ((float) peakNow) + ((RPrev - RNext) / (2*RPrev - 4*RNow + 2*RNext)); + + } + else { + + pitches->array[iSignal] = 0.0f; - pitches->array[iSignal] = ((float) peakNow) + ((RPrev - RNext) / (2*RPrev - 4*RNow + 2*RNext)); + } } diff --git a/src/system/acorr2pitch.h b/src/system/acorr2pitch.h index 3e2adad..abf9b91 100644 --- a/src/system/acorr2pitch.h +++ b/src/system/acorr2pitch.h @@ -4,14 +4,14 @@ #include "../signal/acorr.h" #include "../signal/pitch.h" + #include + typedef struct acorr2pitch_obj { unsigned int nSignals; unsigned int halfFrameSize; unsigned int frameSize; unsigned int winSize; - unsigned int minBin; - unsigned int maxBin; } acorr2pitch_obj; diff --git a/src/system/freq2acorr.c b/src/system/freq2acorr.c index d67bae8..9594df7 100644 --- a/src/system/freq2acorr.c +++ b/src/system/freq2acorr.c @@ -11,7 +11,8 @@ obj->halfFrameSize = halfFrameSize; obj->frameSize = (halfFrameSize-1)*2; - obj->array = (float *) malloc(sizeof(float) * obj->frameSize); + obj->arrayIn = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + obj->arrayOut = (float *) malloc(sizeof(float) * obj->frameSize); obj->fft = fft_construct(obj->frameSize); @@ -21,7 +22,8 @@ void freq2acorr_destroy(freq2acorr_obj * obj) { - free((void *) obj->array); + free((void *) obj->arrayIn); + free((void *) obj->arrayOut); fft_destroy(obj->fft); free((void *) obj); @@ -30,12 +32,27 @@ void freq2acorr_process(freq2acorr_obj * obj, const freqs_obj * freqs, acorrs_obj * acorrs) { unsigned int iSignal; + unsigned int iBin; + + float Yreal; + float Yimag; for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { - fft_c2r(obj->fft, freqs->array[iSignal], obj->array); + memset(obj->arrayIn, 0x00, sizeof(float) * obj->halfFrameSize * 2); + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + Yreal = freqs->array[iSignal][iBin * 2 + 0]; + Yimag = freqs->array[iSignal][iBin * 2 + 1]; + + obj->arrayIn[iBin * 2 + 0] = Yreal * Yreal + Yimag * Yimag; + + } + + fft_c2r(obj->fft, obj->arrayIn, obj->arrayOut); - memcpy(acorrs->array[iSignal], obj->array, sizeof(float) * obj->halfFrameSize); + memcpy(acorrs->array[iSignal], obj->arrayOut, sizeof(float) * obj->halfFrameSize); } diff --git a/src/system/freq2acorr.h b/src/system/freq2acorr.h index f17f9a6..d2941b3 100644 --- a/src/system/freq2acorr.h +++ b/src/system/freq2acorr.h @@ -15,7 +15,8 @@ unsigned int halfFrameSize; unsigned int frameSize; - float * array; + float * arrayIn; + float * arrayOut; fft_obj * fft;