Sound classification completed.
authorFrancoisGrondin <francois.grondin2@usherbrooke.ca>
Thu, 19 Oct 2017 18:43:02 +0000 (14:43 -0400)
committerFrancoisGrondin <francois.grondin2@usherbrooke.ca>
Thu, 19 Oct 2017 18:43:02 +0000 (14:43 -0400)
31 files changed:
CMakeLists.txt
config/azimut_cma.cfg
config/azimut_oma.cfg
config/respeaker.cfg
config/xmos.cfg
demo/configs.c
demo/configs.h
demo/objects.c
demo/objects.h
demo/parameters.c
demo/parameters.h
demo/profiler.c
demo/profiler.h
demo/threads.c
include/odas/odas.h
src/amodule/amod_classify.c [new file with mode: 0644]
src/amodule/amod_classify.h [new file with mode: 0644]
src/connector/con_categories.c [new file with mode: 0644]
src/connector/con_categories.h [new file with mode: 0644]
src/message/msg_categories.c [new file with mode: 0644]
src/message/msg_categories.h [new file with mode: 0644]
src/module/mod_classify.c
src/module/mod_classify.h
src/signal/category.c
src/signal/category.h
src/sink/snk_categories.c [new file with mode: 0644]
src/sink/snk_categories.h [new file with mode: 0644]
src/system/acorr2pitch.c
src/system/acorr2pitch.h
src/system/freq2acorr.c
src/system/freq2acorr.h

index c235b6d50b09a7ac1306685781d212dc9eddbb7c..adf7e5b6f38f62d55af8abefd0c8adf603c3bb5d 100644 (file)
@@ -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
index 4c7c640c8e93c6f84c525a32b0538cfa8640f72e..3206bad19583e5f7c0b7ecdbbd4e039e8689dd1a 100644 (file)
@@ -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";
+        }
+
+    }
+
+}
index bd7369814c0158d507d6fa83a995dfab5b7e7c43..d4f02c65ea1b48cfa810d22ed733d4eb6a3d6648 100644 (file)
@@ -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";
+        }
+
+    }
+
+}
index aee32f0ee83306915055788e61ccf632feb03e8e..17fe52f83c12ec037a150c2aa9a214610ffcacb5 100644 (file)
@@ -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";
+        }
+
+    }
+
+}
index 5a530912d9d4734d5b8ee55956899203a6e010d5..1348aa2717f1cea5f2301315537e39ba8ef4b988 100644 (file)
@@ -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";
+        }
+
+    }
+
+}
index bf38676f792e21a3151cb4f6a5ab669c3d1acf1b..ef1d8d184313e6ead41785f42e0a83bf9b81e18e 100644 (file)
                 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;
 
     }
                 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);
 
     }
index cbcef4c64d30f274b5fbfd117992e69b2e837592..dcc9e8ca1e7d0f1254b7778ceee7a1222c26f162 100644 (file)
         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);
index b53ecd7d36789c10c1619163bb5678ec5702ca0f..2044b0148b1da9107678fc9f7350d52d84a0a78b 100644 (file)
                 // | 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);
 
             // +------------------------------------------------------+
                     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                                                  |
                     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;
 
     }
                     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);
 
     }
                 // | 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);
 
             // +------------------------------------------------------+
                     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                                                  |
         // +----------------------------------------------------------+  
                     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;
 
     }
                     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
index 5210beccfa8ee557d39cf7afb9378aba60a4f266..d38da5d95d6d7f68ab7c2314fa1fa1873d45707c 100644 (file)
         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 {
         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);
index 8d0d42288e660c9e9650cfeb43256a9d4eaf8ba5..d1baaeab24091d1bc3573f8312ac8cc2acd9421c 100644 (file)
             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;
             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;
 
             cfg->fS = parameters_lookup_int(fileConfig, "sss.postfiltered.fS");
 
-
         // +----------------------------------------------------------+
         // | Format                                                   |
         // +----------------------------------------------------------+
         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
index 0598cac702006c80e9ed2a0e71a1cd1774f9a301..694ca2288dc6e731b3a8c9b5895ad15e90eb260c 100644 (file)
     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
index 096a5ab1f2c1f49ac305e0f2478f86160717094d..583b6f9d4198143f6c36c7369b28c32f16276277 100644 (file)
         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;                    
 
         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);
index 8b3dd65aebe11471716c5c48512749a43e4bf094..05dc808ad28bf4a5ba004b3f87c5e5be33926056 100644 (file)
         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);
index 39e5e94ba80125d137948b8beafc5b96d717c9c6..b7c5a7394b6449f44c02c90cf88355b11fa816d0 100644 (file)
                 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) {
                 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) {
                 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) {
                 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) {
 
                     }
 
+            // +------------------------------------------------------+
+            // | 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;
index 93b74a1e569ca1d7334176e6d20ea60e065ac8a9..e9e801c0470e6d4d7f7d047eb151a68391af3702 100644 (file)
@@ -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"
     #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 (file)
index 0000000..01f2c68
--- /dev/null
@@ -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 (file)
index 0000000..c831be9
--- /dev/null
@@ -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 (file)
index 0000000..05dff28
--- /dev/null
@@ -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 (file)
index 0000000..fec8ef1
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __ODAS_CONNECTOR_CATEGORIES
+#define __ODAS_CONNECTOR_CATEGORIES
+
+    #include "../message/msg_categories.h"
+
+    #include <stdlib.h>
+    #include <stdio.h>
+
+    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 (file)
index 0000000..aec6139
--- /dev/null
@@ -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 (file)
index 0000000..1ef1a2c
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __ODAS_MESSAGE_CATEGORIES
+#define __ODAS_MESSAGE_CATEGORIES
+
+    #include <stdlib.h>
+    #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
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..24cce837358837e17ee4331eceb6c231aad3bb24 100644 (file)
@@ -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
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..1297ee1cb5fbaba2d78a1fb1dd2a116f0f4c1f3b 100644 (file)
@@ -0,0 +1,71 @@
+#ifndef __ODAS_MODULE_CLASSIFY
+#define __ODAS_MODULE_CLASSIFY
+
+    #include <stdlib.h>
+
+    #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
index 2ee23033e7d7694d61bc8524830820dff3caecf3..109b2ffd4681627f8872a1266427bb0e4a351ac7 100644 (file)
 
     }
 
+    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;
index 11e4013b414bc8bc123a2fbc5d1fa1353f85e6c9..3a86a256b68ab52420b458f236a11dffae1d5737 100644 (file)
 
     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 (file)
index 0000000..25e429c
--- /dev/null
@@ -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 (file)
index 0000000..6923311
--- /dev/null
@@ -0,0 +1,67 @@
+#ifndef __ODAS_SINK_CATEGORIES
+#define __ODAS_SINK_CATEGORIES
+
+    #include <stdlib.h>
+    #include <stdio.h>
+    #include <string.h>
+
+    #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
index d7378df9c584a3272d0cfa731204e0542cdc52ba..81ad2ac1b3e84f0b5e41ba13698dc1ad849b4792 100644 (file)
@@ -35,6 +35,7 @@
         float maxValue;
         unsigned int maxIndex;
         char isPeak;
+        char peakFound;
 
         unsigned int peakPrev;
         unsigned int peakNow;
 
         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;
                         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));
+            }
 
         }
 
index 3e2adade95e4ce164aa652b871d6d2074d1e9199..abf9b91dfebd8352c05be9d5657347dd25755410 100644 (file)
@@ -4,14 +4,14 @@
     #include "../signal/acorr.h"
     #include "../signal/pitch.h"
 
+    #include <math.h>
+
     typedef struct acorr2pitch_obj {
 
         unsigned int nSignals;
         unsigned int halfFrameSize;
         unsigned int frameSize;
         unsigned int winSize;
-        unsigned int minBin;
-        unsigned int maxBin;
 
     } acorr2pitch_obj;
 
index d67bae8b45b8069c25079058dafb432ae3269d7d..9594df7f16e138164c155eabcab0626a47efe9aa 100644 (file)
@@ -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);
 
     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);
 
         }
 
index f17f9a63f2d83b2edd925091391442a630055244..d2941b349b27f7c3db4fa61751737d7904b02dd3 100644 (file)
@@ -15,7 +15,8 @@
         unsigned int halfFrameSize;
         unsigned int frameSize;
 
-        float * array;
+        float * arrayIn;
+        float * arrayOut;
 
         fft_obj * fft;