From db1110e1af348a36a6c27a55e8516a4101c85b53 Mon Sep 17 00:00:00 2001 From: FrancoisGrondin Date: Wed, 18 Oct 2017 17:11:34 -0400 Subject: [PATCH] Messages and connectors added for sound classification --- CMakeLists.txt | 6 +++ src/aconnector/acon_categories.c | 85 ++++++++++++++++++++++++++++++++ src/aconnector/acon_categories.h | 27 ++++++++++ src/amessage/amsg_categories.c | 64 ++++++++++++++++++++++++ src/amessage/amsg_categories.h | 29 +++++++++++ src/asink/asnk_categories.c | 70 ++++++++++++++++++++++++++ src/asink/asnk_categories.h | 28 +++++++++++ 7 files changed, 309 insertions(+) create mode 100644 src/aconnector/acon_categories.c create mode 100644 src/aconnector/acon_categories.h create mode 100644 src/amessage/amsg_categories.c create mode 100644 src/amessage/amsg_categories.h create mode 100644 src/asink/asnk_categories.c create mode 100644 src/asink/asnk_categories.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d8b37f..c235b6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,10 +105,12 @@ set(SRC src/utils/pcm.c src/utils/random.c + src/aconnector/acon_categories.c src/aconnector/acon_hops.c src/aconnector/acon_pots.c src/aconnector/acon_spectra.c src/aconnector/acon_tracks.c + src/amessage/amsg_categories.c src/amessage/amsg_hops.c src/amessage/amsg_pots.c src/amessage/amsg_spectra.c @@ -120,16 +122,19 @@ set(SRC src/amodule/amod_sss.c src/amodule/amod_sst.c src/amodule/amod_stft.c + src/asink/asnk_categories.c src/asink/asnk_hops.c src/asink/asnk_pots.c src/asink/asnk_spectra.c src/asink/asnk_tracks.c src/asource/asrc_hops.c + src/connector/con_categories.c src/connector/con_hops.c src/connector/con_pots.c src/connector/con_spectra.c src/connector/con_tracks.c + src/message/msg_categories.c src/message/msg_hops.c src/message/msg_pots.c src/message/msg_spectra.c @@ -141,6 +146,7 @@ set(SRC src/module/mod_sss.c src/module/mod_sst.c src/module/mod_stft.c + src/sink/snk_categories.c src/sink/snk_hops.c src/sink/snk_pots.c src/sink/snk_spectra.c diff --git a/src/aconnector/acon_categories.c b/src/aconnector/acon_categories.c new file mode 100644 index 0000000..4570e37 --- /dev/null +++ b/src/aconnector/acon_categories.c @@ -0,0 +1,85 @@ + + #include "acon_categories.h" + + acon_categories_obj * acon_categories_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_categories_cfg * msg_categories_config) { + + acon_categories_obj * obj; + unsigned int iOut; + + obj = (acon_categories_obj *) malloc(sizeof(acon_categories_obj)); + + obj->in = amsg_categories_construct(nMessages, msg_categories_config); + + obj->outs = (amsg_categories_obj **) malloc(sizeof(amsg_categories_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_categories_construct(nMessages, msg_categories_config); + } + + obj->con_categories = con_categories_construct(nOuts, msg_categories_config); + + obj->thread = thread_construct(&acon_categories_thread, (void *) obj); + + return obj; + + } + + void acon_categories_destroy(acon_categories_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_categories->nOuts; + + thread_destroy(obj->thread); + + con_categories_destroy(obj->con_categories); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_categories_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_categories_destroy(obj->in); + + free((void *) obj); + + + } + + void * acon_categories_thread(void * ptr) { + + msg_categories_obj * msg_categories_in; + msg_categories_obj * msg_categories_out; + + acon_categories_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_categories_obj *) ptr; + + nOuts = obj->con_categories->nOuts; + + while(1) { + + msg_categories_in = amsg_categories_filled_pop(obj->in); + msg_categories_copy(obj->con_categories->in, msg_categories_in); + amsg_categories_empty_push(obj->in, msg_categories_in); + + rtnValue = con_categories_process(obj->con_categories); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_categories_out = amsg_categories_empty_pop(obj->outs[iOut]); + msg_categories_copy(msg_categories_out, obj->con_categories->outs[iOut]); + amsg_categories_filled_push(obj->outs[iOut], msg_categories_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_categories.h b/src/aconnector/acon_categories.h new file mode 100644 index 0000000..f857dc8 --- /dev/null +++ b/src/aconnector/acon_categories.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_CATEGORIES +#define __ODAS_ACONNECTOR_CATEGORIES + + #include "../connector/con_categories.h" + #include "../amessage/amsg_categories.h" + #include "../message/msg_categories.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_categories_obj { + + amsg_categories_obj * in; + amsg_categories_obj ** outs; + con_categories_obj * con_categories; + thread_obj * thread; + + } acon_categories_obj; + + acon_categories_obj * acon_categories_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_categories_cfg * msg_categories_config); + + void acon_categories_destroy(acon_categories_obj * obj); + + void * acon_categories_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_categories.c b/src/amessage/amsg_categories.c new file mode 100644 index 0000000..f72cc9c --- /dev/null +++ b/src/amessage/amsg_categories.c @@ -0,0 +1,64 @@ + + #include "amsg_categories.h" + + amsg_categories_obj * amsg_categories_construct(const unsigned int nMessages, const msg_categories_cfg * msg_categories_config) { + + amsg_categories_obj * obj; + unsigned int iMessage; + + obj = (amsg_categories_obj *) malloc(sizeof(amsg_categories_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_categories_construct(msg_categories_config)); + + } + + return obj; + + } + + void amsg_categories_destroy(amsg_categories_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_categories_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_categories_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_categories_obj * amsg_categories_filled_pop(amsg_categories_obj * obj) { + + return ((msg_categories_obj *) fifo_pop(obj->filled)); + + } + + void amsg_categories_filled_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories) { + + fifo_push(obj->filled, (void *) msg_categories); + + } + + msg_categories_obj * amsg_categories_empty_pop(amsg_categories_obj * obj) { + + return ((msg_categories_obj *) fifo_pop(obj->empty)); + + } + + void amsg_categories_empty_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories) { + + fifo_push(obj->empty, (void *) msg_categories); + + } diff --git a/src/amessage/amsg_categories.h b/src/amessage/amsg_categories.h new file mode 100644 index 0000000..dff4ce1 --- /dev/null +++ b/src/amessage/amsg_categories.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_CATEGORIES +#define __ODAS_AMESSAGE_CATEGORIES + + #include + + #include "../message/msg_categories.h" + #include "../utils/fifo.h" + + typedef struct amsg_categories_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_categories_obj; + + amsg_categories_obj * amsg_categories_construct(const unsigned int nMessages, const msg_categories_cfg * msg_categories_config); + + void amsg_categories_destroy(amsg_categories_obj * obj); + + msg_categories_obj * amsg_categories_filled_pop(amsg_categories_obj * obj); + + void amsg_categories_filled_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories); + + msg_categories_obj * amsg_categories_empty_pop(amsg_categories_obj * obj); + + void amsg_categories_empty_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_categories.c b/src/asink/asnk_categories.c new file mode 100644 index 0000000..e2586e8 --- /dev/null +++ b/src/asink/asnk_categories.c @@ -0,0 +1,70 @@ + + #include "asnk_categories.h" + + asnk_categories_obj * asnk_categories_construct(const snk_categories_cfg * snk_categories_config, const msg_categories_cfg * msg_categories_config) { + + asnk_categories_obj * obj; + + obj = (asnk_categories_obj *) malloc(sizeof(asnk_categories_obj)); + + obj->snk_categories = snk_categories_construct(snk_categories_config, msg_categories_config); + obj->in = (amsg_categories_obj *) NULL; + + obj->thread = thread_construct(&asnk_categories_thread, (void *) obj); + + return obj; + + } + + void asnk_categories_destroy(asnk_categories_obj * obj) { + + snk_categories_destroy(obj->snk_categories); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_categories_connect(asnk_categories_obj * obj, amsg_categories_obj * in) { + + obj->in = in; + + } + + void asnk_categories_disconnect(asnk_categories_obj * obj) { + + obj->in = (amsg_categories_obj *) NULL; + + } + + void * asnk_categories_thread(void * ptr) { + + asnk_categories_obj * obj; + msg_categories_obj * msg_categories_in; + int rtnValue; + + obj = (asnk_categories_obj *) ptr; + + // Open the sink + snk_categories_open(obj->snk_categories); + + while(1) { + + // Pop a message, process, and push back + msg_categories_in = amsg_categories_filled_pop(obj->in); + snk_categories_connect(obj->snk_categories, msg_categories_in); + rtnValue = snk_categories_process(obj->snk_categories); + snk_categories_disconnect(obj->snk_categories); + amsg_categories_empty_push(obj->in, msg_categories_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_categories_close(obj->snk_categories); + + } \ No newline at end of file diff --git a/src/asink/asnk_categories.h b/src/asink/asnk_categories.h new file mode 100644 index 0000000..c584b55 --- /dev/null +++ b/src/asink/asnk_categories.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_CATEGORIES +#define __ODAS_ASINK_CATEGORIES + + #include "../amessage/amsg_categories.h" + #include "../sink/snk_categories.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_categories_obj { + + snk_categories_obj * snk_categories; + amsg_categories_obj * in; + thread_obj * thread; + + } asnk_categories_obj; + + asnk_categories_obj * asnk_categories_construct(const snk_categories_cfg * snk_categories_config, const msg_categories_cfg * msg_categories_config); + + void asnk_categories_destroy(asnk_categories_obj * obj); + + void asnk_categories_connect(asnk_categories_obj * obj, amsg_categories_obj * in); + + void asnk_categories_disconnect(asnk_categories_obj * obj); + + void * asnk_categories_thread(void * ptr); + +#endif \ No newline at end of file -- 2.34.1