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
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
};
}
+
+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";
+ }
+
+ }
+
+}
# Input with raw signal from microphones
interface: {
type = "file";
- path = "input_oma.raw";
+ path = "noise_030.raw";
}
}
};
}
+
+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";
+ }
+
+ }
+
+}
};
-}
\ 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";
+ }
+
+ }
+
+}
};
-}
\ 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";
+ }
+
+ }
+
+}
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);
}
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);
// | 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
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);
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
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
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;
}
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 +
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 +
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);
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);
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;
+ #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"
#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"
--- /dev/null
+
+ #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;
+ }
+
+ }
+
+ }
--- /dev/null
+#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
--- /dev/null
+
+ #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
--- /dev/null
+#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
--- /dev/null
+
+ #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);
+
+ }
--- /dev/null
+#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
+
+ #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
+#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
}
+ 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;
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
--- /dev/null
+
+ #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
--- /dev/null
+#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
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));
+ }
}
#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;
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);
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);
}
unsigned int halfFrameSize;
unsigned int frameSize;
- float * array;
+ float * arrayIn;
+ float * arrayOut;
fft_obj * fft;