From 1316c29ebaa55f6be7d1c00a4f66028167e2ddb5 Mon Sep 17 00:00:00 2001 From: FrancoisGrondin Date: Fri, 22 Dec 2017 15:46:19 -0500 Subject: [PATCH] * copy dev to master working tree --- CMakeLists.txt | 222 ++++ README.md | 7 +- config/azimut_cma.cfg | 445 +++++++ config/azimut_oma.cfg | 404 ++++++ config/beam.cfg | 355 ++++++ config/respeaker.cfg | 322 +++++ config/xmos.cfg | 347 +++++ demo/client.c | 292 +++++ demo/configs.c | 502 ++++++++ demo/configs.h | 68 + demo/debug.c | 45 + demo/objects.c | 1514 ++++++++++++++++++++++ demo/objects.h | 130 ++ demo/parameters.c | 2027 ++++++++++++++++++++++++++++++ demo/parameters.h | 104 ++ demo/profiler.c | 177 +++ demo/profiler.h | 71 ++ demo/server.c | 107 ++ demo/threads.c | 1086 ++++++++++++++++ demo/threads.h | 23 + include/odas/odas.h | 66 + octave/pots2var.m | 25 + octave/spectra2var.m | 36 + octave/tracks2var.m | 34 + src/aconnector/acon_categories.c | 85 ++ src/aconnector/acon_categories.h | 27 + src/aconnector/acon_hops.c | 85 ++ src/aconnector/acon_hops.h | 27 + src/aconnector/acon_pots.c | 85 ++ src/aconnector/acon_pots.h | 27 + src/aconnector/acon_powers.c | 85 ++ src/aconnector/acon_powers.h | 27 + src/aconnector/acon_spectra.c | 85 ++ src/aconnector/acon_spectra.h | 27 + src/aconnector/acon_targets.c | 84 ++ src/aconnector/acon_targets.h | 27 + src/aconnector/acon_tracks.c | 84 ++ src/aconnector/acon_tracks.h | 27 + src/ainjector/ainj_targets.c | 72 ++ src/ainjector/ainj_targets.h | 28 + src/amessage/amsg_categories.c | 64 + src/amessage/amsg_categories.h | 29 + src/amessage/amsg_hops.c | 64 + src/amessage/amsg_hops.h | 29 + src/amessage/amsg_pots.c | 64 + src/amessage/amsg_pots.h | 29 + src/amessage/amsg_powers.c | 64 + src/amessage/amsg_powers.h | 29 + src/amessage/amsg_spectra.c | 64 + src/amessage/amsg_spectra.h | 29 + src/amessage/amsg_targets.c | 64 + src/amessage/amsg_targets.h | 29 + src/amessage/amsg_tracks.c | 64 + src/amessage/amsg_tracks.h | 29 + src/amodule/amod_classify.c | 77 ++ src/amodule/amod_classify.h | 30 + src/amodule/amod_istft.c | 71 ++ src/amodule/amod_istft.h | 28 + src/amodule/amod_mapping.c | 71 ++ src/amodule/amod_mapping.h | 27 + src/amodule/amod_noise.c | 72 ++ src/amodule/amod_noise.h | 28 + src/amodule/amod_resample.c | 87 ++ src/amodule/amod_resample.h | 27 + src/amodule/amod_ssl.c | 72 ++ src/amodule/amod_ssl.h | 29 + src/amodule/amod_sss.c | 89 ++ src/amodule/amod_sss.h | 32 + src/amodule/amod_sst.c | 77 ++ src/amodule/amod_sst.h | 31 + src/amodule/amod_stft.c | 71 ++ src/amodule/amod_stft.h | 28 + src/amodule/amod_volume.c | 71 ++ src/amodule/amod_volume.h | 27 + src/asink/asnk_categories.c | 70 ++ src/asink/asnk_categories.h | 28 + src/asink/asnk_hops.c | 70 ++ src/asink/asnk_hops.h | 28 + src/asink/asnk_pots.c | 70 ++ src/asink/asnk_pots.h | 28 + src/asink/asnk_powers.c | 70 ++ src/asink/asnk_powers.h | 28 + src/asink/asnk_spectra.c | 70 ++ src/asink/asnk_spectra.h | 28 + src/asink/asnk_tracks.c | 70 ++ src/asink/asnk_tracks.h | 28 + src/asource/asrc_hops.c | 81 ++ src/asource/asrc_hops.h | 28 + src/connector/con_categories.c | 57 + src/connector/con_categories.h | 24 + src/connector/con_hops.c | 57 + src/connector/con_hops.h | 24 + src/connector/con_pots.c | 57 + src/connector/con_pots.h | 24 + src/connector/con_powers.c | 57 + src/connector/con_powers.h | 24 + src/connector/con_spectra.c | 57 + src/connector/con_spectra.h | 24 + src/connector/con_targets.c | 57 + src/connector/con_targets.h | 24 + src/connector/con_tracks.c | 57 + src/connector/con_tracks.h | 24 + src/general/format.c | 152 +++ src/general/format.h | 41 + src/general/interface.c | 419 ++++++ src/general/interface.h | 51 + src/general/link.c | 47 + src/general/link.h | 23 + src/general/mic.c | 118 ++ src/general/mic.h | 28 + src/general/samplerate.c | 57 + src/general/samplerate.h | 22 + src/general/soundspeed.c | 57 + src/general/soundspeed.h | 22 + src/general/spatialfilter.c | 49 + src/general/spatialfilter.h | 24 + src/general/thread.c | 61 + src/general/thread.h | 30 + src/init/combining.c | 61 + src/init/combining.h | 9 + src/init/delay.c | 148 +++ src/init/delay.h | 24 + src/init/directivity.c | 331 +++++ src/init/directivity.h | 31 + src/init/hit.c | 288 +++++ src/init/hit.h | 26 + src/init/linking.c | 230 ++++ src/init/linking.h | 20 + src/init/scanning.c | 129 ++ src/init/scanning.h | 25 + src/init/space.c | 850 +++++++++++++ src/init/space.h | 30 + src/init/windowing.c | 55 + src/init/windowing.h | 14 + src/injector/inj_targets.c | 110 ++ src/injector/inj_targets.h | 51 + src/message/msg_categories.c | 81 ++ src/message/msg_categories.h | 38 + src/message/msg_hops.c | 82 ++ src/message/msg_hops.h | 40 + src/message/msg_pots.c | 80 ++ src/message/msg_pots.h | 38 + src/message/msg_powers.c | 91 ++ src/message/msg_powers.h | 40 + src/message/msg_spectra.c | 91 ++ src/message/msg_spectra.h | 40 + src/message/msg_targets.c | 80 ++ src/message/msg_targets.h | 38 + src/message/msg_tracks.c | 79 ++ src/message/msg_tracks.h | 38 + src/module/mod_classify.c | 136 ++ src/module/mod_classify.h | 74 ++ src/module/mod_istft.c | 89 ++ src/module/mod_istft.h | 42 + src/module/mod_mapping.c | 97 ++ src/module/mod_mapping.h | 42 + src/module/mod_noise.c | 107 ++ src/module/mod_noise.h | 46 + src/module/mod_resample.c | 475 +++++++ src/module/mod_resample.h | 94 ++ src/module/mod_ssl.c | 336 +++++ src/module/mod_ssl.h | 104 ++ src/module/mod_sss.c | 726 +++++++++++ src/module/mod_sss.h | 154 +++ src/module/mod_sst.c | 1269 +++++++++++++++++++ src/module/mod_sst.h | 142 +++ src/module/mod_stft.c | 90 ++ src/module/mod_stft.h | 41 + src/module/mod_volume.c | 81 ++ src/module/mod_volume.h | 38 + src/signal/acorr.c | 90 ++ src/signal/acorr.h | 26 + src/signal/aimg.c | 42 + src/signal/aimg.h | 21 + src/signal/area.c | 90 ++ src/signal/area.h | 38 + src/signal/assignation.c | 43 + src/signal/assignation.h | 22 + src/signal/beampattern.c | 54 + src/signal/beampattern.h | 27 + src/signal/category.c | 47 + src/signal/category.h | 25 + src/signal/coherence.c | 43 + src/signal/coherence.h | 22 + src/signal/delta.c | 65 + src/signal/delta.h | 23 + src/signal/demixing.c | 95 ++ src/signal/demixing.h | 28 + src/signal/env.c | 101 ++ src/signal/env.h | 28 + src/signal/frame.c | 92 ++ src/signal/frame.h | 24 + src/signal/freq.c | 102 ++ src/signal/freq.h | 28 + src/signal/gain.c | 46 + src/signal/gain.h | 22 + src/signal/hop.c | 100 ++ src/signal/hop.h | 28 + src/signal/impulse.c | 23 + src/signal/impulse.h | 18 + src/signal/index.c | 57 + src/signal/index.h | 23 + src/signal/kalman.c | 28 + src/signal/kalman.h | 22 + src/signal/map.c | 46 + src/signal/map.h | 22 + src/signal/mask.c | 46 + src/signal/mask.h | 22 + src/signal/mixture.c | 128 ++ src/signal/mixture.h | 35 + src/signal/pair.c | 65 + src/signal/pair.h | 23 + src/signal/particle.c | 49 + src/signal/particle.h | 22 + src/signal/pitch.c | 47 + src/signal/pitch.h | 25 + src/signal/point.c | 69 + src/signal/point.h | 23 + src/signal/postprob.c | 64 + src/signal/postprob.h | 25 + src/signal/pot.c | 69 + src/signal/pot.h | 27 + src/signal/scan.c | 81 ++ src/signal/scan.h | 33 + src/signal/spatialgain.c | 78 ++ src/signal/spatialgain.h | 25 + src/signal/spatialindex.c | 95 ++ src/signal/spatialindex.h | 26 + src/signal/spatialmask.c | 87 ++ src/signal/spatialmask.h | 25 + src/signal/steer.c | 85 ++ src/signal/steer.h | 26 + src/signal/target.c | 110 ++ src/signal/target.h | 28 + src/signal/tau.c | 51 + src/signal/tau.h | 23 + src/signal/tdoa.c | 74 ++ src/signal/tdoa.h | 24 + src/signal/track.c | 130 ++ src/signal/track.h | 30 + src/signal/triangle.c | 45 + src/signal/triangle.h | 21 + src/signal/window.c | 23 + src/signal/window.h | 18 + src/signal/xcorr.c | 100 ++ src/signal/xcorr.h | 28 + src/sink/snk_categories.c | 391 ++++++ src/sink/snk_categories.h | 93 ++ src/sink/snk_hops.c | 446 +++++++ src/sink/snk_hops.h | 96 ++ src/sink/snk_pots.c | 388 ++++++ src/sink/snk_pots.h | 94 ++ src/sink/snk_powers.c | 195 +++ src/sink/snk_powers.h | 66 + src/sink/snk_spectra.c | 200 +++ src/sink/snk_spectra.h | 63 + src/sink/snk_tracks.c | 383 ++++++ src/sink/snk_tracks.h | 92 ++ src/source/src_hops.c | 493 ++++++++ src/source/src_hops.h | 83 ++ src/system/acorr2pitch.c | 106 ++ src/system/acorr2pitch.h | 24 + src/system/demixing2env.c | 82 ++ src/system/demixing2env.h | 28 + src/system/demixing2freq.c | 85 ++ src/system/demixing2freq.h | 28 + src/system/env2env.c | 1264 +++++++++++++++++++ src/system/env2env.h | 188 +++ src/system/frame2freq.c | 51 + src/system/frame2freq.h | 30 + src/system/frame2hop.c | 67 + src/system/frame2hop.h | 26 + src/system/freq2acorr.c | 62 + src/system/freq2acorr.h | 31 + src/system/freq2env.c | 46 + src/system/freq2env.h | 21 + src/system/freq2frame.c | 51 + src/system/freq2frame.h | 30 + src/system/freq2freq.c | 256 ++++ src/system/freq2freq.h | 88 ++ src/system/freq2xcorr.c | 53 + src/system/freq2xcorr.h | 28 + src/system/gain2mask.c | 44 + src/system/gain2mask.h | 24 + src/system/hop2frame.c | 59 + src/system/hop2frame.h | 26 + src/system/hop2hop.c | 268 ++++ src/system/hop2hop.h | 67 + src/system/kalman2coherence.c | 171 +++ src/system/kalman2coherence.h | 57 + src/system/kalman2kalman.c | 249 ++++ src/system/kalman2kalman.h | 66 + src/system/mixture2mixture.c | 230 ++++ src/system/mixture2mixture.h | 33 + src/system/particle2coherence.c | 68 + src/system/particle2coherence.h | 23 + src/system/particle2particle.c | 293 +++++ src/system/particle2particle.h | 63 + src/system/pitch2category.c | 158 +++ src/system/pitch2category.h | 43 + src/system/steer2demixing.c | 672 ++++++++++ src/system/steer2demixing.h | 95 ++ src/system/track2gain.c | 116 ++ src/system/track2gain.h | 28 + src/system/track2steer.c | 106 ++ src/system/track2steer.h | 34 + src/system/xcorr2aimg.c | 52 + src/system/xcorr2aimg.h | 25 + src/system/xcorr2xcorr.c | 119 ++ src/system/xcorr2xcorr.h | 26 + src/utils/cmatrix.c | 214 ++++ src/utils/cmatrix.h | 44 + src/utils/fft.c | 77 ++ src/utils/fft.h | 66 + src/utils/fifo.c | 92 ++ src/utils/fifo.h | 34 + src/utils/gaussian.c | 558 ++++++++ src/utils/gaussian.h | 275 ++++ src/utils/gaussjordan.c | 169 +++ src/utils/gaussjordan.h | 22 + src/utils/inverse.c | 98 ++ src/utils/inverse.h | 56 + src/utils/matrix.c | 262 ++++ src/utils/matrix.h | 98 ++ src/utils/pcm.c | 138 ++ src/utils/pcm.h | 13 + src/utils/random.c | 186 +++ src/utils/random.h | 96 ++ src/utils/transcendental.c | 78 ++ src/utils/transcendental.h | 26 + 330 files changed, 36082 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 config/azimut_cma.cfg create mode 100644 config/azimut_oma.cfg create mode 100644 config/beam.cfg create mode 100644 config/respeaker.cfg create mode 100644 config/xmos.cfg create mode 100644 demo/client.c create mode 100644 demo/configs.c create mode 100644 demo/configs.h create mode 100644 demo/debug.c create mode 100644 demo/objects.c create mode 100644 demo/objects.h create mode 100644 demo/parameters.c create mode 100644 demo/parameters.h create mode 100644 demo/profiler.c create mode 100644 demo/profiler.h create mode 100644 demo/server.c create mode 100644 demo/threads.c create mode 100644 demo/threads.h create mode 100644 include/odas/odas.h create mode 100644 octave/pots2var.m create mode 100644 octave/spectra2var.m create mode 100644 octave/tracks2var.m create mode 100644 src/aconnector/acon_categories.c create mode 100644 src/aconnector/acon_categories.h create mode 100644 src/aconnector/acon_hops.c create mode 100644 src/aconnector/acon_hops.h create mode 100644 src/aconnector/acon_pots.c create mode 100644 src/aconnector/acon_pots.h create mode 100644 src/aconnector/acon_powers.c create mode 100644 src/aconnector/acon_powers.h create mode 100644 src/aconnector/acon_spectra.c create mode 100644 src/aconnector/acon_spectra.h create mode 100644 src/aconnector/acon_targets.c create mode 100644 src/aconnector/acon_targets.h create mode 100644 src/aconnector/acon_tracks.c create mode 100644 src/aconnector/acon_tracks.h create mode 100644 src/ainjector/ainj_targets.c create mode 100644 src/ainjector/ainj_targets.h create mode 100644 src/amessage/amsg_categories.c create mode 100644 src/amessage/amsg_categories.h create mode 100644 src/amessage/amsg_hops.c create mode 100644 src/amessage/amsg_hops.h create mode 100644 src/amessage/amsg_pots.c create mode 100644 src/amessage/amsg_pots.h create mode 100644 src/amessage/amsg_powers.c create mode 100644 src/amessage/amsg_powers.h create mode 100644 src/amessage/amsg_spectra.c create mode 100644 src/amessage/amsg_spectra.h create mode 100644 src/amessage/amsg_targets.c create mode 100644 src/amessage/amsg_targets.h create mode 100644 src/amessage/amsg_tracks.c create mode 100644 src/amessage/amsg_tracks.h create mode 100644 src/amodule/amod_classify.c create mode 100644 src/amodule/amod_classify.h create mode 100644 src/amodule/amod_istft.c create mode 100644 src/amodule/amod_istft.h create mode 100644 src/amodule/amod_mapping.c create mode 100644 src/amodule/amod_mapping.h create mode 100644 src/amodule/amod_noise.c create mode 100644 src/amodule/amod_noise.h create mode 100644 src/amodule/amod_resample.c create mode 100644 src/amodule/amod_resample.h create mode 100644 src/amodule/amod_ssl.c create mode 100644 src/amodule/amod_ssl.h create mode 100644 src/amodule/amod_sss.c create mode 100644 src/amodule/amod_sss.h create mode 100644 src/amodule/amod_sst.c create mode 100644 src/amodule/amod_sst.h create mode 100644 src/amodule/amod_stft.c create mode 100644 src/amodule/amod_stft.h create mode 100644 src/amodule/amod_volume.c create mode 100644 src/amodule/amod_volume.h create mode 100644 src/asink/asnk_categories.c create mode 100644 src/asink/asnk_categories.h create mode 100644 src/asink/asnk_hops.c create mode 100644 src/asink/asnk_hops.h create mode 100644 src/asink/asnk_pots.c create mode 100644 src/asink/asnk_pots.h create mode 100644 src/asink/asnk_powers.c create mode 100644 src/asink/asnk_powers.h create mode 100644 src/asink/asnk_spectra.c create mode 100644 src/asink/asnk_spectra.h create mode 100644 src/asink/asnk_tracks.c create mode 100644 src/asink/asnk_tracks.h create mode 100644 src/asource/asrc_hops.c create mode 100644 src/asource/asrc_hops.h create mode 100644 src/connector/con_categories.c create mode 100644 src/connector/con_categories.h create mode 100644 src/connector/con_hops.c create mode 100644 src/connector/con_hops.h create mode 100644 src/connector/con_pots.c create mode 100644 src/connector/con_pots.h create mode 100644 src/connector/con_powers.c create mode 100644 src/connector/con_powers.h create mode 100644 src/connector/con_spectra.c create mode 100644 src/connector/con_spectra.h create mode 100644 src/connector/con_targets.c create mode 100644 src/connector/con_targets.h create mode 100644 src/connector/con_tracks.c create mode 100644 src/connector/con_tracks.h create mode 100644 src/general/format.c create mode 100644 src/general/format.h create mode 100644 src/general/interface.c create mode 100644 src/general/interface.h create mode 100644 src/general/link.c create mode 100644 src/general/link.h create mode 100644 src/general/mic.c create mode 100644 src/general/mic.h create mode 100644 src/general/samplerate.c create mode 100644 src/general/samplerate.h create mode 100644 src/general/soundspeed.c create mode 100644 src/general/soundspeed.h create mode 100644 src/general/spatialfilter.c create mode 100644 src/general/spatialfilter.h create mode 100644 src/general/thread.c create mode 100644 src/general/thread.h create mode 100644 src/init/combining.c create mode 100644 src/init/combining.h create mode 100644 src/init/delay.c create mode 100644 src/init/delay.h create mode 100644 src/init/directivity.c create mode 100644 src/init/directivity.h create mode 100644 src/init/hit.c create mode 100644 src/init/hit.h create mode 100644 src/init/linking.c create mode 100644 src/init/linking.h create mode 100644 src/init/scanning.c create mode 100644 src/init/scanning.h create mode 100644 src/init/space.c create mode 100644 src/init/space.h create mode 100644 src/init/windowing.c create mode 100644 src/init/windowing.h create mode 100644 src/injector/inj_targets.c create mode 100644 src/injector/inj_targets.h create mode 100644 src/message/msg_categories.c create mode 100644 src/message/msg_categories.h create mode 100644 src/message/msg_hops.c create mode 100644 src/message/msg_hops.h create mode 100644 src/message/msg_pots.c create mode 100644 src/message/msg_pots.h create mode 100644 src/message/msg_powers.c create mode 100644 src/message/msg_powers.h create mode 100644 src/message/msg_spectra.c create mode 100644 src/message/msg_spectra.h create mode 100644 src/message/msg_targets.c create mode 100644 src/message/msg_targets.h create mode 100644 src/message/msg_tracks.c create mode 100644 src/message/msg_tracks.h create mode 100644 src/module/mod_classify.c create mode 100644 src/module/mod_classify.h create mode 100644 src/module/mod_istft.c create mode 100644 src/module/mod_istft.h create mode 100644 src/module/mod_mapping.c create mode 100644 src/module/mod_mapping.h create mode 100644 src/module/mod_noise.c create mode 100644 src/module/mod_noise.h create mode 100644 src/module/mod_resample.c create mode 100644 src/module/mod_resample.h create mode 100644 src/module/mod_ssl.c create mode 100644 src/module/mod_ssl.h create mode 100644 src/module/mod_sss.c create mode 100644 src/module/mod_sss.h create mode 100644 src/module/mod_sst.c create mode 100644 src/module/mod_sst.h create mode 100644 src/module/mod_stft.c create mode 100644 src/module/mod_stft.h create mode 100644 src/module/mod_volume.c create mode 100644 src/module/mod_volume.h create mode 100644 src/signal/acorr.c create mode 100644 src/signal/acorr.h create mode 100644 src/signal/aimg.c create mode 100644 src/signal/aimg.h create mode 100644 src/signal/area.c create mode 100644 src/signal/area.h create mode 100644 src/signal/assignation.c create mode 100644 src/signal/assignation.h create mode 100644 src/signal/beampattern.c create mode 100644 src/signal/beampattern.h create mode 100644 src/signal/category.c create mode 100644 src/signal/category.h create mode 100644 src/signal/coherence.c create mode 100644 src/signal/coherence.h create mode 100644 src/signal/delta.c create mode 100644 src/signal/delta.h create mode 100644 src/signal/demixing.c create mode 100644 src/signal/demixing.h create mode 100644 src/signal/env.c create mode 100644 src/signal/env.h create mode 100644 src/signal/frame.c create mode 100644 src/signal/frame.h create mode 100644 src/signal/freq.c create mode 100644 src/signal/freq.h create mode 100644 src/signal/gain.c create mode 100644 src/signal/gain.h create mode 100644 src/signal/hop.c create mode 100644 src/signal/hop.h create mode 100644 src/signal/impulse.c create mode 100644 src/signal/impulse.h create mode 100644 src/signal/index.c create mode 100644 src/signal/index.h create mode 100644 src/signal/kalman.c create mode 100644 src/signal/kalman.h create mode 100644 src/signal/map.c create mode 100644 src/signal/map.h create mode 100644 src/signal/mask.c create mode 100644 src/signal/mask.h create mode 100644 src/signal/mixture.c create mode 100644 src/signal/mixture.h create mode 100644 src/signal/pair.c create mode 100644 src/signal/pair.h create mode 100644 src/signal/particle.c create mode 100644 src/signal/particle.h create mode 100644 src/signal/pitch.c create mode 100644 src/signal/pitch.h create mode 100644 src/signal/point.c create mode 100644 src/signal/point.h create mode 100644 src/signal/postprob.c create mode 100644 src/signal/postprob.h create mode 100644 src/signal/pot.c create mode 100644 src/signal/pot.h create mode 100644 src/signal/scan.c create mode 100644 src/signal/scan.h create mode 100644 src/signal/spatialgain.c create mode 100644 src/signal/spatialgain.h create mode 100644 src/signal/spatialindex.c create mode 100644 src/signal/spatialindex.h create mode 100644 src/signal/spatialmask.c create mode 100644 src/signal/spatialmask.h create mode 100644 src/signal/steer.c create mode 100644 src/signal/steer.h create mode 100644 src/signal/target.c create mode 100644 src/signal/target.h create mode 100644 src/signal/tau.c create mode 100644 src/signal/tau.h create mode 100644 src/signal/tdoa.c create mode 100644 src/signal/tdoa.h create mode 100644 src/signal/track.c create mode 100644 src/signal/track.h create mode 100644 src/signal/triangle.c create mode 100644 src/signal/triangle.h create mode 100644 src/signal/window.c create mode 100644 src/signal/window.h create mode 100644 src/signal/xcorr.c create mode 100644 src/signal/xcorr.h create mode 100644 src/sink/snk_categories.c create mode 100644 src/sink/snk_categories.h create mode 100644 src/sink/snk_hops.c create mode 100644 src/sink/snk_hops.h create mode 100644 src/sink/snk_pots.c create mode 100644 src/sink/snk_pots.h create mode 100644 src/sink/snk_powers.c create mode 100644 src/sink/snk_powers.h create mode 100644 src/sink/snk_spectra.c create mode 100644 src/sink/snk_spectra.h create mode 100644 src/sink/snk_tracks.c create mode 100644 src/sink/snk_tracks.h create mode 100644 src/source/src_hops.c create mode 100644 src/source/src_hops.h create mode 100644 src/system/acorr2pitch.c create mode 100644 src/system/acorr2pitch.h create mode 100644 src/system/demixing2env.c create mode 100644 src/system/demixing2env.h create mode 100644 src/system/demixing2freq.c create mode 100644 src/system/demixing2freq.h create mode 100644 src/system/env2env.c create mode 100644 src/system/env2env.h create mode 100644 src/system/frame2freq.c create mode 100644 src/system/frame2freq.h create mode 100644 src/system/frame2hop.c create mode 100644 src/system/frame2hop.h create mode 100644 src/system/freq2acorr.c create mode 100644 src/system/freq2acorr.h create mode 100644 src/system/freq2env.c create mode 100644 src/system/freq2env.h create mode 100644 src/system/freq2frame.c create mode 100644 src/system/freq2frame.h create mode 100644 src/system/freq2freq.c create mode 100644 src/system/freq2freq.h create mode 100644 src/system/freq2xcorr.c create mode 100644 src/system/freq2xcorr.h create mode 100644 src/system/gain2mask.c create mode 100644 src/system/gain2mask.h create mode 100644 src/system/hop2frame.c create mode 100644 src/system/hop2frame.h create mode 100644 src/system/hop2hop.c create mode 100644 src/system/hop2hop.h create mode 100644 src/system/kalman2coherence.c create mode 100644 src/system/kalman2coherence.h create mode 100644 src/system/kalman2kalman.c create mode 100644 src/system/kalman2kalman.h create mode 100644 src/system/mixture2mixture.c create mode 100644 src/system/mixture2mixture.h create mode 100644 src/system/particle2coherence.c create mode 100644 src/system/particle2coherence.h create mode 100644 src/system/particle2particle.c create mode 100644 src/system/particle2particle.h create mode 100644 src/system/pitch2category.c create mode 100644 src/system/pitch2category.h create mode 100644 src/system/steer2demixing.c create mode 100644 src/system/steer2demixing.h create mode 100644 src/system/track2gain.c create mode 100644 src/system/track2gain.h create mode 100644 src/system/track2steer.c create mode 100644 src/system/track2steer.h create mode 100644 src/system/xcorr2aimg.c create mode 100644 src/system/xcorr2aimg.h create mode 100644 src/system/xcorr2xcorr.c create mode 100644 src/system/xcorr2xcorr.h create mode 100644 src/utils/cmatrix.c create mode 100644 src/utils/cmatrix.h create mode 100644 src/utils/fft.c create mode 100644 src/utils/fft.h create mode 100644 src/utils/fifo.c create mode 100644 src/utils/fifo.h create mode 100644 src/utils/gaussian.c create mode 100644 src/utils/gaussian.h create mode 100644 src/utils/gaussjordan.c create mode 100644 src/utils/gaussjordan.h create mode 100644 src/utils/inverse.c create mode 100644 src/utils/inverse.h create mode 100644 src/utils/matrix.c create mode 100644 src/utils/matrix.h create mode 100644 src/utils/pcm.c create mode 100644 src/utils/pcm.h create mode 100644 src/utils/random.c create mode 100644 src/utils/random.h create mode 100644 src/utils/transcendental.c create mode 100644 src/utils/transcendental.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8a1806c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,222 @@ +cmake_minimum_required(VERSION 2.4.6) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(PC_FFTW3 REQUIRED fftw3f) +pkg_check_modules(PC_ALSA REQUIRED alsa) +pkg_check_modules(PC_LIBCONFIG REQUIRED libconfig) + +include_directories("${PROJECT_SOURCE_DIR}/include") + +set(CMAKE_BUILD_TYPE "Release") + +set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin") +set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/lib") + +set(SRC + + src/general/format.c + src/general/interface.c + src/general/link.c + src/general/mic.c + src/general/samplerate.c + src/general/soundspeed.c + src/general/spatialfilter.c + src/general/thread.c + + src/init/combining.c + src/init/delay.c + src/init/directivity.c + src/init/hit.c + src/init/linking.c + src/init/scanning.c + src/init/space.c + src/init/windowing.c + + src/signal/acorr.c + src/signal/aimg.c + src/signal/area.c + src/signal/assignation.c + src/signal/beampattern.c + src/signal/category.c + src/signal/coherence.c + src/signal/delta.c + src/signal/demixing.c + src/signal/env.c + src/signal/frame.c + src/signal/freq.c + src/signal/gain.c + src/signal/hop.c + src/signal/index.c + src/signal/kalman.c + src/signal/map.c + src/signal/mask.c + src/signal/mixture.c + src/signal/pair.c + src/signal/particle.c + src/signal/pitch.c + src/signal/point.c + src/signal/postprob.c + src/signal/pot.c + src/signal/scan.c + src/signal/spatialgain.c + src/signal/spatialindex.c + src/signal/spatialmask.c + src/signal/steer.c + src/signal/target.c + src/signal/tau.c + src/signal/tdoa.c + src/signal/track.c + src/signal/triangle.c + src/signal/window.c + src/signal/xcorr.c + + src/system/acorr2pitch.c + src/system/demixing2env.c + src/system/demixing2freq.c + src/system/env2env.c + src/system/hop2hop.c + src/system/hop2frame.c + src/system/frame2freq.c + src/system/freq2acorr.c + src/system/freq2env.c + src/system/freq2freq.c + src/system/freq2frame.c + src/system/freq2xcorr.c + src/system/frame2hop.c + src/system/gain2mask.c + src/system/kalman2coherence.c + src/system/kalman2kalman.c + src/system/mixture2mixture.c + src/system/particle2coherence.c + src/system/particle2particle.c + src/system/pitch2category.c + src/system/steer2demixing.c + src/system/track2gain.c + src/system/track2steer.c + src/system/xcorr2aimg.c + src/system/xcorr2xcorr.c + + src/utils/cmatrix.c + src/utils/fft.c + src/utils/fifo.c + src/utils/gaussian.c + src/utils/gaussjordan.c + src/utils/inverse.c + src/utils/matrix.c + src/utils/pcm.c + src/utils/random.c + src/utils/transcendental.c + + src/aconnector/acon_categories.c + src/aconnector/acon_hops.c + src/aconnector/acon_pots.c + src/aconnector/acon_powers.c + src/aconnector/acon_spectra.c + src/aconnector/acon_targets.c + src/aconnector/acon_tracks.c + src/ainjector/ainj_targets.c + src/amessage/amsg_categories.c + src/amessage/amsg_hops.c + src/amessage/amsg_pots.c + src/amessage/amsg_powers.c + src/amessage/amsg_spectra.c + src/amessage/amsg_targets.c + src/amessage/amsg_tracks.c + src/amodule/amod_classify.c + src/amodule/amod_istft.c + src/amodule/amod_mapping.c + src/amodule/amod_noise.c + src/amodule/amod_resample.c + src/amodule/amod_ssl.c + src/amodule/amod_sss.c + src/amodule/amod_sst.c + src/amodule/amod_stft.c + src/amodule/amod_volume.c + src/asink/asnk_categories.c + src/asink/asnk_hops.c + src/asink/asnk_pots.c + src/asink/asnk_powers.c + src/asink/asnk_spectra.c + src/asink/asnk_tracks.c + src/asource/asrc_hops.c + + src/connector/con_categories.c + src/connector/con_hops.c + src/connector/con_pots.c + src/connector/con_powers.c + src/connector/con_spectra.c + src/connector/con_targets.c + src/connector/con_tracks.c + src/injector/inj_targets.c + src/message/msg_categories.c + src/message/msg_hops.c + src/message/msg_pots.c + src/message/msg_powers.c + src/message/msg_spectra.c + src/message/msg_targets.c + src/message/msg_tracks.c + src/module/mod_classify.c + src/module/mod_istft.c + src/module/mod_mapping.c + src/module/mod_noise.c + src/module/mod_resample.c + src/module/mod_ssl.c + src/module/mod_sss.c + src/module/mod_sst.c + src/module/mod_stft.c + src/module/mod_volume.c + src/sink/snk_categories.c + src/sink/snk_hops.c + src/sink/snk_pots.c + src/sink/snk_powers.c + src/sink/snk_spectra.c + src/sink/snk_tracks.c + src/source/src_hops.c + +) + +add_library(odas SHARED + ${SRC} +) + +target_link_libraries(odas + ${PC_FFTW3_LIBRARIES} + ${PC_ALSA_LIBRARIES} + ${PC_LIBCONFIG_LIBRARIES} + m + pthread +) + +add_executable(odascore + demo/client.c + demo/configs.c + demo/objects.c + demo/parameters.c + demo/profiler.c + demo/threads.c +) +target_link_libraries(odascore + odas +) + +add_executable(debug + demo/debug.c +) +target_link_libraries(debug + odas +) + +add_executable(server + demo/server.c +) +target_link_libraries(server + odas +) + +install(TARGETS odas DESTINATION lib) + + diff --git a/README.md b/README.md index e4378ac..0218c12 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# odas -ODAS: Open embeddeD Audition System +# ODAS + +ODAS stands for Open embeddeD Audition System. This is a library dedicated to perform sound source localization, tracking, separation and post-filtering. ODAS is coded entirely in C, for more portability, and is optimized to run easily on low-cost embedded hardware. ODAS is free and open source. + +Have a look at the wiki for more info. \ No newline at end of file diff --git a/config/azimut_cma.cfg b/config/azimut_cma.cfg new file mode 100644 index 0000000..d6f689e --- /dev/null +++ b/config/azimut_cma.cfg @@ -0,0 +1,445 @@ +# Configuration file for ReSpeaker circular sound card + +version = "2.1"; + +# Raw + +raw: +{ + + fS = 16000; + hopSize = 128; + nBits = 16; + nChannels = 16; + + # Input with raw signal from microphones + interface: { + type = "file"; + path = "input_cma.raw"; + } + +} + +# Mapping + +mapping: +{ + + map: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + +} + +# General + +general: +{ + + epsilon = 1E-20; + + size: + { + hopSize = 128; + frameSize = 256; + }; + + samplerate: + { + mu = 16000; + sigma2 = 0.01; + }; + + speedofsound: + { + mu = 343.0; + sigma2 = 25.0; + }; + + mics = ( + + # Microphone 1 + { + mu = ( +0.1250, -0.0725, +0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + }, + + # Microphone 2 + { + mu = ( +0.1250, +0.0725, +0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 3 + { + mu = ( +0.1250, -0.0725, -0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 4 + { + mu = ( +0.1250, +0.0725, -0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 5 + { + mu = ( +0.0725, +0.1250, +0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, +1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 6 + { + mu = ( -0.0725, +0.1250, +0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, +1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 7 + { + mu = ( +0.0725, +0.1250, -0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, +1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 8 + { + mu = ( -0.0725, +0.1250, -0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, +1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 9 + { + mu = ( -0.1250, +0.0725, +0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( -1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 10 + { + mu = ( -0.1250, -0.0725, +0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( -1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 11 + { + mu = ( -0.1250, +0.0725, -0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( -1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 12 + { + mu = ( -0.1250, -0.0725, -0.0725 ); + sigma2 = ( 0.0, 0.0, 0.0, 0.0, +1E-6, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( -1.000, +0.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 13 + { + mu = ( -0.0725, -0.1250, +0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, -1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 14 + { + mu = ( +0.0725, -0.1250, +0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, -1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 15 + { + mu = ( -0.0725, -0.1250, -0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, -1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + }, + + # Microphone 16 + { + mu = ( +0.0725, -0.1250, -0.0725 ); + sigma2 = ( +1E-6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, +1E-6 ); + direction = ( +0.000, -1.000, +0.000 ); + #angle = ( 80.0, 100.0 ); + angle = ( 180.0, 180.0 ); + + } + + ); + + # Spatial filter to include only a range of direction if required + # (may be useful to remove false detections from the floor) + spatialfilter: { + + direction = ( +0.000, +0.000, +1.000 ); + angle = (80.0, 90.0); + + }; + + nThetas = 181; + gainMin = 0.25; + +}; + +# Stationnary noise estimation + +sne: +{ + + b = 3; + alphaS = 0.1; + L = 150; + delta = 3.0; + alphaD = 0.1; + +} + +# Sound Source Localization + +ssl: +{ + + nPots = 4; + nMatches = 10; + probMin = 0.3; + nRefinedLevels = 1; + interpRate = 1; + + # Number of scans: level is the resolution of the sphere + # and delta is the size of the maximum sliding window + # (delta = -1 means the size is automatically computed) + scans = ( + { level = 2; delta = -1; }, + { level = 4; delta = -1; } + ); + + # Output to export potential sources + potential: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +}; + +# Sound Source Tracking + +sst: +{ + + # Mode is either "kalman" or "particle" + + mode = "kalman"; + + # Add is either "static" or "dynamic" + + add = "dynamic"; + + # Parameters used by both the Kalman and particle filter + + active = ( + { weight = 1.0; mu = 0.15; sigma2 = 0.0025 } + ); + + inactive = ( + { weight = 1.0; mu = 0.05; sigma2 = 0.0025 } + ); + + sigmaR2_prob = 0.0025; + sigmaR2_active = 0.0225; + sigmaR2_target = 0.0025; + Pfalse = 0.1; + Pnew = 0.1; + Ptrack = 0.8; + + theta_new = 0.9; + N_prob = 5; + theta_prob = 0.8; + N_inactive = ( 150, 200, 250, 250 ); + theta_inactive = 0.9; + + # Parameters used by the Kalman filter only + + kalman: { + + sigmaQ = 0.001; + + }; + + # Parameters used by the particle filter only + + particle: { + + nParticles = 1000; + st_alpha = 2.0; + st_beta = 0.04; + st_ratio = 0.5; + ve_alpha = 0.05; + ve_beta = 0.2; + ve_ratio = 0.3; + ac_alpha = 0.5; + ac_beta = 0.2; + ac_ratio = 0.2; + Nmin = 0.7; + + }; + + target: (); + + # Output to export tracked sources + tracked: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +} + +sss: +{ + + # Mode is either "dds", "dgss" or "dmvdr" + + mode_sep = "dgss"; + mode_pf = "ms"; + + dds: { + + }; + + dgss: { + + mu = 0.0001; + lambda = 0.5; + + }; + + dmvdr: { + + }; + + ms: { + + alphaPmin = 0.07; + eta = 0.5; + alphaZ = 0.8; + thetaWin = 0.3; + alphaWin = 0.3; + maxAbsenceProb = 0.9; + Gmin = 0.01; + winSizeLocal = 3; + winSizeGlobal = 23; + winSizeFrame = 256; + + }; + + separated: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "separated_cma2.raw"; + } + + }; + + postfiltered: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "postfiltered_cma2.raw"; + } + + }; + +} + +classify: +{ + + frameSize = 1024; + winSize = 3; + tauMin = 32; + tauMax = 200; + deltaTauMax = 7; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.15; + r0 = 0.2; + + category: { + + format = "undefined"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/azimut_oma.cfg b/config/azimut_oma.cfg new file mode 100644 index 0000000..4c791df --- /dev/null +++ b/config/azimut_oma.cfg @@ -0,0 +1,404 @@ +# Configuration file for ReSpeaker circular sound card + +version = "2.1"; + +# Raw + +raw: +{ + + fS = 16000; + hopSize = 128; + nBits = 16; + nChannels = 16; + + # Input with raw signal from microphones + interface: { + type = "file"; + path = "input_oma.raw"; + } + +} + +# Mapping + +mapping: +{ + + map: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + +} + +# General + +general: +{ + + epsilon = 1E-20; + + size: + { + hopSize = 128; + frameSize = 256; + }; + + samplerate: + { + mu = 16000; + sigma2 = 0.01; + }; + + speedofsound: + { + mu = 343.0; + sigma2 = 25.0; + }; + + mics = ( + + # Microphone 1 + { + mu = ( 0.09000, 0.00000, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 2 + { + mu = ( 0.11550, -0.04780, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 3 + { + mu = ( 0.03540, 0.03540, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 4 + { + mu = ( 0.11550, 0.04780, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 5 + { + mu = ( 0.03540, -0.03540, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 6 + { + mu = ( 0.04780, -0.11550, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 7 + { + mu = ( -0.00000, -0.09000, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 8 + { + mu = ( -0.04780, -0.11550, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 9 + { + mu = ( -0.09000, 0.00000, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 10 + { + mu = ( -0.11550, 0.04780, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 11 + { + mu = ( -0.03540, -0.03540, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 12 + { + mu = ( -0.11550, -0.04780, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 13 + { + mu = ( -0.03540, 0.03540, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 14 + { + mu = ( -0.04780, 0.11550, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 15 + { + mu = ( 0.00000, 0.09000, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 16 + { + mu = ( 0.04780, 0.11550, 0.00000 ); + sigma2 = ( 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000010000, 0.0000000000, 0.0000000000, 0.0000000000, 0.0000000000 ); + direction = ( 0.00000, 0.00000, 1.00000 ); + angle = ( 80.0, 100.0 ); + } + + ); + + # Spatial filter to include only a range of direction if required + # (may be useful to remove false detections from the floor) + spatialfilter: { + + direction = ( +0.000, +0.000, +1.000 ); + angle = (80.0, 90.0); + + }; + + nThetas = 181; + gainMin = 0.25; + +}; + +# Stationnary noise estimation + +sne: +{ + + b = 3; + alphaS = 0.1; + L = 150; + delta = 3.0; + alphaD = 0.1; + +} + +# Sound Source Localization + +ssl: +{ + + nPots = 4; + nMatches = 10; + probMin = 0.3; + nRefinedLevels = 1; + interpRate = 1; + + # Number of scans: level is the resolution of the sphere + # and delta is the size of the maximum sliding window + # (delta = -1 means the size is automatically computed) + scans = ( + { level = 2; delta = -1; }, + { level = 4; delta = -1; } + ); + + # Output to export potential sources + potential: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +}; + +# Sound Source Tracking + +sst: +{ + + # Mode is either "kalman" or "particle" + + mode = "kalman"; + + # Parameters used by both the Kalman and particle filter + + active = ( + { weight = 1.0; mu = 0.3; sigma2 = 0.0025 } + ); + + inactive = ( + { weight = 1.0; mu = 0.15; sigma2 = 0.0025 } + ); + + sigmaR2_prob = 0.0025; + sigmaR2_active = 0.0225; + Pfalse = 0.1; + Pnew = 0.1; + Ptrack = 0.8; + + theta_new = 0.9; + N_prob = 5; + theta_prob = 0.8; + N_inactive = ( 150, 200, 250, 250 ); + theta_inactive = 0.9; + + # Parameters used by the Kalman filter only + + kalman: { + + sigmaQ = 0.001; + + }; + + # Parameters used by the particle filter only + + particle: { + + nParticles = 1000; + st_alpha = 2.0; + st_beta = 0.04; + st_ratio = 0.5; + ve_alpha = 0.05; + ve_beta = 0.2; + ve_ratio = 0.3; + ac_alpha = 0.5; + ac_beta = 0.2; + ac_ratio = 0.2; + Nmin = 0.7; + + }; + + # Output to export tracked sources + tracked: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +} + +sss: +{ + + # Mode is either "dds", "dgss" or "dmvdr" + + mode_sep = "dds"; + mode_pf = "ms"; + + dds: { + + }; + + dgss: { + + }; + + dmvdr: { + + }; + + ms: { + + alphaPmin = 0.07; + eta = 0.5; + alphaZ = 0.8; + thetaWin = 0.3; + alphaWin = 0.3; + maxAbsenceProb = 0.9; + Gmin = 0.01; + winSizeLocal = 3; + winSizeGlobal = 23; + winSizeFrame = 256; + + }; + + separated: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "separated_oma.raw"; + } + + }; + + postfiltered: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "postfiltered_oma.raw"; + } + + }; + +} + +classify: +{ + + frameSize = 1024; + winSize = 3; + tauMin = 32; + tauMax = 200; + deltaTauMax = 7; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.15; + r0 = 0.2; + + category: { + + format = "undefined"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/beam.cfg b/config/beam.cfg new file mode 100644 index 0000000..a74c175 --- /dev/null +++ b/config/beam.cfg @@ -0,0 +1,355 @@ +# Configuration file for XMOS circular sound card + +version = "2.1"; + +# Raw + +raw: +{ + + fS = 44100; + hopSize = 512; + nBits = 16; + nChannels = 8; + + # Input from 8SoundsUSB + interface: { + type = "file"; + path = "micsBeam.raw"; + } + +} + +# Mapping + +mapping: +{ + + map: (1, 2, 3, 4, 5, 6, 7, 8); + +} + +# General + +general: +{ + + epsilon = 1E-20; + + size: + { + hopSize = 512; + frameSize = 1024; + }; + + samplerate: + { + mu = 44100; + sigma2 = 0.01; + }; + + speedofsound: + { + mu = 343.0; + sigma2 = 25.0; + }; + + mics = ( + + # Microphone 1 + { + mu = ( +0.085, +0.000, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 2 + { + mu = ( +0.062, -0.062, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 3 + { + mu = ( +0.000, -0.085, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 4 + { + mu = ( -0.062, -0.062, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 5 + { + mu = ( -0.085, +0.000, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 6 + { + mu = ( -0.062, +0.062, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 7 + { + mu = ( +0.000, +0.085, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 8 + { + mu = ( +0.062, +0.062, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + } + + ); + + # Spatial filter to include only a range of direction if required + # (may be useful to remove false detections from the floor) + spatialfilter: { + + direction = ( +0.000, +0.000, +1.000 ); + angle = (80.0, 90.0); + + }; + + nThetas = 181; + gainMin = 0.25; + +}; + +# Stationnary noise estimation + +sne: +{ + + b = 3; + alphaS = 0.1; + L = 150; + delta = 3.0; + alphaD = 0.1; + +} + +# Sound Source Localization + +ssl: +{ + + nPots = 4; + nMatches = 10; + probMin = 0.5; + nRefinedLevels = 1; + interpRate = 1; + + # Number of scans: level is the resolution of the sphere + # and delta is the size of the maximum sliding window + # (delta = -1 means the size is automatically computed) + scans = ( + { level = 2; delta = -1; }, + { level = 4; delta = -1; } + ); + + # Output to export potential sources + potential: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +}; + +# Target sources + +# Sound Source Tracking + +sst: +{ + + # Mode is either "kalman" or "particle" + + mode = "kalman"; + + # Add is either "static" or "dynamic" + + add = "dynamic"; + + # Parameters used by both the Kalman and particle filter + + active = ( + { weight = 1.0; mu = 0.25; sigma2 = 0.0020 } + ); + + inactive = ( + { weight = 1.0; mu = 0.05; sigma2 = 0.0020 } + ); + + sigmaR2_prob = 0.0025; + sigmaR2_active = 0.0225; + sigmaR2_target = 0.0025; + Pfalse = 0.1; + Pnew = 0.1; + Ptrack = 0.8; + + theta_new = 0.9; + N_prob = 5; + theta_prob = 0.8; + N_inactive = ( 150, 200, 250, 250 ); + theta_inactive = 0.9; + + # Parameters used by the Kalman filter only + + kalman: { + + sigmaQ = 0.001; + + }; + + # Parameters used by the particle filter only + + particle: { + + nParticles = 1000; + st_alpha = 2.0; + st_beta = 0.04; + st_ratio = 0.5; + ve_alpha = 0.05; + ve_beta = 0.2; + ve_ratio = 0.3; + ac_alpha = 0.5; + ac_beta = 0.2; + ac_ratio = 0.2; + Nmin = 0.7; + + }; + + target: + ( + { tag = "fan"; x = 0.0; y = 0.0; z = 1.0 } + ); + + # Output to export tracked sources + tracked: { + + format = "json"; + + interface: { + type = "terminal"; + }; + + }; + +} + +sss: +{ + + # Mode is either "dds", "dgss" or "dmvdr" + + mode_sep = "dds"; + mode_pf = "ms"; + + dds: { + + }; + + dgss: { + + mu = 0.01; + lambda = 0.5; + + }; + + dmvdr: { + + }; + + ms: { + + alphaPmin = 0.07; + eta = 0.3; + alphaZ = 0.8; + thetaWin = 0.3; + alphaWin = 0.3; + maxAbsenceProb = 0.9; + Gmin = 0.01; + winSizeLocal = 3; + winSizeGlobal = 33; + winSizeFrame = 1024; + + }; + + separated: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "separated.raw"; + } + + }; + + postfiltered: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "postfiltered.raw"; + } + + }; + +} + +classify: +{ + + frameSize = 4096; + winSize = 3; + tauMin = 88; + tauMax = 551; + deltaTauMax = 20; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.5; + r0 = 0.2; + + category: { + + format = "undefined"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/respeaker.cfg b/config/respeaker.cfg new file mode 100644 index 0000000..92a547e --- /dev/null +++ b/config/respeaker.cfg @@ -0,0 +1,322 @@ +# Configuration file for ReSpeaker circular sound card + +version = "2.1"; + +# Raw + +raw: +{ + + fS = 16000; + hopSize = 128; + nBits = 16; + nChannels = 8; + + # Input with raw signal from microphones + interface: { + type = "soundcard"; + card = 3; + device = 0; + } + +} + +# Mapping + +mapping: +{ + + map: (1, 2, 3, 4, 5, 6, 7); + +} + +# General + +general: +{ + + epsilon = 1E-20; + + size: + { + hopSize = 128; + frameSize = 256; + }; + + samplerate: + { + mu = 16000; + sigma2 = 0.01; + }; + + speedofsound: + { + mu = 343.0; + sigma2 = 25.0; + }; + + mics = ( + + # Microphone 1 + { + mu = ( +0.0000, +0.0000, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + }, + + # Microphone 2 + { + mu = ( -0.0160, +0.0277, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + }, + + # Microphone 3 + { + mu = ( -0.0320, +0.0000, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + }, + + # Microphone 4 + { + mu = ( -0.0160, -0.0277, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + }, + + # Microphone 5 + { + mu = ( +0.0160, -0.0277, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + }, + + # Microphone 6 + { + mu = ( +0.0320, +0.0000, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + }, + + # Microphone 7 + { + mu = ( +0.0160, +0.0277, +0.0000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 90.0 ); + } + + ); + + # Spatial filter to include only a range of direction if required + # (may be useful to remove false detections from the floor) + spatialfilter: { + + direction = ( +0.000, +0.000, +1.000 ); + angle = (80.0, 90.0); + + }; + + nThetas = 181; + gainMin = 0.25; + +}; + +# Stationnary noise estimation + +sne: +{ + + b = 3; + alphaS = 0.1; + L = 150; + delta = 3.0; + alphaD = 0.1; + +} + +# Sound Source Localization + +ssl: +{ + + nPots = 4; + nMatches = 10; + probMin = 0.5; + nRefinedLevels = 1; + interpRate = 1; + + # Number of scans: level is the resolution of the sphere + # and delta is the size of the maximum sliding window + # (delta = -1 means the size is automatically computed) + scans = ( + { level = 2; delta = -1; }, + { level = 4; delta = -1; } + ); + + # Output to export potential sources + potential: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +}; + +# Sound Source Tracking + +sst: +{ + + # Mode is either "kalman" or "particle" + + mode = "kalman"; + + # Parameters used by both the Kalman and particle filter + + active = ( + { weight = 1.0; mu = 0.3; sigma2 = 0.0025 } + ); + + inactive = ( + { weight = 1.0; mu = 0.15; sigma2 = 0.0025 } + ); + + sigmaR2_prob = 0.0025; + sigmaR2_active = 0.0225; + Pfalse = 0.1; + Pnew = 0.1; + Ptrack = 0.8; + + theta_new = 0.9; + N_prob = 5; + theta_prob = 0.8; + N_inactive = ( 150, 200, 250, 250 ); + theta_inactive = 0.9; + + # Parameters used by the Kalman filter only + + kalman: { + + sigmaQ = 0.001; + + }; + + # Parameters used by the particle filter only + + particle: { + + nParticles = 1000; + st_alpha = 2.0; + st_beta = 0.04; + st_ratio = 0.5; + ve_alpha = 0.05; + ve_beta = 0.2; + ve_ratio = 0.3; + ac_alpha = 0.5; + ac_beta = 0.2; + ac_ratio = 0.2; + Nmin = 0.7; + + }; + + # Output to export tracked sources + tracked: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +} + +sss: +{ + + # Mode is either "dds", "dgss" or "dmvdr" + + mode_sep = "dds"; + mode_pf = "ms"; + + dds: { + + }; + + dgss: { + + }; + + dmvdr: { + + }; + + ms: { + + }; + + separated: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "separated.raw"; + } + + }; + + postfiltered: { + + fS = 44100; + hopSize = 512; + nBits = 16; + + interface: { + type = "file"; + path = "postfiltered.raw"; + } + + }; + +} + +classify: +{ + + frameSize = 1024; + winSize = 3; + tauMin = 32; + tauMax = 200; + deltaTauMax = 7; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.15; + r0 = 0.2; + + category: { + + format = "undefined"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/config/xmos.cfg b/config/xmos.cfg new file mode 100644 index 0000000..67354d7 --- /dev/null +++ b/config/xmos.cfg @@ -0,0 +1,347 @@ +# Configuration file for XMOS circular sound card + +version = "2.1"; + +# Raw + +raw: +{ + + fS = 48000; + hopSize = 512; + nBits = 16; + nChannels = 8; + + # Input with raw signal from microphones + interface: { + type = "file"; + path = "input2.raw"; + } + +} + +# Mapping + +mapping: +{ + + map: (1, 2, 3, 4, 5, 6, 7); + +} + +# General + +general: +{ + + epsilon = 1E-20; + + size: + { + hopSize = 128; + frameSize = 256; + }; + + samplerate: + { + mu = 16000; + sigma2 = 0.01; + }; + + speedofsound: + { + mu = 343.0; + sigma2 = 25.0; + }; + + mics = ( + + # Microphone 1 + { + mu = ( +0.000, +0.000, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 2 + { + mu = ( -0.022, -0.037, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 3 + { + mu = ( -0.043, +0.000, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 4 + { + mu = ( -0.022, +0.037, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 5 + { + mu = ( +0.022, +0.037, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 6 + { + mu = ( +0.043, +0.000, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + }, + + # Microphone 7 + { + mu = ( +0.022, -0.037, +0.000 ); + sigma2 = ( +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000, +0.000 ); + direction = ( +0.000, +0.000, +1.000 ); + angle = ( 80.0, 100.0 ); + } + + ); + + # Spatial filter to include only a range of direction if required + # (may be useful to remove false detections from the floor) + spatialfilter: { + + direction = ( +0.000, +0.000, +1.000 ); + angle = (80.0, 100.0); + + }; + + nThetas = 181; + gainMin = 0.25; + +}; + +# Stationnary noise estimation + +sne: +{ + + b = 3; + alphaS = 0.1; + L = 150; + delta = 3.0; + alphaD = 0.1; + +} + +# Sound Source Localization + +ssl: +{ + + nPots = 4; + nMatches = 10; + probMin = 0.5; + nRefinedLevels = 1; + interpRate = 4; + + # Number of scans: level is the resolution of the sphere + # and delta is the size of the maximum sliding window + # (delta = -1 means the size is automatically computed) + scans = ( + { level = 2; delta = -1; }, + { level = 4; delta = -1; } + ); + + # Output to export potential sources + potential: { + + format = "undefined"; + + interface: { + type = "blackhole"; + }; + + }; + +}; + +# Sound Source Tracking + +sst: +{ + + # Mode is either "kalman" or "particle" + + mode = "kalman"; + + # Add is either "static" or "dynamic" + + add = "dynamic"; + + # Parameters used by both the Kalman and particle filter + + active = ( + { weight = 1.0; mu = 0.4; sigma2 = 0.0025 } + ); + + inactive = ( + { weight = 1.0; mu = 0.25; sigma2 = 0.0025 } + ); + + sigmaR2_prob = 0.0025; + sigmaR2_active = 0.0225; + sigmaR2_target = 0.0025; + Pfalse = 0.1; + Pnew = 0.1; + Ptrack = 0.8; + + theta_new = 0.9; + N_prob = 5; + theta_prob = 0.8; + N_inactive = ( 250, 250, 250, 250 ); + theta_inactive = 0.9; + + # Parameters used by the Kalman filter only + + kalman: { + + sigmaQ = 0.001; + + }; + + # Parameters used by the particle filter only + + particle: { + + nParticles = 1000; + st_alpha = 2.0; + st_beta = 0.04; + st_ratio = 0.5; + ve_alpha = 0.05; + ve_beta = 0.2; + ve_ratio = 0.3; + ac_alpha = 0.5; + ac_beta = 0.2; + ac_ratio = 0.2; + Nmin = 0.7; + + }; + + target: (); + + # Output to export tracked sources + tracked: { + + format = "json"; + + interface: { + type = "file"; + path = "tracks.txt"; + }; + + }; + +} + +sss: +{ + + # Mode is either "dds", "dgss" or "dmvdr" + + mode_sep = "dds"; + mode_pf = "ms"; + + gain_sep = 1.0; + gain_pf = 10.0; + + dds: { + + }; + + dgss: { + + mu = 0.01; + lambda = 0.5; + + }; + + dmvdr: { + + }; + + ms: { + + alphaPmin = 0.07; + eta = 0.5; + alphaZ = 0.8; + thetaWin = 0.3; + alphaWin = 0.3; + maxAbsenceProb = 0.9; + Gmin = 0.01; + winSizeLocal = 3; + winSizeGlobal = 23; + winSizeFrame = 256; + + }; + + separated: { + + fS = 16000; + hopSize = 128; + nBits = 16; + + interface: { + type = "file"; + path = "separated.raw"; + }; + + }; + + postfiltered: { + + fS = 16000; + hopSize = 128; + nBits = 16; + gain = 10.0; + + interface: { + type = "file"; + path = "postfiltered.raw"; + }; + + }; + +}; + +classify: +{ + + frameSize = 4096; + winSize = 3; + tauMin = 88; + tauMax = 551; + deltaTauMax = 20; + alpha = 0.3; + gamma = 0.05; + phiMin = 0.5; + r0 = 0.2; + + category: { + + format = "undefined"; + + interface: { + type = "blackhole"; + } + + } + +} diff --git a/demo/client.c b/demo/client.c new file mode 100644 index 0000000..b183af3 --- /dev/null +++ b/demo/client.c @@ -0,0 +1,292 @@ + + #include + + #include "parameters.h" + #include "configs.h" + #include "objects.h" + #include "threads.h" + #include "profiler.h" + + #include + #include + #include + + // +----------------------------------------------------------+ + // | Variables | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Type | + // +------------------------------------------------------+ + + enum processing { + processing_singlethread, + processing_multithread + } type; + + // +------------------------------------------------------+ + // | Getopt | + // +------------------------------------------------------+ + + int c; + char * file_config; + + // +------------------------------------------------------+ + // | Objects | + // +------------------------------------------------------+ + + objects * objs; + aobjects * aobjs; + + // +------------------------------------------------------+ + // | Configurations | + // +------------------------------------------------------+ + + configs * cfgs; + + // +------------------------------------------------------+ + // | Profiler | + // +------------------------------------------------------+ + + profiler * prf; + + // +------------------------------------------------------+ + // | Flag | + // +------------------------------------------------------+ + + char stopProcess; + + // +----------------------------------------------------------+ + // | Signal handler | + // +----------------------------------------------------------+ + + void sighandler(int signum) { + + if (type == processing_singlethread) { + stopProcess = 1; + } + if (type == processing_multithread) { + threads_multiple_stop(aobjs); + } + + } + + // +----------------------------------------------------------+ + // | Main routine | + // +----------------------------------------------------------+ + + int main(int argc, char * argv[]) { + + // +------------------------------------------------------+ + // | Arguments | + // +------------------------------------------------------+ + + file_config = (char *) NULL; + char verbose = 0x00; + + type = processing_multithread; + + while ((c = getopt(argc,argv, "c:hsv")) != -1) { + + switch(c) { + + case 'c': + + file_config = (char *) malloc(sizeof(char) * (strlen(optarg)+1)); + strcpy(file_config, optarg); + + break; + + case 'h': + + printf("+----------------------------------------------------+\n"); + printf("| ODAS (Open embeddeD Audition System) |\n"); + printf("+----------------------------------------------------+\n"); + printf("| Author: Francois Grondin |\n"); + printf("| Email: francois.grondin2@usherbrooke.ca |\n"); + printf("| Website: introlab.3it.usherbrooke.ca |\n"); + printf("| Repository: github.com/introlab/odas |\n"); + printf("| Version: 1.0 |\n"); + printf("+----------------------------------------------------+\n"); + printf("| -c Configuration file (.cfg) |\n"); + printf("| -h Help |\n"); + printf("| -s Process sequentially (no multithread) |\n"); + printf("| -v Verbose |\n"); + printf("+----------------------------------------------------+\n"); + + exit(EXIT_SUCCESS); + + break; + + case 's': + + type = processing_singlethread; + + break; + + case 'v': + + verbose = 0x01; + + break; + + } + + } + + if (file_config == NULL) { + printf("Missing configuration file.\n"); + exit(EXIT_FAILURE); + } + + // +------------------------------------------------------+ + // | Copyright | + // +------------------------------------------------------+ + + if (verbose == 0x01) { + + printf("+--------------------------------------------+\n"); + printf("| ODAS (Open embeddeD Audition System) |\n"); + printf("+--------------------------------------------+\n"); + printf("| Author: Francois Grondin |\n"); + printf("| Email: francois.grondin2@usherbrooke.ca |\n"); + printf("| Website: introlab.3it.usherbrooke.ca |\n"); + printf("| Version: 1.0 |\n"); + printf("+--------------------------------------------+\n"); + + } + + // +------------------------------------------------------+ + // | Single thread | + // +------------------------------------------------------+ + + if (type == processing_singlethread) { + + // +--------------------------------------------------+ + // | Profiler | + // +--------------------------------------------------+ + + prf = profiler_construct(); + + // +--------------------------------------------------+ + // | Configure | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing configurations...... "); fflush(stdout); + + cfgs = configs_construct(file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Construct | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing objects............. "); fflush(stdout); + + objs = objects_construct(cfgs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Processing | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Processing....................... "); fflush(stdout); + + threads_single_open(objs); + stopProcess = 0; + while((threads_single_process(objs, prf) == 0) && (stopProcess == 0)); + threads_single_close(objs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Free memory | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Free memory...................... "); fflush(stdout); + + objects_destroy(objs); + configs_destroy(cfgs); + free((void *) file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Results | + // +--------------------------------------------------+ + + if (verbose == 0x01) profiler_printf(prf); + + profiler_destroy(prf); + + } + + // +------------------------------------------------------+ + // | Multiple threads | + // +------------------------------------------------------+ + + if (type == processing_multithread) { + + // +--------------------------------------------------+ + // | Configure | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing configurations...... "); fflush(stdout); + + cfgs = configs_construct(file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Construct | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing objects............. "); fflush(stdout); + + aobjs = aobjects_construct(cfgs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Launch threads | + // +--------------------------------------------------+ + + signal(SIGINT, sighandler); + + if (verbose == 0x01) printf("| + Launch threads................... "); fflush(stdout); + + threads_multiple_start(aobjs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Wait | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Threads running.................. "); fflush(stdout); + + threads_multiple_join(aobjs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Free memory | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Free memory...................... "); fflush(stdout); + + aobjects_destroy(aobjs); + configs_destroy(cfgs); + free((void *) file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + if (verbose == 0x01) printf("+--------------------------------------------+\n"); + + } + + return 0; + + } diff --git a/demo/configs.c b/demo/configs.c new file mode 100644 index 0000000..e92f8a7 --- /dev/null +++ b/demo/configs.c @@ -0,0 +1,502 @@ + + #include "configs.h" + + configs * configs_construct(const char * file_config) { + + configs * cfgs; + unsigned int iSink; + + cfgs = (configs *) malloc(sizeof(configs)); + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + cfgs->src_hops_mics_config = parameters_src_hops_mics_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_mics_raw_config = parameters_msg_hops_mics_raw_config(file_config); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_mapping_mics_config = parameters_mod_mapping_mics_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_mics_map_config = parameters_msg_hops_mics_map_config(file_config); + + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_resample_mics_config = parameters_mod_resample_mics_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_mics_rs_config = parameters_msg_hops_mics_rs_config(file_config); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_stft_mics_config = parameters_mod_stft_mics_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_spectra_mics_config = parameters_msg_spectra_mics_config(file_config); + + // +----------------------------------------------------------+ + // | Noise | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_noise_mics_config = parameters_mod_noise_mics_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_powers_mics_config = parameters_msg_powers_mics_config(file_config); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_ssl_config = parameters_mod_ssl_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_pots_ssl_config = parameters_msg_pots_ssl_config(file_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_pots_ssl_config = parameters_snk_pots_ssl_config(file_config); + + // +----------------------------------------------------------+ + // | Target | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Injector | + // +------------------------------------------------------+ + + cfgs->inj_targets_sst_config = parameters_inj_targets_sst_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_targets_sst_config = parameters_msg_targets_sst_config(file_config); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_sst_config = parameters_mod_sst_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_tracks_sst_config = parameters_msg_tracks_sst_config(file_config); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + cfgs->snk_tracks_sst_config = parameters_snk_tracks_sst_config(file_config); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_sss_config = parameters_mod_sss_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_spectra_seps_config = parameters_msg_spectra_seps_config(file_config); + cfgs->msg_spectra_pfs_config = parameters_msg_spectra_pfs_config(file_config); + + // +----------------------------------------------------------+ + // | ISTFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_istft_seps_config = parameters_mod_istft_seps_config(file_config); + cfgs->mod_istft_pfs_config = parameters_mod_istft_pfs_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_seps_config = parameters_msg_hops_seps_config(file_config); + cfgs->msg_hops_pfs_config = parameters_msg_hops_pfs_config(file_config); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_resample_seps_config = parameters_mod_resample_seps_config(file_config); + cfgs->mod_resample_pfs_config = parameters_mod_resample_pfs_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_seps_rs_config = parameters_msg_hops_seps_rs_config(file_config); + cfgs->msg_hops_pfs_rs_config = parameters_msg_hops_pfs_rs_config(file_config); + + // +----------------------------------------------------------+ + // | Volume | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + cfgs->mod_volume_seps_config = parameters_mod_volume_seps_config(file_config); + cfgs->mod_volume_pfs_config = parameters_mod_volume_pfs_config(file_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + cfgs->msg_hops_seps_vol_config = parameters_msg_hops_seps_vol_config(file_config); + cfgs->msg_hops_pfs_vol_config = parameters_msg_hops_pfs_vol_config(file_config); + + // +------------------------------------------------------+ + // | Sink | + // +------------------------------------------------------+ + + cfgs->snk_hops_seps_vol_config = parameters_snk_hops_seps_vol_config(file_config); + cfgs->snk_hops_pfs_vol_config = parameters_snk_hops_pfs_vol_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; + + } + + void configs_destroy(configs * cfgs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + src_hops_cfg_destroy(cfgs->src_hops_mics_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_mics_raw_config); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_mapping_cfg_destroy(cfgs->mod_mapping_mics_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_mics_map_config); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_resample_cfg_destroy(cfgs->mod_resample_mics_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_mics_rs_config); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_stft_cfg_destroy(cfgs->mod_stft_mics_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_spectra_cfg_destroy(cfgs->msg_spectra_mics_config); + + // +----------------------------------------------------------+ + // | Noise | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_noise_cfg_destroy(cfgs->mod_noise_mics_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_powers_cfg_destroy(cfgs->msg_powers_mics_config); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_ssl_cfg_destroy(cfgs->mod_ssl_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_pots_cfg_destroy(cfgs->msg_pots_ssl_config); + + // +------------------------------------------------------+ + // | Sink | + // +------------------------------------------------------+ + + snk_pots_cfg_destroy(cfgs->snk_pots_ssl_config); + + // +----------------------------------------------------------+ + // | Target | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Injector | + // +------------------------------------------------------+ + + inj_targets_cfg_destroy(cfgs->inj_targets_sst_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_targets_cfg_destroy(cfgs->msg_targets_sst_config); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_sst_cfg_destroy(cfgs->mod_sst_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_tracks_cfg_destroy(cfgs->msg_tracks_sst_config); + + // +------------------------------------------------------+ + // | Sink | + // +------------------------------------------------------+ + + snk_tracks_cfg_destroy(cfgs->snk_tracks_sst_config); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_sss_cfg_destroy(cfgs->mod_sss_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_spectra_cfg_destroy(cfgs->msg_spectra_seps_config); + msg_spectra_cfg_destroy(cfgs->msg_spectra_pfs_config); + + // +----------------------------------------------------------+ + // | ISTFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_istft_cfg_destroy(cfgs->mod_istft_seps_config); + mod_istft_cfg_destroy(cfgs->mod_istft_pfs_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_seps_config); + msg_hops_cfg_destroy(cfgs->msg_hops_pfs_config); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_resample_cfg_destroy(cfgs->mod_resample_seps_config); + mod_resample_cfg_destroy(cfgs->mod_resample_pfs_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_seps_rs_config); + msg_hops_cfg_destroy(cfgs->msg_hops_pfs_rs_config); + + // +----------------------------------------------------------+ + // | Volume | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_volume_cfg_destroy(cfgs->mod_volume_seps_config); + mod_volume_cfg_destroy(cfgs->mod_volume_pfs_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_hops_cfg_destroy(cfgs->msg_hops_seps_vol_config); + msg_hops_cfg_destroy(cfgs->msg_hops_pfs_vol_config); + + // +------------------------------------------------------+ + // | Sink | + // +------------------------------------------------------+ + + snk_hops_cfg_destroy(cfgs->snk_hops_seps_vol_config); + snk_hops_cfg_destroy(cfgs->snk_hops_pfs_vol_config); + + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + mod_classify_cfg_destroy(cfgs->mod_classify_config); + + // +------------------------------------------------------+ + // | Message | + // +------------------------------------------------------+ + + msg_categories_cfg_destroy(cfgs->msg_categories_config); + + // +------------------------------------------------------+ + // | Sink | + // +------------------------------------------------------+ + + snk_categories_cfg_destroy(cfgs->snk_categories_config); + + free((void *) cfgs); + + } diff --git a/demo/configs.h b/demo/configs.h new file mode 100644 index 0000000..06e5cf8 --- /dev/null +++ b/demo/configs.h @@ -0,0 +1,68 @@ +#ifndef __DEMO_CONFIGS +#define __DEMO_CONFIGS + + #include "parameters.h" + + #include + #include + + typedef struct configs { + + src_hops_cfg * src_hops_mics_config; + msg_hops_cfg * msg_hops_mics_raw_config; + + mod_mapping_cfg * mod_mapping_mics_config; + msg_hops_cfg * msg_hops_mics_map_config; + + mod_resample_cfg * mod_resample_mics_config; + msg_hops_cfg * msg_hops_mics_rs_config; + + mod_stft_cfg * mod_stft_mics_config; + msg_spectra_cfg * msg_spectra_mics_config; + + mod_noise_cfg * mod_noise_mics_config; + msg_powers_cfg * msg_powers_mics_config; + + mod_ssl_cfg * mod_ssl_config; + msg_pots_cfg * msg_pots_ssl_config; + snk_pots_cfg * snk_pots_ssl_config; + + inj_targets_cfg * inj_targets_sst_config; + msg_targets_cfg * msg_targets_sst_config; + + mod_sst_cfg * mod_sst_config; + msg_tracks_cfg * msg_tracks_sst_config; + snk_tracks_cfg * snk_tracks_sst_config; + + mod_sss_cfg * mod_sss_config; + msg_spectra_cfg * msg_spectra_seps_config; + msg_spectra_cfg * msg_spectra_pfs_config; + + mod_istft_cfg * mod_istft_seps_config; + mod_istft_cfg * mod_istft_pfs_config; + msg_hops_cfg * msg_hops_seps_config; + msg_hops_cfg * msg_hops_pfs_config; + + mod_resample_cfg * mod_resample_seps_config; + mod_resample_cfg * mod_resample_pfs_config; + msg_hops_cfg * msg_hops_seps_rs_config; + msg_hops_cfg * msg_hops_pfs_rs_config; + + mod_volume_cfg * mod_volume_seps_config; + mod_volume_cfg * mod_volume_pfs_config; + msg_hops_cfg * msg_hops_seps_vol_config; + msg_hops_cfg * msg_hops_pfs_vol_config; + snk_hops_cfg * snk_hops_seps_vol_config; + snk_hops_cfg * snk_hops_pfs_vol_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); + + void configs_destroy(configs * cfgs); + +#endif \ No newline at end of file diff --git a/demo/debug.c b/demo/debug.c new file mode 100644 index 0000000..7ed41a0 --- /dev/null +++ b/demo/debug.c @@ -0,0 +1,45 @@ + + #include + + #include + #include + + #include "../src/utils/inverse.h" + + int main(int argc, char * argv[]) { + + cmatrix_obj * cmatrix1; + cmatrix_obj * cmatrix2; + inverse_complex_obj * inverse_complex; + + unsigned int iRow; + unsigned int iCol; + unsigned int iIteration; + unsigned int nIterations; + + nIterations = 100000; + + cmatrix1 = cmatrix_construct_zero(16,16); + cmatrix2 = cmatrix_construct_zero(16,16); + inverse_complex = inverse_complex_construct_zero(16,1E-20); + + srand(time(NULL)); + + for (iRow = 0; iRow < 16; iRow++) { + + for (iCol = 0; iCol < 16; iCol++) { + + cmatrix1->real[iRow * 16 + iCol] = ((float) rand()) / ((float) RAND_MAX); + cmatrix1->imag[iRow * 16 + iCol] = ((float) rand()) / ((float) RAND_MAX); + + } + + } + + for (iIteration = 0; iIteration < nIterations; iIteration++) { + + inverse_complex_process(inverse_complex, cmatrix1, cmatrix2); + + } + + } \ No newline at end of file diff --git a/demo/objects.c b/demo/objects.c new file mode 100644 index 0000000..0189357 --- /dev/null +++ b/demo/objects.c @@ -0,0 +1,1514 @@ + + #include "objects.h" + + objects * objects_construct(const configs * cfgs) { + + objects * objs; + unsigned int iSink; + + objs = (objects *) malloc(sizeof(objects)); + + // +----------------------------------------------------------+ + // | Construct | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + objs->src_hops_mics_object = src_hops_construct(cfgs->src_hops_mics_config, + cfgs->msg_hops_mics_raw_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_hops_mics_raw_object = con_hops_construct(1, cfgs->msg_hops_mics_raw_config); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_mapping_mics_object = mod_mapping_construct(cfgs->mod_mapping_mics_config, + cfgs->msg_hops_mics_map_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_hops_mics_map_object = con_hops_construct(1, cfgs->msg_hops_mics_map_config); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_resample_mics_object = mod_resample_construct(cfgs->mod_resample_mics_config, + cfgs->msg_hops_mics_map_config, + cfgs->msg_hops_mics_rs_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_hops_mics_rs_object = con_hops_construct(2, cfgs->msg_hops_mics_rs_config); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_stft_mics_object = mod_stft_construct(cfgs->mod_stft_mics_config, + cfgs->msg_hops_mics_rs_config, + cfgs->msg_spectra_mics_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_spectra_mics_object = con_spectra_construct(3, cfgs->msg_spectra_mics_config); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_noise_mics_object = mod_noise_construct(cfgs->mod_noise_mics_config, + cfgs->msg_spectra_mics_config, + cfgs->msg_powers_mics_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_powers_mics_object = con_powers_construct(1, cfgs->msg_powers_mics_config); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_ssl_object = mod_ssl_construct(cfgs->mod_ssl_config, + cfgs->msg_spectra_mics_config, + cfgs->msg_pots_ssl_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->snk_pots_ssl_object = snk_pots_construct(cfgs->snk_pots_ssl_config, + cfgs->msg_pots_ssl_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_pots_ssl_object = con_pots_construct(2, cfgs->msg_pots_ssl_config); + + // +------------------------------------------------------+ + // | Target | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + objs->inj_targets_sst_object = inj_targets_construct(cfgs->inj_targets_sst_config, + cfgs->msg_hops_mics_rs_config, + cfgs->msg_targets_sst_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_targets_sst_object = con_targets_construct(1, cfgs->msg_targets_sst_config); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_sst_object = mod_sst_construct(cfgs->mod_sst_config, + cfgs->mod_ssl_config, + cfgs->msg_pots_ssl_config, + cfgs->msg_targets_sst_config, + cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->snk_tracks_sst_object = snk_tracks_construct(cfgs->snk_tracks_sst_config, + cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_tracks_sst_object = con_tracks_construct(3, cfgs->msg_tracks_sst_config); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_sss_object = mod_sss_construct(cfgs->mod_sss_config, + cfgs->msg_tracks_sst_config, + cfgs->msg_spectra_mics_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_spectra_seps_object = con_spectra_construct(1, cfgs->msg_spectra_seps_config); + objs->con_spectra_pfs_object = con_spectra_construct(1, cfgs->msg_spectra_pfs_config); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_istft_seps_object = mod_istft_construct(cfgs->mod_istft_seps_config, + cfgs->msg_spectra_seps_config, + cfgs->msg_hops_seps_config); + + objs->mod_istft_pfs_object = mod_istft_construct(cfgs->mod_istft_pfs_config, + cfgs->msg_spectra_pfs_config, + cfgs->msg_hops_pfs_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + 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); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_resample_seps_object = mod_resample_construct(cfgs->mod_resample_seps_config, + cfgs->msg_hops_seps_config, + cfgs->msg_hops_seps_rs_config); + + objs->mod_resample_pfs_object = mod_resample_construct(cfgs->mod_resample_pfs_config, + cfgs->msg_hops_pfs_config, + cfgs->msg_hops_pfs_rs_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_hops_seps_rs_object = con_hops_construct(1, cfgs->msg_hops_seps_rs_config); + objs->con_hops_pfs_rs_object = con_hops_construct(1, cfgs->msg_hops_pfs_rs_config); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_volume_seps_object = mod_volume_construct(cfgs->mod_volume_seps_config, + cfgs->msg_hops_seps_vol_config); + + objs->mod_volume_pfs_object = mod_volume_construct(cfgs->mod_volume_pfs_config, + cfgs->msg_hops_pfs_vol_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->con_hops_seps_vol_object = con_hops_construct(1, cfgs->msg_hops_seps_vol_config); + objs->con_hops_pfs_vol_object = con_hops_construct(1, cfgs->msg_hops_pfs_vol_config); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + objs->snk_hops_seps_vol_object = snk_hops_construct(cfgs->snk_hops_seps_vol_config, + cfgs->msg_hops_seps_vol_config); + + objs->snk_hops_pfs_vol_object = snk_hops_construct(cfgs->snk_hops_pfs_vol_config, + cfgs->msg_hops_pfs_vol_config); + + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->mod_classify_object = mod_classify_construct(cfgs->mod_classify_config, + cfgs->msg_hops_seps_config, + cfgs->msg_tracks_sst_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 | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + src_hops_connect(objs->src_hops_mics_object, + objs->con_hops_mics_raw_object->in); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_mapping_connect(objs->mod_mapping_mics_object, + objs->con_hops_mics_raw_object->outs[0], + objs->con_hops_mics_map_object->in); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_resample_connect(objs->mod_resample_mics_object, + objs->con_hops_mics_map_object->outs[0], + objs->con_hops_mics_rs_object->in); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_stft_connect(objs->mod_stft_mics_object, + objs->con_hops_mics_rs_object->outs[0], + objs->con_spectra_mics_object->in); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_noise_connect(objs->mod_noise_mics_object, + objs->con_spectra_mics_object->outs[0], + objs->con_powers_mics_object->in); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_ssl_connect(objs->mod_ssl_object, + objs->con_spectra_mics_object->outs[1], + objs->con_pots_ssl_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + snk_pots_connect(objs->snk_pots_ssl_object, + objs->con_pots_ssl_object->outs[1]); + + // +------------------------------------------------------+ + // | Target | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + inj_targets_connect(objs->inj_targets_sst_object, + objs->con_hops_mics_rs_object->outs[1], + objs->con_targets_sst_object->in); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_sst_connect(objs->mod_sst_object, + objs->con_pots_ssl_object->outs[0], + objs->con_targets_sst_object->outs[0], + objs->con_tracks_sst_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + snk_tracks_connect(objs->snk_tracks_sst_object, + objs->con_tracks_sst_object->outs[2]); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_sss_connect(objs->mod_sss_object, + objs->con_spectra_mics_object->outs[2], + objs->con_powers_mics_object->outs[0], + objs->con_tracks_sst_object->outs[0], + objs->con_spectra_seps_object->in, + objs->con_spectra_pfs_object->in); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_istft_connect(objs->mod_istft_seps_object, + objs->con_spectra_seps_object->outs[0], + objs->con_hops_seps_object->in); + + mod_istft_connect(objs->mod_istft_pfs_object, + objs->con_spectra_pfs_object->outs[0], + objs->con_hops_pfs_object->in); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_resample_connect(objs->mod_resample_seps_object, + objs->con_hops_seps_object->outs[0], + objs->con_hops_seps_rs_object->in); + + mod_resample_connect(objs->mod_resample_pfs_object, + objs->con_hops_pfs_object->outs[0], + objs->con_hops_pfs_rs_object->in); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_volume_connect(objs->mod_volume_seps_object, + objs->con_hops_seps_rs_object->outs[0], + objs->con_hops_seps_vol_object->in); + + mod_volume_connect(objs->mod_volume_pfs_object, + objs->con_hops_pfs_rs_object->outs[0], + objs->con_hops_pfs_vol_object->in); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + snk_hops_connect(objs->snk_hops_seps_vol_object, + objs->con_hops_seps_vol_object->outs[0]); + + snk_hops_connect(objs->snk_hops_pfs_vol_object, + objs->con_hops_pfs_vol_object->outs[0]); + + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_classify_connect(objs->mod_classify_object, + objs->con_hops_seps_object->outs[1], + objs->con_tracks_sst_object->outs[1], + objs->con_categories_object->in); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + snk_categories_connect(objs->snk_categories_object, + objs->con_categories_object->outs[0]); + + return objs; + + } + + void objects_destroy(objects * objs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Destroy | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + src_hops_destroy(objs->src_hops_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_hops_destroy(objs->con_hops_mics_raw_object); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_mapping_destroy(objs->mod_mapping_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_hops_destroy(objs->con_hops_mics_map_object); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_resample_destroy(objs->mod_resample_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_hops_destroy(objs->con_hops_mics_rs_object); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_stft_destroy(objs->mod_stft_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_spectra_destroy(objs->con_spectra_mics_object); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_noise_destroy(objs->mod_noise_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_powers_destroy(objs->con_powers_mics_object); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_ssl_destroy(objs->mod_ssl_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + snk_pots_destroy(objs->snk_pots_ssl_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_pots_destroy(objs->con_pots_ssl_object); + + // +------------------------------------------------------+ + // | Target | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + inj_targets_destroy(objs->inj_targets_sst_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_targets_destroy(objs->con_targets_sst_object); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_sst_destroy(objs->mod_sst_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + snk_tracks_destroy(objs->snk_tracks_sst_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_tracks_destroy(objs->con_tracks_sst_object); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_sss_destroy(objs->mod_sss_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_spectra_destroy(objs->con_spectra_seps_object); + con_spectra_destroy(objs->con_spectra_pfs_object); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_istft_destroy(objs->mod_istft_seps_object); + mod_istft_destroy(objs->mod_istft_pfs_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_hops_destroy(objs->con_hops_seps_object); + con_hops_destroy(objs->con_hops_pfs_object); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_resample_destroy(objs->mod_resample_seps_object); + mod_resample_destroy(objs->mod_resample_pfs_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_hops_destroy(objs->con_hops_seps_rs_object); + con_hops_destroy(objs->con_hops_pfs_rs_object); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + mod_volume_destroy(objs->mod_volume_seps_object); + mod_volume_destroy(objs->mod_volume_pfs_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + con_hops_destroy(objs->con_hops_seps_vol_object); + con_hops_destroy(objs->con_hops_pfs_vol_object); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + snk_hops_destroy(objs->snk_hops_seps_vol_object); + snk_hops_destroy(objs->snk_hops_pfs_vol_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); + + } + + aobjects * aobjects_construct(const configs * cfgs) { + + aobjects * objs; + unsigned int iSink; + + objs = (aobjects *) malloc(sizeof(aobjects)); + + objs->nMessages = 100; + + // +----------------------------------------------------------+ + // | Construct | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + objs->asrc_hops_mics_object = asrc_hops_construct(cfgs->src_hops_mics_config, + cfgs->msg_hops_mics_raw_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_hops_mics_raw_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_mics_raw_config); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_mapping_mics_object = amod_mapping_construct(cfgs->mod_mapping_mics_config, + cfgs->msg_hops_mics_map_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_hops_mics_map_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_mics_map_config); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_resample_mics_object = amod_resample_construct(cfgs->mod_resample_mics_config, + cfgs->msg_hops_mics_map_config, + cfgs->msg_hops_mics_rs_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_hops_mics_rs_object = acon_hops_construct(2, objs->nMessages, cfgs->msg_hops_mics_rs_config); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_stft_mics_object = amod_stft_construct(cfgs->mod_stft_mics_config, + cfgs->msg_hops_mics_rs_config, + cfgs->msg_spectra_mics_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_spectra_mics_object = acon_spectra_construct(3, objs->nMessages, cfgs->msg_spectra_mics_config); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_noise_mics_object = amod_noise_construct(cfgs->mod_noise_mics_config, + cfgs->msg_spectra_mics_config, + cfgs->msg_powers_mics_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_powers_mics_object = acon_powers_construct(1, objs->nMessages, cfgs->msg_powers_mics_config); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_ssl_object = amod_ssl_construct(cfgs->mod_ssl_config, + cfgs->msg_spectra_mics_config, + cfgs->msg_pots_ssl_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_pots_ssl_object = asnk_pots_construct(cfgs->snk_pots_ssl_config, + cfgs->msg_pots_ssl_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_pots_ssl_object = acon_pots_construct(2, objs->nMessages, cfgs->msg_pots_ssl_config); + + // +------------------------------------------------------+ + // | Target | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + objs->ainj_targets_sst_object = ainj_targets_construct(cfgs->inj_targets_sst_config, + cfgs->msg_hops_mics_rs_config, + cfgs->msg_targets_sst_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_targets_sst_object = acon_targets_construct(1, objs->nMessages, cfgs->msg_targets_sst_config); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_sst_object = amod_sst_construct(cfgs->mod_sst_config, + cfgs->mod_ssl_config, + cfgs->msg_pots_ssl_config, + cfgs->msg_targets_sst_config, + cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + objs->asnk_tracks_sst_object = asnk_tracks_construct(cfgs->snk_tracks_sst_config, + cfgs->msg_tracks_sst_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_tracks_sst_object = acon_tracks_construct(3, objs->nMessages, cfgs->msg_tracks_sst_config); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_sss_object = amod_sss_construct(cfgs->mod_sss_config, + cfgs->msg_tracks_sst_config, + cfgs->msg_spectra_mics_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_spectra_seps_object = acon_spectra_construct(1, objs->nMessages, cfgs->msg_spectra_seps_config); + objs->acon_spectra_pfs_object = acon_spectra_construct(1, objs->nMessages, cfgs->msg_spectra_pfs_config); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_istft_seps_object = amod_istft_construct(cfgs->mod_istft_seps_config, + cfgs->msg_spectra_seps_config, + cfgs->msg_hops_seps_config); + + objs->amod_istft_pfs_object = amod_istft_construct(cfgs->mod_istft_pfs_config, + cfgs->msg_spectra_pfs_config, + cfgs->msg_hops_pfs_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + 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); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_resample_seps_object = amod_resample_construct(cfgs->mod_resample_seps_config, + cfgs->msg_hops_seps_config, + cfgs->msg_hops_seps_rs_config); + + objs->amod_resample_pfs_object = amod_resample_construct(cfgs->mod_resample_pfs_config, + cfgs->msg_hops_pfs_config, + cfgs->msg_hops_pfs_rs_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_hops_seps_rs_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_seps_rs_config); + + objs->acon_hops_pfs_rs_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_pfs_rs_config); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_volume_seps_object = amod_volume_construct(cfgs->mod_volume_seps_config, + cfgs->msg_hops_seps_vol_config); + + objs->amod_volume_pfs_object = amod_volume_construct(cfgs->mod_volume_pfs_config, + cfgs->msg_hops_pfs_vol_config); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + objs->acon_hops_seps_vol_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_seps_vol_config); + + objs->acon_hops_pfs_vol_object = acon_hops_construct(1, objs->nMessages, cfgs->msg_hops_pfs_vol_config); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + objs->asnk_hops_seps_vol_object = asnk_hops_construct(cfgs->snk_hops_seps_vol_config, + cfgs->msg_hops_seps_vol_config); + + objs->asnk_hops_pfs_vol_object = asnk_hops_construct(cfgs->snk_hops_pfs_vol_config, + cfgs->msg_hops_pfs_vol_config); + + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + objs->amod_classify_object = amod_classify_construct(cfgs->mod_classify_config, + cfgs->msg_hops_seps_config, + cfgs->msg_tracks_sst_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 | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + asrc_hops_connect(objs->asrc_hops_mics_object, + objs->acon_hops_mics_raw_object->in); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_mapping_connect(objs->amod_mapping_mics_object, + objs->acon_hops_mics_raw_object->outs[0], + objs->acon_hops_mics_map_object->in); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_resample_connect(objs->amod_resample_mics_object, + objs->acon_hops_mics_map_object->outs[0], + objs->acon_hops_mics_rs_object->in); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_stft_connect(objs->amod_stft_mics_object, + objs->acon_hops_mics_rs_object->outs[0], + objs->acon_spectra_mics_object->in); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_noise_connect(objs->amod_noise_mics_object, + objs->acon_spectra_mics_object->outs[0], + objs->acon_powers_mics_object->in); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_ssl_connect(objs->amod_ssl_object, + objs->acon_spectra_mics_object->outs[1], + objs->acon_pots_ssl_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + asnk_pots_connect(objs->asnk_pots_ssl_object, + objs->acon_pots_ssl_object->outs[1]); + + // +------------------------------------------------------+ + // | Target | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + ainj_targets_connect(objs->ainj_targets_sst_object, + objs->acon_hops_mics_rs_object->outs[1], + objs->acon_targets_sst_object->in); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sst_connect(objs->amod_sst_object, + objs->acon_pots_ssl_object->outs[0], + objs->acon_targets_sst_object->outs[0], + objs->acon_tracks_sst_object->in); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + asnk_tracks_connect(objs->asnk_tracks_sst_object, + objs->acon_tracks_sst_object->outs[2]); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sss_connect(objs->amod_sss_object, + objs->acon_spectra_mics_object->outs[2], + objs->acon_powers_mics_object->outs[0], + objs->acon_tracks_sst_object->outs[0], + objs->acon_spectra_seps_object->in, + objs->acon_spectra_pfs_object->in); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_istft_connect(objs->amod_istft_seps_object, + objs->acon_spectra_seps_object->outs[0], + objs->acon_hops_seps_object->in); + + amod_istft_connect(objs->amod_istft_pfs_object, + objs->acon_spectra_pfs_object->outs[0], + objs->acon_hops_pfs_object->in); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_resample_connect(objs->amod_resample_seps_object, + objs->acon_hops_seps_object->outs[0], + objs->acon_hops_seps_rs_object->in); + + amod_resample_connect(objs->amod_resample_pfs_object, + objs->acon_hops_pfs_object->outs[0], + objs->acon_hops_pfs_rs_object->in); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_volume_connect(objs->amod_volume_seps_object, + objs->acon_hops_seps_rs_object->outs[0], + objs->acon_hops_seps_vol_object->in); + + amod_volume_connect(objs->amod_volume_pfs_object, + objs->acon_hops_pfs_rs_object->outs[0], + objs->acon_hops_pfs_vol_object->in); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + asnk_hops_connect(objs->asnk_hops_seps_vol_object, + objs->acon_hops_seps_vol_object->outs[0]); + + asnk_hops_connect(objs->asnk_hops_pfs_vol_object, + objs->acon_hops_pfs_vol_object->outs[0]); + + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_classify_connect(objs->amod_classify_object, + objs->acon_hops_seps_object->outs[1], + objs->acon_tracks_sst_object->outs[1], + objs->acon_categories_object->in); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + asnk_categories_connect(objs->asnk_categories_object, + objs->acon_categories_object->outs[0]); + + return objs; + + } + + void aobjects_destroy(aobjects * objs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Destroy | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + asrc_hops_destroy(objs->asrc_hops_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_mics_raw_object); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_mapping_destroy(objs->amod_mapping_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_mics_map_object); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_resample_destroy(objs->amod_resample_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_mics_rs_object); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_stft_destroy(objs->amod_stft_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_spectra_destroy(objs->acon_spectra_mics_object); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_noise_destroy(objs->amod_noise_mics_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_powers_destroy(objs->acon_powers_mics_object); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_ssl_destroy(objs->amod_ssl_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + asnk_pots_destroy(objs->asnk_pots_ssl_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_pots_destroy(objs->acon_pots_ssl_object); + + // +------------------------------------------------------+ + // | Target | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + ainj_targets_destroy(objs->ainj_targets_sst_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_targets_destroy(objs->acon_targets_sst_object); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sst_destroy(objs->amod_sst_object); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + asnk_tracks_destroy(objs->asnk_tracks_sst_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_tracks_destroy(objs->acon_tracks_sst_object); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_sss_destroy(objs->amod_sss_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_spectra_destroy(objs->acon_spectra_seps_object); + acon_spectra_destroy(objs->acon_spectra_pfs_object); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_istft_destroy(objs->amod_istft_seps_object); + amod_istft_destroy(objs->amod_istft_pfs_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_seps_object); + acon_hops_destroy(objs->acon_hops_pfs_object); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_resample_destroy(objs->amod_resample_seps_object); + amod_resample_destroy(objs->amod_resample_pfs_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_seps_rs_object); + acon_hops_destroy(objs->acon_hops_pfs_rs_object); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_volume_destroy(objs->amod_volume_seps_object); + amod_volume_destroy(objs->amod_volume_pfs_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_hops_destroy(objs->acon_hops_seps_vol_object); + acon_hops_destroy(objs->acon_hops_pfs_vol_object); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + asnk_hops_destroy(objs->asnk_hops_seps_vol_object); + asnk_hops_destroy(objs->asnk_hops_pfs_vol_object); + + // +------------------------------------------------------+ + // | Classify | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + amod_classify_destroy(objs->amod_classify_object); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + acon_categories_destroy(objs->acon_categories_object); + + // +--------------------------------------------------+ + // | Sink | + // +--------------------------------------------------+ + + asnk_categories_destroy(objs->asnk_categories_object); + + free((void *) objs); + + } \ No newline at end of file diff --git a/demo/objects.h b/demo/objects.h new file mode 100644 index 0000000..dbb3abf --- /dev/null +++ b/demo/objects.h @@ -0,0 +1,130 @@ +#ifndef __DEMO_OBJECTS +#define __DEMO_OBJECTS + + #include "configs.h" + + #include + #include + #include + + typedef struct objects { + + src_hops_obj * src_hops_mics_object; + con_hops_obj * con_hops_mics_raw_object; + + mod_mapping_obj * mod_mapping_mics_object; + con_hops_obj * con_hops_mics_map_object; + + mod_resample_obj * mod_resample_mics_object; + con_hops_obj * con_hops_mics_rs_object; + + mod_stft_obj * mod_stft_mics_object; + con_spectra_obj * con_spectra_mics_object; + + mod_noise_obj * mod_noise_mics_object; + con_powers_obj * con_powers_mics_object; + + mod_ssl_obj * mod_ssl_object; + snk_pots_obj * snk_pots_ssl_object; + con_pots_obj * con_pots_ssl_object; + + inj_targets_obj * inj_targets_sst_object; + con_targets_obj * con_targets_sst_object; + + mod_sst_obj * mod_sst_object; + snk_tracks_obj * snk_tracks_sst_object; + con_tracks_obj * con_tracks_sst_object; + + mod_sss_obj * mod_sss_object; + con_spectra_obj * con_spectra_seps_object; + con_spectra_obj * con_spectra_pfs_object; + + mod_istft_obj * mod_istft_seps_object; + mod_istft_obj * mod_istft_pfs_object; + con_hops_obj * con_hops_seps_object; + con_hops_obj * con_hops_pfs_object; + + mod_resample_obj * mod_resample_seps_object; + mod_resample_obj * mod_resample_pfs_object; + con_hops_obj * con_hops_seps_rs_object; + con_hops_obj * con_hops_pfs_rs_object; + + mod_volume_obj * mod_volume_seps_object; + mod_volume_obj * mod_volume_pfs_object; + con_hops_obj * con_hops_seps_vol_object; + con_hops_obj * con_hops_pfs_vol_object; + snk_hops_obj * snk_hops_seps_vol_object; + snk_hops_obj * snk_hops_pfs_vol_object; + + mod_classify_obj * mod_classify_object; + con_categories_obj * con_categories_object; + snk_categories_obj * snk_categories_object; + + } objects; + + typedef struct aobjects { + + unsigned int nMessages; + + asrc_hops_obj * asrc_hops_mics_object; + acon_hops_obj * acon_hops_mics_raw_object; + + amod_mapping_obj * amod_mapping_mics_object; + acon_hops_obj * acon_hops_mics_map_object; + + amod_resample_obj * amod_resample_mics_object; + acon_hops_obj * acon_hops_mics_rs_object; + + amod_stft_obj * amod_stft_mics_object; + acon_spectra_obj * acon_spectra_mics_object; + + amod_noise_obj * amod_noise_mics_object; + acon_powers_obj * acon_powers_mics_object; + + amod_ssl_obj * amod_ssl_object; + asnk_pots_obj * asnk_pots_ssl_object; + acon_pots_obj * acon_pots_ssl_object; + + ainj_targets_obj * ainj_targets_sst_object; + acon_targets_obj * acon_targets_sst_object; + + amod_sst_obj * amod_sst_object; + asnk_tracks_obj * asnk_tracks_sst_object; + acon_tracks_obj * acon_tracks_sst_object; + + amod_sss_obj * amod_sss_object; + acon_spectra_obj * acon_spectra_seps_object; + acon_spectra_obj * acon_spectra_pfs_object; + + amod_istft_obj * amod_istft_seps_object; + amod_istft_obj * amod_istft_pfs_object; + acon_hops_obj * acon_hops_seps_object; + acon_hops_obj * acon_hops_pfs_object; + + amod_resample_obj * amod_resample_seps_object; + amod_resample_obj * amod_resample_pfs_object; + acon_hops_obj * acon_hops_seps_rs_object; + acon_hops_obj * acon_hops_pfs_rs_object; + + amod_volume_obj * amod_volume_seps_object; + amod_volume_obj * amod_volume_pfs_object; + acon_hops_obj * acon_hops_seps_vol_object; + acon_hops_obj * acon_hops_pfs_vol_object; + asnk_hops_obj * asnk_hops_seps_vol_object; + asnk_hops_obj * asnk_hops_pfs_vol_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); + + void objects_destroy(objects * objs); + + aobjects * aobjects_construct(const configs * cfgs); + + void aobjects_destroy(aobjects * objs); + +#endif \ No newline at end of file diff --git a/demo/parameters.c b/demo/parameters.c new file mode 100644 index 0000000..4b43509 --- /dev/null +++ b/demo/parameters.c @@ -0,0 +1,2027 @@ + + #include "parameters.h" + + int parameters_lookup_int(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + int rtnValue; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + rtnValue = config_setting_get_int(setting); + + config_destroy(&cfg); + + return rtnValue; + + } + + float parameters_lookup_float(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + float rtnValue; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + rtnValue = (float) config_setting_get_float(setting); + + config_destroy(&cfg); + + return rtnValue; + + } + + char * parameters_lookup_string(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + const char * tmpStr; + char * rtnStr; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + tmpStr = config_setting_get_string(setting); + + rtnStr = (char *) malloc(sizeof(char) * (strlen(tmpStr)+1)); + strcpy(rtnStr, tmpStr); + + config_destroy(&cfg); + + return rtnStr; + + } + + unsigned int parameters_count(const char * file, const char * path) { + + config_t cfg; + config_setting_t * setting; + unsigned int rtnValue; + + config_init(&cfg); + + if(!config_read_file(&cfg, file)) + { + + printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + + exit(EXIT_FAILURE); + + } + + if ((setting = config_lookup(&cfg, path)) == NULL) { + + printf("Cannot find path \"%s\" in config file \"%s\"\n",path,file); + + exit(EXIT_FAILURE); + + } + + rtnValue = config_setting_length(setting); + + config_destroy(&cfg); + + return rtnValue; + + } + + src_hops_cfg * parameters_src_hops_mics_config(const char * fileConfig) { + + src_hops_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = src_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpInt1 = parameters_lookup_int(fileConfig, "raw.nBits"); + + if ((tmpInt1 == 8) || (tmpInt1 == 16) || (tmpInt1 == 24) || (tmpInt1 == 32)) { + cfg->format = format_construct_binary_int(tmpInt1); + } + else { + printf("raw.nBits: Invalid number of bits\n"); + exit(EXIT_FAILURE); + } + + // +----------------------------------------------------------+ + // | Interface | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "raw.interface.type"); + + if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "raw.interface.path"); + + cfg->interface = interface_construct_file(tmpStr2); + + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "raw.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "raw.interface.port"); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "soundcard") == 0) { + + tmpInt1 = parameters_lookup_int(fileConfig, "raw.interface.card"); + tmpInt2 = parameters_lookup_int(fileConfig, "raw.interface.device"); + + cfg->interface = interface_construct_soundcard(tmpInt1, tmpInt2); + + } + else { + printf("raw.interface.type: Invalid type\n"); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr1); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_mics_raw_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "raw.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_lookup_int(fileConfig, "raw.nChannels"); + + return cfg; + + } + + + mod_mapping_cfg * parameters_mod_mapping_mics_config(const char * fileConfig) { + + mod_mapping_cfg * cfg; + unsigned int nLinks; + unsigned int iLink; + char * tmpStr1; + + cfg = mod_mapping_cfg_construct(); + + // +----------------------------------------------------------+ + // | Links | + // +----------------------------------------------------------+ + + nLinks = parameters_count(fileConfig, "mapping.map"); + cfg->links = links_construct_zero(nLinks); + + for (iLink = 0; iLink < nLinks; iLink++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "mapping.map.[%u]", iLink); + cfg->links->array[iLink] = parameters_lookup_int(fileConfig, tmpStr1); + free((void *) tmpStr1); + + } + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_mics_map_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "raw.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "raw.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + mod_resample_cfg * parameters_mod_resample_mics_config(const char * fileConfig) { + + mod_resample_cfg * cfg; + + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = mod_resample_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rates | + // +----------------------------------------------------------+ + + tmpInt1 = parameters_lookup_int(fileConfig, "raw.fS"); + tmpInt2 = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + if (tmpInt1 < tmpInt2) { + printf("general.samplerate.mu: This sample rate must be smaller or equal to raw.fS"); + exit(EXIT_FAILURE); + } + + cfg->fSin = tmpInt1; + cfg->fSout = tmpInt2; + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_mics_rs_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "general.size.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + mod_stft_cfg * parameters_mod_stft_mics_config(const char * fileConfig) { + + mod_stft_cfg * cfg; + + cfg = mod_stft_cfg_construct(); + + return cfg; + + } + + msg_spectra_cfg * parameters_msg_spectra_mics_config(const char * fileConfig) { + + msg_spectra_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + mod_noise_cfg * parameters_mod_noise_mics_config(const char * fileConfig) { + + mod_noise_cfg * cfg; + + cfg = mod_noise_cfg_construct(); + + // +----------------------------------------------------------+ + // | Hanning window size | + // +----------------------------------------------------------+ + + cfg->bSize = parameters_lookup_int(fileConfig, "sne.b"); + + // +----------------------------------------------------------+ + // | alphaS | + // +----------------------------------------------------------+ + + cfg->alphaS = parameters_lookup_float(fileConfig, "sne.alphaS"); + + // +----------------------------------------------------------+ + // | Number of frames | + // +----------------------------------------------------------+ + + cfg->L = parameters_lookup_int(fileConfig, "sne.L"); + + // +----------------------------------------------------------+ + // | delta | + // +----------------------------------------------------------+ + + cfg->delta = parameters_lookup_float(fileConfig, "sne.delta"); + + // +----------------------------------------------------------+ + // | alphaD | + // +----------------------------------------------------------+ + + cfg->alphaD = parameters_lookup_float(fileConfig, "sne.alphaD"); + + return cfg; + + } + + msg_powers_cfg * parameters_msg_powers_mics_config(const char * fileConfig) { + + msg_powers_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_powers_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "mapping.map"); + + return cfg; + + } + + mod_ssl_cfg * parameters_mod_ssl_config(const char * fileConfig) { + + mod_ssl_cfg * cfg; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int iSample; + unsigned int iLevel; + + char * tmpLabel; + char * tmpString; + + cfg = mod_ssl_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + nChannels = parameters_count(fileConfig, "general.mics"); + + cfg->mics = mics_construct_zero(nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + // +--------------------------------------------------+ + // | Mu | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].mu.[%u]", iChannel, iSample); + cfg->mics->mu[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Sigma2 | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 9; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].sigma2.[%u]", iChannel, iSample); + cfg->mics->sigma2[iChannel * 9 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Direction | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].direction.[%u]", iChannel, iSample); + cfg->mics->direction[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Angle | + // +--------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 0); + cfg->mics->thetaAllPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 1); + cfg->mics->thetaNoPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->samplerate = samplerate_construct_zero(); + + cfg->samplerate->mu = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + cfg->samplerate->sigma2 = parameters_lookup_float(fileConfig, "general.samplerate.sigma2"); + + // +----------------------------------------------------------+ + // | Sound speed | + // +----------------------------------------------------------+ + + cfg->soundspeed = soundspeed_construct_zero(); + + cfg->soundspeed->mu = parameters_lookup_float(fileConfig, "general.speedofsound.mu"); + cfg->soundspeed->sigma2 = parameters_lookup_float(fileConfig, "general.speedofsound.sigma2"); + + // +----------------------------------------------------------+ + // | Interpolation | + // +----------------------------------------------------------+ + + cfg->interpRate = parameters_lookup_int(fileConfig, "ssl.interpRate"); + + // +----------------------------------------------------------+ + // | Epsilon | + // +----------------------------------------------------------+ + + cfg->epsilon = parameters_lookup_float(fileConfig, "general.epsilon"); + + // +----------------------------------------------------------+ + // | Levels | + // +----------------------------------------------------------+ + + cfg->nLevels = parameters_count(fileConfig, "ssl.scans"); + + cfg->levels = (unsigned int *) malloc(sizeof(unsigned int) * cfg->nLevels); + cfg->deltas = (signed int *) malloc(sizeof(signed int) * cfg->nLevels); + + for (iLevel = 0; iLevel < cfg->nLevels; iLevel++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "ssl.scans.[%u].level", iLevel); + cfg->levels[iLevel] = parameters_lookup_int(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "ssl.scans.[%u].delta", iLevel); + cfg->deltas[iLevel] = parameters_lookup_int(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Matches | + // +----------------------------------------------------------+ + + cfg->nMatches = parameters_lookup_int(fileConfig, "ssl.nMatches"); + + // +----------------------------------------------------------+ + // | Minimum probability | + // +----------------------------------------------------------+ + + cfg->probMin = parameters_lookup_float(fileConfig, "ssl.probMin"); + + // +----------------------------------------------------------+ + // | Number of refined levels | + // +----------------------------------------------------------+ + + cfg->nRefinedLevels = parameters_lookup_int(fileConfig, "ssl.nRefinedLevels"); + + // +----------------------------------------------------------+ + // | Number of thetas | + // +----------------------------------------------------------+ + + cfg->nThetas = parameters_lookup_int(fileConfig, "general.nThetas"); + + // +----------------------------------------------------------+ + // | Number of thetas | + // +----------------------------------------------------------+ + + cfg->gainMin = parameters_lookup_float(fileConfig, "general.gainMin"); + + // +----------------------------------------------------------+ + // | Spatial filter | + // +----------------------------------------------------------+ + + cfg->spatialfilter = spatialfilter_construct_zero(); + + cfg->spatialfilter->direction[0] = parameters_lookup_float(fileConfig, "general.spatialfilter.direction.[0]"); + cfg->spatialfilter->direction[1] = parameters_lookup_float(fileConfig, "general.spatialfilter.direction.[1]"); + cfg->spatialfilter->direction[2] = parameters_lookup_float(fileConfig, "general.spatialfilter.direction.[2]"); + cfg->spatialfilter->thetaAllPass = parameters_lookup_float(fileConfig, "general.spatialfilter.angle.[0]"); + cfg->spatialfilter->thetaNoPass = parameters_lookup_float(fileConfig, "general.spatialfilter.angle.[1]"); + + return cfg; + + } + + msg_pots_cfg * parameters_msg_pots_ssl_config(const char * fileConfig) { + + msg_pots_cfg * cfg; + + cfg = msg_pots_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Number of potential sources | + // +----------------------------------------------------------+ + + cfg->nPots = parameters_lookup_int(fileConfig, "ssl.nPots"); + + return cfg; + + } + + snk_pots_cfg * parameters_snk_pots_ssl_config(const char * fileConfig) { + + snk_pots_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_pots_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "ssl.potential.format"); + + if (strcmp(tmpStr1, "json") == 0) { cfg->format = format_construct_text_json(); } + else if (strcmp(tmpStr1, "binary") == 0) { cfg->format = format_construct_binary_float(); } + else if (strcmp(tmpStr1, "undefined") == 0) { cfg->format = format_construct_undefined(); } + else { printf("ssl.potential.format: Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Interface | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "ssl.potential.interface.type"); + + if (strcmp(tmpStr1, "blackhole") == 0) { + + cfg->interface = interface_construct_blackhole(); + + } + else if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "ssl.potential.interface.path"); + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "ssl.potential.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "ssl.potential.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("ssl.potential.interface.type: Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + inj_targets_cfg * parameters_inj_targets_sst_config(const char * fileConfig) { + + inj_targets_cfg * cfg; + unsigned int iTarget; + unsigned int nTargets; + float x, y, z; + char * tmpStr1; + char * tmpStr2; + + cfg = inj_targets_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of targets | + // +----------------------------------------------------------+ + + nTargets = parameters_count(fileConfig, "sst.target"); + + cfg->nTargets = nTargets; + + // +----------------------------------------------------------+ + // | Targets | + // +----------------------------------------------------------+ + + cfg->targets = targets_construct_zero(nTargets); + + for (iTarget = 0; iTarget < nTargets; iTarget++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.target.[%u].tag",iTarget); + tmpStr2 = parameters_lookup_string(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.target.[%u].x",iTarget); + x = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.target.[%u].y",iTarget); + y = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.target.[%u].z",iTarget); + z = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + strcpy(cfg->targets->tags[iTarget],tmpStr2); + cfg->targets->array[iTarget *3 + 0] = x; + cfg->targets->array[iTarget *3 + 1] = y; + cfg->targets->array[iTarget *3 + 2] = z; + + free((void *) tmpStr2); + + } + + return cfg; + + } + + msg_targets_cfg * parameters_msg_targets_sst_config(const char * fileConfig) { + + msg_targets_cfg * cfg; + unsigned int nTargets; + + cfg = msg_targets_cfg_construct(); + + // +----------------------------------------------------------+ + // | Number of targets | + // +----------------------------------------------------------+ + + nTargets = parameters_count(fileConfig, "sst.target"); + + cfg->nTargets = nTargets; + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + return cfg; + + } + + mod_sst_cfg * parameters_mod_sst_config(const char * fileConfig) { + + mod_sst_cfg * cfg; + + unsigned int nGaussians; + unsigned int iGaussian; + float weight; + float mu; + float sigma; + + unsigned int iTrack; + char * tmpStr1; + + cfg = mod_sst_cfg_construct(); + + // +----------------------------------------------------------+ + // | Mode | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sst.mode"); + + if (strcmp(tmpStr1, "kalman") == 0) { + cfg->mode = 'k'; + } + else if (strcmp(tmpStr1, "particle") == 0) { + cfg->mode = 'p'; + } + else { + printf("sst.mode: Invalid filter type.\n"); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Add | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sst.add"); + + if (strcmp(tmpStr1, "dynamic") == 0) { + cfg->add = 'd'; + } + else if (strcmp(tmpStr1, "static") == 0) { + cfg->add = 's'; + } + else { + printf("sst.add: Invalid add type.\n"); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | nTracksMax | + // +----------------------------------------------------------+ + + cfg->nTracksMax = parameters_count(fileConfig, "sst.N_inactive"); + + // +----------------------------------------------------------+ + // | hopSize | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "general.size.hopSize"); + + // +----------------------------------------------------------+ + // | Kalman | + // +----------------------------------------------------------+ + + cfg->sigmaQ = parameters_lookup_float(fileConfig, "sst.kalman.sigmaQ"); + + // +----------------------------------------------------------+ + // | Particles | + // +----------------------------------------------------------+ + + cfg->nParticles = parameters_lookup_int(fileConfig, "sst.particle.nParticles"); + cfg->st_alpha = parameters_lookup_float(fileConfig, "sst.particle.st_alpha"); + cfg->st_beta = parameters_lookup_float(fileConfig, "sst.particle.st_beta"); + cfg->st_ratio = parameters_lookup_float(fileConfig, "sst.particle.st_ratio"); + cfg->ve_alpha = parameters_lookup_float(fileConfig, "sst.particle.ve_alpha"); + cfg->ve_beta = parameters_lookup_float(fileConfig, "sst.particle.ve_beta"); + cfg->ve_ratio = parameters_lookup_float(fileConfig, "sst.particle.ve_ratio"); + cfg->ac_alpha = parameters_lookup_float(fileConfig, "sst.particle.ac_alpha"); + cfg->ac_beta = parameters_lookup_float(fileConfig, "sst.particle.ac_beta"); + cfg->ac_ratio = parameters_lookup_float(fileConfig, "sst.particle.ac_ratio"); + cfg->Nmin = parameters_lookup_float(fileConfig, "sst.particle.Nmin"); + + // +----------------------------------------------------------+ + // | Epsilon | + // +----------------------------------------------------------+ + + cfg->epsilon = parameters_lookup_float(fileConfig, "general.epsilon"); + + // +----------------------------------------------------------+ + // | SigmaR | + // +----------------------------------------------------------+ + + cfg->sigmaR_active = sqrtf(parameters_lookup_float(fileConfig, "sst.sigmaR2_active")); + cfg->sigmaR_prob = sqrtf(parameters_lookup_float(fileConfig, "sst.sigmaR2_prob")); + cfg->sigmaR_target = sqrtf(parameters_lookup_float(fileConfig, "sst.sigmaR2_target")); + + // +----------------------------------------------------------+ + // | GMM Active | + // +----------------------------------------------------------+ + + nGaussians = parameters_count(fileConfig, "sst.active"); + + cfg->active_gmm = gaussians_1d_construct_null(nGaussians); + + for (iGaussian = 0; iGaussian < nGaussians; iGaussian++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.active.[%u].weight",iGaussian); + weight = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.active.[%u].mu",iGaussian); + mu = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.active.[%u].sigma2",iGaussian); + sigma = sqrtf(parameters_lookup_float(fileConfig, tmpStr1)); + free((void *) tmpStr1); + + cfg->active_gmm->array[iGaussian] = gaussian_1d_construct_weightmusigma(weight, mu, sigma); + } + + // +----------------------------------------------------------+ + // | GMM Inactive | + // +----------------------------------------------------------+ + + nGaussians = parameters_count(fileConfig, "sst.inactive"); + + cfg->inactive_gmm = gaussians_1d_construct_null(nGaussians); + + for (iGaussian = 0; iGaussian < nGaussians; iGaussian++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.inactive.[%u].weight",iGaussian); + weight = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.inactive.[%u].mu",iGaussian); + mu = parameters_lookup_float(fileConfig, tmpStr1); + free((void *) tmpStr1); + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.inactive.[%u].sigma2",iGaussian); + sigma = sqrtf(parameters_lookup_float(fileConfig, tmpStr1)); + free((void *) tmpStr1); + + cfg->inactive_gmm->array[iGaussian] = gaussian_1d_construct_weightmusigma(weight, mu, sigma); + } + + // +----------------------------------------------------------+ + // | Pfalse, Pnew and Ptrack | + // +----------------------------------------------------------+ + + cfg->Pfalse = parameters_lookup_float(fileConfig, "sst.Pfalse"); + cfg->Pnew = parameters_lookup_float(fileConfig, "sst.Pnew"); + cfg->Ptrack = parameters_lookup_float(fileConfig, "sst.Ptrack"); + + // +----------------------------------------------------------+ + // | New | + // +----------------------------------------------------------+ + + cfg->theta_new = parameters_lookup_float(fileConfig, "sst.theta_new"); + + // +----------------------------------------------------------+ + // | Prob | + // +----------------------------------------------------------+ + + cfg->theta_prob = parameters_lookup_float(fileConfig, "sst.theta_prob"); + cfg->N_prob = parameters_lookup_int(fileConfig, "sst.N_prob"); + + // +----------------------------------------------------------+ + // | Inactive | + // +----------------------------------------------------------+ + + cfg->theta_inactive = parameters_lookup_float(fileConfig, "sst.theta_inactive"); + cfg->N_inactive = (unsigned int *) malloc(sizeof(unsigned int) * cfg->nTracksMax); + + for (iTrack = 0; iTrack < cfg->nTracksMax; iTrack++) { + + tmpStr1 = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr1, "sst.N_inactive.[%u]", iTrack); + cfg->N_inactive[iTrack] = parameters_lookup_int(fileConfig, tmpStr1); + free((void *) tmpStr1); + + } + + return cfg; + + } + + msg_tracks_cfg * parameters_msg_tracks_sst_config(const char * fileConfig) { + + msg_tracks_cfg * cfg; + + cfg = msg_tracks_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Number of tracked sources | + // +----------------------------------------------------------+ + + cfg->nTracks = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + snk_tracks_cfg * parameters_snk_tracks_sst_config(const char * fileConfig) { + + snk_tracks_cfg * cfg; + char * tmpStr1; + char * tmpStr2; + char * tmpLabel; + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = snk_tracks_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sst.tracked.format"); + + if (strcmp(tmpStr1, "json") == 0) { cfg->format = format_construct_text_json(); } + else if (strcmp(tmpStr1, "binary") == 0) { cfg->format = format_construct_binary_float(); } + else if (strcmp(tmpStr1, "undefined") == 0) { cfg->format = format_construct_undefined(); } + else { printf("sst.tracked.format: Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Interface | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sst.tracked.interface.type"); + + if (strcmp(tmpStr1, "blackhole") == 0) { + + cfg->interface = interface_construct_blackhole(); + + } + else if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "sst.tracked.interface.path"); + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "sst.tracked.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "sst.tracked.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("sst.tracked.interface.type: Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + + } + + mod_sss_cfg * parameters_mod_sss_config(const char * fileConfig) { + + mod_sss_cfg * cfg; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int iSample; + + char * tmpStr1; + char * tmpLabel; + + cfg = mod_sss_cfg_construct(); + + // +----------------------------------------------------------+ + // | Mode | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sss.mode_sep"); + + if (strcmp(tmpStr1, "dds") == 0) { + cfg->mode_sep = 'd'; + } + else if (strcmp(tmpStr1, "dgss") == 0) { + cfg->mode_sep = 'g'; + } + else if (strcmp(tmpStr1, "dmvdr") == 0) { + cfg->mode_sep = 'm'; + } + else { + printf("sss.mode_sep: Invalid separation method.\n"); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr1); + + tmpStr1 = parameters_lookup_string(fileConfig, "sss.mode_pf"); + + if (strcmp(tmpStr1, "ms") == 0) { + cfg->mode_pf = 'm'; + } + else { + printf("sss.mode_pf: Invalid post-filtering method.\n"); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + nChannels = parameters_count(fileConfig, "general.mics"); + + cfg->mics = mics_construct_zero(nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + // +--------------------------------------------------+ + // | Mu | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].mu.[%u]", iChannel, iSample); + cfg->mics->mu[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Sigma2 | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 9; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].sigma2.[%u]", iChannel, iSample); + cfg->mics->sigma2[iChannel * 9 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Direction | + // +--------------------------------------------------+ + + for (iSample = 0; iSample < 3; iSample++) { + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].direction.[%u]", iChannel, iSample); + cfg->mics->direction[iChannel * 3 + iSample] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +--------------------------------------------------+ + // | Angle | + // +--------------------------------------------------+ + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 0); + cfg->mics->thetaAllPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + tmpLabel = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpLabel, "general.mics.[%u].angle.[%u]", iChannel, 1); + cfg->mics->thetaNoPass[iChannel] = parameters_lookup_float(fileConfig, tmpLabel); + free((void *) tmpLabel); + + } + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->samplerate = samplerate_construct_zero(); + + cfg->samplerate->mu = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + cfg->samplerate->sigma2 = parameters_lookup_float(fileConfig, "general.samplerate.sigma2"); + + // +----------------------------------------------------------+ + // | Sound speed | + // +----------------------------------------------------------+ + + cfg->soundspeed = soundspeed_construct_zero(); + + cfg->soundspeed->mu = parameters_lookup_float(fileConfig, "general.speedofsound.mu"); + cfg->soundspeed->sigma2 = parameters_lookup_float(fileConfig, "general.speedofsound.sigma2"); + + // +----------------------------------------------------------+ + // | Spatial filter | + // +----------------------------------------------------------+ + + cfg->spatialfilter = spatialfilter_construct_zero(); + + cfg->spatialfilter->direction[0] = parameters_lookup_float(fileConfig, "general.spatialfilter.direction.[0]"); + cfg->spatialfilter->direction[1] = parameters_lookup_float(fileConfig, "general.spatialfilter.direction.[1]"); + cfg->spatialfilter->direction[2] = parameters_lookup_float(fileConfig, "general.spatialfilter.direction.[2]"); + cfg->spatialfilter->thetaAllPass = parameters_lookup_float(fileConfig, "general.spatialfilter.angle.[0]"); + cfg->spatialfilter->thetaNoPass = parameters_lookup_float(fileConfig, "general.spatialfilter.angle.[1]"); + + // +----------------------------------------------------------+ + // | Number of thetas | + // +----------------------------------------------------------+ + + cfg->nThetas = parameters_lookup_int(fileConfig, "general.nThetas"); + + // +----------------------------------------------------------+ + // | Number of thetas | + // +----------------------------------------------------------+ + + cfg->gainMin = parameters_lookup_float(fileConfig, "general.gainMin"); + + // +----------------------------------------------------------+ + // | Epsilon | + // +----------------------------------------------------------+ + + cfg->epsilon = parameters_lookup_float(fileConfig, "general.epsilon"); + + // +----------------------------------------------------------+ + // | Mu | + // +----------------------------------------------------------+ + + cfg->sep_gss_mu = parameters_lookup_float(fileConfig, "sss.dgss.mu"); + + // +----------------------------------------------------------+ + // | Lambda | + // +----------------------------------------------------------+ + + cfg->sep_gss_lambda = parameters_lookup_float(fileConfig, "sss.dgss.lambda"); + + // +----------------------------------------------------------+ + // | Hanning window size | + // +----------------------------------------------------------+ + + cfg->pf_multi_bSize = parameters_lookup_int(fileConfig, "sne.b"); + + // +----------------------------------------------------------+ + // | alphaS | + // +----------------------------------------------------------+ + + cfg->pf_multi_alphaS = parameters_lookup_float(fileConfig, "sne.alphaS"); + + // +----------------------------------------------------------+ + // | Number of frames | + // +----------------------------------------------------------+ + + cfg->pf_multi_L = parameters_lookup_int(fileConfig, "sne.L"); + + // +----------------------------------------------------------+ + // | delta | + // +----------------------------------------------------------+ + + cfg->pf_multi_delta = parameters_lookup_float(fileConfig, "sne.delta"); + + // +----------------------------------------------------------+ + // | alphaD | + // +----------------------------------------------------------+ + + cfg->pf_multi_alphaD = parameters_lookup_float(fileConfig, "sne.alphaD"); + + // +----------------------------------------------------------+ + // | eta | + // +----------------------------------------------------------+ + + cfg->pf_multi_eta = parameters_lookup_float(fileConfig, "sss.ms.eta"); + + // +----------------------------------------------------------+ + // | alphaZ | + // +----------------------------------------------------------+ + + cfg->pf_multi_alphaZ = parameters_lookup_float(fileConfig, "sss.ms.alphaZ"); + + // +----------------------------------------------------------+ + // | alphaPmin | + // +----------------------------------------------------------+ + + cfg->pf_multi_alphaPmin = parameters_lookup_float(fileConfig, "sss.ms.alphaPmin"); + + // +----------------------------------------------------------+ + // | thetaWin | + // +----------------------------------------------------------+ + + cfg->pf_multi_thetaWin = parameters_lookup_float(fileConfig, "sss.ms.thetaWin"); + + // +----------------------------------------------------------+ + // | alphaWin | + // +----------------------------------------------------------+ + + cfg->pf_multi_alphaWin = parameters_lookup_float(fileConfig, "sss.ms.alphaWin"); + + // +----------------------------------------------------------+ + // | maxAbsenceProb | + // +----------------------------------------------------------+ + + cfg->pf_multi_maxAbsenceProb = parameters_lookup_float(fileConfig, "sss.ms.maxAbsenceProb"); + + // +----------------------------------------------------------+ + // | Gmin | + // +----------------------------------------------------------+ + + cfg->pf_multi_Gmin = parameters_lookup_float(fileConfig, "sss.ms.Gmin"); + + // +----------------------------------------------------------+ + // | winSizeLocal | + // +----------------------------------------------------------+ + + cfg->pf_multi_winSizeLocal = parameters_lookup_int(fileConfig, "sss.ms.winSizeLocal"); + + // +----------------------------------------------------------+ + // | winSizeGlobal | + // +----------------------------------------------------------+ + + cfg->pf_multi_winSizeGlobal = parameters_lookup_int(fileConfig, "sss.ms.winSizeGlobal"); + + // +----------------------------------------------------------+ + // | winSizeFrame | + // +----------------------------------------------------------+ + + cfg->pf_multi_winSizeFrame = parameters_lookup_int(fileConfig, "sss.ms.winSizeFrame"); + + return cfg; + + } + + msg_spectra_cfg * parameters_msg_spectra_seps_config(const char * fileConfig) { + + msg_spectra_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Half frame size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + msg_spectra_cfg * parameters_msg_spectra_pfs_config(const char * fileConfig) { + + msg_spectra_cfg * cfg; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + cfg = msg_spectra_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Half frame size | + // +----------------------------------------------------------+ + + cfg->halfFrameSize = parameters_lookup_int(fileConfig, "general.size.frameSize") / 2 + 1; + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + mod_istft_cfg * parameters_mod_istft_seps_config(const char * fileConfig) { + + mod_istft_cfg * cfg; + + cfg = mod_istft_cfg_construct(); + + return cfg; + + } + + mod_istft_cfg * parameters_mod_istft_pfs_config(const char * fileConfig) { + + mod_istft_cfg * cfg; + + cfg = mod_istft_cfg_construct(); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_seps_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "general.size.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_pfs_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "general.size.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + mod_resample_cfg * parameters_mod_resample_seps_config(const char * fileConfig) { + + mod_resample_cfg * cfg; + + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = mod_resample_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rates | + // +----------------------------------------------------------+ + + tmpInt1 = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + tmpInt2 = parameters_lookup_int(fileConfig, "sss.separated.fS"); + + cfg->fSin = tmpInt1; + cfg->fSout = tmpInt2; + + return cfg; + + } + + mod_resample_cfg * parameters_mod_resample_pfs_config(const char * fileConfig) { + + mod_resample_cfg * cfg; + + unsigned int tmpInt1; + unsigned int tmpInt2; + + cfg = mod_resample_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rates | + // +----------------------------------------------------------+ + + tmpInt1 = parameters_lookup_int(fileConfig, "general.samplerate.mu"); + tmpInt2 = parameters_lookup_int(fileConfig, "sss.postfiltered.fS"); + + cfg->fSin = tmpInt1; + cfg->fSout = tmpInt2; + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_seps_rs_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "sss.separated.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "sss.separated.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_pfs_rs_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "sss.postfiltered.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "sss.postfiltered.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + mod_volume_cfg * parameters_mod_volume_seps_config(const char * fileConfig) { + + mod_volume_cfg * cfg; + + cfg = mod_volume_cfg_construct(); + + // +----------------------------------------------------------+ + // | Gain | + // +----------------------------------------------------------+ + + cfg->gain = parameters_lookup_float(fileConfig, "sss.gain_sep"); + + return cfg; + + } + + mod_volume_cfg * parameters_mod_volume_pfs_config(const char * fileConfig) { + + mod_volume_cfg * cfg; + + cfg = mod_volume_cfg_construct(); + + // +----------------------------------------------------------+ + // | Gain | + // +----------------------------------------------------------+ + + cfg->gain = parameters_lookup_float(fileConfig, "sss.gain_pf"); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_seps_vol_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "sss.separated.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "sss.separated.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + msg_hops_cfg * parameters_msg_hops_pfs_vol_config(const char * fileConfig) { + + msg_hops_cfg * cfg; + + cfg = msg_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "sss.postfiltered.fS"); + + // +----------------------------------------------------------+ + // | Hop size | + // +----------------------------------------------------------+ + + cfg->hopSize = parameters_lookup_int(fileConfig, "sss.postfiltered.hopSize"); + + // +----------------------------------------------------------+ + // | Number of channels | + // +----------------------------------------------------------+ + + cfg->nChannels = parameters_count(fileConfig, "sst.N_inactive"); + + return cfg; + + } + + snk_hops_cfg * parameters_snk_hops_seps_vol_config(const char * fileConfig) { + + snk_hops_cfg * cfg; + unsigned int tmpInt1; + char * tmpStr1; + char * tmpStr2; + + cfg = snk_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "sss.separated.fS"); + + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpInt1 = parameters_lookup_int(fileConfig, "sss.separated.nBits"); + + if ((tmpInt1 == 8) || (tmpInt1 == 16) || (tmpInt1 == 24) || (tmpInt1 == 32)) { + cfg->format = format_construct_binary_int(tmpInt1); + } + else { + printf("raw.nBits: Invalid number of bits\n"); + exit(EXIT_FAILURE); + } + + // +----------------------------------------------------------+ + // | Interface | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sss.separated.interface.type"); + + if (strcmp(tmpStr1, "blackhole") == 0) { + + cfg->interface = interface_construct_blackhole(); + cfg->format = format_construct_undefined(); + + } + else if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "sss.separated.interface.path"); + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "sss.separated.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "sss.separated.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("sss.separated.interface.type: Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } + + snk_hops_cfg * parameters_snk_hops_pfs_vol_config(const char * fileConfig) { + + snk_hops_cfg * cfg; + unsigned int tmpInt1; + char * tmpStr1; + char * tmpStr2; + + cfg = snk_hops_cfg_construct(); + + // +----------------------------------------------------------+ + // | Sample rate | + // +----------------------------------------------------------+ + + cfg->fS = parameters_lookup_int(fileConfig, "sss.postfiltered.fS"); + + // +----------------------------------------------------------+ + // | Format | + // +----------------------------------------------------------+ + + tmpInt1 = parameters_lookup_int(fileConfig, "sss.postfiltered.nBits"); + + if ((tmpInt1 == 8) || (tmpInt1 == 16) || (tmpInt1 == 24) || (tmpInt1 == 32)) { + cfg->format = format_construct_binary_int(tmpInt1); + } + else { + printf("raw.nBits: Invalid number of bits\n"); + exit(EXIT_FAILURE); + } + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "sss.postfiltered.interface.type"); + + if (strcmp(tmpStr1, "blackhole") == 0) { + + cfg->interface = interface_construct_blackhole(); + cfg->format = format_construct_undefined(); + + } + else if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "sss.postfiltered.interface.path"); + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "sss.postfiltered.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "sss.postfiltered.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("sss.postfiltered.interface.type: Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + 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"); + + // +----------------------------------------------------------+ + // | r0 | + // +----------------------------------------------------------+ + + cfg->r0 = parameters_lookup_float(fileConfig, "classify.r0"); + + 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 if (strcmp(tmpStr1, "undefined") == 0) { cfg->format = format_construct_undefined(); } + else { printf("classify.category.format: Invalid format\n"); exit(EXIT_FAILURE); } + + free((void *) tmpStr1); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + tmpStr1 = parameters_lookup_string(fileConfig, "classify.category.interface.type"); + + if (strcmp(tmpStr1, "blackhole") == 0) { + + cfg->interface = interface_construct_blackhole(); + + } + else if (strcmp(tmpStr1, "file") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "classify.category.interface.path"); + cfg->interface = interface_construct_file(tmpStr2); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "socket") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "classify.category.interface.ip"); + tmpInt1 = parameters_lookup_int(fileConfig, "classify.category.interface.port"); + + cfg->interface = interface_construct_socket(tmpStr2, tmpInt1); + free((void *) tmpStr2); + + } + else if (strcmp(tmpStr1, "terminal") == 0) { + + cfg->interface = interface_construct_terminal(); + + } + else { + + printf("classify.category.interface.type: Invalid type\n"); + exit(EXIT_FAILURE); + + } + + free((void *) tmpStr1); + + return cfg; + + } \ No newline at end of file diff --git a/demo/parameters.h b/demo/parameters.h new file mode 100644 index 0000000..10daacd --- /dev/null +++ b/demo/parameters.h @@ -0,0 +1,104 @@ +#ifndef __DEMO_PARAMETERS +#define __DEMO_PARAMETERS + + #include + #include + + int parameters_lookup_int(const char * file, const char * path); + + float parameters_lookup_float(const char * file, const char * path); + + char * parameters_lookup_string(const char * file, const char * path); + + unsigned int parameters_count(const char * file, const char * path); + + + src_hops_cfg * parameters_src_hops_mics_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_mics_raw_config(const char * fileConfig); + + + mod_mapping_cfg * parameters_mod_mapping_mics_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_mics_map_config(const char * fileConfig); + + + mod_resample_cfg * parameters_mod_resample_mics_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_mics_rs_config(const char * fileConfig); + + + mod_stft_cfg * parameters_mod_stft_mics_config(const char * fileConfig); + + msg_spectra_cfg * parameters_msg_spectra_mics_config(const char * fileConfig); + + + mod_noise_cfg * parameters_mod_noise_mics_config(const char * fileConfig); + + msg_powers_cfg * parameters_msg_powers_mics_config(const char * fileConfig); + + + mod_ssl_cfg * parameters_mod_ssl_config(const char * fileConfig); + + msg_pots_cfg * parameters_msg_pots_ssl_config(const char * fileConfig); + + snk_pots_cfg * parameters_snk_pots_ssl_config(const char * fileConfig); + + + inj_targets_cfg * parameters_inj_targets_sst_config(const char * fileConfig); + + msg_targets_cfg * parameters_msg_targets_sst_config(const char * fileConfig); + + + mod_sst_cfg * parameters_mod_sst_config(const char * fileConfig); + + msg_tracks_cfg * parameters_msg_tracks_sst_config(const char * fileConfig); + + snk_tracks_cfg * parameters_snk_tracks_sst_config(const char * fileConfig); + + + mod_sss_cfg * parameters_mod_sss_config(const char * fileConfig); + + msg_spectra_cfg * parameters_msg_spectra_seps_config(const char * fileConfig); + + msg_spectra_cfg * parameters_msg_spectra_pfs_config(const char * fileConfig); + + + mod_istft_cfg * parameters_mod_istft_seps_config(const char * fileConfig); + + mod_istft_cfg * parameters_mod_istft_pfs_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_seps_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_pfs_config(const char * fileConfig); + + + mod_resample_cfg * parameters_mod_resample_seps_config(const char * fileConfig); + + mod_resample_cfg * parameters_mod_resample_pfs_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_seps_rs_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_pfs_rs_config(const char * fileConfig); + + + mod_volume_cfg * parameters_mod_volume_seps_config(const char * fileConfig); + + mod_volume_cfg * parameters_mod_volume_pfs_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_seps_vol_config(const char * fileConfig); + + msg_hops_cfg * parameters_msg_hops_pfs_vol_config(const char * fileConfig); + + snk_hops_cfg * parameters_snk_hops_seps_vol_config(const char * fileConfig); + + snk_hops_cfg * parameters_snk_hops_pfs_vol_config(const char * fileConfig); + + + mod_classify_cfg * parameters_mod_classify_config(const char * fileConfig); + + msg_categories_cfg * parameters_msg_categories_config(const char * fileConfig); + + snk_categories_cfg * parameters_snk_categories_config(const char * fileConfig); + +#endif \ No newline at end of file diff --git a/demo/profiler.c b/demo/profiler.c new file mode 100644 index 0000000..cccabab --- /dev/null +++ b/demo/profiler.c @@ -0,0 +1,177 @@ + + #include "profiler.h" + + profiler * profiler_construct(void) { + + profiler * prf; + + prf = (profiler *) malloc(sizeof(profiler)); + + prf->duration = 0.0f; + + prf->src_hops_mics_prf = 0.0f; + prf->con_hops_mics_raw_prf = 0.0f; + + prf->mod_mapping_mics_prf = 0.0f; + prf->con_hops_mics_map_prf = 0.0f; + + prf->mod_resample_mics_prf = 0.0f; + prf->con_hops_mics_rs_prf = 0.0f; + + prf->mod_stft_mics_prf = 0.0f; + prf->con_spectra_mics_prf = 0.0f; + + prf->mod_noise_mics_prf = 0.0f; + prf->con_powers_mics_prf = 0.0f; + + prf->mod_ssl_prf = 0.0f; + prf->con_pots_ssl_prf = 0.0f; + prf->snk_pots_ssl_prf = 0.0f; + + prf->inj_targets_sst_prf = 0.0f; + prf->con_targets_sst_prf = 0.0f; + + prf->mod_sst_prf = 0.0f; + prf->con_tracks_sst_prf = 0.0f; + prf->snk_tracks_sst_prf = 0.0f; + + prf->mod_sss_prf = 0.0f; + prf->con_spectra_seps_prf = 0.0f; + prf->con_spectra_pfs_prf = 0.0f; + + prf->mod_istft_seps_prf = 0.0f;; + prf->mod_istft_pfs_prf = 0.0f;; + prf->con_hops_seps_prf = 0.0f; + prf->con_hops_pfs_prf = 0.0f; + + prf->mod_resample_seps_prf = 0.0f; + prf->mod_resample_pfs_prf = 0.0f; + prf->con_hops_seps_rs_prf = 0.0f; + prf->con_hops_pfs_rs_prf = 0.0f; + + prf->mod_volume_seps_prf = 0.0f; + prf->mod_volume_pfs_prf = 0.0f; + prf->con_hops_seps_vol_prf = 0.0f; + prf->con_hops_pfs_vol_prf = 0.0f; + prf->snk_hops_seps_vol_prf = 0.0f; + prf->snk_hops_pfs_vol_prf = 0.0f; + + prf->mod_classify_prf = 0.0f; + prf->con_categories_prf = 0.0f; + prf->snk_categories_prf = 0.0f; + + return prf; + + } + + void profiler_destroy(profiler * prf) { + + free((void *) prf); + + } + + void profiler_printf(const profiler * prf) { + + float source, sink, module, injector, connector; + float total; + + source = prf->src_hops_mics_prf; + + sink = prf->snk_pots_ssl_prf + + prf->snk_tracks_sst_prf + + prf->snk_hops_seps_vol_prf + + prf->snk_hops_pfs_vol_prf + + prf->snk_categories_prf; + + module = prf->mod_mapping_mics_prf + + prf->mod_resample_mics_prf + + prf->mod_stft_mics_prf + + prf->mod_noise_mics_prf + + prf->mod_ssl_prf + + prf->mod_sst_prf + + prf->mod_sss_prf + + prf->mod_istft_seps_prf + + prf->mod_istft_pfs_prf + + prf->mod_resample_seps_prf + + prf->mod_resample_pfs_prf + + prf->mod_volume_seps_prf + + prf->mod_volume_pfs_prf + + prf->mod_classify_prf; + + injector = prf->inj_targets_sst_prf; + + connector = prf->con_hops_mics_raw_prf + + prf->con_hops_mics_map_prf + + prf->con_hops_mics_rs_prf + + prf->con_spectra_mics_prf + + prf->con_powers_mics_prf + + prf->con_pots_ssl_prf + + prf->con_targets_sst_prf + + prf->con_tracks_sst_prf + + prf->con_spectra_seps_prf + + prf->con_spectra_pfs_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_seps_vol_prf + + prf->con_hops_pfs_vol_prf + + prf->con_categories_prf; + + total = source + sink + module + connector; + + printf("+--------------------------------------------+\n"); + printf("| Profiler summary |\n"); + printf("+--------------------------------------------+\n"); + printf("| + Raw |\n"); + printf("| - Source.......... %07.3f (%06.2f%%) |\n",prf->src_hops_mics_prf,roundf(10000.0f * prf->src_hops_mics_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_hops_mics_raw_prf,roundf(10000.0f * prf->con_hops_mics_raw_prf / prf->duration) / 100.0f); + printf("| + Mapping |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_mapping_mics_prf,roundf(10000.0f * prf->mod_mapping_mics_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_hops_mics_map_prf,roundf(10000.0f * prf->con_hops_mics_map_prf / prf->duration) / 100.0f); + printf("| + Resample |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_resample_mics_prf,roundf(10000.0f * prf->mod_resample_mics_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_hops_mics_rs_prf,roundf(10000.0f * prf->con_hops_mics_rs_prf / prf->duration) / 100.0f); + printf("| + STFT |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_stft_mics_prf,roundf(10000.0f * prf->mod_stft_mics_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_spectra_mics_prf,roundf(10000.0f * prf->con_spectra_mics_prf / prf->duration) / 100.0f); + printf("| + Noise |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_noise_mics_prf,roundf(10000.0f * prf->mod_noise_mics_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_powers_mics_prf,roundf(10000.0f * prf->con_powers_mics_prf / prf->duration) / 100.0f); + printf("| + SSL |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_ssl_prf,roundf(10000.0f * prf->mod_ssl_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_pots_ssl_prf,roundf(10000.0f * prf->con_pots_ssl_prf / prf->duration) / 100.0f); + printf("| - Sink............ %07.3f (%06.2f%%) |\n",prf->snk_pots_ssl_prf,roundf(10000.0f * prf->snk_pots_ssl_prf / prf->duration) / 100.0f); + printf("| + Target |\n"); + printf("| - Injector........ %07.3f (%06.2f%%) |\n",prf->inj_targets_sst_prf,roundf(10000.0f * prf->inj_targets_sst_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_targets_sst_prf,roundf(10000.0f * prf->con_targets_sst_prf / prf->duration) / 100.0f); + printf("| + SST |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_sst_prf,roundf(10000.0f * prf->mod_sst_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",prf->con_tracks_sst_prf,roundf(10000.0f * prf->con_tracks_sst_prf / prf->duration) / 100.0f); + printf("| - Sink............ %07.3f (%06.2f%%) |\n",prf->snk_tracks_sst_prf,roundf(10000.0f * prf->snk_tracks_sst_prf / prf->duration) / 100.0f); + printf("| + SSS |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",prf->mod_sss_prf,roundf(10000.0f * prf->mod_sss_prf / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",(prf->con_spectra_seps_prf+prf->con_spectra_pfs_prf),roundf(10000.0f * (prf->con_spectra_seps_prf+prf->con_spectra_pfs_prf) / 100.0f)); + printf("| + ISTFT |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",(prf->mod_istft_seps_prf+prf->mod_istft_pfs_prf),roundf(10000.0f * (prf->mod_istft_seps_prf+prf->mod_istft_pfs_prf) / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",(prf->con_hops_seps_prf+prf->con_hops_pfs_prf),roundf(10000.0f * (prf->con_hops_seps_prf+prf->con_hops_pfs_prf) / prf->duration) / 100.0f); + printf("| + Resample |\n"); + 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("| + Volume |\n"); + printf("| - Module.......... %07.3f (%06.2f%%) |\n",(prf->mod_volume_seps_prf+prf->mod_volume_pfs_prf),roundf(10000.0f * (prf->mod_volume_seps_prf+prf->mod_volume_pfs_prf) / prf->duration) / 100.0f); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",(prf->con_hops_seps_vol_prf+prf->con_hops_pfs_vol_prf),roundf(10000.0f * (prf->con_hops_seps_vol_prf+prf->con_hops_pfs_vol_prf) / prf->duration) / 100.0f); + printf("| - Sink............ %07.3f (%06.2f%%) |\n",(prf->snk_hops_seps_vol_prf+prf->snk_hops_pfs_vol_prf),roundf(10000.0f * (prf->snk_hops_seps_vol_prf+prf->snk_hops_pfs_vol_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); + printf("| - Connector....... %07.3f (%06.2f%%) |\n",connector,roundf(10000.0f * connector / prf->duration) / 100.0f); + printf("| - Source.......... %07.3f (%06.2f%%) |\n",source,roundf(10000.0f * source / prf->duration) / 100.0f); + printf("| - Sink............ %07.3f (%06.2f%%) |\n",sink,roundf(10000.0f * sink / prf->duration) / 100.0f); + printf("+--------------------------------------------+\n"); + + } \ No newline at end of file diff --git a/demo/profiler.h b/demo/profiler.h new file mode 100644 index 0000000..bf803be --- /dev/null +++ b/demo/profiler.h @@ -0,0 +1,71 @@ +#ifndef __DEMO_PROFILER +#define __DEMO_PROFILER + + #include + #include + #include + + typedef struct profiler { + + float duration; + + float src_hops_mics_prf; + float con_hops_mics_raw_prf; + + float mod_mapping_mics_prf; + float con_hops_mics_map_prf; + + float mod_resample_mics_prf; + float con_hops_mics_rs_prf; + + float mod_stft_mics_prf; + float con_spectra_mics_prf; + + float mod_noise_mics_prf; + float con_powers_mics_prf; + + float mod_ssl_prf; + float con_pots_ssl_prf; + float snk_pots_ssl_prf; + + float inj_targets_sst_prf; + float con_targets_sst_prf; + + float mod_sst_prf; + float con_tracks_sst_prf; + float snk_tracks_sst_prf; + + float mod_sss_prf; + float con_spectra_seps_prf; + float con_spectra_pfs_prf; + + float mod_istft_seps_prf; + float mod_istft_pfs_prf; + float con_hops_seps_prf; + float con_hops_pfs_prf; + + float mod_resample_seps_prf; + float mod_resample_pfs_prf; + float con_hops_seps_rs_prf; + float con_hops_pfs_rs_prf; + + float mod_volume_seps_prf; + float mod_volume_pfs_prf; + float con_hops_seps_vol_prf; + float con_hops_pfs_vol_prf; + float snk_hops_seps_vol_prf; + float snk_hops_pfs_vol_prf; + + float mod_classify_prf; + float con_categories_prf; + float snk_categories_prf; + + } profiler; + + profiler * profiler_construct(void); + + void profiler_destroy(profiler * prf); + + void profiler_printf(const profiler * prf); + +#endif \ No newline at end of file diff --git a/demo/server.c b/demo/server.c new file mode 100644 index 0000000..b1b803d --- /dev/null +++ b/demo/server.c @@ -0,0 +1,107 @@ + #include + #include + #include + #include + #include + #include + #include + #include + + int main(int argc, char* argv[]) + { + + char verbose = 0x00; + + int server_id; + struct sockaddr_in server_address; + int connection_id; + char * message; + int messageSize; + + int c; + unsigned int portNumber; + char * fileName; + FILE * fp; + + const unsigned int nBytes = 10240; + + while ((c = getopt(argc,argv, "p:o:hv")) != -1) { + + switch(c) { + + case 'h': + + printf("+----------------------------------------------------+\n"); + printf("| ODAS (Open embeddeD Audition System) |\n"); + printf("+----------------------------------------------------+\n"); + printf("| Author: Francois Grondin |\n"); + printf("| Email: francois.grondin2@usherbrooke.ca |\n"); + printf("| Website: introlab.3it.usherbrooke.ca |\n"); + printf("| Repository: github.com/introlab/odas |\n"); + printf("| Version: 1.0 |\n"); + printf("+----------------------------------------------------+\n"); + printf("| -h Help |\n"); + printf("| -o Output file |\n"); + printf("| -p Port number |\n"); + printf("| -v Verbose |\n"); + printf("+----------------------------------------------------+\n"); + + exit(EXIT_SUCCESS); + + case 'o': + + fileName = (char *) malloc(sizeof(char) * (strlen(optarg)+1)); + strcpy(fileName, optarg); + + break; + + case 'p': + + portNumber = atoi(optarg); + + break; + + + } + + } + + server_id = socket(AF_INET, SOCK_STREAM, 0); + + server_address.sin_family = AF_INET; + server_address.sin_addr.s_addr = htonl(INADDR_ANY); + server_address.sin_port = htons(portNumber); + + printf("Opening file............. "); fflush(stdout); + fp = fopen(fileName, "wb"); + printf("[OK]\n"); + + printf("Binding socket........... "); fflush(stdout); + bind(server_id, (struct sockaddr *) &server_address, sizeof(server_address)); + printf("[OK]\n"); + + printf("Listening socket......... "); fflush(stdout); + listen(server_id, 1); + printf("[OK]\n"); + + printf("Waiting for connection... "); fflush(stdout); + connection_id = accept(server_id, (struct sockaddr*) NULL, NULL); + printf("[OK]\n"); + + message = (char *) malloc(sizeof(char) * nBytes); + + printf("Receiving data........... "); fflush(stdout); + while( (messageSize = recv(connection_id, message, nBytes, 0)) > 0) { + + message[messageSize] = 0x00; + + fwrite(message, messageSize, sizeof(char), fp); + + } + printf("[OK]\n"); + + printf("Closing file............. "); fflush(stdout); + fclose(fp); + printf("[OK]\n"); + + } \ No newline at end of file diff --git a/demo/threads.c b/demo/threads.c new file mode 100644 index 0000000..bdefd2c --- /dev/null +++ b/demo/threads.c @@ -0,0 +1,1086 @@ + + #include "threads.h" + + void threads_multiple_start(aobjects * aobjs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + thread_start(aobjs->asrc_hops_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_hops_mics_raw_object->thread); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_mapping_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_hops_mics_map_object->thread); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_resample_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_hops_mics_rs_object->thread); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_stft_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_spectra_mics_object->thread); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_noise_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_powers_mics_object->thread); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_ssl_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + thread_start(aobjs->asnk_pots_ssl_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_pots_ssl_object->thread); + + // +----------------------------------------------------------+ + // | Targets | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Injector | + // +------------------------------------------------------+ + + thread_start(aobjs->ainj_targets_sst_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_targets_sst_object->thread); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_sst_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + thread_start(aobjs->asnk_tracks_sst_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_tracks_sst_object->thread); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_sss_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_spectra_seps_object->thread); + thread_start(aobjs->acon_spectra_pfs_object->thread); + + // +----------------------------------------------------------+ + // | ISTFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_start(aobjs->amod_istft_seps_object->thread); + thread_start(aobjs->amod_istft_pfs_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_start(aobjs->acon_hops_seps_object->thread); + thread_start(aobjs->acon_hops_pfs_object->thread); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + thread_start(aobjs->amod_resample_seps_object->thread); + thread_start(aobjs->amod_resample_pfs_object->thread); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + thread_start(aobjs->acon_hops_seps_rs_object->thread); + thread_start(aobjs->acon_hops_pfs_rs_object->thread); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + thread_start(aobjs->amod_volume_seps_object->thread); + thread_start(aobjs->amod_volume_pfs_object->thread); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + thread_start(aobjs->asnk_hops_seps_vol_object->thread); + thread_start(aobjs->asnk_hops_pfs_vol_object->thread); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + thread_start(aobjs->acon_hops_seps_vol_object->thread); + thread_start(aobjs->acon_hops_pfs_vol_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) { + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + thread_stop(aobjs->asrc_hops_mics_object->thread); + + // Stops the source that generate frames to process. + // This will generate a "zero" message that will stop + // all following threads. + + } + + void threads_multiple_join(aobjects * aobjs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + thread_join(aobjs->asrc_hops_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_hops_mics_raw_object->thread); + + // +----------------------------------------------------------+ + // | Mapping | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_mapping_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_hops_mics_map_object->thread); + + // +----------------------------------------------------------+ + // | Resample | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_resample_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_hops_mics_rs_object->thread); + + // +----------------------------------------------------------+ + // | STFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_stft_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_spectra_mics_object->thread); + + // +----------------------------------------------------------+ + // | Noise | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_noise_mics_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_powers_mics_object->thread); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_ssl_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + thread_join(aobjs->asnk_pots_ssl_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_pots_ssl_object->thread); + + // +----------------------------------------------------------+ + // | Targets | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Injector | + // +------------------------------------------------------+ + + thread_join(aobjs->ainj_targets_sst_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_targets_sst_object->thread); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_sst_object->thread); + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + thread_join(aobjs->asnk_tracks_sst_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_tracks_sst_object->thread); + + // +----------------------------------------------------------+ + // | SSS | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_sss_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_spectra_seps_object->thread); + thread_join(aobjs->acon_spectra_pfs_object->thread); + + // +----------------------------------------------------------+ + // | ISTFT | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Module | + // +------------------------------------------------------+ + + thread_join(aobjs->amod_istft_seps_object->thread); + thread_join(aobjs->amod_istft_pfs_object->thread); + + // +------------------------------------------------------+ + // | Connector | + // +------------------------------------------------------+ + + thread_join(aobjs->acon_hops_seps_object->thread); + thread_join(aobjs->acon_hops_pfs_object->thread); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + thread_join(aobjs->amod_resample_seps_object->thread); + thread_join(aobjs->amod_resample_pfs_object->thread); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + thread_join(aobjs->acon_hops_seps_rs_object->thread); + thread_join(aobjs->acon_hops_pfs_rs_object->thread); + + // +------------------------------------------------------+ + // | Volume | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + thread_join(aobjs->amod_volume_seps_object->thread); + thread_join(aobjs->amod_volume_pfs_object->thread); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + thread_join(aobjs->asnk_hops_seps_vol_object->thread); + thread_join(aobjs->asnk_hops_pfs_vol_object->thread); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + thread_join(aobjs->acon_hops_seps_vol_object->thread); + thread_join(aobjs->acon_hops_pfs_vol_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) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + src_hops_open(objs->src_hops_mics_object); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_pots_open(objs->snk_pots_ssl_object); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_tracks_open(objs->snk_tracks_sst_object); + + // +----------------------------------------------------------+ + // | Volume | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_hops_open(objs->snk_hops_seps_vol_object); + snk_hops_open(objs->snk_hops_pfs_vol_object); + + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_categories_open(objs->snk_categories_object); + + } + + void threads_single_close(objects * objs) { + + unsigned int iSink; + + // +----------------------------------------------------------+ + // | Raw | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Source | + // +------------------------------------------------------+ + + src_hops_close(objs->src_hops_mics_object); + + // +----------------------------------------------------------+ + // | SSL | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_pots_close(objs->snk_pots_ssl_object); + + // +----------------------------------------------------------+ + // | SST | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_tracks_close(objs->snk_tracks_sst_object); + + // +----------------------------------------------------------+ + // | Volume | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_hops_close(objs->snk_hops_seps_vol_object); + snk_hops_close(objs->snk_hops_pfs_vol_object); + + // +----------------------------------------------------------+ + // | Classify | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Sinks | + // +------------------------------------------------------+ + + snk_categories_close(objs->snk_categories_object); + + } + + int threads_single_process(objects * objs, profiler * prf) { + + int rtnValue; + int rtnResample; + unsigned int iSink; + + clock_t begin, end; + + prf->duration += ((float) (objs->src_hops_mics_object->hopSize)) / ((float) (objs->src_hops_mics_object->fS)); + + // +----------------------------------------------------------+ + // | SECTION I | + // +----------------------------------------------------------- + + // +------------------------------------------------------+ + // | Raw | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Source | + // +--------------------------------------------------+ + + begin = clock(); + rtnValue = src_hops_process(objs->src_hops_mics_object); + end = clock(); + prf->src_hops_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_mics_raw_object); + end = clock(); + prf->con_hops_mics_raw_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | Mapping | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_mapping_process(objs->mod_mapping_mics_object); + end = clock(); + prf->mod_mapping_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_mics_map_object); + end = clock(); + prf->con_hops_mics_map_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_resample_process_push(objs->mod_resample_mics_object); + end = clock(); + prf->mod_resample_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------------------+ + // | SECTION II | + // +----------------------------------------------------------- + + // Loop through section II as long as there are frames to process from the resample module + while(1) { + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + rtnResample = mod_resample_process_pop(objs->mod_resample_mics_object); + end = clock(); + prf->mod_resample_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // If there is no frames to process, stop + if (rtnResample == -1) { + break; + } + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_mics_rs_object); + end = clock(); + prf->con_hops_mics_rs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | STFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_stft_process(objs->mod_stft_mics_object); + end = clock(); + prf->mod_stft_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_spectra_process(objs->con_spectra_mics_object); + end = clock(); + prf->con_spectra_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | Noise | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_noise_process(objs->mod_noise_mics_object); + end = clock(); + prf->mod_noise_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_powers_process(objs->con_powers_mics_object); + end = clock(); + prf->con_powers_mics_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | SSL | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_ssl_process(objs->mod_ssl_object); + end = clock(); + prf->mod_ssl_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_pots_process(objs->con_pots_ssl_object); + end = clock(); + prf->con_pots_ssl_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + begin = clock(); + snk_pots_process(objs->snk_pots_ssl_object); + end = clock(); + prf->snk_pots_ssl_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | Targets | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Injector | + // +--------------------------------------------------+ + + begin = clock(); + inj_targets_process(objs->inj_targets_sst_object); + end = clock(); + prf->inj_targets_sst_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_targets_process(objs->con_targets_sst_object); + end = clock(); + prf->con_targets_sst_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | SST | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_sst_process(objs->mod_sst_object); + end = clock(); + prf->mod_sst_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_tracks_process(objs->con_tracks_sst_object); + end = clock(); + prf->con_tracks_sst_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Sinks | + // +--------------------------------------------------+ + + begin = clock(); + snk_tracks_process(objs->snk_tracks_sst_object); + end = clock(); + prf->snk_tracks_sst_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | SSS | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_sss_process(objs->mod_sss_object); + end = clock(); + prf->mod_sss_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_spectra_process(objs->con_spectra_seps_object); + end = clock(); + prf->con_spectra_seps_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + begin = clock(); + con_spectra_process(objs->con_spectra_pfs_object); + end = clock(); + prf->con_spectra_pfs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | ISTFT | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_istft_process(objs->mod_istft_seps_object); + end = clock(); + prf->mod_istft_seps_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + begin = clock(); + mod_istft_process(objs->mod_istft_pfs_object); + end = clock(); + prf->mod_istft_pfs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +--------------------------------------------------+ + // | Connector | + // +--------------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_seps_object); + end = clock(); + prf->con_hops_seps_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + begin = clock(); + con_hops_process(objs->con_hops_pfs_object); + end = clock(); + prf->con_hops_pfs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | Resample | + // +------------------------------------------------------+ + + // +--------------------------------------------------+ + // | Module | + // +--------------------------------------------------+ + + begin = clock(); + mod_resample_process_push(objs->mod_resample_seps_object); + end = clock(); + prf->mod_resample_seps_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + begin = clock(); + mod_resample_process_push(objs->mod_resample_pfs_object); + end = clock(); + prf->mod_resample_pfs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +------------------------------------------------------+ + // | SECTION III | + // +------------------------------------------------------+ + + while(1) { + + // +----------------------------------------------+ + // | Module | + // +----------------------------------------------+ + + begin = clock(); + rtnResample = mod_resample_process_pop(objs->mod_resample_seps_object); + end = clock(); + prf->mod_resample_seps_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // If there is no frames to process, stop + if (rtnResample == -1) { + break; + } + + // +----------------------------------------------+ + // | Connector | + // +----------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_seps_rs_object); + end = clock(); + prf->con_hops_seps_rs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------+ + // | Module | + // +----------------------------------------------+ + + begin = clock(); + mod_volume_process(objs->mod_volume_seps_object); + end = clock(); + prf->mod_volume_seps_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------+ + // | Connector | + // +----------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_seps_vol_object); + end = clock(); + prf->con_hops_seps_vol_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------+ + // | Sink | + // +----------------------------------------------+ + + begin = clock(); + snk_hops_process(objs->snk_hops_seps_vol_object); + end = clock(); + prf->snk_hops_seps_vol_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + } + + + while(1) { + + // +----------------------------------------------+ + // | Module | + // +----------------------------------------------+ + + begin = clock(); + rtnResample = mod_resample_process_pop(objs->mod_resample_pfs_object); + end = clock(); + prf->mod_resample_pfs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // If there is no frames to process, stop + if (rtnResample == -1) { + break; + } + + // +----------------------------------------------+ + // | Connector | + // +----------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_pfs_rs_object); + end = clock(); + prf->con_hops_pfs_rs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------+ + // | Module | + // +----------------------------------------------+ + + begin = clock(); + mod_volume_process(objs->mod_volume_pfs_object); + end = clock(); + prf->mod_volume_pfs_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------+ + // | Connector | + // +----------------------------------------------+ + + begin = clock(); + con_hops_process(objs->con_hops_pfs_vol_object); + end = clock(); + prf->con_hops_pfs_vol_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + // +----------------------------------------------+ + // | Sink | + // +----------------------------------------------+ + + begin = clock(); + snk_hops_process(objs->snk_hops_pfs_vol_object); + end = clock(); + prf->snk_hops_pfs_vol_prf += (float) (((double) (end-begin)) / CLOCKS_PER_SEC); + + } + + // +------------------------------------------------------+ + // | 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; + + } \ No newline at end of file diff --git a/demo/threads.h b/demo/threads.h new file mode 100644 index 0000000..64a1376 --- /dev/null +++ b/demo/threads.h @@ -0,0 +1,23 @@ +#ifndef __DEMO_THREADS +#define __DEMO_THREADS + + #include "objects.h" + #include "profiler.h" + + #include + + #include + + void threads_multiple_start(aobjects * aobjs); + + void threads_multiple_stop(aobjects * aobjs); + + void threads_multiple_join(aobjects * aobjs); + + void threads_single_open(objects * objs); + + void threads_single_close(objects * objs); + + int threads_single_process(objects * objs, profiler * prf); + +#endif \ No newline at end of file diff --git a/include/odas/odas.h b/include/odas/odas.h new file mode 100644 index 0000000..2c8c2b9 --- /dev/null +++ b/include/odas/odas.h @@ -0,0 +1,66 @@ + + #include "../../src/connector/con_categories.h" + #include "../../src/connector/con_hops.h" + #include "../../src/connector/con_pots.h" + #include "../../src/connector/con_powers.h" + #include "../../src/connector/con_spectra.h" + #include "../../src/connector/con_targets.h" + #include "../../src/connector/con_tracks.h" + #include "../../src/injector/inj_targets.h" + #include "../../src/message/msg_categories.h" + #include "../../src/message/msg_hops.h" + #include "../../src/message/msg_pots.h" + #include "../../src/message/msg_powers.h" + #include "../../src/message/msg_spectra.h" + #include "../../src/message/msg_targets.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_noise.h" + #include "../../src/module/mod_resample.h" + #include "../../src/module/mod_ssl.h" + #include "../../src/module/mod_sst.h" + #include "../../src/module/mod_sss.h" + #include "../../src/module/mod_stft.h" + #include "../../src/module/mod_volume.h" + #include "../../src/sink/snk_categories.h" + #include "../../src/sink/snk_hops.h" + #include "../../src/sink/snk_pots.h" + #include "../../src/sink/snk_powers.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_powers.h" + #include "../../src/aconnector/acon_spectra.h" + #include "../../src/aconnector/acon_targets.h" + #include "../../src/aconnector/acon_tracks.h" + #include "../../src/ainjector/ainj_targets.h" + #include "../../src/amessage/amsg_categories.h" + #include "../../src/amessage/amsg_hops.h" + #include "../../src/amessage/amsg_pots.h" + #include "../../src/amessage/amsg_powers.h" + #include "../../src/amessage/amsg_spectra.h" + #include "../../src/amessage/amsg_targets.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_noise.h" + #include "../../src/amodule/amod_resample.h" + #include "../../src/amodule/amod_ssl.h" + #include "../../src/amodule/amod_sst.h" + #include "../../src/amodule/amod_sss.h" + #include "../../src/amodule/amod_stft.h" + #include "../../src/amodule/amod_volume.h" + #include "../../src/asink/asnk_categories.h" + #include "../../src/asink/asnk_hops.h" + #include "../../src/asink/asnk_pots.h" + #include "../../src/asink/asnk_powers.h" + #include "../../src/asink/asnk_spectra.h" + #include "../../src/asink/asnk_tracks.h" + #include "../../src/asource/asrc_hops.h" diff --git a/octave/pots2var.m b/octave/pots2var.m new file mode 100644 index 0000000..f6859e0 --- /dev/null +++ b/octave/pots2var.m @@ -0,0 +1,25 @@ +function pots = pots2var(filename, nPots) + + fid = fopen(filename,'rb'); + vector = fread(fid,inf,'float'); + fclose(fid); + + pots = cell(nPots,1); + nFrames = size(vector,1)/(4*nPots); + + for iPot = 1:1:nPots + + pots{iPot} = zeros(nFrames, 4); + + for iFrame = 1:1:nFrames + + iStart = (iFrame-1) * 4 * nPots + (iPot-1) * 4 + 1; + iStop = iStart + 3; + + pots{iPot}(iFrame,:) = vector(iStart:1:iStop); + + end + + end + +return \ No newline at end of file diff --git a/octave/spectra2var.m b/octave/spectra2var.m new file mode 100644 index 0000000..d06cc4d --- /dev/null +++ b/octave/spectra2var.m @@ -0,0 +1,36 @@ +function spectra = spectra2var(filename, frameSize, nChannels) + + fid = fopen(filename,'rb'); + vector = fread(fid,inf,'float'); + fclose(fid); + + vectorReal = vector(1:2:length(vector)); + vectorComplex = vector(2:2:length(vector)); + vectorRC = vectorReal + 1i * vectorComplex; + + halfFrameSize = frameSize/2 + 1; + nSamplesPerFrame = nChannels * halfFrameSize; + + nSamples = length(vectorRC); + nFrames = nSamples / nSamplesPerFrame; + + spectra = cell(nChannels,1); + + for iChannel = 1:1:nChannels + + spectra{iChannel} = zeros(nFrames, halfFrameSize); + + for iFrame = 1:1:nFrames + + iStart = (iFrame-1) * (nChannels * halfFrameSize) + iChannel; + iStop = iStart + halfFrameSize * nChannels - 1; + + indexes = iStart:nChannels:iStop; + + spectra{iChannel}(iFrame,:) = vectorRC(indexes); + + end + + end + +return \ No newline at end of file diff --git a/octave/tracks2var.m b/octave/tracks2var.m new file mode 100644 index 0000000..7a67033 --- /dev/null +++ b/octave/tracks2var.m @@ -0,0 +1,34 @@ +function tracks = tracks2var(filename, nTracks) + + fid = fopen(filename,'rb'); + tmp = fread(fid,inf,'int8'); + fclose(fid); + + nFrames = length(tmp) / (20 * nTracks); + tracks = cell(nTracks,1); + + for iTrack = 1:1:nTracks + + tracks{iTrack} = zeros(nFrames,4); + + end + + fid = fopen(filename,'rb'); + + for iFrame = 1:1:nFrames + + ids = fread(fid, nTracks, 'uint64'); + xyzs = fread(fid, nTracks * 3, 'float'); + + for iTrack = 1:1:nTracks + + tracks{iTrack}(iFrame,1) = double(ids(iTrack)); + tracks{iTrack}(iFrame,2:1:4) = xyzs(((iTrack-1)*3+1):1:((iTrack-1)*3+3)); + + end + + end + + fclose(fid); + +return \ No newline at end of file diff --git a/src/aconnector/acon_categories.c b/src/aconnector/acon_categories.c new file mode 100644 index 0000000..4570e37 --- /dev/null +++ b/src/aconnector/acon_categories.c @@ -0,0 +1,85 @@ + + #include "acon_categories.h" + + acon_categories_obj * acon_categories_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_categories_cfg * msg_categories_config) { + + acon_categories_obj * obj; + unsigned int iOut; + + obj = (acon_categories_obj *) malloc(sizeof(acon_categories_obj)); + + obj->in = amsg_categories_construct(nMessages, msg_categories_config); + + obj->outs = (amsg_categories_obj **) malloc(sizeof(amsg_categories_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_categories_construct(nMessages, msg_categories_config); + } + + obj->con_categories = con_categories_construct(nOuts, msg_categories_config); + + obj->thread = thread_construct(&acon_categories_thread, (void *) obj); + + return obj; + + } + + void acon_categories_destroy(acon_categories_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_categories->nOuts; + + thread_destroy(obj->thread); + + con_categories_destroy(obj->con_categories); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_categories_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_categories_destroy(obj->in); + + free((void *) obj); + + + } + + void * acon_categories_thread(void * ptr) { + + msg_categories_obj * msg_categories_in; + msg_categories_obj * msg_categories_out; + + acon_categories_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_categories_obj *) ptr; + + nOuts = obj->con_categories->nOuts; + + while(1) { + + msg_categories_in = amsg_categories_filled_pop(obj->in); + msg_categories_copy(obj->con_categories->in, msg_categories_in); + amsg_categories_empty_push(obj->in, msg_categories_in); + + rtnValue = con_categories_process(obj->con_categories); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_categories_out = amsg_categories_empty_pop(obj->outs[iOut]); + msg_categories_copy(msg_categories_out, obj->con_categories->outs[iOut]); + amsg_categories_filled_push(obj->outs[iOut], msg_categories_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_categories.h b/src/aconnector/acon_categories.h new file mode 100644 index 0000000..f857dc8 --- /dev/null +++ b/src/aconnector/acon_categories.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_CATEGORIES +#define __ODAS_ACONNECTOR_CATEGORIES + + #include "../connector/con_categories.h" + #include "../amessage/amsg_categories.h" + #include "../message/msg_categories.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_categories_obj { + + amsg_categories_obj * in; + amsg_categories_obj ** outs; + con_categories_obj * con_categories; + thread_obj * thread; + + } acon_categories_obj; + + acon_categories_obj * acon_categories_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_categories_cfg * msg_categories_config); + + void acon_categories_destroy(acon_categories_obj * obj); + + void * acon_categories_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/aconnector/acon_hops.c b/src/aconnector/acon_hops.c new file mode 100644 index 0000000..0edc5d3 --- /dev/null +++ b/src/aconnector/acon_hops.c @@ -0,0 +1,85 @@ + + #include "acon_hops.h" + + acon_hops_obj * acon_hops_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_hops_cfg * msg_hops_config) { + + acon_hops_obj * obj; + unsigned int iOut; + + obj = (acon_hops_obj *) malloc(sizeof(acon_hops_obj)); + + obj->in = amsg_hops_construct(nMessages, msg_hops_config); + + obj->outs = (amsg_hops_obj **) malloc(sizeof(amsg_hops_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_hops_construct(nMessages, msg_hops_config); + } + + obj->con_hops = con_hops_construct(nOuts, msg_hops_config); + + obj->thread = thread_construct(&acon_hops_thread, (void *) obj); + + return obj; + + } + + void acon_hops_destroy(acon_hops_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_hops->nOuts; + + thread_destroy(obj->thread); + + con_hops_destroy(obj->con_hops); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_hops_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_hops_destroy(obj->in); + + free((void *) obj); + + + } + + void * acon_hops_thread(void * ptr) { + + msg_hops_obj * msg_hops_in; + msg_hops_obj * msg_hops_out; + + acon_hops_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_hops_obj *) ptr; + + nOuts = obj->con_hops->nOuts; + + while(1) { + + msg_hops_in = amsg_hops_filled_pop(obj->in); + msg_hops_copy(obj->con_hops->in, msg_hops_in); + amsg_hops_empty_push(obj->in, msg_hops_in); + + rtnValue = con_hops_process(obj->con_hops); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_hops_out = amsg_hops_empty_pop(obj->outs[iOut]); + msg_hops_copy(msg_hops_out, obj->con_hops->outs[iOut]); + amsg_hops_filled_push(obj->outs[iOut], msg_hops_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_hops.h b/src/aconnector/acon_hops.h new file mode 100644 index 0000000..965849e --- /dev/null +++ b/src/aconnector/acon_hops.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_HOPS +#define __ODAS_ACONNECTOR_HOPS + + #include "../connector/con_hops.h" + #include "../amessage/amsg_hops.h" + #include "../message/msg_hops.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_hops_obj { + + amsg_hops_obj * in; + amsg_hops_obj ** outs; + con_hops_obj * con_hops; + thread_obj * thread; + + } acon_hops_obj; + + acon_hops_obj * acon_hops_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_hops_cfg * msg_hops_config); + + void acon_hops_destroy(acon_hops_obj * obj); + + void * acon_hops_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/aconnector/acon_pots.c b/src/aconnector/acon_pots.c new file mode 100644 index 0000000..c838f40 --- /dev/null +++ b/src/aconnector/acon_pots.c @@ -0,0 +1,85 @@ + + #include "acon_pots.h" + + acon_pots_obj * acon_pots_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_pots_cfg * msg_pots_config) { + + acon_pots_obj * obj; + unsigned int iOut; + + obj = (acon_pots_obj *) malloc(sizeof(acon_pots_obj)); + + obj->in = amsg_pots_construct(nMessages, msg_pots_config); + + obj->outs = (amsg_pots_obj **) malloc(sizeof(amsg_pots_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_pots_construct(nMessages, msg_pots_config); + } + + obj->con_pots = con_pots_construct(nOuts, msg_pots_config); + + obj->thread = thread_construct(&acon_pots_thread, (void *) obj); + + return obj; + + } + + void acon_pots_destroy(acon_pots_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_pots->nOuts; + + thread_destroy(obj->thread); + + con_pots_destroy(obj->con_pots); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_pots_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_pots_destroy(obj->in); + + free((void *) obj); + + + } + + void * acon_pots_thread(void * ptr) { + + msg_pots_obj * msg_pots_in; + msg_pots_obj * msg_pots_out; + + acon_pots_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_pots_obj *) ptr; + + nOuts = obj->con_pots->nOuts; + + while(1) { + + msg_pots_in = amsg_pots_filled_pop(obj->in); + msg_pots_copy(obj->con_pots->in, msg_pots_in); + amsg_pots_empty_push(obj->in, msg_pots_in); + + rtnValue = con_pots_process(obj->con_pots); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_pots_out = amsg_pots_empty_pop(obj->outs[iOut]); + msg_pots_copy(msg_pots_out, obj->con_pots->outs[iOut]); + amsg_pots_filled_push(obj->outs[iOut], msg_pots_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_pots.h b/src/aconnector/acon_pots.h new file mode 100644 index 0000000..13268ba --- /dev/null +++ b/src/aconnector/acon_pots.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_POTS +#define __ODAS_ACONNECTOR_POTS + + #include "../connector/con_pots.h" + #include "../amessage/amsg_pots.h" + #include "../message/msg_pots.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_pots_obj { + + amsg_pots_obj * in; + amsg_pots_obj ** outs; + con_pots_obj * con_pots; + thread_obj * thread; + + } acon_pots_obj; + + acon_pots_obj * acon_pots_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_pots_cfg * msg_pots_config); + + void acon_pots_destroy(acon_pots_obj * obj); + + void * acon_pots_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/aconnector/acon_powers.c b/src/aconnector/acon_powers.c new file mode 100644 index 0000000..f742bde --- /dev/null +++ b/src/aconnector/acon_powers.c @@ -0,0 +1,85 @@ + + #include "acon_powers.h" + + acon_powers_obj * acon_powers_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_powers_cfg * msg_powers_config) { + + acon_powers_obj * obj; + unsigned int iOut; + + obj = (acon_powers_obj *) malloc(sizeof(acon_powers_obj)); + + obj->in = amsg_powers_construct(nMessages, msg_powers_config); + + obj->outs = (amsg_powers_obj **) malloc(sizeof(amsg_powers_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_powers_construct(nMessages, msg_powers_config); + } + + obj->con_powers = con_powers_construct(nOuts, msg_powers_config); + + obj->thread = thread_construct(&acon_powers_thread, (void *) obj); + + return obj; + + } + + void acon_powers_destroy(acon_powers_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_powers->nOuts; + + thread_destroy(obj->thread); + + con_powers_destroy(obj->con_powers); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_powers_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_powers_destroy(obj->in); + + free((void *) obj); + + + } + + void * acon_powers_thread(void * ptr) { + + msg_powers_obj * msg_powers_in; + msg_powers_obj * msg_powers_out; + + acon_powers_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_powers_obj *) ptr; + + nOuts = obj->con_powers->nOuts; + + while(1) { + + msg_powers_in = amsg_powers_filled_pop(obj->in); + msg_powers_copy(obj->con_powers->in, msg_powers_in); + amsg_powers_empty_push(obj->in, msg_powers_in); + + rtnValue = con_powers_process(obj->con_powers); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_powers_out = amsg_powers_empty_pop(obj->outs[iOut]); + msg_powers_copy(msg_powers_out, obj->con_powers->outs[iOut]); + amsg_powers_filled_push(obj->outs[iOut], msg_powers_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_powers.h b/src/aconnector/acon_powers.h new file mode 100644 index 0000000..51034e8 --- /dev/null +++ b/src/aconnector/acon_powers.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_POWERS +#define __ODAS_ACONNECTOR_POWERS + + #include "../connector/con_powers.h" + #include "../amessage/amsg_powers.h" + #include "../message/msg_powers.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_powers_obj { + + amsg_powers_obj * in; + amsg_powers_obj ** outs; + con_powers_obj * con_powers; + thread_obj * thread; + + } acon_powers_obj; + + acon_powers_obj * acon_powers_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_powers_cfg * msg_powers_config); + + void acon_powers_destroy(acon_powers_obj * obj); + + void * acon_powers_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/aconnector/acon_spectra.c b/src/aconnector/acon_spectra.c new file mode 100644 index 0000000..bd8fcd8 --- /dev/null +++ b/src/aconnector/acon_spectra.c @@ -0,0 +1,85 @@ + + #include "acon_spectra.h" + + acon_spectra_obj * acon_spectra_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_spectra_cfg * msg_spectra_config) { + + acon_spectra_obj * obj; + unsigned int iOut; + + obj = (acon_spectra_obj *) malloc(sizeof(acon_spectra_obj)); + + obj->in = amsg_spectra_construct(nMessages, msg_spectra_config); + + obj->outs = (amsg_spectra_obj **) malloc(sizeof(amsg_spectra_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_spectra_construct(nMessages, msg_spectra_config); + } + + obj->con_spectra = con_spectra_construct(nOuts, msg_spectra_config); + + obj->thread = thread_construct(&acon_spectra_thread, (void *) obj); + + return obj; + + } + + void acon_spectra_destroy(acon_spectra_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_spectra->nOuts; + + thread_destroy(obj->thread); + + con_spectra_destroy(obj->con_spectra); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_spectra_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_spectra_destroy(obj->in); + + free((void *) obj); + + + } + + void * acon_spectra_thread(void * ptr) { + + msg_spectra_obj * msg_spectra_in; + msg_spectra_obj * msg_spectra_out; + + acon_spectra_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_spectra_obj *) ptr; + + nOuts = obj->con_spectra->nOuts; + + while(1) { + + msg_spectra_in = amsg_spectra_filled_pop(obj->in); + msg_spectra_copy(obj->con_spectra->in, msg_spectra_in); + amsg_spectra_empty_push(obj->in, msg_spectra_in); + + rtnValue = con_spectra_process(obj->con_spectra); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_spectra_out = amsg_spectra_empty_pop(obj->outs[iOut]); + msg_spectra_copy(msg_spectra_out, obj->con_spectra->outs[iOut]); + amsg_spectra_filled_push(obj->outs[iOut], msg_spectra_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_spectra.h b/src/aconnector/acon_spectra.h new file mode 100644 index 0000000..ed05177 --- /dev/null +++ b/src/aconnector/acon_spectra.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_SPECTRA +#define __ODAS_ACONNECTOR_SPECTRA + + #include "../connector/con_spectra.h" + #include "../amessage/amsg_spectra.h" + #include "../message/msg_spectra.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_spectra_obj { + + amsg_spectra_obj * in; + amsg_spectra_obj ** outs; + con_spectra_obj * con_spectra; + thread_obj * thread; + + } acon_spectra_obj; + + acon_spectra_obj * acon_spectra_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_spectra_cfg * msg_spectra_config); + + void acon_spectra_destroy(acon_spectra_obj * obj); + + void * acon_spectra_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/aconnector/acon_targets.c b/src/aconnector/acon_targets.c new file mode 100644 index 0000000..af9dfbd --- /dev/null +++ b/src/aconnector/acon_targets.c @@ -0,0 +1,84 @@ + + #include "acon_targets.h" + + acon_targets_obj * acon_targets_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_targets_cfg * msg_targets_config) { + + acon_targets_obj * obj; + unsigned int iOut; + + obj = (acon_targets_obj *) malloc(sizeof(acon_targets_obj)); + + obj->in = amsg_targets_construct(nMessages, msg_targets_config); + + obj->outs = (amsg_targets_obj **) malloc(sizeof(amsg_targets_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_targets_construct(nMessages, msg_targets_config); + } + + obj->con_targets = con_targets_construct(nOuts, msg_targets_config); + + obj->thread = thread_construct(&acon_targets_thread, (void *) obj); + + return obj; + + } + + void acon_targets_destroy(acon_targets_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_targets->nOuts; + + thread_destroy(obj->thread); + + con_targets_destroy(obj->con_targets); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_targets_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_targets_destroy(obj->in); + + free((void *) obj); + + } + + void * acon_targets_thread(void * ptr) { + + msg_targets_obj * msg_targets_in; + msg_targets_obj * msg_targets_out; + + acon_targets_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_targets_obj *) ptr; + + nOuts = obj->con_targets->nOuts; + + while(1) { + + msg_targets_in = amsg_targets_filled_pop(obj->in); + msg_targets_copy(obj->con_targets->in, msg_targets_in); + amsg_targets_empty_push(obj->in, msg_targets_in); + + rtnValue = con_targets_process(obj->con_targets); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_targets_out = amsg_targets_empty_pop(obj->outs[iOut]); + msg_targets_copy(msg_targets_out, obj->con_targets->outs[iOut]); + amsg_targets_filled_push(obj->outs[iOut], msg_targets_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_targets.h b/src/aconnector/acon_targets.h new file mode 100644 index 0000000..633809e --- /dev/null +++ b/src/aconnector/acon_targets.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_TARGETS +#define __ODAS_ACONNECTOR_TARGETS + + #include "../connector/con_targets.h" + #include "../amessage/amsg_targets.h" + #include "../message/msg_targets.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_targets_obj { + + amsg_targets_obj * in; + amsg_targets_obj ** outs; + con_targets_obj * con_targets; + thread_obj * thread; + + } acon_targets_obj; + + acon_targets_obj * acon_targets_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_targets_cfg * msg_targets_config); + + void acon_targets_destroy(acon_targets_obj * obj); + + void * acon_targets_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/aconnector/acon_tracks.c b/src/aconnector/acon_tracks.c new file mode 100644 index 0000000..006f66d --- /dev/null +++ b/src/aconnector/acon_tracks.c @@ -0,0 +1,84 @@ + + #include "acon_tracks.h" + + acon_tracks_obj * acon_tracks_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_tracks_cfg * msg_tracks_config) { + + acon_tracks_obj * obj; + unsigned int iOut; + + obj = (acon_tracks_obj *) malloc(sizeof(acon_tracks_obj)); + + obj->in = amsg_tracks_construct(nMessages, msg_tracks_config); + + obj->outs = (amsg_tracks_obj **) malloc(sizeof(amsg_tracks_obj *) * nOuts); + for (iOut = 0; iOut < nOuts; iOut++) { + obj->outs[iOut] = amsg_tracks_construct(nMessages, msg_tracks_config); + } + + obj->con_tracks = con_tracks_construct(nOuts, msg_tracks_config); + + obj->thread = thread_construct(&acon_tracks_thread, (void *) obj); + + return obj; + + } + + void acon_tracks_destroy(acon_tracks_obj * obj) { + + unsigned int iOut; + unsigned int nOuts; + + nOuts = obj->con_tracks->nOuts; + + thread_destroy(obj->thread); + + con_tracks_destroy(obj->con_tracks); + + for (iOut = 0; iOut < nOuts; iOut++) { + amsg_tracks_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + amsg_tracks_destroy(obj->in); + + free((void *) obj); + + } + + void * acon_tracks_thread(void * ptr) { + + msg_tracks_obj * msg_tracks_in; + msg_tracks_obj * msg_tracks_out; + + acon_tracks_obj * obj; + unsigned int iOut; + unsigned int nOuts; + int rtnValue; + + obj = (acon_tracks_obj *) ptr; + + nOuts = obj->con_tracks->nOuts; + + while(1) { + + msg_tracks_in = amsg_tracks_filled_pop(obj->in); + msg_tracks_copy(obj->con_tracks->in, msg_tracks_in); + amsg_tracks_empty_push(obj->in, msg_tracks_in); + + rtnValue = con_tracks_process(obj->con_tracks); + + for (iOut = 0; iOut < nOuts; iOut++) { + + msg_tracks_out = amsg_tracks_empty_pop(obj->outs[iOut]); + msg_tracks_copy(msg_tracks_out, obj->con_tracks->outs[iOut]); + amsg_tracks_filled_push(obj->outs[iOut], msg_tracks_out); + + } + + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/aconnector/acon_tracks.h b/src/aconnector/acon_tracks.h new file mode 100644 index 0000000..471b867 --- /dev/null +++ b/src/aconnector/acon_tracks.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_ACONNECTOR_TRACKS +#define __ODAS_ACONNECTOR_TRACKS + + #include "../connector/con_tracks.h" + #include "../amessage/amsg_tracks.h" + #include "../message/msg_tracks.h" + #include "../general/thread.h" + + #include + #include + + typedef struct acon_tracks_obj { + + amsg_tracks_obj * in; + amsg_tracks_obj ** outs; + con_tracks_obj * con_tracks; + thread_obj * thread; + + } acon_tracks_obj; + + acon_tracks_obj * acon_tracks_construct(const unsigned int nOuts, const unsigned int nMessages, const msg_tracks_cfg * msg_tracks_config); + + void acon_tracks_destroy(acon_tracks_obj * obj); + + void * acon_tracks_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/ainjector/ainj_targets.c b/src/ainjector/ainj_targets.c new file mode 100644 index 0000000..b4e8e18 --- /dev/null +++ b/src/ainjector/ainj_targets.c @@ -0,0 +1,72 @@ + + #include "ainj_targets.h" + + ainj_targets_obj * ainj_targets_construct(const inj_targets_cfg * inj_targets_config, const msg_hops_cfg * msg_hops_config, const msg_targets_cfg * msg_targets_config) { + + ainj_targets_obj * obj; + + obj = (ainj_targets_obj *) malloc(sizeof(ainj_targets_obj)); + + obj->inj_targets = inj_targets_construct(inj_targets_config, msg_hops_config, msg_targets_config); + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_targets_obj *) NULL; + + obj->thread = thread_construct(&ainj_targets_thread, (void *) obj); + + return obj; + + } + + void ainj_targets_destroy(ainj_targets_obj * obj) { + + inj_targets_destroy(obj->inj_targets); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void ainj_targets_connect(ainj_targets_obj * obj, amsg_hops_obj * in, amsg_targets_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void ainj_targets_disconnect(ainj_targets_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_targets_obj *) NULL; + + } + + void * ainj_targets_thread(void * ptr) { + + ainj_targets_obj * obj; + msg_hops_obj * msg_hops_in; + msg_targets_obj * msg_targets_out; + int rtnValue; + + obj = (ainj_targets_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_hops_in = amsg_hops_filled_pop(obj->in); + msg_targets_out = amsg_targets_empty_pop(obj->out); + inj_targets_connect(obj->inj_targets, msg_hops_in, msg_targets_out); + rtnValue = inj_targets_process(obj->inj_targets); + inj_targets_disconnect(obj->inj_targets); + amsg_hops_empty_push(obj->in, msg_hops_in); + amsg_targets_filled_push(obj->out, msg_targets_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + + } \ No newline at end of file diff --git a/src/ainjector/ainj_targets.h b/src/ainjector/ainj_targets.h new file mode 100644 index 0000000..60af2da --- /dev/null +++ b/src/ainjector/ainj_targets.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_AINJECTOR_TARGETS +#define __ODAS_AINJECTOR_TARGETS + + #include "../injector/inj_targets.h" + #include "../amessage/amsg_hops.h" + #include "../amessage/amsg_targets.h" + #include "../general/thread.h" + + typedef struct ainj_targets_obj { + + inj_targets_obj * inj_targets; + amsg_hops_obj * in; + amsg_targets_obj * out; + thread_obj * thread; + + } ainj_targets_obj; + + ainj_targets_obj * ainj_targets_construct(const inj_targets_cfg * inj_targets_config, const msg_hops_cfg * msg_hops_config, const msg_targets_cfg * msg_targets_config); + + void ainj_targets_destroy(ainj_targets_obj * obj); + + void ainj_targets_connect(ainj_targets_obj * obj, amsg_hops_obj * in, amsg_targets_obj * out); + + void ainj_targets_disconnect(ainj_targets_obj * obj); + + void * ainj_targets_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_categories.c b/src/amessage/amsg_categories.c new file mode 100644 index 0000000..f72cc9c --- /dev/null +++ b/src/amessage/amsg_categories.c @@ -0,0 +1,64 @@ + + #include "amsg_categories.h" + + amsg_categories_obj * amsg_categories_construct(const unsigned int nMessages, const msg_categories_cfg * msg_categories_config) { + + amsg_categories_obj * obj; + unsigned int iMessage; + + obj = (amsg_categories_obj *) malloc(sizeof(amsg_categories_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_categories_construct(msg_categories_config)); + + } + + return obj; + + } + + void amsg_categories_destroy(amsg_categories_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_categories_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_categories_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_categories_obj * amsg_categories_filled_pop(amsg_categories_obj * obj) { + + return ((msg_categories_obj *) fifo_pop(obj->filled)); + + } + + void amsg_categories_filled_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories) { + + fifo_push(obj->filled, (void *) msg_categories); + + } + + msg_categories_obj * amsg_categories_empty_pop(amsg_categories_obj * obj) { + + return ((msg_categories_obj *) fifo_pop(obj->empty)); + + } + + void amsg_categories_empty_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories) { + + fifo_push(obj->empty, (void *) msg_categories); + + } diff --git a/src/amessage/amsg_categories.h b/src/amessage/amsg_categories.h new file mode 100644 index 0000000..dff4ce1 --- /dev/null +++ b/src/amessage/amsg_categories.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_CATEGORIES +#define __ODAS_AMESSAGE_CATEGORIES + + #include + + #include "../message/msg_categories.h" + #include "../utils/fifo.h" + + typedef struct amsg_categories_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_categories_obj; + + amsg_categories_obj * amsg_categories_construct(const unsigned int nMessages, const msg_categories_cfg * msg_categories_config); + + void amsg_categories_destroy(amsg_categories_obj * obj); + + msg_categories_obj * amsg_categories_filled_pop(amsg_categories_obj * obj); + + void amsg_categories_filled_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories); + + msg_categories_obj * amsg_categories_empty_pop(amsg_categories_obj * obj); + + void amsg_categories_empty_push(amsg_categories_obj * obj, msg_categories_obj * msg_categories); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_hops.c b/src/amessage/amsg_hops.c new file mode 100644 index 0000000..3073c2d --- /dev/null +++ b/src/amessage/amsg_hops.c @@ -0,0 +1,64 @@ + + #include "amsg_hops.h" + + amsg_hops_obj * amsg_hops_construct(const unsigned int nMessages, const msg_hops_cfg * msg_hops_config) { + + amsg_hops_obj * obj; + unsigned int iMessage; + + obj = (amsg_hops_obj *) malloc(sizeof(amsg_hops_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_hops_construct(msg_hops_config)); + + } + + return obj; + + } + + void amsg_hops_destroy(amsg_hops_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_hops_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_hops_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_hops_obj * amsg_hops_filled_pop(amsg_hops_obj * obj) { + + return ((msg_hops_obj *) fifo_pop(obj->filled)); + + } + + void amsg_hops_filled_push(amsg_hops_obj * obj, msg_hops_obj * msg_hops) { + + fifo_push(obj->filled, (void *) msg_hops); + + } + + msg_hops_obj * amsg_hops_empty_pop(amsg_hops_obj * obj) { + + return ((msg_hops_obj *) fifo_pop(obj->empty)); + + } + + void amsg_hops_empty_push(amsg_hops_obj * obj, msg_hops_obj * msg_hops) { + + fifo_push(obj->empty, (void *) msg_hops); + + } \ No newline at end of file diff --git a/src/amessage/amsg_hops.h b/src/amessage/amsg_hops.h new file mode 100644 index 0000000..a86a81f --- /dev/null +++ b/src/amessage/amsg_hops.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_HOPS +#define __ODAS_AMESSAGE_HOPS + + #include + + #include "../message/msg_hops.h" + #include "../utils/fifo.h" + + typedef struct amsg_hops_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_hops_obj; + + amsg_hops_obj * amsg_hops_construct(const unsigned int nMessages, const msg_hops_cfg * msg_hops_config); + + void amsg_hops_destroy(amsg_hops_obj * obj); + + msg_hops_obj * amsg_hops_filled_pop(amsg_hops_obj * obj); + + void amsg_hops_filled_push(amsg_hops_obj * obj, msg_hops_obj * msg_hops); + + msg_hops_obj * amsg_hops_empty_pop(amsg_hops_obj * obj); + + void amsg_hops_empty_push(amsg_hops_obj * obj, msg_hops_obj * msg_hops); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_pots.c b/src/amessage/amsg_pots.c new file mode 100644 index 0000000..5bef3a2 --- /dev/null +++ b/src/amessage/amsg_pots.c @@ -0,0 +1,64 @@ + + #include "amsg_pots.h" + + amsg_pots_obj * amsg_pots_construct(const unsigned int nMessages, const msg_pots_cfg * msg_pots_config) { + + amsg_pots_obj * obj; + unsigned int iMessage; + + obj = (amsg_pots_obj *) malloc(sizeof(amsg_pots_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_pots_construct(msg_pots_config)); + + } + + return obj; + + } + + void amsg_pots_destroy(amsg_pots_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_pots_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_pots_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_pots_obj * amsg_pots_filled_pop(amsg_pots_obj * obj) { + + return ((msg_pots_obj *) fifo_pop(obj->filled)); + + } + + void amsg_pots_filled_push(amsg_pots_obj * obj, msg_pots_obj * msg_pots) { + + fifo_push(obj->filled, (void *) msg_pots); + + } + + msg_pots_obj * amsg_pots_empty_pop(amsg_pots_obj * obj) { + + return ((msg_pots_obj *) fifo_pop(obj->empty)); + + } + + void amsg_pots_empty_push(amsg_pots_obj * obj, msg_pots_obj * msg_pots) { + + fifo_push(obj->empty, (void *) msg_pots); + + } \ No newline at end of file diff --git a/src/amessage/amsg_pots.h b/src/amessage/amsg_pots.h new file mode 100644 index 0000000..377fd67 --- /dev/null +++ b/src/amessage/amsg_pots.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_POTS +#define __ODAS_AMESSAGE_POTS + + #include + + #include "../message/msg_pots.h" + #include "../utils/fifo.h" + + typedef struct amsg_pots_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_pots_obj; + + amsg_pots_obj * amsg_pots_construct(const unsigned int nMessages, const msg_pots_cfg * msg_pots_config); + + void amsg_pots_destroy(amsg_pots_obj * obj); + + msg_pots_obj * amsg_pots_filled_pop(amsg_pots_obj * obj); + + void amsg_pots_filled_push(amsg_pots_obj * obj, msg_pots_obj * msg_pots); + + msg_pots_obj * amsg_pots_empty_pop(amsg_pots_obj * obj); + + void amsg_pots_empty_push(amsg_pots_obj * obj, msg_pots_obj * msg_pots); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_powers.c b/src/amessage/amsg_powers.c new file mode 100644 index 0000000..33f97d3 --- /dev/null +++ b/src/amessage/amsg_powers.c @@ -0,0 +1,64 @@ + + #include "amsg_powers.h" + + amsg_powers_obj * amsg_powers_construct(const unsigned int nMessages, const msg_powers_cfg * msg_powers_config) { + + amsg_powers_obj * obj; + unsigned int iMessage; + + obj = (amsg_powers_obj *) malloc(sizeof(amsg_powers_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_powers_construct(msg_powers_config)); + + } + + return obj; + + } + + void amsg_powers_destroy(amsg_powers_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_powers_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_powers_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_powers_obj * amsg_powers_filled_pop(amsg_powers_obj * obj) { + + return ((msg_powers_obj *) fifo_pop(obj->filled)); + + } + + void amsg_powers_filled_push(amsg_powers_obj * obj, msg_powers_obj * msg_powers) { + + fifo_push(obj->filled, (void *) msg_powers); + + } + + msg_powers_obj * amsg_powers_empty_pop(amsg_powers_obj * obj) { + + return ((msg_powers_obj *) fifo_pop(obj->empty)); + + } + + void amsg_powers_empty_push(amsg_powers_obj * obj, msg_powers_obj * msg_powers) { + + fifo_push(obj->empty, (void *) msg_powers); + + } \ No newline at end of file diff --git a/src/amessage/amsg_powers.h b/src/amessage/amsg_powers.h new file mode 100644 index 0000000..f714bb5 --- /dev/null +++ b/src/amessage/amsg_powers.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_POWERS +#define __ODAS_AMESSAGE_POWERS + + #include + + #include "../message/msg_powers.h" + #include "../utils/fifo.h" + + typedef struct amsg_powers_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_powers_obj; + + amsg_powers_obj * amsg_powers_construct(const unsigned int nMessages, const msg_powers_cfg * msg_powers_config); + + void amsg_powers_destroy(amsg_powers_obj * obj); + + msg_powers_obj * amsg_powers_filled_pop(amsg_powers_obj * obj); + + void amsg_powers_filled_push(amsg_powers_obj * obj, msg_powers_obj * msg_powers); + + msg_powers_obj * amsg_powers_empty_pop(amsg_powers_obj * obj); + + void amsg_powers_empty_push(amsg_powers_obj * obj, msg_powers_obj * msg_powers); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_spectra.c b/src/amessage/amsg_spectra.c new file mode 100644 index 0000000..e2e1b1d --- /dev/null +++ b/src/amessage/amsg_spectra.c @@ -0,0 +1,64 @@ + + #include "amsg_spectra.h" + + amsg_spectra_obj * amsg_spectra_construct(const unsigned int nMessages, const msg_spectra_cfg * msg_spectra_config) { + + amsg_spectra_obj * obj; + unsigned int iMessage; + + obj = (amsg_spectra_obj *) malloc(sizeof(amsg_spectra_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_spectra_construct(msg_spectra_config)); + + } + + return obj; + + } + + void amsg_spectra_destroy(amsg_spectra_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_spectra_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_spectra_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_spectra_obj * amsg_spectra_filled_pop(amsg_spectra_obj * obj) { + + return ((msg_spectra_obj *) fifo_pop(obj->filled)); + + } + + void amsg_spectra_filled_push(amsg_spectra_obj * obj, msg_spectra_obj * msg_spectra) { + + fifo_push(obj->filled, (void *) msg_spectra); + + } + + msg_spectra_obj * amsg_spectra_empty_pop(amsg_spectra_obj * obj) { + + return ((msg_spectra_obj *) fifo_pop(obj->empty)); + + } + + void amsg_spectra_empty_push(amsg_spectra_obj * obj, msg_spectra_obj * msg_spectra) { + + fifo_push(obj->empty, (void *) msg_spectra); + + } \ No newline at end of file diff --git a/src/amessage/amsg_spectra.h b/src/amessage/amsg_spectra.h new file mode 100644 index 0000000..df83d0e --- /dev/null +++ b/src/amessage/amsg_spectra.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_SPECTRA +#define __ODAS_AMESSAGE_SPECTRA + + #include + + #include "../message/msg_spectra.h" + #include "../utils/fifo.h" + + typedef struct amsg_spectra_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_spectra_obj; + + amsg_spectra_obj * amsg_spectra_construct(const unsigned int nMessages, const msg_spectra_cfg * msg_spectra_config); + + void amsg_spectra_destroy(amsg_spectra_obj * obj); + + msg_spectra_obj * amsg_spectra_filled_pop(amsg_spectra_obj * obj); + + void amsg_spectra_filled_push(amsg_spectra_obj * obj, msg_spectra_obj * msg_spectra); + + msg_spectra_obj * amsg_spectra_empty_pop(amsg_spectra_obj * obj); + + void amsg_spectra_empty_push(amsg_spectra_obj * obj, msg_spectra_obj * msg_spectra); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_targets.c b/src/amessage/amsg_targets.c new file mode 100644 index 0000000..b8fadeb --- /dev/null +++ b/src/amessage/amsg_targets.c @@ -0,0 +1,64 @@ + + #include "amsg_targets.h" + + amsg_targets_obj * amsg_targets_construct(const unsigned int nMessages, const msg_targets_cfg * msg_targets_config) { + + amsg_targets_obj * obj; + unsigned int iMessage; + + obj = (amsg_targets_obj *) malloc(sizeof(amsg_targets_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_targets_construct(msg_targets_config)); + + } + + return obj; + + } + + void amsg_targets_destroy(amsg_targets_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_targets_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_targets_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_targets_obj * amsg_targets_filled_pop(amsg_targets_obj * obj) { + + return ((msg_targets_obj *) fifo_pop(obj->filled)); + + } + + void amsg_targets_filled_push(amsg_targets_obj * obj, msg_targets_obj * msg_targets) { + + fifo_push(obj->filled, (void *) msg_targets); + + } + + msg_targets_obj * amsg_targets_empty_pop(amsg_targets_obj * obj) { + + return ((msg_targets_obj *) fifo_pop(obj->empty)); + + } + + void amsg_targets_empty_push(amsg_targets_obj * obj, msg_targets_obj * msg_targets) { + + fifo_push(obj->empty, (void *) msg_targets); + + } \ No newline at end of file diff --git a/src/amessage/amsg_targets.h b/src/amessage/amsg_targets.h new file mode 100644 index 0000000..da8f72e --- /dev/null +++ b/src/amessage/amsg_targets.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_TARGETS +#define __ODAS_AMESSAGE_TARGETS + + #include + + #include "../message/msg_targets.h" + #include "../utils/fifo.h" + + typedef struct amsg_targets_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_targets_obj; + + amsg_targets_obj * amsg_targets_construct(const unsigned int nMessages, const msg_targets_cfg * msg_targets_config); + + void amsg_targets_destroy(amsg_targets_obj * obj); + + msg_targets_obj * amsg_targets_filled_pop(amsg_targets_obj * obj); + + void amsg_targets_filled_push(amsg_targets_obj * obj, msg_targets_obj * msg_targets); + + msg_targets_obj * amsg_targets_empty_pop(amsg_targets_obj * obj); + + void amsg_targets_empty_push(amsg_targets_obj * obj, msg_targets_obj * msg_targets); + +#endif \ No newline at end of file diff --git a/src/amessage/amsg_tracks.c b/src/amessage/amsg_tracks.c new file mode 100644 index 0000000..f104599 --- /dev/null +++ b/src/amessage/amsg_tracks.c @@ -0,0 +1,64 @@ + + #include "amsg_tracks.h" + + amsg_tracks_obj * amsg_tracks_construct(const unsigned int nMessages, const msg_tracks_cfg * msg_tracks_config) { + + amsg_tracks_obj * obj; + unsigned int iMessage; + + obj = (amsg_tracks_obj *) malloc(sizeof(amsg_tracks_obj)); + + obj->nMessages = nMessages; + obj->filled = fifo_construct_zero(nMessages); + obj->empty = fifo_construct_zero(nMessages); + + for (iMessage = 0; iMessage < nMessages; iMessage++) { + + fifo_push(obj->empty, (void *) msg_tracks_construct(msg_tracks_config)); + + } + + return obj; + + } + + void amsg_tracks_destroy(amsg_tracks_obj * obj) { + + while(fifo_nElements(obj->filled) > 0) { + msg_tracks_destroy((void *) fifo_pop(obj->filled)); + } + + while(fifo_nElements(obj->empty) > 0) { + msg_tracks_destroy((void *) fifo_pop(obj->empty)); + } + + fifo_destroy(obj->filled); + fifo_destroy(obj->empty); + + free((void *) obj); + + } + + msg_tracks_obj * amsg_tracks_filled_pop(amsg_tracks_obj * obj) { + + return ((msg_tracks_obj *) fifo_pop(obj->filled)); + + } + + void amsg_tracks_filled_push(amsg_tracks_obj * obj, msg_tracks_obj * msg_tracks) { + + fifo_push(obj->filled, (void *) msg_tracks); + + } + + msg_tracks_obj * amsg_tracks_empty_pop(amsg_tracks_obj * obj) { + + return ((msg_tracks_obj *) fifo_pop(obj->empty)); + + } + + void amsg_tracks_empty_push(amsg_tracks_obj * obj, msg_tracks_obj * msg_tracks) { + + fifo_push(obj->empty, (void *) msg_tracks); + + } \ No newline at end of file diff --git a/src/amessage/amsg_tracks.h b/src/amessage/amsg_tracks.h new file mode 100644 index 0000000..bd717a4 --- /dev/null +++ b/src/amessage/amsg_tracks.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMESSAGE_TRACKS +#define __ODAS_AMESSAGE_TRACKS + + #include + + #include "../message/msg_tracks.h" + #include "../utils/fifo.h" + + typedef struct amsg_tracks_obj { + + unsigned int nMessages; + fifo_obj * filled; + fifo_obj * empty; + + } amsg_tracks_obj; + + amsg_tracks_obj * amsg_tracks_construct(const unsigned int nMessages, const msg_tracks_cfg * msg_tracks_config); + + void amsg_tracks_destroy(amsg_tracks_obj * obj); + + msg_tracks_obj * amsg_tracks_filled_pop(amsg_tracks_obj * obj); + + void amsg_tracks_filled_push(amsg_tracks_obj * obj, msg_tracks_obj * msg_tracks); + + msg_tracks_obj * amsg_tracks_empty_pop(amsg_tracks_obj * obj); + + void amsg_tracks_empty_push(amsg_tracks_obj * obj, msg_tracks_obj * msg_tracks); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_classify.c b/src/amodule/amod_classify.c new file mode 100644 index 0000000..f889782 --- /dev/null +++ b/src/amodule/amod_classify.c @@ -0,0 +1,77 @@ + + #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_tracks_cfg * msg_tracks_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_tracks_config, msg_categories_config); + + obj->in1 = (amsg_hops_obj *) NULL; + obj->in2 = (amsg_tracks_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 * in1, amsg_tracks_obj * in2, amsg_categories_obj * out) { + + obj->in1 = in1; + obj->in2 = in2; + obj->out = out; + + } + + void amod_classify_disconnect(amod_classify_obj * obj) { + + obj->in1 = (amsg_hops_obj *) NULL; + obj->in2 = (amsg_tracks_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_tracks_obj * msg_tracks_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->in1); + msg_tracks_in = amsg_tracks_filled_pop(obj->in2); + msg_categories_out = amsg_categories_empty_pop(obj->out); + mod_classify_connect(obj->mod_classify, msg_hops_in, msg_tracks_in, msg_categories_out); + rtnValue = mod_classify_process(obj->mod_classify); + mod_classify_disconnect(obj->mod_classify); + amsg_hops_empty_push(obj->in1, msg_hops_in); + amsg_tracks_empty_push(obj->in2, msg_tracks_in); + amsg_categories_filled_push(obj->out, msg_categories_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } diff --git a/src/amodule/amod_classify.h b/src/amodule/amod_classify.h new file mode 100644 index 0000000..8e0d250 --- /dev/null +++ b/src/amodule/amod_classify.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_AMODULE_CLASSIFY +#define __ODAS_AMODULE_CLASSIFY + + #include "../module/mod_classify.h" + #include "../amessage/amsg_hops.h" + #include "../amessage/amsg_tracks.h" + #include "../amessage/amsg_categories.h" + #include "../general/thread.h" + + typedef struct amod_classify_obj { + + mod_classify_obj * mod_classify; + amsg_hops_obj * in1; + amsg_tracks_obj * in2; + 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_tracks_cfg * msg_tracks_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 * in1, amsg_tracks_obj * in2, 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/amodule/amod_istft.c b/src/amodule/amod_istft.c new file mode 100644 index 0000000..7f49144 --- /dev/null +++ b/src/amodule/amod_istft.c @@ -0,0 +1,71 @@ + + #include "amod_istft.h" + + amod_istft_obj * amod_istft_construct(const mod_istft_cfg * mod_istft_config, const msg_spectra_cfg * msg_spectra_config, const msg_hops_cfg * msg_hops_config) { + + amod_istft_obj * obj; + + obj = (amod_istft_obj *) malloc(sizeof(amod_istft_obj)); + + obj->mod_istft = mod_istft_construct(mod_istft_config, msg_spectra_config, msg_hops_config); + + obj->in = (amsg_spectra_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&amod_istft_thread, (void *) obj); + + return obj; + + } + + void amod_istft_destroy(amod_istft_obj * obj) { + + mod_istft_destroy(obj->mod_istft); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_istft_connect(amod_istft_obj * obj, amsg_spectra_obj * in, amsg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_istft_disconnect(amod_istft_obj * obj) { + + obj->in = (amsg_spectra_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + } + + void * amod_istft_thread(void * ptr) { + + amod_istft_obj * obj; + msg_spectra_obj * msg_spectra_in; + msg_hops_obj * msg_hops_out; + int rtnValue; + + obj = (amod_istft_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_spectra_in = amsg_spectra_filled_pop(obj->in); + msg_hops_out = amsg_hops_empty_pop(obj->out); + mod_istft_connect(obj->mod_istft, msg_spectra_in, msg_hops_out); + rtnValue = mod_istft_process(obj->mod_istft); + mod_istft_disconnect(obj->mod_istft); + amsg_spectra_empty_push(obj->in, msg_spectra_in); + amsg_hops_filled_push(obj->out, msg_hops_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_istft.h b/src/amodule/amod_istft.h new file mode 100644 index 0000000..aead265 --- /dev/null +++ b/src/amodule/amod_istft.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_AMODULE_ISTFT +#define __ODAS_AMODULE_ISTFT + + #include "../module/mod_istft.h" + #include "../amessage/amsg_spectra.h" + #include "../amessage/amsg_hops.h" + #include "../general/thread.h" + + typedef struct amod_istft_obj { + + mod_istft_obj * mod_istft; + amsg_spectra_obj * in; + amsg_hops_obj * out; + thread_obj * thread; + + } amod_istft_obj; + + amod_istft_obj * amod_istft_construct(const mod_istft_cfg * mod_istft_config, const msg_spectra_cfg * msg_spectra_config, const msg_hops_cfg * msg_hops_config); + + void amod_istft_destroy(amod_istft_obj * obj); + + void amod_istft_connect(amod_istft_obj * obj, amsg_spectra_obj * in, amsg_hops_obj * out); + + void amod_istft_disconnect(amod_istft_obj * obj); + + void * amod_istft_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_mapping.c b/src/amodule/amod_mapping.c new file mode 100644 index 0000000..3d64286 --- /dev/null +++ b/src/amodule/amod_mapping.c @@ -0,0 +1,71 @@ + + #include "amod_mapping.h" + + amod_mapping_obj * amod_mapping_construct(const mod_mapping_cfg * mod_mapping_config, const msg_hops_cfg * msg_hops_config) { + + amod_mapping_obj * obj; + + obj = (amod_mapping_obj *) malloc(sizeof(amod_mapping_obj)); + + obj->mod_mapping = mod_mapping_construct(mod_mapping_config, msg_hops_config); + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&amod_mapping_thread, (void *) obj); + + return obj; + + } + + void amod_mapping_destroy(amod_mapping_obj * obj) { + + mod_mapping_destroy(obj->mod_mapping); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_mapping_connect(amod_mapping_obj * obj, amsg_hops_obj * in, amsg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_mapping_disconnect(amod_mapping_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + } + + void * amod_mapping_thread(void * ptr) { + + amod_mapping_obj * obj; + msg_hops_obj * msg_hops_in; + msg_hops_obj * msg_hops_out; + int rtnValue; + + obj = (amod_mapping_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_hops_in = amsg_hops_filled_pop(obj->in); + msg_hops_out = amsg_hops_empty_pop(obj->out); + mod_mapping_connect(obj->mod_mapping, msg_hops_in, msg_hops_out); + rtnValue = mod_mapping_process(obj->mod_mapping); + mod_mapping_disconnect(obj->mod_mapping); + amsg_hops_empty_push(obj->in, msg_hops_in); + amsg_hops_filled_push(obj->out, msg_hops_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_mapping.h b/src/amodule/amod_mapping.h new file mode 100644 index 0000000..529cc56 --- /dev/null +++ b/src/amodule/amod_mapping.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_AMODULE_MAPPING +#define __ODAS_AMODULE_MAPPING + + #include "../module/mod_mapping.h" + #include "../amessage/amsg_hops.h" + #include "../general/thread.h" + + typedef struct amod_mapping_obj { + + mod_mapping_obj * mod_mapping; + amsg_hops_obj * in; + amsg_hops_obj * out; + thread_obj * thread; + + } amod_mapping_obj; + + amod_mapping_obj * amod_mapping_construct(const mod_mapping_cfg * mod_mapping_config, const msg_hops_cfg * msg_hops_config); + + void amod_mapping_destroy(amod_mapping_obj * obj); + + void amod_mapping_connect(amod_mapping_obj * obj, amsg_hops_obj * in, amsg_hops_obj * out); + + void amod_mapping_disconnect(amod_mapping_obj * obj); + + void * amod_mapping_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_noise.c b/src/amodule/amod_noise.c new file mode 100644 index 0000000..89e20d5 --- /dev/null +++ b/src/amodule/amod_noise.c @@ -0,0 +1,72 @@ + + #include "amod_noise.h" + + amod_noise_obj * amod_noise_construct(const mod_noise_cfg * mod_noise_config, const msg_spectra_cfg * msg_spectra_config, const msg_powers_cfg * msg_powers_config) { + + amod_noise_obj * obj; + + obj = (amod_noise_obj *) malloc(sizeof(amod_noise_obj)); + + obj->mod_noise = mod_noise_construct(mod_noise_config, msg_spectra_config, msg_powers_config); + + obj->in = (amsg_spectra_obj *) NULL; + obj->out = (amsg_powers_obj *) NULL; + + obj->thread = thread_construct(&amod_noise_thread, (void *) obj); + + return obj; + + + } + + void amod_noise_destroy(amod_noise_obj * obj) { + + mod_noise_destroy(obj->mod_noise); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_noise_connect(amod_noise_obj * obj, amsg_spectra_obj * in, amsg_powers_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_noise_disconnect(amod_noise_obj * obj) { + + obj->in = (amsg_spectra_obj *) NULL; + obj->out = (amsg_powers_obj *) NULL; + + } + + void * amod_noise_thread(void * ptr) { + + amod_noise_obj * obj; + msg_spectra_obj * msg_spectra_in; + msg_powers_obj * msg_powers_out; + int rtnValue; + + obj = (amod_noise_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_spectra_in = amsg_spectra_filled_pop(obj->in); + msg_powers_out = amsg_powers_empty_pop(obj->out); + mod_noise_connect(obj->mod_noise, msg_spectra_in, msg_powers_out); + rtnValue = mod_noise_process(obj->mod_noise); + mod_noise_disconnect(obj->mod_noise); + amsg_spectra_empty_push(obj->in, msg_spectra_in); + amsg_powers_filled_push(obj->out, msg_powers_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_noise.h b/src/amodule/amod_noise.h new file mode 100644 index 0000000..2df7ca9 --- /dev/null +++ b/src/amodule/amod_noise.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_AMODULE_NOISE +#define __ODAS_AMODULE_NOISE + + #include "../module/mod_noise.h" + #include "../amessage/amsg_spectra.h" + #include "../amessage/amsg_powers.h" + #include "../general/thread.h" + + typedef struct amod_noise_obj { + + mod_noise_obj * mod_noise; + amsg_spectra_obj * in; + amsg_powers_obj * out; + thread_obj * thread; + + } amod_noise_obj; + + amod_noise_obj * amod_noise_construct(const mod_noise_cfg * mod_noise_config, const msg_spectra_cfg * msg_spectra_config, const msg_powers_cfg * msg_powers_config); + + void amod_noise_destroy(amod_noise_obj * obj); + + void amod_noise_connect(amod_noise_obj * obj, amsg_spectra_obj * in, amsg_powers_obj * out); + + void amod_noise_disconnect(amod_noise_obj * obj); + + void * amod_noise_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_resample.c b/src/amodule/amod_resample.c new file mode 100644 index 0000000..ae58728 --- /dev/null +++ b/src/amodule/amod_resample.c @@ -0,0 +1,87 @@ + + #include "amod_resample.h" + + amod_resample_obj * amod_resample_construct(const mod_resample_cfg * mod_resample_config, const msg_hops_cfg * msg_hops_in_config, const msg_hops_cfg * msg_hops_out_config) { + + amod_resample_obj * obj; + + obj = (amod_resample_obj *) malloc(sizeof(amod_resample_obj)); + + obj->mod_resample = mod_resample_construct(mod_resample_config, msg_hops_in_config, msg_hops_out_config); + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&amod_resample_thread, (void *) obj); + + return obj; + + } + + void amod_resample_destroy(amod_resample_obj * obj) { + + mod_resample_destroy(obj->mod_resample); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_resample_connect(amod_resample_obj * obj, amsg_hops_obj * in, amsg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_resample_disconnect(amod_resample_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + } + + void * amod_resample_thread(void * ptr) { + + amod_resample_obj * obj; + msg_hops_obj * msg_hops_in; + msg_hops_obj * msg_hops_out; + int rtnValuePush; + int rtnValuePop; + + obj = (amod_resample_obj *) ptr; + + rtnValuePush = 0; + rtnValuePop = 0; + + while(1) { + + if (rtnValuePush != -1) { + msg_hops_in = amsg_hops_filled_pop(obj->in); + } + if (rtnValuePop != -1) { + msg_hops_out = amsg_hops_empty_pop(obj->out); + } + + mod_resample_connect(obj->mod_resample, msg_hops_in, msg_hops_out); + rtnValuePush = mod_resample_process_push(obj->mod_resample); + rtnValuePop = mod_resample_process_pop(obj->mod_resample); + mod_resample_disconnect(obj->mod_resample); + + if (rtnValuePush != -1) { + amsg_hops_empty_push(obj->in, msg_hops_in); + } + if (rtnValuePop != -1) { + amsg_hops_filled_push(obj->out, msg_hops_out); + } + + // If this is the last frame + if ((rtnValuePush == -1) && (rtnValuePop == -1)) { + amsg_hops_empty_push(obj->in, msg_hops_in); + amsg_hops_filled_push(obj->out, msg_hops_out); + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_resample.h b/src/amodule/amod_resample.h new file mode 100644 index 0000000..2a0911b --- /dev/null +++ b/src/amodule/amod_resample.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_AMODULE_RESAMPLE +#define __ODAS_AMODULE_RESAMPLE + + #include "../module/mod_resample.h" + #include "../amessage/amsg_hops.h" + #include "../general/thread.h" + + typedef struct amod_resample_obj { + + mod_resample_obj * mod_resample; + amsg_hops_obj * in; + amsg_hops_obj * out; + thread_obj * thread; + + } amod_resample_obj; + + amod_resample_obj * amod_resample_construct(const mod_resample_cfg * mod_resample_config, const msg_hops_cfg * msg_hops_in_config, const msg_hops_cfg * msg_hops_out_config); + + void amod_resample_destroy(amod_resample_obj * obj); + + void amod_resample_connect(amod_resample_obj * obj, amsg_hops_obj * in, amsg_hops_obj * out); + + void amod_resample_disconnect(amod_resample_obj * obj); + + void * amod_resample_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_ssl.c b/src/amodule/amod_ssl.c new file mode 100644 index 0000000..91cc855 --- /dev/null +++ b/src/amodule/amod_ssl.c @@ -0,0 +1,72 @@ + + #include "amod_ssl.h" + + amod_ssl_obj * amod_ssl_construct(const mod_ssl_cfg * mod_ssl_config, const msg_spectra_cfg * msg_spectra_config, const msg_pots_cfg * msg_pots_config) { + + amod_ssl_obj * obj; + + obj = (amod_ssl_obj *) malloc(sizeof(amod_ssl_obj)); + + obj->mod_ssl = mod_ssl_construct(mod_ssl_config, msg_spectra_config, msg_pots_config); + + obj->in = (amsg_spectra_obj *) NULL; + obj->out = (amsg_pots_obj *) NULL; + + obj->thread = thread_construct(&amod_ssl_thread, (void *) obj); + + return obj; + + } + + void amod_ssl_destroy(amod_ssl_obj * obj) { + + mod_ssl_destroy(obj->mod_ssl); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_ssl_connect(amod_ssl_obj * obj, amsg_spectra_obj * in, amsg_pots_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_ssl_disconnect(amod_ssl_obj * obj) { + + obj->in = (amsg_spectra_obj *) NULL; + obj->out = (amsg_pots_obj *) NULL; + + } + + void * amod_ssl_thread(void * ptr) { + + amod_ssl_obj * obj; + msg_spectra_obj * msg_spectra_in; + msg_pots_obj * msg_pots_out; + int rtnValue; + + obj = (amod_ssl_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_spectra_in = amsg_spectra_filled_pop(obj->in); + msg_pots_out = amsg_pots_empty_pop(obj->out); + mod_ssl_connect(obj->mod_ssl, msg_spectra_in, msg_pots_out); + rtnValue = mod_ssl_process(obj->mod_ssl); + mod_ssl_disconnect(obj->mod_ssl); + amsg_spectra_empty_push(obj->in, msg_spectra_in); + amsg_pots_filled_push(obj->out, msg_pots_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + + } + + } diff --git a/src/amodule/amod_ssl.h b/src/amodule/amod_ssl.h new file mode 100644 index 0000000..6427bc1 --- /dev/null +++ b/src/amodule/amod_ssl.h @@ -0,0 +1,29 @@ +#ifndef __ODAS_AMODULE_SSL +#define __ODAS_AMODULE_SSL + + #include "../module/mod_ssl.h" + #include "../amessage/amsg_spectra.h" + #include "../amessage/amsg_powers.h" + #include "../amessage/amsg_pots.h" + #include "../general/thread.h" + + typedef struct amod_ssl_obj { + + mod_ssl_obj * mod_ssl; + amsg_spectra_obj * in; + amsg_pots_obj * out; + thread_obj * thread; + + } amod_ssl_obj; + + amod_ssl_obj * amod_ssl_construct(const mod_ssl_cfg * mod_ssl_config, const msg_spectra_cfg * msg_spectra_config, const msg_pots_cfg * msg_pots_config); + + void amod_ssl_destroy(amod_ssl_obj * obj); + + void amod_ssl_connect(amod_ssl_obj * obj, amsg_spectra_obj * in, amsg_pots_obj * out); + + void amod_ssl_disconnect(amod_ssl_obj * obj); + + void * amod_ssl_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_sss.c b/src/amodule/amod_sss.c new file mode 100644 index 0000000..1a12d78 --- /dev/null +++ b/src/amodule/amod_sss.c @@ -0,0 +1,89 @@ + + #include "amod_sss.h" + + amod_sss_obj * amod_sss_construct(const mod_sss_cfg * mod_sss_config, const msg_tracks_cfg * msg_tracks_config, const msg_spectra_cfg * msg_spectra_config) { + + amod_sss_obj * obj; + + obj = (amod_sss_obj *) malloc(sizeof(amod_sss_obj)); + + obj->mod_sss = mod_sss_construct(mod_sss_config, msg_tracks_config, msg_spectra_config); + + obj->in1 = (amsg_spectra_obj *) NULL; + obj->in2 = (amsg_powers_obj *) NULL; + obj->in3 = (amsg_tracks_obj *) NULL; + obj->out1 = (amsg_spectra_obj *) NULL; + obj->out2 = (amsg_spectra_obj *) NULL; + + obj->thread = thread_construct(&amod_sss_thread, (void *) obj); + + return obj; + + } + + void amod_sss_destroy(amod_sss_obj * obj) { + + mod_sss_destroy(obj->mod_sss); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_sss_connect(amod_sss_obj * obj, amsg_spectra_obj * in1, amsg_powers_obj * in2, amsg_tracks_obj * in3, amsg_spectra_obj * out1, amsg_spectra_obj * out2) { + + obj->in1 = in1; + obj->in2 = in2; + obj->in3 = in3; + obj->out1 = out1; + obj->out2 = out2; + + } + + void amod_sss_disconnect(amod_sss_obj * obj) { + + obj->in1 = (amsg_spectra_obj *) NULL; + obj->in2 = (amsg_powers_obj *) NULL; + obj->in3 = (amsg_tracks_obj *) NULL; + obj->out1 = (amsg_spectra_obj *) NULL; + obj->out2 = (amsg_spectra_obj *) NULL; + + } + + void * amod_sss_thread(void * ptr) { + + amod_sss_obj * obj; + msg_spectra_obj * msg_spectra_in; + msg_powers_obj * msg_powers_in; + msg_tracks_obj * msg_tracks_in; + msg_spectra_obj * msg_spectra_out1; + msg_spectra_obj * msg_spectra_out2; + int rtnValue; + + obj = (amod_sss_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_spectra_in = amsg_spectra_filled_pop(obj->in1); + msg_powers_in = amsg_powers_filled_pop(obj->in2); + msg_tracks_in = amsg_tracks_filled_pop(obj->in3); + msg_spectra_out1 = amsg_spectra_empty_pop(obj->out1); + msg_spectra_out2 = amsg_spectra_empty_pop(obj->out2); + mod_sss_connect(obj->mod_sss, msg_spectra_in, msg_powers_in, msg_tracks_in, msg_spectra_out1, msg_spectra_out2); + rtnValue = mod_sss_process(obj->mod_sss); + mod_sss_disconnect(obj->mod_sss); + amsg_spectra_empty_push(obj->in1, msg_spectra_in); + amsg_powers_empty_push(obj->in2, msg_powers_in); + amsg_tracks_empty_push(obj->in3, msg_tracks_in); + amsg_spectra_filled_push(obj->out1, msg_spectra_out1); + amsg_spectra_filled_push(obj->out2, msg_spectra_out2); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } diff --git a/src/amodule/amod_sss.h b/src/amodule/amod_sss.h new file mode 100644 index 0000000..ff3b8c9 --- /dev/null +++ b/src/amodule/amod_sss.h @@ -0,0 +1,32 @@ +#ifndef __ODAS_AMODULE_SSS +#define __ODAS_AMODULE_SSS + + #include "../module/mod_sss.h" + #include "../amessage/amsg_powers.h" + #include "../amessage/amsg_tracks.h" + #include "../amessage/amsg_spectra.h" + #include "../general/thread.h" + + typedef struct amod_sss_obj { + + mod_sss_obj * mod_sss; + amsg_spectra_obj * in1; + amsg_powers_obj * in2; + amsg_tracks_obj * in3; + amsg_spectra_obj * out1; + amsg_spectra_obj * out2; + thread_obj * thread; + + } amod_sss_obj; + + amod_sss_obj * amod_sss_construct(const mod_sss_cfg * mod_sss_config, const msg_tracks_cfg * msg_tracks_config, const msg_spectra_cfg * msg_spectra_config); + + void amod_sss_destroy(amod_sss_obj * obj); + + void amod_sss_connect(amod_sss_obj * obj, amsg_spectra_obj * in1, amsg_powers_obj * in2, amsg_tracks_obj * in3, amsg_spectra_obj * out1, amsg_spectra_obj * out2); + + void amod_sss_disconnect(amod_sss_obj * obj); + + void * amod_sss_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_sst.c b/src/amodule/amod_sst.c new file mode 100644 index 0000000..29680b1 --- /dev/null +++ b/src/amodule/amod_sst.c @@ -0,0 +1,77 @@ + + #include "amod_sst.h" + + amod_sst_obj * amod_sst_construct(const mod_sst_cfg * mod_sst_config, const mod_ssl_cfg * mod_ssl_config, const msg_pots_cfg * msg_pots_config, const msg_targets_cfg * msg_targets_config, const msg_tracks_cfg * msg_tracks_config) { + + amod_sst_obj * obj; + + obj = (amod_sst_obj *) malloc(sizeof(amod_sst_obj)); + + obj->mod_sst = mod_sst_construct(mod_sst_config, mod_ssl_config, msg_pots_config, msg_targets_config, msg_tracks_config); + + obj->in1 = (amsg_pots_obj *) NULL; + obj->in2 = (amsg_targets_obj *) NULL; + obj->out = (amsg_tracks_obj *) NULL; + + obj->thread = thread_construct(&amod_sst_thread, (void *) obj); + + return obj; + + } + + void amod_sst_destroy(amod_sst_obj * obj) { + + mod_sst_destroy(obj->mod_sst); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_sst_connect(amod_sst_obj * obj, amsg_pots_obj * in1, amsg_targets_obj * in2, amsg_tracks_obj * out) { + + obj->in1 = in1; + obj->in2 = in2; + obj->out = out; + + } + + void amod_sst_disconnect(amod_sst_obj * obj) { + + obj->in1 = (amsg_pots_obj *) NULL; + obj->in2 = (amsg_targets_obj *) NULL; + obj->out = (amsg_tracks_obj *) NULL; + + } + + void * amod_sst_thread(void * ptr) { + + amod_sst_obj * obj; + msg_pots_obj * msg_pots_in; + msg_targets_obj * msg_targets_in; + msg_tracks_obj * msg_tracks_out; + int rtnValue; + + obj = (amod_sst_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_pots_in = amsg_pots_filled_pop(obj->in1); + msg_targets_in = amsg_targets_filled_pop(obj->in2); + msg_tracks_out = amsg_tracks_empty_pop(obj->out); + mod_sst_connect(obj->mod_sst, msg_pots_in, msg_targets_in, msg_tracks_out); + rtnValue = mod_sst_process(obj->mod_sst); + mod_sst_disconnect(obj->mod_sst); + amsg_pots_empty_push(obj->in1, msg_pots_in); + amsg_targets_empty_push(obj->in2, msg_targets_in); + amsg_tracks_filled_push(obj->out, msg_tracks_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_sst.h b/src/amodule/amod_sst.h new file mode 100644 index 0000000..e638164 --- /dev/null +++ b/src/amodule/amod_sst.h @@ -0,0 +1,31 @@ +#ifndef __ODAS_AMODULE_SST +#define __ODAS_AMODULE_SST + + #include "../module/mod_ssl.h" + #include "../module/mod_sst.h" + #include "../amessage/amsg_pots.h" + #include "../amessage/amsg_targets.h" + #include "../amessage/amsg_tracks.h" + #include "../general/thread.h" + + typedef struct amod_sst_obj { + + mod_sst_obj * mod_sst; + amsg_pots_obj * in1; + amsg_targets_obj * in2; + amsg_tracks_obj * out; + thread_obj * thread; + + } amod_sst_obj; + + amod_sst_obj * amod_sst_construct(const mod_sst_cfg * mod_sst_config, const mod_ssl_cfg * mod_ssl_config, const msg_pots_cfg * msg_pots_config, const msg_targets_cfg * msg_targets_config, const msg_tracks_cfg * msg_tracks_config); + + void amod_sst_destroy(amod_sst_obj * obj); + + void amod_sst_connect(amod_sst_obj * obj, amsg_pots_obj * in1, amsg_targets_obj * in2, amsg_tracks_obj * out); + + void amod_sst_disconnect(amod_sst_obj * obj); + + void * amod_sst_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_stft.c b/src/amodule/amod_stft.c new file mode 100644 index 0000000..c785290 --- /dev/null +++ b/src/amodule/amod_stft.c @@ -0,0 +1,71 @@ + + #include "amod_stft.h" + + amod_stft_obj * amod_stft_construct(const mod_stft_cfg * mod_stft_config, const msg_hops_cfg * msg_hops_config, const msg_spectra_cfg * msg_spectra_config) { + + amod_stft_obj * obj; + + obj = (amod_stft_obj *) malloc(sizeof(amod_stft_obj)); + + obj->mod_stft = mod_stft_construct(mod_stft_config, msg_hops_config, msg_spectra_config); + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_spectra_obj *) NULL; + + obj->thread = thread_construct(&amod_stft_thread, (void *) obj); + + return obj; + + } + + void amod_stft_destroy(amod_stft_obj * obj) { + + mod_stft_destroy(obj->mod_stft); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_stft_connect(amod_stft_obj * obj, amsg_hops_obj * in, amsg_spectra_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_stft_disconnect(amod_stft_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_spectra_obj *) NULL; + + } + + void * amod_stft_thread(void * ptr) { + + amod_stft_obj * obj; + msg_hops_obj * msg_hops_in; + msg_spectra_obj * msg_spectra_out; + int rtnValue; + + obj = (amod_stft_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_hops_in = amsg_hops_filled_pop(obj->in); + msg_spectra_out = amsg_spectra_empty_pop(obj->out); + mod_stft_connect(obj->mod_stft, msg_hops_in, msg_spectra_out); + rtnValue = mod_stft_process(obj->mod_stft); + mod_stft_disconnect(obj->mod_stft); + amsg_hops_empty_push(obj->in, msg_hops_in); + amsg_spectra_filled_push(obj->out, msg_spectra_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_stft.h b/src/amodule/amod_stft.h new file mode 100644 index 0000000..363aba0 --- /dev/null +++ b/src/amodule/amod_stft.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_AMODULE_STFT +#define __ODAS_AMODULE_STFT + + #include "../module/mod_stft.h" + #include "../amessage/amsg_hops.h" + #include "../amessage/amsg_spectra.h" + #include "../general/thread.h" + + typedef struct amod_stft_obj { + + mod_stft_obj * mod_stft; + amsg_hops_obj * in; + amsg_spectra_obj * out; + thread_obj * thread; + + } amod_stft_obj; + + amod_stft_obj * amod_stft_construct(const mod_stft_cfg * mod_stft_config, const msg_hops_cfg * msg_hops_config, const msg_spectra_cfg * msg_spectra_config); + + void amod_stft_destroy(amod_stft_obj * obj); + + void amod_stft_connect(amod_stft_obj * obj, amsg_hops_obj * in, amsg_spectra_obj * out); + + void amod_stft_disconnect(amod_stft_obj * obj); + + void * amod_stft_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/amodule/amod_volume.c b/src/amodule/amod_volume.c new file mode 100644 index 0000000..f7f1e6e --- /dev/null +++ b/src/amodule/amod_volume.c @@ -0,0 +1,71 @@ + + #include "amod_volume.h" + + amod_volume_obj * amod_volume_construct(const mod_volume_cfg * mod_volume_config, const msg_hops_cfg * msg_hops_config) { + + amod_volume_obj * obj; + + obj = (amod_volume_obj *) malloc(sizeof(amod_volume_obj)); + + obj->mod_volume = mod_volume_construct(mod_volume_config, msg_hops_config); + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&amod_volume_thread, (void *) obj); + + return obj; + + } + + void amod_volume_destroy(amod_volume_obj * obj) { + + mod_volume_destroy(obj->mod_volume); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void amod_volume_connect(amod_volume_obj * obj, amsg_hops_obj * in, amsg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void amod_volume_disconnect(amod_volume_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + obj->out = (amsg_hops_obj *) NULL; + + } + + void * amod_volume_thread(void * ptr) { + + amod_volume_obj * obj; + msg_hops_obj * msg_hops_in; + msg_hops_obj * msg_hops_out; + int rtnValue; + + obj = (amod_volume_obj *) ptr; + + while(1) { + + // Pop a message, process, and push back + msg_hops_in = amsg_hops_filled_pop(obj->in); + msg_hops_out = amsg_hops_empty_pop(obj->out); + mod_volume_connect(obj->mod_volume, msg_hops_in, msg_hops_out); + rtnValue = mod_volume_process(obj->mod_volume); + mod_volume_disconnect(obj->mod_volume); + amsg_hops_empty_push(obj->in, msg_hops_in); + amsg_hops_filled_push(obj->out, msg_hops_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + } \ No newline at end of file diff --git a/src/amodule/amod_volume.h b/src/amodule/amod_volume.h new file mode 100644 index 0000000..8693c23 --- /dev/null +++ b/src/amodule/amod_volume.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_AMODULE_VOLUME +#define __ODAS_AMODULE_VOLUME + + #include "../module/mod_volume.h" + #include "../amessage/amsg_hops.h" + #include "../general/thread.h" + + typedef struct amod_volume_obj { + + mod_volume_obj * mod_volume; + amsg_hops_obj * in; + amsg_hops_obj * out; + thread_obj * thread; + + } amod_volume_obj; + + amod_volume_obj * amod_volume_construct(const mod_volume_cfg * mod_volume_config, const msg_hops_cfg * msg_hops_config); + + void amod_volume_destroy(amod_volume_obj * obj); + + void amod_volume_connect(amod_volume_obj * obj, amsg_hops_obj * in, amsg_hops_obj * out); + + void amod_volume_disconnect(amod_volume_obj * obj); + + void * amod_volume_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_categories.c b/src/asink/asnk_categories.c new file mode 100644 index 0000000..e2586e8 --- /dev/null +++ b/src/asink/asnk_categories.c @@ -0,0 +1,70 @@ + + #include "asnk_categories.h" + + asnk_categories_obj * asnk_categories_construct(const snk_categories_cfg * snk_categories_config, const msg_categories_cfg * msg_categories_config) { + + asnk_categories_obj * obj; + + obj = (asnk_categories_obj *) malloc(sizeof(asnk_categories_obj)); + + obj->snk_categories = snk_categories_construct(snk_categories_config, msg_categories_config); + obj->in = (amsg_categories_obj *) NULL; + + obj->thread = thread_construct(&asnk_categories_thread, (void *) obj); + + return obj; + + } + + void asnk_categories_destroy(asnk_categories_obj * obj) { + + snk_categories_destroy(obj->snk_categories); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_categories_connect(asnk_categories_obj * obj, amsg_categories_obj * in) { + + obj->in = in; + + } + + void asnk_categories_disconnect(asnk_categories_obj * obj) { + + obj->in = (amsg_categories_obj *) NULL; + + } + + void * asnk_categories_thread(void * ptr) { + + asnk_categories_obj * obj; + msg_categories_obj * msg_categories_in; + int rtnValue; + + obj = (asnk_categories_obj *) ptr; + + // Open the sink + snk_categories_open(obj->snk_categories); + + while(1) { + + // Pop a message, process, and push back + msg_categories_in = amsg_categories_filled_pop(obj->in); + snk_categories_connect(obj->snk_categories, msg_categories_in); + rtnValue = snk_categories_process(obj->snk_categories); + snk_categories_disconnect(obj->snk_categories); + amsg_categories_empty_push(obj->in, msg_categories_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_categories_close(obj->snk_categories); + + } \ No newline at end of file diff --git a/src/asink/asnk_categories.h b/src/asink/asnk_categories.h new file mode 100644 index 0000000..c584b55 --- /dev/null +++ b/src/asink/asnk_categories.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_CATEGORIES +#define __ODAS_ASINK_CATEGORIES + + #include "../amessage/amsg_categories.h" + #include "../sink/snk_categories.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_categories_obj { + + snk_categories_obj * snk_categories; + amsg_categories_obj * in; + thread_obj * thread; + + } asnk_categories_obj; + + asnk_categories_obj * asnk_categories_construct(const snk_categories_cfg * snk_categories_config, const msg_categories_cfg * msg_categories_config); + + void asnk_categories_destroy(asnk_categories_obj * obj); + + void asnk_categories_connect(asnk_categories_obj * obj, amsg_categories_obj * in); + + void asnk_categories_disconnect(asnk_categories_obj * obj); + + void * asnk_categories_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_hops.c b/src/asink/asnk_hops.c new file mode 100644 index 0000000..9988b0e --- /dev/null +++ b/src/asink/asnk_hops.c @@ -0,0 +1,70 @@ + + #include "asnk_hops.h" + + asnk_hops_obj * asnk_hops_construct(const snk_hops_cfg * snk_hops_config, const msg_hops_cfg * msg_hops_config) { + + asnk_hops_obj * obj; + + obj = (asnk_hops_obj *) malloc(sizeof(asnk_hops_obj)); + + obj->snk_hops = snk_hops_construct(snk_hops_config, msg_hops_config); + obj->in = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&asnk_hops_thread, (void *) obj); + + return obj; + + } + + void asnk_hops_destroy(asnk_hops_obj * obj) { + + snk_hops_destroy(obj->snk_hops); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_hops_connect(asnk_hops_obj * obj, amsg_hops_obj * in) { + + obj->in = in; + + } + + void asnk_hops_disconnect(asnk_hops_obj * obj) { + + obj->in = (amsg_hops_obj *) NULL; + + } + + void * asnk_hops_thread(void * ptr) { + + asnk_hops_obj * obj; + msg_hops_obj * msg_hops_in; + int rtnValue; + + obj = (asnk_hops_obj *) ptr; + + // Open the sink + snk_hops_open(obj->snk_hops); + + while(1) { + + // Pop a message, process, and push back + msg_hops_in = amsg_hops_filled_pop(obj->in); + snk_hops_connect(obj->snk_hops, msg_hops_in); + rtnValue = snk_hops_process(obj->snk_hops); + snk_hops_disconnect(obj->snk_hops); + amsg_hops_empty_push(obj->in, msg_hops_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_hops_close(obj->snk_hops); + + } \ No newline at end of file diff --git a/src/asink/asnk_hops.h b/src/asink/asnk_hops.h new file mode 100644 index 0000000..0f23071 --- /dev/null +++ b/src/asink/asnk_hops.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_HOPS +#define __ODAS_ASINK_HOPS + + #include "../amessage/amsg_hops.h" + #include "../sink/snk_hops.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_hops_obj { + + snk_hops_obj * snk_hops; + amsg_hops_obj * in; + thread_obj * thread; + + } asnk_hops_obj; + + asnk_hops_obj * asnk_hops_construct(const snk_hops_cfg * snk_hops_config, const msg_hops_cfg * msg_hops_config); + + void asnk_hops_destroy(asnk_hops_obj * obj); + + void asnk_hops_connect(asnk_hops_obj * obj, amsg_hops_obj * in); + + void asnk_hops_disconnect(asnk_hops_obj * obj); + + void * asnk_hops_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_pots.c b/src/asink/asnk_pots.c new file mode 100644 index 0000000..71d251d --- /dev/null +++ b/src/asink/asnk_pots.c @@ -0,0 +1,70 @@ + + #include "asnk_pots.h" + + asnk_pots_obj * asnk_pots_construct(const snk_pots_cfg * snk_pots_config, const msg_pots_cfg * msg_pots_config) { + + asnk_pots_obj * obj; + + obj = (asnk_pots_obj *) malloc(sizeof(asnk_pots_obj)); + + obj->snk_pots = snk_pots_construct(snk_pots_config, msg_pots_config); + obj->in = (amsg_pots_obj *) NULL; + + obj->thread = thread_construct(&asnk_pots_thread, (void *) obj); + + return obj; + + } + + void asnk_pots_destroy(asnk_pots_obj * obj) { + + snk_pots_destroy(obj->snk_pots); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_pots_connect(asnk_pots_obj * obj, amsg_pots_obj * in) { + + obj->in = in; + + } + + void asnk_pots_disconnect(asnk_pots_obj * obj) { + + obj->in = (amsg_pots_obj *) NULL; + + } + + void * asnk_pots_thread(void * ptr) { + + asnk_pots_obj * obj; + msg_pots_obj * msg_pots_in; + int rtnValue; + + obj = (asnk_pots_obj *) ptr; + + // Open the sink + snk_pots_open(obj->snk_pots); + + while(1) { + + // Pop a message, process, and push back + msg_pots_in = amsg_pots_filled_pop(obj->in); + snk_pots_connect(obj->snk_pots, msg_pots_in); + rtnValue = snk_pots_process(obj->snk_pots); + snk_pots_disconnect(obj->snk_pots); + amsg_pots_empty_push(obj->in, msg_pots_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_pots_close(obj->snk_pots); + + } \ No newline at end of file diff --git a/src/asink/asnk_pots.h b/src/asink/asnk_pots.h new file mode 100644 index 0000000..2e14e1f --- /dev/null +++ b/src/asink/asnk_pots.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_POTS +#define __ODAS_ASINK_POTS + + #include "../amessage/amsg_pots.h" + #include "../sink/snk_pots.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_pots_obj { + + snk_pots_obj * snk_pots; + amsg_pots_obj * in; + thread_obj * thread; + + } asnk_pots_obj; + + asnk_pots_obj * asnk_pots_construct(const snk_pots_cfg * snk_pots_config, const msg_pots_cfg * msg_pots_config); + + void asnk_pots_destroy(asnk_pots_obj * obj); + + void asnk_pots_connect(asnk_pots_obj * obj, amsg_pots_obj * in); + + void asnk_pots_disconnect(asnk_pots_obj * obj); + + void * asnk_pots_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_powers.c b/src/asink/asnk_powers.c new file mode 100644 index 0000000..623caa3 --- /dev/null +++ b/src/asink/asnk_powers.c @@ -0,0 +1,70 @@ + + #include "asnk_powers.h" + + asnk_powers_obj * asnk_powers_construct(const snk_powers_cfg * snk_powers_config, const msg_powers_cfg * msg_powers_config) { + + asnk_powers_obj * obj; + + obj = (asnk_powers_obj *) malloc(sizeof(asnk_powers_obj)); + + obj->snk_powers = snk_powers_construct(snk_powers_config, msg_powers_config); + obj->in = (amsg_powers_obj *) NULL; + + obj->thread = thread_construct(&asnk_powers_thread, (void *) obj); + + return obj; + + } + + void asnk_powers_destroy(asnk_powers_obj * obj) { + + snk_powers_destroy(obj->snk_powers); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_powers_connect(asnk_powers_obj * obj, amsg_powers_obj * in) { + + obj->in = in; + + } + + void asnk_powers_disconnect(asnk_powers_obj * obj) { + + obj->in = (amsg_powers_obj *) NULL; + + } + + void * asnk_powers_thread(void * ptr) { + + asnk_powers_obj * obj; + msg_powers_obj * msg_powers_in; + int rtnValue; + + obj = (asnk_powers_obj *) ptr; + + // Open the sink + snk_powers_open(obj->snk_powers); + + while(1) { + + // Pop a message, process, and push back + msg_powers_in = amsg_powers_filled_pop(obj->in); + snk_powers_connect(obj->snk_powers, msg_powers_in); + rtnValue = snk_powers_process(obj->snk_powers); + snk_powers_disconnect(obj->snk_powers); + amsg_powers_empty_push(obj->in, msg_powers_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_powers_close(obj->snk_powers); + + } \ No newline at end of file diff --git a/src/asink/asnk_powers.h b/src/asink/asnk_powers.h new file mode 100644 index 0000000..e5afb21 --- /dev/null +++ b/src/asink/asnk_powers.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_POWERS +#define __ODAS_ASINK_POWERS + + #include "../amessage/amsg_powers.h" + #include "../sink/snk_powers.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_powers_obj { + + snk_powers_obj * snk_powers; + amsg_powers_obj * in; + thread_obj * thread; + + } asnk_powers_obj; + + asnk_powers_obj * asnk_powers_construct(const snk_powers_cfg * snk_powers_config, const msg_powers_cfg * msg_powers_config); + + void asnk_powers_destroy(asnk_powers_obj * obj); + + void asnk_powers_connect(asnk_powers_obj * obj, amsg_powers_obj * in); + + void asnk_powers_disconnect(asnk_powers_obj * obj); + + void * asnk_powers_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_spectra.c b/src/asink/asnk_spectra.c new file mode 100644 index 0000000..db928fc --- /dev/null +++ b/src/asink/asnk_spectra.c @@ -0,0 +1,70 @@ + + #include "asnk_spectra.h" + + asnk_spectra_obj * asnk_spectra_construct(const snk_spectra_cfg * snk_spectra_config, const msg_spectra_cfg * msg_spectra_config) { + + asnk_spectra_obj * obj; + + obj = (asnk_spectra_obj *) malloc(sizeof(asnk_spectra_obj)); + + obj->snk_spectra = snk_spectra_construct(snk_spectra_config, msg_spectra_config); + obj->in = (amsg_spectra_obj *) NULL; + + obj->thread = thread_construct(&asnk_spectra_thread, (void *) obj); + + return obj; + + } + + void asnk_spectra_destroy(asnk_spectra_obj * obj) { + + snk_spectra_destroy(obj->snk_spectra); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_spectra_connect(asnk_spectra_obj * obj, amsg_spectra_obj * in) { + + obj->in = in; + + } + + void asnk_spectra_disconnect(asnk_spectra_obj * obj) { + + obj->in = (amsg_spectra_obj *) NULL; + + } + + void * asnk_spectra_thread(void * ptr) { + + asnk_spectra_obj * obj; + msg_spectra_obj * msg_spectra_in; + int rtnValue; + + obj = (asnk_spectra_obj *) ptr; + + // Open the sink + snk_spectra_open(obj->snk_spectra); + + while(1) { + + // Pop a message, process, and push back + msg_spectra_in = amsg_spectra_filled_pop(obj->in); + snk_spectra_connect(obj->snk_spectra, msg_spectra_in); + rtnValue = snk_spectra_process(obj->snk_spectra); + snk_spectra_disconnect(obj->snk_spectra); + amsg_spectra_empty_push(obj->in, msg_spectra_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_spectra_close(obj->snk_spectra); + + } \ No newline at end of file diff --git a/src/asink/asnk_spectra.h b/src/asink/asnk_spectra.h new file mode 100644 index 0000000..89e39a9 --- /dev/null +++ b/src/asink/asnk_spectra.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_SPECTRA +#define __ODAS_ASINK_SPECTRA + + #include "../amessage/amsg_spectra.h" + #include "../sink/snk_spectra.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_spectra_obj { + + snk_spectra_obj * snk_spectra; + amsg_spectra_obj * in; + thread_obj * thread; + + } asnk_spectra_obj; + + asnk_spectra_obj * asnk_spectra_construct(const snk_spectra_cfg * snk_spectra_config, const msg_spectra_cfg * msg_spectra_config); + + void asnk_spectra_destroy(asnk_spectra_obj * obj); + + void asnk_spectra_connect(asnk_spectra_obj * obj, amsg_spectra_obj * in); + + void asnk_spectra_disconnect(asnk_spectra_obj * obj); + + void * asnk_spectra_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asink/asnk_tracks.c b/src/asink/asnk_tracks.c new file mode 100644 index 0000000..a9fc3c6 --- /dev/null +++ b/src/asink/asnk_tracks.c @@ -0,0 +1,70 @@ + + #include "asnk_tracks.h" + + asnk_tracks_obj * asnk_tracks_construct(const snk_tracks_cfg * snk_tracks_config, const msg_tracks_cfg * msg_tracks_config) { + + asnk_tracks_obj * obj; + + obj = (asnk_tracks_obj *) malloc(sizeof(asnk_tracks_obj)); + + obj->snk_tracks = snk_tracks_construct(snk_tracks_config, msg_tracks_config); + obj->in = (amsg_tracks_obj *) NULL; + + obj->thread = thread_construct(&asnk_tracks_thread, (void *) obj); + + return obj; + + } + + void asnk_tracks_destroy(asnk_tracks_obj * obj) { + + snk_tracks_destroy(obj->snk_tracks); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asnk_tracks_connect(asnk_tracks_obj * obj, amsg_tracks_obj * in) { + + obj->in = in; + + } + + void asnk_tracks_disconnect(asnk_tracks_obj * obj) { + + obj->in = (amsg_tracks_obj *) NULL; + + } + + void * asnk_tracks_thread(void * ptr) { + + asnk_tracks_obj * obj; + msg_tracks_obj * msg_tracks_in; + int rtnValue; + + obj = (asnk_tracks_obj *) ptr; + + // Open the sink + snk_tracks_open(obj->snk_tracks); + + while(1) { + + // Pop a message, process, and push back + msg_tracks_in = amsg_tracks_filled_pop(obj->in); + snk_tracks_connect(obj->snk_tracks, msg_tracks_in); + rtnValue = snk_tracks_process(obj->snk_tracks); + snk_tracks_disconnect(obj->snk_tracks); + amsg_tracks_empty_push(obj->in, msg_tracks_in); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + } + + // Close the sink + snk_tracks_close(obj->snk_tracks); + + } \ No newline at end of file diff --git a/src/asink/asnk_tracks.h b/src/asink/asnk_tracks.h new file mode 100644 index 0000000..8acb0ef --- /dev/null +++ b/src/asink/asnk_tracks.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASINK_TRACKS +#define __ODAS_ASINK_TRACKS + + #include "../amessage/amsg_tracks.h" + #include "../sink/snk_tracks.h" + #include "../general/thread.h" + + #include + + typedef struct asnk_tracks_obj { + + snk_tracks_obj * snk_tracks; + amsg_tracks_obj * in; + thread_obj * thread; + + } asnk_tracks_obj; + + asnk_tracks_obj * asnk_tracks_construct(const snk_tracks_cfg * snk_tracks_config, const msg_tracks_cfg * msg_tracks_config); + + void asnk_tracks_destroy(asnk_tracks_obj * obj); + + void asnk_tracks_connect(asnk_tracks_obj * obj, amsg_tracks_obj * in); + + void asnk_tracks_disconnect(asnk_tracks_obj * obj); + + void * asnk_tracks_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/asource/asrc_hops.c b/src/asource/asrc_hops.c new file mode 100644 index 0000000..753f3ef --- /dev/null +++ b/src/asource/asrc_hops.c @@ -0,0 +1,81 @@ + + #include "asrc_hops.h" + + asrc_hops_obj * asrc_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config) { + + asrc_hops_obj * obj; + + obj = (asrc_hops_obj *) malloc(sizeof(asrc_hops_obj)); + + obj->src_hops = src_hops_construct(src_hops_config, msg_hops_config); + obj->out = (amsg_hops_obj *) NULL; + + obj->thread = thread_construct(&asrc_hops_thread, (void *) obj); + + return obj; + + } + + void asrc_hops_destroy(asrc_hops_obj * obj) { + + src_hops_destroy(obj->src_hops); + thread_destroy(obj->thread); + + free((void *) obj); + + } + + void asrc_hops_connect(asrc_hops_obj * obj, amsg_hops_obj * out) { + + obj->out = out; + + } + + void asrc_hops_disconnect(asrc_hops_obj * obj) { + + obj->out = (amsg_hops_obj *) NULL; + + } + + void * asrc_hops_thread(void * ptr) { + + asrc_hops_obj * obj; + msg_hops_obj * msg_hops_out; + int rtnValue; + + obj = (asrc_hops_obj *) ptr; + + // Open the source + src_hops_open(obj->src_hops); + + while(1) { + + // Pop a message, process, and push back + msg_hops_out = amsg_hops_empty_pop(obj->out); + src_hops_connect(obj->src_hops, msg_hops_out); + rtnValue = src_hops_process(obj->src_hops); + src_hops_disconnect(obj->src_hops); + amsg_hops_filled_push(obj->out, msg_hops_out); + + // If this is the last frame, rtnValue = -1 + if (rtnValue == -1) { + break; + } + + // Some other process may ask to stop the thread + if (thread_askedToStop(obj->thread) == 1) { + break; + } + + } + + // Close the source + src_hops_close(obj->src_hops); + + // Send the "0" message, that kills all connected threads + // that will consume this message + msg_hops_out = amsg_hops_empty_pop(obj->out); + msg_hops_zero(msg_hops_out); + amsg_hops_filled_push(obj->out, msg_hops_out); + + } \ No newline at end of file diff --git a/src/asource/asrc_hops.h b/src/asource/asrc_hops.h new file mode 100644 index 0000000..050fc24 --- /dev/null +++ b/src/asource/asrc_hops.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_ASOURCE_HOPS +#define __ODAS_ASOURCE_HOPS + + #include "../amessage/amsg_hops.h" + #include "../source/src_hops.h" + #include "../general/thread.h" + + #include + + typedef struct asrc_hops_obj { + + src_hops_obj * src_hops; + amsg_hops_obj * out; + thread_obj * thread; + + } asrc_hops_obj; + + asrc_hops_obj * asrc_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config); + + void asrc_hops_destroy(asrc_hops_obj * obj); + + void asrc_hops_connect(asrc_hops_obj * obj, amsg_hops_obj * out); + + void asrc_hops_disconnect(asrc_hops_obj * obj); + + void * asrc_hops_thread(void * ptr); + +#endif \ No newline at end of file diff --git a/src/connector/con_categories.c b/src/connector/con_categories.c new file mode 100644 index 0000000..05dff28 --- /dev/null +++ b/src/connector/con_categories.c @@ -0,0 +1,57 @@ + + #include "con_categories.h" + + con_categories_obj * con_categories_construct(const unsigned int nOuts, const msg_categories_cfg * msg_categories_config) { + + con_categories_obj * obj; + unsigned int iOut; + + obj = (con_categories_obj *) malloc(sizeof(con_categories_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_categories_construct(msg_categories_config); + + obj->outs = (msg_categories_obj **) malloc(sizeof(msg_categories_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_categories_construct(msg_categories_config); + } + + return obj; + + } + + void con_categories_destroy(con_categories_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_categories_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_categories_destroy(obj->in); + + free((void *) obj); + + } + + int con_categories_process(con_categories_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_categories_copy(obj->outs[iOut], obj->in); + } + + if (msg_categories_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_categories.h b/src/connector/con_categories.h new file mode 100644 index 0000000..fec8ef1 --- /dev/null +++ b/src/connector/con_categories.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_CATEGORIES +#define __ODAS_CONNECTOR_CATEGORIES + + #include "../message/msg_categories.h" + + #include + #include + + typedef struct con_categories_obj { + + msg_categories_obj * in; + msg_categories_obj ** outs; + + unsigned int nOuts; + + } con_categories_obj; + + con_categories_obj * con_categories_construct(const unsigned int nOuts, const msg_categories_cfg * msg_categories_config); + + void con_categories_destroy(con_categories_obj * obj); + + int con_categories_process(con_categories_obj * obj); + +#endif \ No newline at end of file diff --git a/src/connector/con_hops.c b/src/connector/con_hops.c new file mode 100644 index 0000000..bb1a1f6 --- /dev/null +++ b/src/connector/con_hops.c @@ -0,0 +1,57 @@ + + #include "con_hops.h" + + con_hops_obj * con_hops_construct(const unsigned int nOuts, const msg_hops_cfg * msg_hops_config) { + + con_hops_obj * obj; + unsigned int iOut; + + obj = (con_hops_obj *) malloc(sizeof(con_hops_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_hops_construct(msg_hops_config); + + obj->outs = (msg_hops_obj **) malloc(sizeof(msg_hops_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_hops_construct(msg_hops_config); + } + + return obj; + + } + + void con_hops_destroy(con_hops_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_hops_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_hops_destroy(obj->in); + + free((void *) obj); + + } + + int con_hops_process(con_hops_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_hops_copy(obj->outs[iOut], obj->in); + } + + if (msg_hops_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_hops.h b/src/connector/con_hops.h new file mode 100644 index 0000000..1882d9f --- /dev/null +++ b/src/connector/con_hops.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_HOPS +#define __ODAS_CONNECTOR_HOPS + + #include "../message/msg_hops.h" + + #include + #include + + typedef struct con_hops_obj { + + msg_hops_obj * in; + msg_hops_obj ** outs; + + unsigned int nOuts; + + } con_hops_obj; + + con_hops_obj * con_hops_construct(const unsigned int nOuts, const msg_hops_cfg * msg_hops_config); + + void con_hops_destroy(con_hops_obj * obj); + + int con_hops_process(con_hops_obj * obj); + +#endif \ No newline at end of file diff --git a/src/connector/con_pots.c b/src/connector/con_pots.c new file mode 100644 index 0000000..a4fa06a --- /dev/null +++ b/src/connector/con_pots.c @@ -0,0 +1,57 @@ + + #include "con_pots.h" + + con_pots_obj * con_pots_construct(const unsigned int nOuts, const msg_pots_cfg * msg_pots_config) { + + con_pots_obj * obj; + unsigned int iOut; + + obj = (con_pots_obj *) malloc(sizeof(con_pots_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_pots_construct(msg_pots_config); + + obj->outs = (msg_pots_obj **) malloc(sizeof(msg_pots_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_pots_construct(msg_pots_config); + } + + return obj; + + } + + void con_pots_destroy(con_pots_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_pots_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_pots_destroy(obj->in); + + free((void *) obj); + + } + + int con_pots_process(con_pots_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_pots_copy(obj->outs[iOut], obj->in); + } + + if (msg_pots_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_pots.h b/src/connector/con_pots.h new file mode 100644 index 0000000..d861dc6 --- /dev/null +++ b/src/connector/con_pots.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_POTS +#define __ODAS_CONNECTOR_POTS + + #include "../message/msg_pots.h" + + #include + #include + + typedef struct con_pots_obj { + + msg_pots_obj * in; + msg_pots_obj ** outs; + + unsigned int nOuts; + + } con_pots_obj; + + con_pots_obj * con_pots_construct(const unsigned int nOuts, const msg_pots_cfg * msg_pots_config); + + void con_pots_destroy(con_pots_obj * obj); + + int con_pots_process(con_pots_obj * obj); + +#endif \ No newline at end of file diff --git a/src/connector/con_powers.c b/src/connector/con_powers.c new file mode 100644 index 0000000..09accb6 --- /dev/null +++ b/src/connector/con_powers.c @@ -0,0 +1,57 @@ + + #include "con_powers.h" + + con_powers_obj * con_powers_construct(const unsigned int nOuts, const msg_powers_cfg * msg_powers_config) { + + con_powers_obj * obj; + unsigned int iOut; + + obj = (con_powers_obj *) malloc(sizeof(con_powers_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_powers_construct(msg_powers_config); + + obj->outs = (msg_powers_obj **) malloc(sizeof(msg_powers_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_powers_construct(msg_powers_config); + } + + return obj; + + } + + void con_powers_destroy(con_powers_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_powers_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_powers_destroy(obj->in); + + free((void *) obj); + + } + + int con_powers_process(con_powers_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_powers_copy(obj->outs[iOut], obj->in); + } + + if (msg_powers_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_powers.h b/src/connector/con_powers.h new file mode 100644 index 0000000..5541b4c --- /dev/null +++ b/src/connector/con_powers.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_POWERS +#define __ODAS_CONNECTOR_POWERS + + #include "../message/msg_powers.h" + + #include + #include + + typedef struct con_powers_obj { + + msg_powers_obj * in; + msg_powers_obj ** outs; + + unsigned int nOuts; + + } con_powers_obj; + + con_powers_obj * con_powers_construct(const unsigned int nOuts, const msg_powers_cfg * msg_powers_config); + + void con_powers_destroy(con_powers_obj * obj); + + int con_powers_process(con_powers_obj * obj); + +#endif \ No newline at end of file diff --git a/src/connector/con_spectra.c b/src/connector/con_spectra.c new file mode 100644 index 0000000..cc1e3f8 --- /dev/null +++ b/src/connector/con_spectra.c @@ -0,0 +1,57 @@ + + #include "con_spectra.h" + + con_spectra_obj * con_spectra_construct(const unsigned int nOuts, const msg_spectra_cfg * msg_spectra_config) { + + con_spectra_obj * obj; + unsigned int iOut; + + obj = (con_spectra_obj *) malloc(sizeof(con_spectra_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_spectra_construct(msg_spectra_config); + + obj->outs = (msg_spectra_obj **) malloc(sizeof(msg_spectra_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_spectra_construct(msg_spectra_config); + } + + return obj; + + } + + void con_spectra_destroy(con_spectra_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_spectra_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_spectra_destroy(obj->in); + + free((void *) obj); + + } + + int con_spectra_process(con_spectra_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_spectra_copy(obj->outs[iOut], obj->in); + } + + if (msg_spectra_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_spectra.h b/src/connector/con_spectra.h new file mode 100644 index 0000000..1d6b45a --- /dev/null +++ b/src/connector/con_spectra.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_SPECTRA +#define __ODAS_CONNECTOR_SPECTRA + + #include "../message/msg_spectra.h" + + #include + #include + + typedef struct con_spectra_obj { + + msg_spectra_obj * in; + msg_spectra_obj ** outs; + + unsigned int nOuts; + + } con_spectra_obj; + + con_spectra_obj * con_spectra_construct(const unsigned int nOuts, const msg_spectra_cfg * msg_spectra_config); + + void con_spectra_destroy(con_spectra_obj * obj); + + int con_spectra_process(con_spectra_obj * obj); + +#endif \ No newline at end of file diff --git a/src/connector/con_targets.c b/src/connector/con_targets.c new file mode 100644 index 0000000..96dd85d --- /dev/null +++ b/src/connector/con_targets.c @@ -0,0 +1,57 @@ + + #include "con_targets.h" + + con_targets_obj * con_targets_construct(const unsigned int nOuts, const msg_targets_cfg * msg_targets_config) { + + con_targets_obj * obj; + unsigned int iOut; + + obj = (con_targets_obj *) malloc(sizeof(con_targets_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_targets_construct(msg_targets_config); + + obj->outs = (msg_targets_obj **) malloc(sizeof(msg_targets_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_targets_construct(msg_targets_config); + } + + return obj; + + } + + void con_targets_destroy(con_targets_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_targets_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_targets_destroy(obj->in); + + free((void *) obj); + + } + + int con_targets_process(con_targets_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_targets_copy(obj->outs[iOut], obj->in); + } + + if (msg_targets_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_targets.h b/src/connector/con_targets.h new file mode 100644 index 0000000..4d8828f --- /dev/null +++ b/src/connector/con_targets.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_TARGETS +#define __ODAS_CONNECTOR_TARGETS + + #include "../message/msg_targets.h" + + #include + #include + + typedef struct con_targets_obj { + + msg_targets_obj * in; + msg_targets_obj ** outs; + + unsigned int nOuts; + + } con_targets_obj; + + con_targets_obj * con_targets_construct(const unsigned int nOuts, const msg_targets_cfg * msg_targets_config); + + void con_targets_destroy(con_targets_obj * obj); + + int con_targets_process(con_targets_obj * obj); + +#endif \ No newline at end of file diff --git a/src/connector/con_tracks.c b/src/connector/con_tracks.c new file mode 100644 index 0000000..45794f4 --- /dev/null +++ b/src/connector/con_tracks.c @@ -0,0 +1,57 @@ + + #include "con_tracks.h" + + con_tracks_obj * con_tracks_construct(const unsigned int nOuts, const msg_tracks_cfg * msg_tracks_config) { + + con_tracks_obj * obj; + unsigned int iOut; + + obj = (con_tracks_obj *) malloc(sizeof(con_tracks_obj)); + + obj->nOuts = nOuts; + + obj->in = msg_tracks_construct(msg_tracks_config); + + obj->outs = (msg_tracks_obj **) malloc(sizeof(msg_tracks_obj *) * nOuts); + for (iOut = 0; iOut < obj->nOuts; iOut++) { + obj->outs[iOut] = msg_tracks_construct(msg_tracks_config); + } + + return obj; + + } + + void con_tracks_destroy(con_tracks_obj * obj) { + + unsigned int iOut; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_tracks_destroy(obj->outs[iOut]); + } + free((void *) obj->outs); + + msg_tracks_destroy(obj->in); + + free((void *) obj); + + } + + int con_tracks_process(con_tracks_obj * obj) { + + unsigned int iOut; + int rtnValue; + + for (iOut = 0; iOut < obj->nOuts; iOut++) { + msg_tracks_copy(obj->outs[iOut], obj->in); + } + + if (msg_tracks_isZero(obj->in) == 1) { + rtnValue = -1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/connector/con_tracks.h b/src/connector/con_tracks.h new file mode 100644 index 0000000..4466576 --- /dev/null +++ b/src/connector/con_tracks.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_CONNECTOR_TRACKS +#define __ODAS_CONNECTOR_TRACKS + + #include "../message/msg_tracks.h" + + #include + #include + + typedef struct con_tracks_obj { + + msg_tracks_obj * in; + msg_tracks_obj ** outs; + + unsigned int nOuts; + + } con_tracks_obj; + + con_tracks_obj * con_tracks_construct(const unsigned int nOuts, const msg_tracks_cfg * msg_tracks_config); + + void con_tracks_destroy(con_tracks_obj * obj); + + int con_tracks_process(con_tracks_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/format.c b/src/general/format.c new file mode 100644 index 0000000..f2cab0c --- /dev/null +++ b/src/general/format.c @@ -0,0 +1,152 @@ + + #include "format.h" + + format_obj * format_construct() { + + format_obj * obj; + + obj = (format_obj *) malloc(sizeof(format_obj)); + + obj->type = format_undefined; + + return obj; + + } + + format_obj * format_construct_undefined() { + + format_obj * obj; + + obj = (format_obj *) malloc(sizeof(format_obj)); + + obj->type = format_undefined; + + return obj; + + } + + format_obj * format_construct_binary_int(const unsigned int nBits) { + + format_obj * obj; + + obj = (format_obj *) malloc(sizeof(format_obj)); + + switch(nBits) { + + case 8: + + obj->type = format_binary_int08; + + break; + + case 16: + + obj->type = format_binary_int16; + + break; + + case 24: + + obj->type = format_binary_int24; + + break; + + case 32: + + obj->type = format_binary_int32; + + break; + + default: + + printf("Wrong number of bits.\n"); + exit(EXIT_FAILURE); + + break; + + } + + return obj; + + } + + format_obj * format_construct_binary_float() { + + format_obj * obj; + + obj = (format_obj *) malloc(sizeof(format_obj)); + + obj->type = format_binary_float; + + return obj; + + } + + format_obj * format_construct_text_json() { + + format_obj * obj; + + obj = (format_obj *) malloc(sizeof(format_obj)); + + obj->type = format_text_json; + + return obj; + + } + + format_obj * format_clone(const format_obj * obj) { + + format_obj * clone; + + clone = format_construct(); + + clone->type = obj->type; + + return clone; + + } + + void format_destroy(format_obj * obj) { + + free((void *) obj); + + } + + void format_printf(const format_obj * obj) { + + if (obj != NULL) { + + switch(obj->type) { + + case format_binary_int08: + printf("type = binary_int08\n"); + break; + + case format_binary_int16: + printf("type = binary_int16\n"); + break; + + case format_binary_int24: + printf("type = binary_int24\n"); + break; + + case format_binary_int32: + printf("type = binary_int32\n"); + break; + + case format_binary_float: + printf("type = binary_float\n"); + break; + + case format_text_json: + printf("type = text_json\n"); + break; + + } + + } + else { + printf("(null)\n"); + } + + } \ No newline at end of file diff --git a/src/general/format.h b/src/general/format.h new file mode 100644 index 0000000..95c3769 --- /dev/null +++ b/src/general/format.h @@ -0,0 +1,41 @@ +#ifndef __ODAS_GENERAL_FORMAT +#define __ODAS_GENERAL_FORMAT + + #include + #include + + typedef enum format_type { + + format_undefined = 0, + format_binary_int08 = 8, + format_binary_int16 = 16, + format_binary_int24 = 24, + format_binary_int32 = 32, + format_binary_float = 1, + format_text_json = 2, + + } format_type; + + typedef struct format_obj { + + format_type type; + + } format_obj; + + format_obj * format_construct(); + + format_obj * format_construct_undefined(); + + format_obj * format_construct_binary_int(const unsigned int nBits); + + format_obj * format_construct_binary_float(); + + format_obj * format_construct_text_json(); + + format_obj * format_clone(const format_obj * obj); + + void format_destroy(format_obj * obj); + + void format_printf(const format_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/interface.c b/src/general/interface.c new file mode 100644 index 0000000..e16e9df --- /dev/null +++ b/src/general/interface.c @@ -0,0 +1,419 @@ + + #include "interface.h" + + interface_obj * interface_construct() { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_undefined; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) NULL; + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) NULL; + obj->port = 0; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->card = 0; + obj->device = 0; + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + + interface_obj * interface_construct_blackhole() { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_blackhole; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) NULL; + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) NULL; + obj->port = 0; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->card = 0; + obj->device = 0; + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + + interface_obj * interface_construct_file(const char * fileName) { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_file; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) malloc(sizeof(char) * (strlen(fileName)+1)); + strcpy(obj->fileName, fileName); + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) NULL; + obj->port = 0; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->card = 0; + obj->device = 0; + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + + interface_obj * interface_construct_socket(const char * ip, const unsigned int port) { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_socket; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) NULL; + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) malloc(sizeof(char) * (strlen(ip)+1)); + strcpy(obj->ip, ip); + obj->port = port; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->card = 0; + obj->device = 0; + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + + interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device) { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_soundcard; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) NULL; + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) NULL; + obj->port = 0; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->card = card; + obj->device = device; + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + + interface_obj * interface_construct_terminal(void) { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_terminal; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) NULL; + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) NULL; + obj->port = 0; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->card = 0; + obj->device = 0; + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + + interface_obj * interface_clone(const interface_obj * obj) { + + interface_obj * clone; + + clone = interface_construct(); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + clone->type = obj->type; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + if (obj->type == interface_file) { + + clone->fileName = (char *) malloc(sizeof(char) * (strlen(obj->fileName) + 1)); + strcpy(clone->fileName, obj->fileName); + + } + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + if (obj->type == interface_socket) { + + clone->ip = (char *) malloc(sizeof(char) * (strlen(obj->ip) + 1)); + strcpy(clone->ip, obj->ip); + clone->port = obj->port; + + } + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + if (obj->type == interface_soundcard) { + + clone->card = obj->card; + clone->device = obj->device; + + } + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return clone; + + } + + void interface_destroy(interface_obj * obj) { + + if (obj->fileName != NULL) { + + free((void *) obj->fileName); + + } + + if (obj->ip != NULL) { + + free((void *) obj->ip); + + } + + free((void *) obj); + + } + + void interface_printf(const interface_obj * obj) { + + if (obj != NULL) { + + switch(obj->type) { + + case interface_blackhole: + + printf("type = blackhole\n"); + + break; + + case interface_file: + + printf("type = file, fileName = %s\n",obj->fileName); + + break; + + case interface_socket: + + printf("type = socket, ip = %s, port = %u\n",obj->ip,obj->port); + + break; + + case interface_soundcard: + + printf("type = soundcard, card = %u, device = %u\n",obj->card,obj->device); + + break; + + case interface_terminal: + + printf("type = terminal\n"); + + break; + + } + + } + else { + + printf("(null)\n"); + + } + + } \ No newline at end of file diff --git a/src/general/interface.h b/src/general/interface.h new file mode 100644 index 0000000..e7f50bd --- /dev/null +++ b/src/general/interface.h @@ -0,0 +1,51 @@ +#ifndef __ODAS_GENERAL_INTERFACE +#define __ODAS_GENERAL_INTERFACE + + #include + #include + #include + + typedef enum interface_type { + + interface_undefined = 0, + interface_blackhole = 1, + interface_file = 2, + interface_socket = 3, + interface_soundcard = 4, + interface_terminal = 5, + + } interface_type; + + typedef struct interface_obj { + + interface_type type; + + char * fileName; + + char * ip; + unsigned int port; + + unsigned int card; + unsigned int device; + + } interface_obj; + + interface_obj * interface_construct(); + + interface_obj * interface_construct_blackhole(); + + interface_obj * interface_construct_file(const char * fileName); + + interface_obj * interface_construct_socket(const char * ip, const unsigned int port); + + interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device); + + interface_obj * interface_construct_terminal(void); + + interface_obj * interface_clone(const interface_obj * obj); + + void interface_destroy(interface_obj * obj); + + void interface_printf(const interface_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/link.c b/src/general/link.c new file mode 100644 index 0000000..d2609ad --- /dev/null +++ b/src/general/link.c @@ -0,0 +1,47 @@ + + #include "link.h" + + links_obj * links_construct_zero(const unsigned int nLinks) { + + links_obj * obj; + + obj = (links_obj *) malloc(sizeof(links_obj)); + + obj->nLinks = nLinks; + obj->array = (unsigned int *) malloc(sizeof(unsigned int) * nLinks); + memset(obj->array, 0x00, sizeof(unsigned int) * nLinks); + + return obj; + + } + + links_obj * links_clone(const links_obj * obj) { + + links_obj * clone; + + clone = (links_obj *) malloc(sizeof(links_obj)); + + clone->nLinks = obj->nLinks; + clone->array = (unsigned int *) malloc(sizeof(unsigned int) * obj->nLinks); + memcpy(clone->array, obj->array, sizeof(unsigned int) * obj->nLinks); + + return clone; + + } + + void links_destroy(links_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void links_printf(const links_obj * obj) { + + unsigned int iLink; + + for (iLink = 0; iLink < obj->nLinks; iLink++) { + printf("(%u): %u\n",iLink,obj->array[iLink]); + } + + } \ No newline at end of file diff --git a/src/general/link.h b/src/general/link.h new file mode 100644 index 0000000..94599cc --- /dev/null +++ b/src/general/link.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_GENERAL_LINK +#define __ODAS_GENERAL_LINK + + #include + #include + #include + + typedef struct links_obj { + + unsigned int * array; + unsigned int nLinks; + + } links_obj; + + links_obj * links_construct_zero(const unsigned int nLinks); + + links_obj * links_clone(const links_obj * obj); + + void links_destroy(links_obj * obj); + + void links_printf(const links_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/mic.c b/src/general/mic.c new file mode 100644 index 0000000..5657fac --- /dev/null +++ b/src/general/mic.c @@ -0,0 +1,118 @@ + + #include "mic.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + mics_obj * mics_construct_zero(const unsigned int nChannels) { + + mics_obj * obj; + + obj = (mics_obj *) malloc(sizeof(mics_obj)); + + obj->nChannels = nChannels; + obj->nPairs = nChannels * (nChannels - 1) / 2; + obj->mu = (float *) malloc(sizeof(float) * nChannels * 3); + memset(obj->mu, 0x00, sizeof(float) * nChannels * 3); + obj->sigma2 = (float *) malloc(sizeof(float) * nChannels * 9); + memset(obj->sigma2, 0x00, sizeof(float) * nChannels * 9); + obj->direction = (float *) malloc(sizeof(float) * nChannels * 3); + memset(obj->direction, 0x00, sizeof(float) * nChannels * 3); + obj->thetaAllPass = (float *) malloc(sizeof(float) * nChannels); + memset(obj->thetaAllPass, 0x00, sizeof(float) * nChannels); + obj->thetaNoPass = (float *) malloc(sizeof(float) * nChannels); + memset(obj->thetaNoPass, 0x00, sizeof(float) * nChannels); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + mics_obj * mics_clone(const mics_obj * obj) { + + mics_obj * clone; + + clone = (mics_obj *) malloc(sizeof(mics_obj)); + + clone->nChannels = obj->nChannels; + clone->nPairs = obj->nPairs; + clone->mu = (float *) malloc(sizeof(float) * obj->nChannels * 3); + memcpy(clone->mu, obj->mu, sizeof(float) * obj->nChannels * 3); + clone->sigma2 = (float *) malloc(sizeof(float) * obj->nChannels * 9); + memcpy(clone->sigma2, obj->sigma2, sizeof(float) * obj->nChannels * 9); + clone->direction = (float *) malloc(sizeof(float) * obj->nChannels * 3); + memcpy(clone->direction, obj->direction, sizeof(float) * obj->nChannels * 3); + clone->thetaAllPass = (float *) malloc(sizeof(float) * obj->nChannels); + memcpy(clone->thetaAllPass, obj->thetaAllPass, sizeof(float) * obj->nChannels); + clone->thetaNoPass = (float *) malloc(sizeof(float) * obj->nChannels); + memcpy(clone->thetaNoPass, obj->thetaNoPass, sizeof(float) * obj->nChannels); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void mics_destroy(mics_obj * obj) { + + free((void *) obj->mu); + free((void *) obj->sigma2); + free((void *) obj->direction); + free((void *) obj->thetaAllPass); + free((void *) obj->thetaNoPass); + + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void mics_printf(const mics_obj * obj) { + + unsigned int iChannel; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + printf("(%02u): mu = (%+1.3f, %+1.3f, %+1.3f)\n", + iChannel, + obj->mu[iChannel * 3 + 0], + obj->mu[iChannel * 3 + 1], + obj->mu[iChannel * 3 + 2]); + + printf(" / %+1.3f %+1.3f %+1.3f \\\n", + obj->sigma2[iChannel * 9 + 0], + obj->sigma2[iChannel * 9 + 1], + obj->sigma2[iChannel * 9 + 2]); + + printf(" Sigma2 = | %+1.3f %+1.3f %+1.3f |\n", + obj->sigma2[iChannel * 9 + 3], + obj->sigma2[iChannel * 9 + 4], + obj->sigma2[iChannel * 9 + 5]); + + printf(" \\ %+1.3f %+1.3f %+1.3f /\n", + obj->sigma2[iChannel * 9 + 6], + obj->sigma2[iChannel * 9 + 7], + obj->sigma2[iChannel * 9 + 8]); + + printf(" direction = (%+1.3f, %+1.3f, %+1.3f)\n", + obj->direction[iChannel * 3 + 0], + obj->direction[iChannel * 3 + 1], + obj->direction[iChannel * 3 + 2]); + + printf(" thetaAllPass = %+1.3f\n", + obj->thetaAllPass[iChannel]); + + printf(" thetaNoPass = %+1.3f\n", + obj->thetaNoPass[iChannel]); + + } + + } \ No newline at end of file diff --git a/src/general/mic.h b/src/general/mic.h new file mode 100644 index 0000000..ff682d9 --- /dev/null +++ b/src/general/mic.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_GENERAL_MIC +#define __ODAS_GENERAL_MIC + + #include + #include + #include + + typedef struct mics_obj { + + unsigned int nChannels; + unsigned int nPairs; + float * mu; + float * sigma2; + float * direction; + float * thetaAllPass; + float * thetaNoPass; + + } mics_obj; + + mics_obj * mics_construct_zero(const unsigned int nChannels); + + mics_obj * mics_clone(const mics_obj * obj); + + void mics_destroy(mics_obj * obj); + + void mics_printf(const mics_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/samplerate.c b/src/general/samplerate.c new file mode 100644 index 0000000..8aac0c8 --- /dev/null +++ b/src/general/samplerate.c @@ -0,0 +1,57 @@ + + #include "samplerate.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + samplerate_obj * samplerate_construct_zero(void) { + + samplerate_obj * obj; + + obj = (samplerate_obj *) malloc(sizeof(samplerate_obj)); + + obj->mu = 0; + obj->sigma2 = 0.0f; + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + samplerate_obj * samplerate_clone(const samplerate_obj * obj) { + + samplerate_obj * clone; + + clone = (samplerate_obj *) malloc(sizeof(samplerate_obj)); + + clone->mu = obj->mu; + clone->sigma2 = obj->sigma2; + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void samplerate_destroy(samplerate_obj * obj) { + + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void samplerate_printf(const samplerate_obj * obj) { + + printf("mu = %u\n",obj->mu); + printf("sigma2 = %f\n",obj->sigma2); + + } \ No newline at end of file diff --git a/src/general/samplerate.h b/src/general/samplerate.h new file mode 100644 index 0000000..392ef15 --- /dev/null +++ b/src/general/samplerate.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_GENERAL_SAMPLERATE +#define __ODAS_GENERAL_SAMPLERATE + + #include + #include + + typedef struct samplerate_obj { + + unsigned int mu; + float sigma2; + + } samplerate_obj; + + samplerate_obj * samplerate_construct_zero(void); + + samplerate_obj * samplerate_clone(const samplerate_obj * obj); + + void samplerate_destroy(samplerate_obj * obj); + + void samplerate_printf(const samplerate_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/soundspeed.c b/src/general/soundspeed.c new file mode 100644 index 0000000..7619a59 --- /dev/null +++ b/src/general/soundspeed.c @@ -0,0 +1,57 @@ + + #include "soundspeed.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + soundspeed_obj * soundspeed_construct_zero(void) { + + soundspeed_obj * obj; + + obj = (soundspeed_obj *) malloc(sizeof(soundspeed_obj)); + + obj->mu = 0.0f; + obj->sigma2 = 0.0f; + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + soundspeed_obj * soundspeed_clone(const soundspeed_obj * obj) { + + soundspeed_obj * clone; + + clone = (soundspeed_obj *) malloc(sizeof(soundspeed_obj)); + + clone->mu = obj->mu; + clone->sigma2 = obj->sigma2; + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void soundspeed_destroy(soundspeed_obj * obj) { + + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void soundspeed_printf(const soundspeed_obj * obj) { + + printf("mu = %f\n",obj->mu); + printf("sigma2 = %f\n",obj->sigma2); + + } \ No newline at end of file diff --git a/src/general/soundspeed.h b/src/general/soundspeed.h new file mode 100644 index 0000000..770a61e --- /dev/null +++ b/src/general/soundspeed.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_GENERAL_SOUNDSPEED +#define __ODAS_GENERAL_SOUNDSPEED + + #include + #include + + typedef struct soundspeed_obj { + + float mu; + float sigma2; + + } soundspeed_obj; + + soundspeed_obj * soundspeed_construct_zero(void); + + soundspeed_obj * soundspeed_clone(const soundspeed_obj * obj); + + void soundspeed_destroy(soundspeed_obj * obj); + + void soundspeed_printf(const soundspeed_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/spatialfilter.c b/src/general/spatialfilter.c new file mode 100644 index 0000000..f17b2a4 --- /dev/null +++ b/src/general/spatialfilter.c @@ -0,0 +1,49 @@ + + #include "spatialfilter.h" + + spatialfilter_obj * spatialfilter_construct_zero(void) { + + spatialfilter_obj * obj; + + obj = (spatialfilter_obj *) malloc(sizeof(spatialfilter_obj)); + + obj->direction = (float *) malloc(sizeof(float) * 3); + memset(obj->direction, 0x00, sizeof(float) * 3); + + obj->thetaAllPass = 0.0f; + obj->thetaNoPass = 0.0f; + + return obj; + + } + + spatialfilter_obj * spatialfilter_clone(const spatialfilter_obj * obj) { + + spatialfilter_obj * clone; + + clone = (spatialfilter_obj *) malloc(sizeof(spatialfilter_obj)); + + clone->direction = (float *) malloc(sizeof(float) * 3); + memcpy(clone->direction, obj->direction, sizeof(float) * 3); + + clone->thetaAllPass = obj->thetaAllPass; + clone->thetaNoPass = obj->thetaNoPass; + + return clone; + + } + + void spatialfilter_destroy(spatialfilter_obj * obj) { + + free((void *) obj->direction); + free((void *) obj); + + } + + void spatialfilter_printf(const spatialfilter_obj * obj) { + + printf("direction = (%+1.3f,%+1.3f,%+1.3f)\n", obj->direction[0], obj->direction[1], obj->direction[2]); + printf("thetaAllPass = %f\n", obj->thetaAllPass); + printf("thetaNoPass = %f\n", obj->thetaNoPass); + + } diff --git a/src/general/spatialfilter.h b/src/general/spatialfilter.h new file mode 100644 index 0000000..3568f53 --- /dev/null +++ b/src/general/spatialfilter.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_SIGNAL_SPATIALFILTER +#define __ODAS_SIGNAL_SPATIALFILTER + + #include + #include + #include + + typedef struct spatialfilter_obj { + + float * direction; + float thetaAllPass; + float thetaNoPass; + + } spatialfilter_obj; + + spatialfilter_obj * spatialfilter_construct_zero(void); + + spatialfilter_obj * spatialfilter_clone(const spatialfilter_obj * obj); + + void spatialfilter_destroy(spatialfilter_obj * obj); + + void spatialfilter_printf(const spatialfilter_obj * obj); + +#endif \ No newline at end of file diff --git a/src/general/thread.c b/src/general/thread.c new file mode 100644 index 0000000..9a5822d --- /dev/null +++ b/src/general/thread.c @@ -0,0 +1,61 @@ + + #include "thread.h" + + thread_obj * thread_construct(void * (* start_routine) (void *), void * arg) { + + thread_obj * obj; + + obj = (thread_obj *) malloc(sizeof(thread_obj)); + + pthread_mutex_init(&(obj->use), NULL); + obj->stop = 0; + obj->start_routine = start_routine; + obj->arg = arg; + + return obj; + + } + + void thread_destroy(thread_obj * obj) { + + pthread_mutex_destroy(&(obj->use)); + + free((void *) obj); + + } + + void thread_start(thread_obj * obj) { + + pthread_mutex_lock(&(obj->use)); + obj->stop = 0; + pthread_create(&(obj->thread), NULL, obj->start_routine, obj->arg); + pthread_mutex_unlock(&(obj->use)); + + } + + void thread_stop(thread_obj * obj) { + + pthread_mutex_lock(&(obj->use)); + obj->stop = 1; + pthread_mutex_unlock(&(obj->use)); + + } + + char thread_askedToStop(thread_obj * obj) { + + char rtnValue; + + pthread_mutex_lock(&(obj->use)); + rtnValue = obj->stop; + pthread_mutex_unlock(&(obj->use)); + + return rtnValue; + + } + + void thread_join(thread_obj * obj) { + + pthread_join(obj->thread, NULL); + + } + \ No newline at end of file diff --git a/src/general/thread.h b/src/general/thread.h new file mode 100644 index 0000000..328c4aa --- /dev/null +++ b/src/general/thread.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_GENERAL_THREAD +#define __ODAS_GENERAL_THREAD + + #include + #include + #include + + typedef struct thread_obj { + + pthread_mutex_t use; + char stop; + pthread_t thread; + void * (* start_routine) (void *); + void * arg; + + } thread_obj; + + thread_obj * thread_construct(void * (* start_routine) (void *), void * arg); + + void thread_destroy(thread_obj * obj); + + void thread_start(thread_obj * obj); + + void thread_stop(thread_obj * obj); + + char thread_askedToStop(thread_obj * obj); + + void thread_join(thread_obj * obj); + +#endif \ No newline at end of file diff --git a/src/init/combining.c b/src/init/combining.c new file mode 100644 index 0000000..c744bf5 --- /dev/null +++ b/src/init/combining.c @@ -0,0 +1,61 @@ + + #include "combining.h" + + assignations_obj * combining_generate(const unsigned int nPots, const unsigned int nTracks) { + + assignations_obj * obj; + + unsigned int nCombinations; + unsigned int iCombination; + unsigned int iPot; + + signed int carry; + signed int digit; + + nCombinations = 1; + + for (iPot = 0; iPot < nPots; iPot++) { + + nCombinations *= (2+nTracks); + + } + + obj = assignations_construct_zero(nCombinations, nPots); + + for (iPot = 0; iPot < nPots; iPot++) { + + obj->array[iPot] = -2; + + } + + for (iCombination = 1; iCombination < nCombinations; iCombination++) { + + carry = 1; + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + digit = obj->array[(iCombination-1) * obj->nPots + obj->nPots - iPot - 1]; + + digit += carry; + + if (digit == nTracks) { + + digit = -2; + carry = 1; + + } + else { + + carry = 0; + + } + + obj->array[iCombination * obj->nPots + obj->nPots - iPot - 1] = digit; + + } + + } + + return obj; + + } diff --git a/src/init/combining.h b/src/init/combining.h new file mode 100644 index 0000000..2fa3dc4 --- /dev/null +++ b/src/init/combining.h @@ -0,0 +1,9 @@ +#ifndef __ODAS_INIT_COMBINING +#define __ODAS_INIT_COMBINING + + #include + #include "../signal/assignation.h" + + assignations_obj * combining_generate(const unsigned int nPots, const unsigned int nTracks); + +#endif \ No newline at end of file diff --git a/src/init/delay.c b/src/init/delay.c new file mode 100644 index 0000000..6dc3c6d --- /dev/null +++ b/src/init/delay.c @@ -0,0 +1,148 @@ + + #include "delay.h" + + tdoas_obj * delay_tdoas(const points_obj * points, const mics_obj * mics, const soundspeed_obj * soundspeed, const unsigned int fS, const unsigned int frameSize, const unsigned int interpRate) { + + tdoas_obj * obj; + + unsigned int nPairs; + + unsigned int iChannel1; + unsigned int iChannel2; + unsigned int iPair; + unsigned int iPoint; + + float diff, dist, tau; + unsigned int tdoa; + + nPairs = mics->nChannels * (mics->nChannels -1) / 2; + + obj = tdoas_construct_zero(points->nPoints,nPairs); + + for (iPair = 0; iPair < nPairs; iPair++) { + + obj->min[iPair] = frameSize * interpRate - 1; + obj->max[iPair] = 0; + + } + + for (iPoint = 0; iPoint < points->nPoints; iPoint++) { + + iPair = 0; + + for (iChannel1 = 0; iChannel1 < mics->nChannels; iChannel1++) { + + for (iChannel2 = (iChannel1+1); iChannel2 < mics->nChannels; iChannel2++) { + + dist = 0.0f; + dist += (mics->mu[iChannel1*3+0] - mics->mu[iChannel2*3+0]) * points->array[iPoint*3+0]; + dist += (mics->mu[iChannel1*3+1] - mics->mu[iChannel2*3+1]) * points->array[iPoint*3+1]; + dist += (mics->mu[iChannel1*3+2] - mics->mu[iChannel2*3+2]) * points->array[iPoint*3+2]; + + tau = -1.0f * (((float) fS * interpRate) / soundspeed->mu) * dist; + + tdoa = (unsigned int) (roundf(tau)+(float) (interpRate * frameSize/2)); + obj->array[iPoint*nPairs+iPair] = tdoa; + + if (tdoa < obj->min[iPair]) { + obj->min[iPair] = tdoa; + } + if (tdoa > obj->max[iPair]) { + obj->max[iPair] = tdoa; + } + + iPair++; + + } + + } + + } + + return obj; + + } + + taus_obj * delay_taus(const points_obj * points, const mics_obj * mics, const soundspeed_obj * soundspeed, const unsigned int fS, const unsigned int frameSize, const unsigned int interpRate) { + + taus_obj * obj; + + unsigned int nPairs; + + unsigned int iChannel1; + unsigned int iChannel2; + unsigned int iPair; + unsigned int iPoint; + + float mu_t; + float sigma2_t; + float mu_d; + float sigma2_d; + float mu_tau; + float sigma2_tau; + + float mu_ij_x, mu_ij_y, mu_ij_z; + float sigma_ij_xx, sigma_ij_xy, sigma_ij_xz; + float sigma_ij_yx, sigma_ij_yy, sigma_ij_yz; + float sigma_ij_zx, sigma_ij_zy, sigma_ij_zz; + + nPairs = mics->nChannels * (mics->nChannels -1) / 2; + + obj = taus_construct_zero(points->nPoints, nPairs); + + mu_t = -1.0f * ((float) fS * interpRate) / soundspeed->mu; + sigma2_t = ((float) fS * interpRate) * soundspeed->sigma2 / (soundspeed->mu * soundspeed->mu); + + iPair = 0; + + for (iChannel1 = 0; iChannel1 < mics->nChannels; iChannel1++) { + + for (iChannel2 = (iChannel1+1); iChannel2 < mics->nChannels; iChannel2++) { + + mu_ij_x = mics->mu[iChannel1*3+0] - mics->mu[iChannel2*3+0]; + mu_ij_y = mics->mu[iChannel1*3+1] - mics->mu[iChannel2*3+1]; + mu_ij_z = mics->mu[iChannel1*3+2] - mics->mu[iChannel2*3+2]; + + sigma_ij_xx = mics->sigma2[iChannel1*9+0]; + sigma_ij_xy = mics->sigma2[iChannel1*9+1]; + sigma_ij_xz = mics->sigma2[iChannel1*9+2]; + sigma_ij_yx = mics->sigma2[iChannel1*9+3]; + sigma_ij_yy = mics->sigma2[iChannel1*9+4]; + sigma_ij_yz = mics->sigma2[iChannel1*9+5]; + sigma_ij_zx = mics->sigma2[iChannel1*9+6]; + sigma_ij_zy = mics->sigma2[iChannel1*9+7]; + sigma_ij_zz = mics->sigma2[iChannel1*9+8]; + + for (iPoint = 0; iPoint < points->nPoints; iPoint++) { + + mu_d = mu_ij_x * points->array[iPoint*3+0] + + mu_ij_y * points->array[iPoint*3+1] + + mu_ij_z * points->array[iPoint*3+2]; + + sigma2_d = points->array[iPoint*3+0] * sigma_ij_xx * points->array[iPoint*3+0] + + points->array[iPoint*3+0] * sigma_ij_xy * points->array[iPoint*3+1] + + points->array[iPoint*3+0] * sigma_ij_xz * points->array[iPoint*3+2] + + points->array[iPoint*3+1] * sigma_ij_yx * points->array[iPoint*3+0] + + points->array[iPoint*3+1] * sigma_ij_yy * points->array[iPoint*3+1] + + points->array[iPoint*3+1] * sigma_ij_yz * points->array[iPoint*3+2] + + points->array[iPoint*3+2] * sigma_ij_zx * points->array[iPoint*3+0] + + points->array[iPoint*3+2] * sigma_ij_zy * points->array[iPoint*3+1] + + points->array[iPoint*3+2] * sigma_ij_zz * points->array[iPoint*3+2]; + + mu_tau = mu_t * mu_d; + sigma2_tau = mu_t*mu_t*sigma2_d + mu_d*mu_d*sigma2_t; + + obj->mu[iPoint*nPairs+iPair] = mu_tau + (float) (interpRate*frameSize/2); + obj->sigma2[iPoint*nPairs+iPair] = sigma2_tau; + + } + + iPair++; + + } + + } + + return obj; + + } \ No newline at end of file diff --git a/src/init/delay.h b/src/init/delay.h new file mode 100644 index 0000000..7aec099 --- /dev/null +++ b/src/init/delay.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_INIT_DELAY +#define __ODAS_INIT_DELAY + + #include + + #include "../general/mic.h" + #include "../general/soundspeed.h" + + #include "../signal/delta.h" + #include "../signal/point.h" + #include "../signal/tdoa.h" + #include "../signal/tau.h" + + tdoas_obj * delay_tdoas(const points_obj * points, const mics_obj * mics, const soundspeed_obj * soundspeed, const unsigned int fS, const unsigned int frameSize, const unsigned int interpRate); + + //tdoas_obj * delay_tdoas_minmax(const tdoas_obj * tdoas, const deltas_obj * deltas); + + //void delay_tdoas_allminmax(tdoas_obj * tdoas, const tdoas_obj * minmax); + + taus_obj * delay_taus(const points_obj * points, const mics_obj * mics, const soundspeed_obj * soundspeed, const unsigned int fS, const unsigned int frameSize, const unsigned int interpRate); + +#endif + + \ No newline at end of file diff --git a/src/init/directivity.c b/src/init/directivity.c new file mode 100644 index 0000000..249b92d --- /dev/null +++ b/src/init/directivity.c @@ -0,0 +1,331 @@ + + #include "directivity.h" + + beampatterns_obj * directivity_beampattern_mics(const mics_obj * mics, const unsigned int nThetas) { + + beampatterns_obj * obj; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int iTheta; + float theta; + float xap, xnp, x0; + float alpha; + + nChannels = mics->nChannels; + + obj = beampatterns_construct_zero(nChannels, nThetas); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + obj->minThetas[iChannel] = 0.0f; + obj->maxThetas[iChannel] = 180.0f; + obj->deltaThetas[iChannel] = (obj->maxThetas[iChannel] - obj->minThetas[iChannel]) / ((float) (nThetas - 1)); + + for (iTheta = 0; iTheta < nThetas; iTheta++) { + + theta = ((float) iTheta) * obj->deltaThetas[iChannel] + obj->minThetas[iChannel]; + + if (theta <= mics->thetaAllPass[iChannel]) { + + obj->gains[iChannel * nThetas + iTheta] = 1.0f; + + } + else if (theta >= mics->thetaNoPass[iChannel]) { + + obj->gains[iChannel * nThetas + iTheta] = 0.0f; + + } + else { + + xap = mics->thetaAllPass[iChannel]; + xnp = mics->thetaNoPass[iChannel]; + + x0 = (xap + xnp) / 2.0f; + alpha = 20.0f / (xnp - xap); + + obj->gains[iChannel * nThetas + iTheta] = 1.0f / (1.0f + expf(alpha * (theta - x0))); + + } + + } + + } + + return obj; + + } + + beampatterns_obj * directivity_beampattern_spatialfilter(const spatialfilter_obj * spatialfilter, const unsigned int nThetas) { + + beampatterns_obj * obj; + + unsigned int iTheta; + float theta; + float xap, xnp, x0; + float alpha; + + obj = beampatterns_construct_zero(1, nThetas); + + obj->minThetas[0] = 0.0f; + obj->maxThetas[0] = 180.0f; + obj->deltaThetas[0] = (obj->maxThetas[0] - obj->minThetas[0]) / ((float) (nThetas - 1)); + + for (iTheta = 0; iTheta < nThetas; iTheta++) { + + theta = ((float) iTheta) * obj->deltaThetas[0] + obj->minThetas[0]; + + if (theta <= spatialfilter->thetaAllPass) { + + obj->gains[iTheta] = 1.0f; + + } + else if (theta >= spatialfilter->thetaNoPass) { + + obj->gains[iTheta] = 0.0f; + + } + else { + + xap = spatialfilter->thetaAllPass; + xnp = spatialfilter->thetaNoPass; + + x0 = (xap + xnp) / 2.0f; + alpha = 20.0f / (xnp - xap); + + obj->gains[iTheta] = 1.0f / (1.0f + expf(alpha * (theta - x0))); + + } + + } + + return obj; + + } + + spatialgains_obj * directivity_spatialgains(const mics_obj * mics, const beampatterns_obj * beampatterns_mics, const spatialfilter_obj * spatialfilter, const beampatterns_obj * beampatterns_spatialfilter, const points_obj * points) { + + spatialgains_obj * obj; + + unsigned int nChannels; + unsigned int iChannel; + unsigned int nPoints; + unsigned int iPoint; + float dx, dy, dz, dNorm; + float sx, sy, sz, sNorm; + float ux, uy, uz, uNorm; + float projMic; + float projFilter; + float thetaMic; + float thetaFilter; + signed int iThetaMic; + signed int iThetaFilter; + unsigned int nThetasMic; + unsigned int nThetasFilter; + + float gainMic; + float gainFilter; + + nChannels = mics->nChannels; + nPoints = points->nPoints; + nThetasMic = beampatterns_mics->nThetas; + nThetasFilter = beampatterns_spatialfilter->nThetas; + + obj = spatialgains_construct_zero(nChannels, nPoints); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + dx = mics->direction[iChannel * 3 + 0]; + dy = mics->direction[iChannel * 3 + 1]; + dz = mics->direction[iChannel * 3 + 2]; + + dNorm = sqrtf(dx * dx + dy * dy + dz * dz); + + sx = spatialfilter->direction[0]; + sy = spatialfilter->direction[1]; + sz = spatialfilter->direction[2]; + + sNorm = sqrtf(sx * sx + sy * sy + sz * sz); + + for (iPoint = 0; iPoint < nPoints; iPoint++) { + + ux = points->array[iPoint * 3 + 0]; + uy = points->array[iPoint * 3 + 1]; + uz = points->array[iPoint * 3 + 2]; + + uNorm = sqrtf(ux * ux + uy * uy + uz * uz); + + projMic = dx * ux + dy * uy + dz * uz; + projFilter = sx * ux + sy * uy + sz * uz; + + thetaMic = (360.0f/(2.0f * M_PI)) * acosf(projMic / (dNorm * uNorm)); + thetaFilter = (360.0f/(2.0f * M_PI)) * acosf(projFilter / (sNorm * uNorm)); + + iThetaMic = roundf((thetaMic - beampatterns_mics->minThetas[iChannel]) / (beampatterns_mics->deltaThetas[iChannel]) + beampatterns_mics->minThetas[iChannel]); + iThetaFilter = roundf((thetaFilter - beampatterns_spatialfilter->minThetas[0]) / (beampatterns_spatialfilter->deltaThetas[0]) + beampatterns_spatialfilter->minThetas[0]); + + if (iThetaMic < 0) { + iThetaMic = 0; + } + if (iThetaMic >= nThetasMic) { + iThetaMic = nThetasMic - 1; + } + + if (iThetaFilter < 0) { + iThetaFilter = 0; + } + if (iThetaFilter >= nThetasFilter) { + iThetaFilter = nThetasFilter - 1; + } + + gainMic = beampatterns_mics->gains[iChannel * nThetasMic + iThetaMic]; + gainFilter = beampatterns_spatialfilter->gains[iThetaFilter]; + + obj->array[iPoint * nChannels + iChannel] = gainMic * gainFilter; + + } + + } + + return obj; + + } + + spatialmasks_obj * directivity_spatialmasks(const spatialgains_obj * spatialgains, const float gainMin) { + + spatialmasks_obj * obj; + + unsigned int nChannels; + unsigned int nPairs; + unsigned int nPoints; + + unsigned int iChannel1, iChannel2; + unsigned int iPair; + unsigned int iPoint; + float gain; + + nChannels = spatialgains->nChannels; + nPairs = nChannels * (nChannels - 1) / 2; + nPoints = spatialgains->nPoints; + + obj = spatialmasks_construct_zero(nPoints, nPairs); + + for (iPoint = 0; iPoint < nPoints; iPoint++) { + + iPair = 0; + + for (iChannel1 = 0; iChannel1 < nChannels; iChannel1++) { + + for (iChannel2 = (iChannel1 + 1); iChannel2 < nChannels; iChannel2++) { + + gain = spatialgains->array[iPoint * nChannels + iChannel1] * spatialgains->array[iPoint * nChannels + iChannel2]; + + if (gain >= gainMin) { + + obj->array[iPoint * nPairs + iPair] = 0x01; + + } + else { + + obj->array[iPoint * nPairs + iPair] = 0x00; + + } + + iPair++; + + } + + } + + } + + return obj; + + } + + spatialindexes_obj * directivity_spatialindexes(const spatialmasks_obj * spatialmasks) { + + spatialindexes_obj * obj; + + unsigned int nPoints; + unsigned int nPairs; + unsigned int iPoint; + unsigned int iPair; + + nPoints = spatialmasks->nPoints; + nPairs = spatialmasks->nPairs; + + obj = spatialindexes_construct_zero(nPoints, nPairs); + + for (iPoint = 0; iPoint < nPoints; iPoint++) { + + obj->count[iPoint] = 0; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (spatialmasks->array[iPoint * nPairs + iPair] == 0x01) { + + obj->array[iPoint * nPairs + obj->count[iPoint]] = iPair; + obj->count[iPoint]++; + + } + + } + + } + + return obj; + + } + + pairs_obj * directivity_pairs(const spatialmasks_obj * spatialmasks) { + + pairs_obj * obj; + + unsigned int nPoints; + unsigned int nPairs; + unsigned int iPoint; + unsigned int iPair; + + nPoints = spatialmasks->nPoints; + nPairs = spatialmasks->nPairs; + + obj = pairs_construct_zero(nPairs); + + for (iPair = 0; iPair < nPairs; iPair++) { + + for (iPoint = 0; iPoint < nPoints; iPoint++) { + + if (spatialmasks->array[iPoint * nPairs + iPair] == 0x01) { + + obj->array[iPair] = 0x01; + break; + + } + + } + + } + + return obj; + + } + + void directivity_pairsadd(pairs_obj * destPairs, const pairs_obj * srcPairs) { + + unsigned int iPair; + unsigned int nPairs; + + nPairs = srcPairs->nPairs; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (srcPairs->array[iPair] == 0x01) { + + destPairs->array[iPair] = 0x01; + + } + + } + + } \ No newline at end of file diff --git a/src/init/directivity.h b/src/init/directivity.h new file mode 100644 index 0000000..2111759 --- /dev/null +++ b/src/init/directivity.h @@ -0,0 +1,31 @@ +#ifndef __ODAS_INIT_DIRECTIVITY +#define __ODAS_INIT_DIRECTIVITY + + #include + #include + + #include "../general/mic.h" + #include "../general/spatialfilter.h" + + #include "../signal/beampattern.h" + #include "../signal/pair.h" + #include "../signal/point.h" + #include "../signal/spatialgain.h" + #include "../signal/spatialindex.h" + #include "../signal/spatialmask.h" + + beampatterns_obj * directivity_beampattern_mics(const mics_obj * mics, const unsigned int nThetas); + + beampatterns_obj * directivity_beampattern_spatialfilter(const spatialfilter_obj * spatialfilter, const unsigned int nThetas); + + spatialgains_obj * directivity_spatialgains(const mics_obj * mics, const beampatterns_obj * beampatterns_mics, const spatialfilter_obj * spatialfilter, const beampatterns_obj * beampatterns_spatialfilter, const points_obj * points); + + spatialmasks_obj * directivity_spatialmasks(const spatialgains_obj * spatialgains, const float minGain); + + spatialindexes_obj * directivity_spatialindexes(const spatialmasks_obj * spatialmasks); + + pairs_obj * directivity_pairs(const spatialmasks_obj * spatialmasks); + + void directivity_pairsadd(pairs_obj * destPairs, const pairs_obj * srcPairs); + +#endif \ No newline at end of file diff --git a/src/init/hit.c b/src/init/hit.c new file mode 100644 index 0000000..d9e767b --- /dev/null +++ b/src/init/hit.c @@ -0,0 +1,288 @@ + + #include "hit.h" + + areas_obj * hit_areas_zero(const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas) { + + areas_obj * areas; + + unsigned int nPointsDiscrete; + unsigned int nPointsResolution; + unsigned int nResolutionsPerDiscrete; + unsigned int nPairs; + + nPointsDiscrete = tdoas->nPoints; + nPointsResolution = taus->nPoints; + nResolutionsPerDiscrete = nPointsResolution / nPointsDiscrete; + nPairs = taus->nPairs; + + areas = areas_construct_zero(nPointsDiscrete, nResolutionsPerDiscrete, nPairs); + + return areas; + + } + + void hit_areas_pair(areas_obj * areas, const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas, const spatialmasks_obj * spatialmasks, const unsigned int iPair) { + + unsigned int iPointDiscrete; + unsigned int nPointsDiscrete; + unsigned int iPointResolution; + unsigned int nPointsResolution; + unsigned int iResolutionPerDiscrete; + unsigned int nResolutionsPerDiscrete; + unsigned int nPairs; + + float delta; + float tdoa; + + float mu; + float sigma2; + float expr1; + float expr2; + float prob; + + nPointsDiscrete = tdoas->nPoints; + nPointsResolution = taus->nPoints; + nResolutionsPerDiscrete = nPointsResolution / nPointsDiscrete; + nPairs = taus->nPairs; + + delta = (float) deltas->array[iPair]; + + for (iPointDiscrete = 0; iPointDiscrete < nPointsDiscrete; iPointDiscrete++) { + + tdoa = (float) tdoas->array[iPointDiscrete * nPairs + iPair]; + + for (iResolutionPerDiscrete = 0; iResolutionPerDiscrete < nResolutionsPerDiscrete; iResolutionPerDiscrete++) { + + iPointResolution = iPointDiscrete * nResolutionsPerDiscrete + iResolutionPerDiscrete; + + if (spatialmasks->array[iPointDiscrete * nPairs + iPair] == 0x01) { + + mu = taus->mu[iPointResolution * nPairs + iPair]; + sigma2 = taus->sigma2[iPointResolution * nPairs + iPair]; + + expr1 = (tdoa + delta + 0.5f - mu) / (sqrtf(2.0f * sigma2)); + expr2 = (tdoa - delta - 0.5f - mu) / (sqrtf(2.0f * sigma2)); + + prob = 0.5f * (erff(expr1) - erff(expr2)); + + areas->array[iPointResolution * nPairs + iPair] = prob; + + } + + } + + } + + } + + float hit_areas_min(const areas_obj * areas, const spatialmasks_obj * spatialmasks) { + + unsigned int iPointDiscrete; + unsigned int nPointsDiscrete; + unsigned int iResolutionPerDiscrete; + unsigned int nResolutionsPerDiscrete; + unsigned int iPair; + unsigned int nPairs; + unsigned int iPointResolution; + + float prob; + unsigned int count; + float minValue; + float minValuePoint; + + nPointsDiscrete = areas->nPointsDiscrete; + nResolutionsPerDiscrete = areas->nResolutionsPerDiscrete; + nPairs = areas->nPairs; + + minValue = +INFINITY; + + for (iPointDiscrete = 0; iPointDiscrete < nPointsDiscrete; iPointDiscrete++) { + + count = 0; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (spatialmasks->array[iPointDiscrete * nPairs + iPair] == 0x01) { + + count++; + + } + + } + + if (count > 0) { + + minValuePoint = +INFINITY; + + for (iResolutionPerDiscrete = 0; iResolutionPerDiscrete < nResolutionsPerDiscrete; iResolutionPerDiscrete++) { + + iPointResolution = iPointDiscrete * nResolutionsPerDiscrete + iResolutionPerDiscrete; + + prob = 0.0f; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (spatialmasks->array[iPointDiscrete * nPairs + iPair] == 0x01) { + + prob += areas->array[iPointResolution * nPairs + iPair]; + + } + + } + + if (prob < minValuePoint) { + minValuePoint = prob; + } + + } + + minValuePoint /= ((float) count); + + if (minValuePoint < minValue) { + minValue = minValuePoint; + } + + } + + } + + return minValue; + + } + + area_obj * hit_area_zero(const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas) { + + area_obj * area; + + unsigned int nPairs; + + nPairs = taus->nPairs; + + area = area_construct_zero(nPairs); + + return area; + + } + + void hit_area_pair(area_obj * area, const areas_obj * areas, const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas, const spatialmasks_obj * spatialmasks, const unsigned int iPair) { + + unsigned int iPointDiscrete; + unsigned int nPointsDiscrete; + unsigned int iPointResolution; + unsigned int nPointsResolution; + unsigned int iResolutionPerDiscrete; + unsigned int nResolutionsPerDiscrete; + unsigned int nPairs; + unsigned int count; + + nPointsDiscrete = tdoas->nPoints; + nPointsResolution = taus->nPoints; + nResolutionsPerDiscrete = nPointsResolution / nPointsDiscrete; + nPairs = taus->nPairs; + + area->array[iPair] = 0.0f; + count = 0; + + for (iPointDiscrete = 0; iPointDiscrete < nPointsDiscrete; iPointDiscrete++) { + + for (iResolutionPerDiscrete = 0; iResolutionPerDiscrete < nResolutionsPerDiscrete; iResolutionPerDiscrete++) { + + iPointResolution = iPointDiscrete * nResolutionsPerDiscrete + iResolutionPerDiscrete; + + if (spatialmasks->array[iPointDiscrete * nPairs + iPair] == 0x01) { + + area->array[iPair] += areas->array[iPointResolution * nPairs + iPair]; + count++; + + } + + } + + } + + if (count > 0) { + area->array[iPair] /= ((float) count); + } + else { + area->array[iPair] = 1.0f; + } + + } + + deltas_obj * hit_train(const taus_obj * taus, const tdoas_obj * tdoas, const spatialmasks_obj * spatialmasks, const float probMin) { + + deltas_obj * deltas; + areas_obj * areas; + area_obj * area; + + unsigned int iPair; + unsigned int nPairs; + float minValue; + unsigned int minIndex; + + nPairs = taus->nPairs; + + deltas = deltas_construct_zero(nPairs); + areas = hit_areas_zero(taus, tdoas, deltas); + area = hit_area_zero(taus, tdoas, deltas); + + for (iPair = 0; iPair < nPairs; iPair++) { + + hit_areas_pair(areas, taus, tdoas, deltas, spatialmasks, iPair); + hit_area_pair(area, areas, taus, tdoas, deltas, spatialmasks, iPair); + + } + + while(1) { + + minValue = hit_areas_min(areas, spatialmasks); + + if (minValue >= probMin) { + break; + } + + minValue = +INFINITY; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (area->array[iPair] < minValue) { + minValue = area->array[iPair]; + minIndex = iPair; + } + + } + + deltas->array[minIndex]++; + + hit_areas_pair(areas, taus, tdoas, deltas, spatialmasks, minIndex); + hit_area_pair(area, areas, taus, tdoas, deltas, spatialmasks, minIndex); + + } + + areas_destroy(areas); + area_destroy(area); + + return deltas; + + } + + deltas_obj * hit_constant(const tdoas_obj * tdoas, const unsigned int delta) { + + unsigned int iPair; + unsigned int nPairs; + + deltas_obj * deltas; + + nPairs = tdoas->nPairs; + + deltas = deltas_construct_zero(nPairs); + + for (iPair = 0; iPair < nPairs; iPair++) { + + deltas->array[iPair] = delta; + + } + + return deltas; + + } \ No newline at end of file diff --git a/src/init/hit.h b/src/init/hit.h new file mode 100644 index 0000000..f3c0875 --- /dev/null +++ b/src/init/hit.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_INIT_HIT +#define __ODAS_INIT_HIT + + #include + + #include "../signal/area.h" + #include "../signal/tau.h" + #include "../signal/tdoa.h" + #include "../signal/delta.h" + #include "../signal/spatialmask.h" + + areas_obj * hit_areas_zero(const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas); + + void hit_areas_pair(areas_obj * areas, const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas, const spatialmasks_obj * spatialmasks, const unsigned int iPair); + + float hit_areas_min(const areas_obj * areas, const spatialmasks_obj * spatialmasks); + + area_obj * hit_area_zero(const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas); + + void hit_area_pair(area_obj * area, const areas_obj * areas, const taus_obj * taus, const tdoas_obj * tdoas, const deltas_obj * deltas, const spatialmasks_obj * spatialmasks, const unsigned int iPair); + + deltas_obj * hit_train(const taus_obj * taus, const tdoas_obj * tdoas, const spatialmasks_obj * spatialmasks, const float probMin); + + deltas_obj * hit_constant(const tdoas_obj * tdoas, const unsigned int delta); + +#endif diff --git a/src/init/linking.c b/src/init/linking.c new file mode 100644 index 0000000..19e5ac9 --- /dev/null +++ b/src/init/linking.c @@ -0,0 +1,230 @@ + + #include "linking.h" + + maps_obj * linking_maps(const tdoas_obj * tdoasCoarse, const tdoas_obj * tdoasFine, const deltas_obj * deltasCoarse, const deltas_obj * deltasFine, const spatialmasks_obj * spatialmasksCoarse, const spatialmasks_obj * spatialmasksFine, const unsigned int nMatches) { + + maps_obj * obj; + float * scores; + + unsigned int lambdaCoarseLeft; + unsigned int lambdaCoarseRight; + unsigned int lambdaFineLeft; + unsigned int lambdaFineRight; + + float score; + + unsigned int iFine; + unsigned int iCoarse; + unsigned int iPair; + unsigned int iMatch; + + unsigned int nFines; + unsigned int nCoarses; + unsigned int nPairs; + + char isActive; + + float maxValue; + unsigned int maxIndex; + + if (tdoasCoarse != NULL) { + + nFines = tdoasFine->nPoints; + nCoarses = tdoasCoarse->nPoints; + nPairs = tdoasFine->nPairs; + + obj = maps_construct_zero(nCoarses, nFines); + scores = (float *) malloc(sizeof(float) * nCoarses); + + for (iFine = 0; iFine < nFines; iFine++) { + + isActive = 0x00; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (spatialmasksFine->array[iFine * nPairs + iPair] == 0x01) { + + isActive = 0x01; + break; + + } + + } + + if (isActive == 0x01) { + + for (iCoarse = 0; iCoarse < nCoarses; iCoarse++) { + + scores[iCoarse] = 0.0f; + + for (iPair = 0; iPair < nPairs; iPair++) { + + if ((spatialmasksCoarse->array[iCoarse * nPairs + iPair] == 0x01) && (spatialmasksFine->array[iFine * nPairs + iPair] == 0x01)) { + + lambdaCoarseLeft = tdoasCoarse->array[iCoarse * nPairs + iPair] - deltasCoarse->array[iPair]; + lambdaCoarseRight = tdoasCoarse->array[iCoarse * nPairs + iPair] + deltasCoarse->array[iPair]; + lambdaFineLeft = tdoasFine->array[iFine * nPairs + iPair] - deltasFine->array[iPair]; + lambdaFineRight = tdoasFine->array[iFine * nPairs + iPair] + deltasFine->array[iPair]; + + scores[iCoarse] += linking_overlap(lambdaCoarseLeft,lambdaCoarseRight,lambdaFineLeft,lambdaFineRight); + + } + + } + + } + + for (iMatch = 0; iMatch < nMatches; iMatch++) { + + maxValue = 0.0f; + maxIndex = 0; + + for (iCoarse = 0; iCoarse < nCoarses; iCoarse++) { + + if (scores[iCoarse] > maxValue) { + + maxValue = scores[iCoarse]; + maxIndex = iCoarse; + + } + + } + + obj->array[iFine * obj->nCoarses + maxIndex] = 0x01; + scores[maxIndex] = 0.0f; + + } + + } + + } + + free((void *) scores); + + } + else { + + nFines = tdoasFine->nPoints; + nPairs = tdoasFine->nPairs; + + obj = maps_construct_zero(1, nFines); + + for (iFine = 0; iFine < nFines; iFine++) { + + for (iPair = 0; iPair < nPairs; iPair++) { + + if (spatialmasksFine->array[iFine * nPairs + iPair] == 0x01) { + + obj->array[iFine] = 0x01; + break; + + } + + } + + } + + } + + return obj; + + } + + indexes_obj * linking_indexes(const maps_obj * maps) { + + indexes_obj * obj; + + unsigned int iFine; + unsigned int iCoarse; + unsigned int nFines; + unsigned int nFinesMax; + + nFinesMax = 0; + + for (iCoarse = 0; iCoarse < maps->nCoarses; iCoarse++) { + + nFines = 0; + + for (iFine = 0; iFine < maps->nFines; iFine++) { + + if (maps->array[iFine * maps->nCoarses + iCoarse] == 0x01) { + + nFines++; + + } + + } + + if (nFines > nFinesMax) { + nFinesMax = nFines; + } + + } + + obj = indexes_construct_zero(maps->nCoarses,nFinesMax); + + for (iCoarse = 0; iCoarse < maps->nCoarses; iCoarse++) { + + nFines = 0; + + for (iFine = 0; iFine < maps->nFines; iFine++) { + + if (maps->array[iFine * maps->nCoarses + iCoarse] == 0x01) { + + obj->array[iCoarse * nFinesMax + nFines] = iFine; + nFines++; + + } + + } + + obj->count[iCoarse] = nFines; + + } + + return obj; + + } + + float linking_overlap(const float lambdaCoarseLeft, const float lambdaCoarseRight, const float lambdaFineLeft, const float lambdaFineRight) { + + float overlap; + float lambdaMaxLeft; + float lambdaMinRight; + + if ((lambdaCoarseRight >= lambdaFineLeft) && (lambdaCoarseLeft <= lambdaFineRight)) { + + if (lambdaCoarseLeft > lambdaFineLeft) { + + lambdaMaxLeft = lambdaCoarseLeft; + + } + else { + + lambdaMaxLeft = lambdaFineLeft; + + } + + if (lambdaCoarseRight < lambdaFineRight) { + + lambdaMinRight = lambdaCoarseRight; + + } + else { + + lambdaMinRight = lambdaFineRight; + + } + + overlap = lambdaMinRight - lambdaMaxLeft + 1.0f; + + } + else { + + overlap = 0.0f; + + } + + return overlap; + + } \ No newline at end of file diff --git a/src/init/linking.h b/src/init/linking.h new file mode 100644 index 0000000..872e9e9 --- /dev/null +++ b/src/init/linking.h @@ -0,0 +1,20 @@ +#ifndef __ODAS_INIT_LINKING +#define __ODAS_INIT_LINKING + + #include + #include + #include + + #include "../signal/delta.h" + #include "../signal/index.h" + #include "../signal/map.h" + #include "../signal/tdoa.h" + #include "../signal/spatialmask.h" + + maps_obj * linking_maps(const tdoas_obj * tdoasCoarse, const tdoas_obj * tdoasFine, const deltas_obj * deltasCoarse, const deltas_obj * deltasFine, const spatialmasks_obj * spatialmasksCoarse, const spatialmasks_obj * spatialmasksFine, const unsigned int nMatches); + + indexes_obj * linking_indexes(const maps_obj * maps); + + float linking_overlap(const float lambdaCoarseLeft, const float lambdaCoarseRight, const float lambdaFineLeft, const float lambdaFineRight); + +#endif \ No newline at end of file diff --git a/src/init/scanning.c b/src/init/scanning.c new file mode 100644 index 0000000..4c0265a --- /dev/null +++ b/src/init/scanning.c @@ -0,0 +1,129 @@ + + #include "scanning.h" + + scans_obj * scanning_init_scans(const mics_obj * mics, const spatialfilter_obj * spatialfilter, const unsigned int nLevels, const unsigned int * levels, const unsigned int fS, const soundspeed_obj * soundspeed, const unsigned int nMatches, const unsigned int frameSize, const signed int * deltas, const float probMin, const unsigned int nRefineLevels, const unsigned int nThetas, const float gainMin, const unsigned int interpRate) { + + scans_obj * obj; + unsigned int iLevel; + + beampatterns_obj * beampatterns_mics; + beampatterns_obj * beampatterns_spatialfilter; + spatialgains_obj * spatialgains; + spatialmasks_obj ** spatialmasks; + pairs_obj * pairs; + points_obj * pointsRefined; + taus_obj * taus; + maps_obj * maps; + + obj = scans_construct_null(nLevels); + + obj->pairs = pairs_construct_zero(mics->nPairs); + beampatterns_mics = directivity_beampattern_mics(mics, nThetas); + beampatterns_spatialfilter = directivity_beampattern_spatialfilter(spatialfilter, nThetas); + + spatialmasks = (spatialmasks_obj **) malloc(sizeof(spatialmasks_obj *) * nLevels); + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + + // Generate points + obj->points[iLevel] = space_sphere(levels[iLevel]); + + // Generate TDOAs + obj->tdoas[iLevel] = delay_tdoas(obj->points[iLevel], + mics, + soundspeed, + fS, + frameSize, + interpRate); + + // Generate gains in space + spatialgains = directivity_spatialgains(mics, + beampatterns_mics, + spatialfilter, + beampatterns_spatialfilter, + obj->points[iLevel]); + + // Generate masks in space + spatialmasks[iLevel] = directivity_spatialmasks(spatialgains, + gainMin); + spatialgains_destroy(spatialgains); + + // Generate masks for pairs + pairs = directivity_pairs(spatialmasks[iLevel]); + directivity_pairsadd(obj->pairs, pairs); + pairs_destroy(pairs); + + // Generate indexes in space + obj->spatialindexes[iLevel] = directivity_spatialindexes(spatialmasks[iLevel]); + + // Generate deltas + if (deltas[iLevel] < 0) { + + pointsRefined = space_points_fine(obj->points[iLevel], + nRefineLevels); + + taus = delay_taus(pointsRefined, + mics, + soundspeed, + fS, + frameSize, + interpRate); + + obj->deltas[iLevel] = hit_train(taus, + obj->tdoas[iLevel], + spatialmasks[iLevel], + probMin); + + points_destroy(pointsRefined); + + taus_destroy(taus); + + } + else { + + obj->deltas[iLevel] = hit_constant(obj->tdoas[iLevel], + deltas[iLevel]); + + } + + } + + beampatterns_destroy(beampatterns_mics); + beampatterns_destroy(beampatterns_spatialfilter); + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + + if (iLevel == 0) { + + maps = linking_maps(NULL, obj->tdoas[0], + NULL, obj->deltas[0], + NULL, spatialmasks[0], + nMatches); + + } + else { + + maps = linking_maps(obj->tdoas[iLevel-1], obj->tdoas[iLevel], + obj->deltas[iLevel-1], obj->deltas[iLevel], + spatialmasks[iLevel-1], spatialmasks[iLevel], + nMatches); + + } + + obj->indexes[iLevel] = linking_indexes(maps); + + maps_destroy(maps); + + } + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + + spatialmasks_destroy(spatialmasks[iLevel]); + + } + + free((void *) spatialmasks); + + return obj; + + } diff --git a/src/init/scanning.h b/src/init/scanning.h new file mode 100644 index 0000000..728e4b9 --- /dev/null +++ b/src/init/scanning.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_INIT_SCANNING +#define __ODAS_INIT_SCANNING + + #include "../general/mic.h" + #include "../general/soundspeed.h" + #include "../general/spatialfilter.h" + + #include "../signal/beampattern.h" + #include "../signal/scan.h" + #include "../signal/spatialgain.h" + #include "../signal/spatialindex.h" + #include "../signal/spatialmask.h" + #include "../signal/map.h" + #include "../signal/pair.h" + #include "../signal/tau.h" + + #include "../init/delay.h" + #include "../init/directivity.h" + #include "../init/hit.h" + #include "../init/linking.h" + #include "../init/space.h" + + scans_obj * scanning_init_scans(const mics_obj * mics, const spatialfilter_obj * spatialfilter, const unsigned int nLevels, const unsigned int * levels, const unsigned int fS, const soundspeed_obj * soundspeed, const unsigned int nMatches, const unsigned int frameSize, const signed int * deltas, const float probMin, const unsigned int nRefineLevels, const unsigned int nThetas, const float gainMin, const unsigned int interpRate); + +#endif \ No newline at end of file diff --git a/src/init/space.c b/src/init/space.c new file mode 100644 index 0000000..308c9b7 --- /dev/null +++ b/src/init/space.c @@ -0,0 +1,850 @@ + + #include "space.h" + + triangles_obj * space_triangles_level_zero(void) { + + points_obj * points; + triangles_obj * triangles; + + unsigned int iPoint; + unsigned int iTriangle; + + float h,r; + + h = sqrtf(5.0f)/5.0f; + r = (2.0f/5.0f)*sqrtf(5.0f); + + points = points_construct_zero(12); + + points->array[0 * 3 + 0] = 0.0f; + points->array[0 * 3 + 1] = 0.0f; + points->array[0 * 3 + 2] = 1.0f; + points->array[11 * 3 + 0] = 0.0f; + points->array[11 * 3 + 1] = 0.0f; + points->array[11 * 3 + 2] = -1.0f; + + for (iPoint = 0; iPoint < 5; iPoint++) { + + points->array[(iPoint+1) * 3 + 0] = r * sinf(2*M_PI*((float) iPoint)/5.0f); + points->array[(iPoint+1) * 3 + 1] = r * cosf(2*M_PI*((float) iPoint)/5.0f); + points->array[(iPoint+1) * 3 + 2] = h; + + points->array[(iPoint+6) * 3 + 0] = -1.0f * r * sinf(2*M_PI*((float) iPoint)/5.0f); + points->array[(iPoint+6) * 3 + 1] = -1.0f * r * cosf(2*M_PI*((float) iPoint)/5.0f); + points->array[(iPoint+6) * 3 + 2] = -1.0f * h; + + } + + triangles = triangles_construct_zero(20); + + // Triangle 0: Points 0, 2, 1 + triangles->array[0 * 9 + 0] = points->array[0 * 3 + 0]; + triangles->array[0 * 9 + 1] = points->array[0 * 3 + 1]; + triangles->array[0 * 9 + 2] = points->array[0 * 3 + 2]; + triangles->array[0 * 9 + 3] = points->array[2 * 3 + 0]; + triangles->array[0 * 9 + 4] = points->array[2 * 3 + 1]; + triangles->array[0 * 9 + 5] = points->array[2 * 3 + 2]; + triangles->array[0 * 9 + 6] = points->array[1 * 3 + 0]; + triangles->array[0 * 9 + 7] = points->array[1 * 3 + 1]; + triangles->array[0 * 9 + 8] = points->array[1 * 3 + 2]; + + // Triangle 1: Points 0, 3, 2 + triangles->array[1 * 9 + 0] = points->array[0 * 3 + 0]; + triangles->array[1 * 9 + 1] = points->array[0 * 3 + 1]; + triangles->array[1 * 9 + 2] = points->array[0 * 3 + 2]; + triangles->array[1 * 9 + 3] = points->array[3 * 3 + 0]; + triangles->array[1 * 9 + 4] = points->array[3 * 3 + 1]; + triangles->array[1 * 9 + 5] = points->array[3 * 3 + 2]; + triangles->array[1 * 9 + 6] = points->array[2 * 3 + 0]; + triangles->array[1 * 9 + 7] = points->array[2 * 3 + 1]; + triangles->array[1 * 9 + 8] = points->array[2 * 3 + 2]; + + // Triangle 2: Points 0, 4, 3 + triangles->array[2 * 9 + 0] = points->array[0 * 3 + 0]; + triangles->array[2 * 9 + 1] = points->array[0 * 3 + 1]; + triangles->array[2 * 9 + 2] = points->array[0 * 3 + 2]; + triangles->array[2 * 9 + 3] = points->array[4 * 3 + 0]; + triangles->array[2 * 9 + 4] = points->array[4 * 3 + 1]; + triangles->array[2 * 9 + 5] = points->array[4 * 3 + 2]; + triangles->array[2 * 9 + 6] = points->array[3 * 3 + 0]; + triangles->array[2 * 9 + 7] = points->array[3 * 3 + 1]; + triangles->array[2 * 9 + 8] = points->array[3 * 3 + 2]; + + // Triangle 3: Points 0, 5, 4 + triangles->array[3 * 9 + 0] = points->array[0 * 3 + 0]; + triangles->array[3 * 9 + 1] = points->array[0 * 3 + 1]; + triangles->array[3 * 9 + 2] = points->array[0 * 3 + 2]; + triangles->array[3 * 9 + 3] = points->array[5 * 3 + 0]; + triangles->array[3 * 9 + 4] = points->array[5 * 3 + 1]; + triangles->array[3 * 9 + 5] = points->array[5 * 3 + 2]; + triangles->array[3 * 9 + 6] = points->array[4 * 3 + 0]; + triangles->array[3 * 9 + 7] = points->array[4 * 3 + 1]; + triangles->array[3 * 9 + 8] = points->array[4 * 3 + 2]; + + // Triangle 4: Points 0, 1, 5 + triangles->array[4 * 9 + 0] = points->array[0 * 3 + 0]; + triangles->array[4 * 9 + 1] = points->array[0 * 3 + 1]; + triangles->array[4 * 9 + 2] = points->array[0 * 3 + 2]; + triangles->array[4 * 9 + 3] = points->array[1 * 3 + 0]; + triangles->array[4 * 9 + 4] = points->array[1 * 3 + 1]; + triangles->array[4 * 9 + 5] = points->array[1 * 3 + 2]; + triangles->array[4 * 9 + 6] = points->array[5 * 3 + 0]; + triangles->array[4 * 9 + 7] = points->array[5 * 3 + 1]; + triangles->array[4 * 9 + 8] = points->array[5 * 3 + 2]; + + // Triangle 5: Points 9, 1, 2 + triangles->array[5 * 9 + 0] = points->array[9 * 3 + 0]; + triangles->array[5 * 9 + 1] = points->array[9 * 3 + 1]; + triangles->array[5 * 9 + 2] = points->array[9 * 3 + 2]; + triangles->array[5 * 9 + 3] = points->array[1 * 3 + 0]; + triangles->array[5 * 9 + 4] = points->array[1 * 3 + 1]; + triangles->array[5 * 9 + 5] = points->array[1 * 3 + 2]; + triangles->array[5 * 9 + 6] = points->array[2 * 3 + 0]; + triangles->array[5 * 9 + 7] = points->array[2 * 3 + 1]; + triangles->array[5 * 9 + 8] = points->array[2 * 3 + 2]; + + // Triangle 6: Points 10, 2, 3 + triangles->array[6 * 9 + 0] = points->array[10 * 3 + 0]; + triangles->array[6 * 9 + 1] = points->array[10 * 3 + 1]; + triangles->array[6 * 9 + 2] = points->array[10 * 3 + 2]; + triangles->array[6 * 9 + 3] = points->array[2 * 3 + 0]; + triangles->array[6 * 9 + 4] = points->array[2 * 3 + 1]; + triangles->array[6 * 9 + 5] = points->array[2 * 3 + 2]; + triangles->array[6 * 9 + 6] = points->array[3 * 3 + 0]; + triangles->array[6 * 9 + 7] = points->array[3 * 3 + 1]; + triangles->array[6 * 9 + 8] = points->array[3 * 3 + 2]; + + // Triangle 7: Points 6, 3, 4 + triangles->array[7 * 9 + 0] = points->array[6 * 3 + 0]; + triangles->array[7 * 9 + 1] = points->array[6 * 3 + 1]; + triangles->array[7 * 9 + 2] = points->array[6 * 3 + 2]; + triangles->array[7 * 9 + 3] = points->array[3 * 3 + 0]; + triangles->array[7 * 9 + 4] = points->array[3 * 3 + 1]; + triangles->array[7 * 9 + 5] = points->array[3 * 3 + 2]; + triangles->array[7 * 9 + 6] = points->array[4 * 3 + 0]; + triangles->array[7 * 9 + 7] = points->array[4 * 3 + 1]; + triangles->array[7 * 9 + 8] = points->array[4 * 3 + 2]; + + // Triangle 8: Points 7, 4, 5 + triangles->array[8 * 9 + 0] = points->array[7 * 3 + 0]; + triangles->array[8 * 9 + 1] = points->array[7 * 3 + 1]; + triangles->array[8 * 9 + 2] = points->array[7 * 3 + 2]; + triangles->array[8 * 9 + 3] = points->array[4 * 3 + 0]; + triangles->array[8 * 9 + 4] = points->array[4 * 3 + 1]; + triangles->array[8 * 9 + 5] = points->array[4 * 3 + 2]; + triangles->array[8 * 9 + 6] = points->array[5 * 3 + 0]; + triangles->array[8 * 9 + 7] = points->array[5 * 3 + 1]; + triangles->array[8 * 9 + 8] = points->array[5 * 3 + 2]; + + // Triangle 9: Points 8, 5, 1 + triangles->array[9 * 9 + 0] = points->array[8 * 3 + 0]; + triangles->array[9 * 9 + 1] = points->array[8 * 3 + 1]; + triangles->array[9 * 9 + 2] = points->array[8 * 3 + 2]; + triangles->array[9 * 9 + 3] = points->array[5 * 3 + 0]; + triangles->array[9 * 9 + 4] = points->array[5 * 3 + 1]; + triangles->array[9 * 9 + 5] = points->array[5 * 3 + 2]; + triangles->array[9 * 9 + 6] = points->array[1 * 3 + 0]; + triangles->array[9 * 9 + 7] = points->array[1 * 3 + 1]; + triangles->array[9 * 9 + 8] = points->array[1 * 3 + 2]; + + // Triangle 10: Points 4, 7, 6 + triangles->array[10 * 9 + 0] = points->array[4 * 3 + 0]; + triangles->array[10 * 9 + 1] = points->array[4 * 3 + 1]; + triangles->array[10 * 9 + 2] = points->array[4 * 3 + 2]; + triangles->array[10 * 9 + 3] = points->array[7 * 3 + 0]; + triangles->array[10 * 9 + 4] = points->array[7 * 3 + 1]; + triangles->array[10 * 9 + 5] = points->array[7 * 3 + 2]; + triangles->array[10 * 9 + 6] = points->array[6 * 3 + 0]; + triangles->array[10 * 9 + 7] = points->array[6 * 3 + 1]; + triangles->array[10 * 9 + 8] = points->array[6 * 3 + 2]; + + // Triangle 11: Points 5, 8, 7 + triangles->array[11 * 9 + 0] = points->array[5 * 3 + 0]; + triangles->array[11 * 9 + 1] = points->array[5 * 3 + 1]; + triangles->array[11 * 9 + 2] = points->array[5 * 3 + 2]; + triangles->array[11 * 9 + 3] = points->array[8 * 3 + 0]; + triangles->array[11 * 9 + 4] = points->array[8 * 3 + 1]; + triangles->array[11 * 9 + 5] = points->array[8 * 3 + 2]; + triangles->array[11 * 9 + 6] = points->array[7 * 3 + 0]; + triangles->array[11 * 9 + 7] = points->array[7 * 3 + 1]; + triangles->array[11 * 9 + 8] = points->array[7 * 3 + 2]; + + // Triangle 12: Points 1, 9, 8 + triangles->array[12 * 9 + 0] = points->array[1 * 3 + 0]; + triangles->array[12 * 9 + 1] = points->array[1 * 3 + 1]; + triangles->array[12 * 9 + 2] = points->array[1 * 3 + 2]; + triangles->array[12 * 9 + 3] = points->array[9 * 3 + 0]; + triangles->array[12 * 9 + 4] = points->array[9 * 3 + 1]; + triangles->array[12 * 9 + 5] = points->array[9 * 3 + 2]; + triangles->array[12 * 9 + 6] = points->array[8 * 3 + 0]; + triangles->array[12 * 9 + 7] = points->array[8 * 3 + 1]; + triangles->array[12 * 9 + 8] = points->array[8 * 3 + 2]; + + // Triangle 13: Points 2, 10, 9 + triangles->array[13 * 9 + 0] = points->array[2 * 3 + 0]; + triangles->array[13 * 9 + 1] = points->array[2 * 3 + 1]; + triangles->array[13 * 9 + 2] = points->array[2 * 3 + 2]; + triangles->array[13 * 9 + 3] = points->array[10 * 3 + 0]; + triangles->array[13 * 9 + 4] = points->array[10 * 3 + 1]; + triangles->array[13 * 9 + 5] = points->array[10 * 3 + 2]; + triangles->array[13 * 9 + 6] = points->array[9 * 3 + 0]; + triangles->array[13 * 9 + 7] = points->array[9 * 3 + 1]; + triangles->array[13 * 9 + 8] = points->array[9 * 3 + 2]; + + // Triangle 14: Points 3, 6, 10 + triangles->array[14 * 9 + 0] = points->array[3 * 3 + 0]; + triangles->array[14 * 9 + 1] = points->array[3 * 3 + 1]; + triangles->array[14 * 9 + 2] = points->array[3 * 3 + 2]; + triangles->array[14 * 9 + 3] = points->array[6 * 3 + 0]; + triangles->array[14 * 9 + 4] = points->array[6 * 3 + 1]; + triangles->array[14 * 9 + 5] = points->array[6 * 3 + 2]; + triangles->array[14 * 9 + 6] = points->array[10 * 3 + 0]; + triangles->array[14 * 9 + 7] = points->array[10 * 3 + 1]; + triangles->array[14 * 9 + 8] = points->array[10 * 3 + 2]; + + // Triangle 15: Points 11, 6, 7 + triangles->array[15 * 9 + 0] = points->array[11 * 3 + 0]; + triangles->array[15 * 9 + 1] = points->array[11 * 3 + 1]; + triangles->array[15 * 9 + 2] = points->array[11 * 3 + 2]; + triangles->array[15 * 9 + 3] = points->array[6 * 3 + 0]; + triangles->array[15 * 9 + 4] = points->array[6 * 3 + 1]; + triangles->array[15 * 9 + 5] = points->array[6 * 3 + 2]; + triangles->array[15 * 9 + 6] = points->array[7 * 3 + 0]; + triangles->array[15 * 9 + 7] = points->array[7 * 3 + 1]; + triangles->array[15 * 9 + 8] = points->array[7 * 3 + 2]; + + // Triangle 16: Points 11, 7, 8 + triangles->array[16 * 9 + 0] = points->array[11 * 3 + 0]; + triangles->array[16 * 9 + 1] = points->array[11 * 3 + 1]; + triangles->array[16 * 9 + 2] = points->array[11 * 3 + 2]; + triangles->array[16 * 9 + 3] = points->array[7 * 3 + 0]; + triangles->array[16 * 9 + 4] = points->array[7 * 3 + 1]; + triangles->array[16 * 9 + 5] = points->array[7 * 3 + 2]; + triangles->array[16 * 9 + 6] = points->array[8 * 3 + 0]; + triangles->array[16 * 9 + 7] = points->array[8 * 3 + 1]; + triangles->array[16 * 9 + 8] = points->array[8 * 3 + 2]; + + // Triangle 17: Points 11, 8, 9 + triangles->array[17 * 9 + 0] = points->array[11 * 3 + 0]; + triangles->array[17 * 9 + 1] = points->array[11 * 3 + 1]; + triangles->array[17 * 9 + 2] = points->array[11 * 3 + 2]; + triangles->array[17 * 9 + 3] = points->array[8 * 3 + 0]; + triangles->array[17 * 9 + 4] = points->array[8 * 3 + 1]; + triangles->array[17 * 9 + 5] = points->array[8 * 3 + 2]; + triangles->array[17 * 9 + 6] = points->array[9 * 3 + 0]; + triangles->array[17 * 9 + 7] = points->array[9 * 3 + 1]; + triangles->array[17 * 9 + 8] = points->array[9 * 3 + 2]; + + // Triangle 18: Points 11, 9, 10 + triangles->array[18 * 9 + 0] = points->array[11 * 3 + 0]; + triangles->array[18 * 9 + 1] = points->array[11 * 3 + 1]; + triangles->array[18 * 9 + 2] = points->array[11 * 3 + 2]; + triangles->array[18 * 9 + 3] = points->array[9 * 3 + 0]; + triangles->array[18 * 9 + 4] = points->array[9 * 3 + 1]; + triangles->array[18 * 9 + 5] = points->array[9 * 3 + 2]; + triangles->array[18 * 9 + 6] = points->array[10 * 3 + 0]; + triangles->array[18 * 9 + 7] = points->array[10 * 3 + 1]; + triangles->array[18 * 9 + 8] = points->array[10 * 3 + 2]; + + // Triangle 19: Points 11, 10, 6 + triangles->array[19 * 9 + 0] = points->array[11 * 3 + 0]; + triangles->array[19 * 9 + 1] = points->array[11 * 3 + 1]; + triangles->array[19 * 9 + 2] = points->array[11 * 3 + 2]; + triangles->array[19 * 9 + 3] = points->array[10 * 3 + 0]; + triangles->array[19 * 9 + 4] = points->array[10 * 3 + 1]; + triangles->array[19 * 9 + 5] = points->array[10 * 3 + 2]; + triangles->array[19 * 9 + 6] = points->array[6 * 3 + 0]; + triangles->array[19 * 9 + 7] = points->array[6 * 3 + 1]; + triangles->array[19 * 9 + 8] = points->array[6 * 3 + 2]; + + points_destroy(points); + + return triangles; + + } + + triangles_obj * space_triangles_level_next(const triangles_obj * triangles) { + + triangles_obj * obj; + unsigned int iTriangle; + + float point1[3]; + float point2[3]; + float point3[3]; + float pointA[3]; + float pointB[3]; + float pointC[3]; + float norm1; + float norm2; + float norm3; + + obj = triangles_construct_zero(triangles->nTriangles * 4); + + for (iTriangle = 0; iTriangle < triangles->nTriangles; iTriangle++) { + + pointA[0] = triangles->array[iTriangle*9+0]; + pointA[1] = triangles->array[iTriangle*9+1]; + pointA[2] = triangles->array[iTriangle*9+2]; + pointB[0] = triangles->array[iTriangle*9+3]; + pointB[1] = triangles->array[iTriangle*9+4]; + pointB[2] = triangles->array[iTriangle*9+5]; + pointC[0] = triangles->array[iTriangle*9+6]; + pointC[1] = triangles->array[iTriangle*9+7]; + pointC[2] = triangles->array[iTriangle*9+8]; + + point1[0] = pointA[0] + pointB[0]; + point1[1] = pointA[1] + pointB[1]; + point1[2] = pointA[2] + pointB[2]; + point2[0] = pointB[0] + pointC[0]; + point2[1] = pointB[1] + pointC[1]; + point2[2] = pointB[2] + pointC[2]; + point3[0] = pointC[0] + pointA[0]; + point3[1] = pointC[1] + pointA[1]; + point3[2] = pointC[2] + pointA[2]; + + norm1 = sqrtf(point1[0] * point1[0] + point1[1] * point1[1] + point1[2] * point1[2]); + norm2 = sqrtf(point2[0] * point2[0] + point2[1] * point2[1] + point2[2] * point2[2]); + norm3 = sqrtf(point3[0] * point3[0] + point3[1] * point3[1] + point3[2] * point3[2]); + + point1[0] /= norm1; + point1[1] /= norm1; + point1[2] /= norm1; + point2[0] /= norm2; + point2[1] /= norm2; + point2[2] /= norm2; + point3[0] /= norm3; + point3[1] /= norm3; + point3[2] /= norm3; + + obj->array[(iTriangle*4+0)*9+0] = pointA[0]; + obj->array[(iTriangle*4+0)*9+1] = pointA[1]; + obj->array[(iTriangle*4+0)*9+2] = pointA[2]; + obj->array[(iTriangle*4+0)*9+3] = point1[0]; + obj->array[(iTriangle*4+0)*9+4] = point1[1]; + obj->array[(iTriangle*4+0)*9+5] = point1[2]; + obj->array[(iTriangle*4+0)*9+6] = point3[0]; + obj->array[(iTriangle*4+0)*9+7] = point3[1]; + obj->array[(iTriangle*4+0)*9+8] = point3[2]; + + obj->array[(iTriangle*4+1)*9+0] = point1[0]; + obj->array[(iTriangle*4+1)*9+1] = point1[1]; + obj->array[(iTriangle*4+1)*9+2] = point1[2]; + obj->array[(iTriangle*4+1)*9+3] = pointB[0]; + obj->array[(iTriangle*4+1)*9+4] = pointB[1]; + obj->array[(iTriangle*4+1)*9+5] = pointB[2]; + obj->array[(iTriangle*4+1)*9+6] = point2[0]; + obj->array[(iTriangle*4+1)*9+7] = point2[1]; + obj->array[(iTriangle*4+1)*9+8] = point2[2]; + + obj->array[(iTriangle*4+2)*9+0] = point1[0]; + obj->array[(iTriangle*4+2)*9+1] = point1[1]; + obj->array[(iTriangle*4+2)*9+2] = point1[2]; + obj->array[(iTriangle*4+2)*9+3] = point2[0]; + obj->array[(iTriangle*4+2)*9+4] = point2[1]; + obj->array[(iTriangle*4+2)*9+5] = point2[2]; + obj->array[(iTriangle*4+2)*9+6] = point3[0]; + obj->array[(iTriangle*4+2)*9+7] = point3[1]; + obj->array[(iTriangle*4+2)*9+8] = point3[2]; + + obj->array[(iTriangle*4+3)*9+0] = point3[0]; + obj->array[(iTriangle*4+3)*9+1] = point3[1]; + obj->array[(iTriangle*4+3)*9+2] = point3[2]; + obj->array[(iTriangle*4+3)*9+3] = point2[0]; + obj->array[(iTriangle*4+3)*9+4] = point2[1]; + obj->array[(iTriangle*4+3)*9+5] = point2[2]; + obj->array[(iTriangle*4+3)*9+6] = pointC[0]; + obj->array[(iTriangle*4+3)*9+7] = pointC[1]; + obj->array[(iTriangle*4+3)*9+8] = pointC[2]; + + } + + return obj; + + } + + triangles_obj * space_triangles_level_level(const unsigned int level) { + + triangles_obj * obj; + triangles_obj * triangles; + unsigned int iLevel; + + obj = space_triangles_level_zero(); + + for (iLevel = 0; iLevel < level; iLevel++) { + triangles = space_triangles_level_next(obj); + triangles_destroy(obj); + obj = triangles; + } + + return obj; + + } + + triangles_obj * space_triangles_points(const points_obj * points, const unsigned int index) { + + unsigned int iPoint; + float x1, y1, z1; + float x2, y2, z2; + float dx, dy, dz; + float dist, minDist; + unsigned int iPointMin; + float ux, uy, uz; + float tx, ty, tz; + float x0, y0, z0; + float xR, yR, zR; + unsigned int iAngle; + unsigned int nAngles; + float theta; + float R11, R12, R13, R21, R22, R23, R31, R32, R33; + float dot; + float norm; + + triangles_obj * triangles_octo; + points_obj * points_octo; + + x1 = points->array[index*3+0]; + y1 = points->array[index*3+1]; + z1 = points->array[index*3+2]; + + minDist = +INFINITY; + + for (iPoint = 0; iPoint < points->nPoints; iPoint++) { + + if (iPoint != index) { + + x2 = points->array[iPoint*3+0]; + y2 = points->array[iPoint*3+1]; + z2 = points->array[iPoint*3+2]; + + dx = x1 - x2; + dy = y1 - y2; + dz = z1 - z2; + + dist = dx*dx + dy*dy + dz*dz; + + if (dist < minDist) { + + minDist = dist; + iPointMin = iPoint; + + } + + } + + } + + ux = points->array[index*3+0]; + uy = points->array[index*3+1]; + uz = points->array[index*3+2]; + + x1 = points->array[iPointMin*3+0]; + y1 = points->array[iPointMin*3+1]; + z1 = points->array[iPointMin*3+2]; + + dot = (ux*x1) + (uy*y1) + (uz*z1); + + x0 = ux + x1 - dot * ux; + y0 = uy + y1 - dot * uy; + z0 = uz + z1 - dot * uz; + + /* + tx = ux - x0; + ty = uy - y0; + tz = uz - z0; + + tx *= 0.75f; + ty *= 0.75f; + tz *= 0.75f; + + x0 = ux - tx; + y0 = uy - ty; + z0 = uz - tz; + */ + + nAngles = 8; + + points_octo = points_construct_zero(nAngles); + + for (iAngle = 0; iAngle < nAngles; iAngle++) { + + theta = 2*M_PI * ((float) iAngle) / ((float) nAngles); + + R11 = cosf(theta) + (ux*ux) * (1.0f - cosf(theta)); + R12 = (ux*uy) * (1.0f - cosf(theta)) - uz * sinf(theta); + R13 = (ux*uz) * (1.0f - cosf(theta)) + uy * sinf(theta); + R21 = (uy*ux) * (1.0f - cosf(theta)) + uz * sinf(theta); + R22 = cosf(theta) + (uy*uy) * (1.0f - cosf(theta)); + R23 = (uy*uz) * (1.0f - cosf(theta)) - ux * sinf(theta); + R31 = (uz*ux) * (1.0f - cosf(theta)) - uy * sinf(theta); + R32 = (uz*uy) * (1.0f - cosf(theta)) + ux * sinf(theta); + R33 = cosf(theta) + (uz*uz) * (1.0f - cosf(theta)); + + xR = R11 * x0 + R12 * y0 + R13 * z0; + yR = R21 * x0 + R22 * y0 + R23 * z0; + zR = R31 * x0 + R32 * y0 + R33 * z0; + + norm = sqrtf(xR*xR + yR*yR + zR*zR); + + xR /= norm; + yR /= norm; + zR /= norm; + + points_octo->array[iAngle*3+0] = xR; + points_octo->array[iAngle*3+1] = yR; + points_octo->array[iAngle*3+2] = zR; + + } + + triangles_octo = triangles_construct_zero(nAngles); + + for (iAngle = 0; iAngle < (nAngles-1); iAngle++) { + + triangles_octo->array[iAngle*9+0] = points_octo->array[iAngle*3+0]; + triangles_octo->array[iAngle*9+1] = points_octo->array[iAngle*3+1]; + triangles_octo->array[iAngle*9+2] = points_octo->array[iAngle*3+2]; + triangles_octo->array[iAngle*9+3] = ux; + triangles_octo->array[iAngle*9+4] = uy; + triangles_octo->array[iAngle*9+5] = uz; + triangles_octo->array[iAngle*9+6] = points_octo->array[(iAngle+1)*3+0]; + triangles_octo->array[iAngle*9+7] = points_octo->array[(iAngle+1)*3+1]; + triangles_octo->array[iAngle*9+8] = points_octo->array[(iAngle+1)*3+2]; + + } + + triangles_octo->array[iAngle*9+0] = points_octo->array[(nAngles-1)*3+0]; + triangles_octo->array[iAngle*9+1] = points_octo->array[(nAngles-1)*3+1]; + triangles_octo->array[iAngle*9+2] = points_octo->array[(nAngles-1)*3+2]; + triangles_octo->array[iAngle*9+3] = ux; + triangles_octo->array[iAngle*9+4] = uy; + triangles_octo->array[iAngle*9+5] = uz; + triangles_octo->array[iAngle*9+6] = points_octo->array[0]; + triangles_octo->array[iAngle*9+7] = points_octo->array[1]; + triangles_octo->array[iAngle*9+8] = points_octo->array[2]; + + points_destroy(points_octo); + + return triangles_octo; + + } + + points_obj * space_points_triangles(const triangles_obj * triangles) { + + unsigned int iTriangle; + unsigned int iPointInTriangle; + unsigned int iPoint; + unsigned int iPoint2; + unsigned int nPoints; + + float diff, dist; + float point[3]; + + float shortestDistance; + float limitDistance; + + char * added; + unsigned int iPointCompare; + float distance; + float dx, dy, dz; + + points_obj * pointsAll; + points_obj * pointsContainer; + points_obj * pointsUnique; + + // Copy all points from triangles in an array of points + + pointsAll = points_construct_zero(triangles->nTriangles*3); + + nPoints = 0; + + for (iTriangle = 0; iTriangle < triangles->nTriangles; iTriangle++) { + + for (iPointInTriangle = 0; iPointInTriangle < 3; iPointInTriangle++) { + + point[0] = triangles->array[iTriangle * 9 + iPointInTriangle * 3 + 0]; + point[1] = triangles->array[iTriangle * 9 + iPointInTriangle * 3 + 1]; + point[2] = triangles->array[iTriangle * 9 + iPointInTriangle * 3 + 2]; + + pointsAll->array[nPoints * 3 + 0] = point[0]; + pointsAll->array[nPoints * 3 + 1] = point[1]; + pointsAll->array[nPoints * 3 + 2] = point[2]; + nPoints++; + + } + + } + + // Shortest distance + + shortestDistance = space_distances_shortest_triangles(triangles); + limitDistance = 0.5 * shortestDistance; + + // Remove duplicate + + added = (char *) malloc(pointsAll->nPoints * sizeof(char)); + memset((void *) added, 0x00, pointsAll->nPoints * sizeof(char)); + + pointsContainer = points_construct_zero(pointsAll->nPoints); + + nPoints = 0; + + for (iPoint = 0; iPoint < pointsAll->nPoints; iPoint++) { + + if (added[iPoint] == 0x00) { + + for (iPoint2 = 0; iPoint2 < pointsAll->nPoints; iPoint2++) { + + dx = pointsAll->array[iPoint*3+0] - pointsAll->array[iPoint2*3+0]; + dy = pointsAll->array[iPoint*3+1] - pointsAll->array[iPoint2*3+1]; + dz = pointsAll->array[iPoint*3+2] - pointsAll->array[iPoint2*3+2]; + + distance = dx * dx + dy * dy + dz * dz; + + if (distance < (limitDistance*limitDistance)) { + + added[iPoint2] = 0x01; + + } + + } + + added[iPoint] = 0x02; + nPoints++; + + } + + } + + // Load unique points + + pointsUnique = points_construct_zero(nPoints); + nPoints = 0; + + for (iPoint = 0; iPoint < pointsContainer->nPoints; iPoint++) { + + if (added[iPoint] == 0x02) { + + pointsUnique->array[nPoints*3+0] = pointsAll->array[iPoint*3+0]; + pointsUnique->array[nPoints*3+1] = pointsAll->array[iPoint*3+1]; + pointsUnique->array[nPoints*3+2] = pointsAll->array[iPoint*3+2]; + + nPoints++; + + } + + } + + points_destroy(pointsAll); + points_destroy(pointsContainer); + + free((void *) added); + + return pointsUnique; + + } + + points_obj * space_points_fine(const points_obj * points, const unsigned int level) { + + points_obj * obj; + + unsigned int nPointsCoarse; + unsigned int nPointsFine; + unsigned int nFinesPerCoarse; + unsigned int pow2, pow4; + unsigned int iLevel; + + unsigned int iCoarse; + triangles_obj * triangles1; + triangles_obj * triangles2; + points_obj * pointsFine; + + pow2 = 1; + pow4 = 1; + + for (iLevel = 1; iLevel <= level; iLevel++) { + + pow2 *= 2; + pow4 *= 4; + + } + + nFinesPerCoarse = (4 * (pow2 + pow4) + 1); + + nPointsCoarse = points->nPoints; + nPointsFine = nPointsCoarse * nFinesPerCoarse; + + obj = points_construct_zero(nPointsFine); + + for (iCoarse = 0; iCoarse < nPointsCoarse; iCoarse++) { + + triangles1 = space_triangles_points(points, iCoarse); + + for (iLevel = 0; iLevel < level; iLevel++) { + + triangles2 = space_triangles_level_next(triangles1); + triangles_destroy(triangles1); + triangles1 = triangles2; + + } + + pointsFine = space_points_triangles(triangles1); + triangles_destroy(triangles1); + + memcpy(&(obj->array[iCoarse*nFinesPerCoarse*3]), pointsFine->array, nFinesPerCoarse * 3 * sizeof(float)); + points_destroy(pointsFine); + + } + + return obj; + + } + + points_obj * space_sphere(const unsigned int level) { + + points_obj * obj; + triangles_obj * triangles; + + triangles = space_triangles_level_level(level); + obj = space_points_triangles(triangles); + triangles_destroy(triangles); + + return obj; + + } + + points_obj * space_halfsphere(const unsigned int level) { + + points_obj * obj; + + triangles_obj * triangles; + points_obj * pointsSphere; + unsigned int nPoints; + unsigned int iPoint; + + triangles = space_triangles_level_level(level); + pointsSphere = space_points_triangles(triangles); + + nPoints = 0; + + for (iPoint = 0; iPoint < pointsSphere->nPoints; iPoint++) { + + if (pointsSphere->array[iPoint*3+2] >= 0.0f) { + + nPoints++; + + } + + } + + obj = points_construct_zero(nPoints); + nPoints = 0; + + for (iPoint = 0; iPoint < pointsSphere->nPoints; iPoint++) { + + if (pointsSphere->array[iPoint*3+2] >= 0.0f) { + + obj->array[nPoints*3+0] = pointsSphere->array[iPoint*3+0]; + obj->array[nPoints*3+1] = pointsSphere->array[iPoint*3+1]; + obj->array[nPoints*3+2] = pointsSphere->array[iPoint*3+2]; + + nPoints++; + + } + + } + + triangles_destroy(triangles); + points_destroy(pointsSphere); + + return obj; + + } + + float space_distances_shortest_triangles(const triangles_obj * triangles) { + + float shortestDistance; + float x1, y1, z1; + float x2, y2, z2; + float x3, y3, z3; + float dist12, dist23, dist31; + unsigned int iTriangle; + + shortestDistance = +INFINITY; + + for (iTriangle = 0; iTriangle < triangles->nTriangles; iTriangle++) { + + x1 = triangles->array[iTriangle * 9 + 0]; + y1 = triangles->array[iTriangle * 9 + 1]; + z1 = triangles->array[iTriangle * 9 + 2]; + x2 = triangles->array[iTriangle * 9 + 3]; + y2 = triangles->array[iTriangle * 9 + 4]; + z2 = triangles->array[iTriangle * 9 + 5]; + x3 = triangles->array[iTriangle * 9 + 6]; + y3 = triangles->array[iTriangle * 9 + 7]; + z3 = triangles->array[iTriangle * 9 + 8]; + + dist12 = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2); + dist23 = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3) + (z2-z3)*(z2-z3); + dist31 = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) + (z3-z1)*(z3-z1); + + if (dist12 < shortestDistance) { + shortestDistance = dist12; + } + if (dist23 < shortestDistance) { + shortestDistance = dist23; + } + if (dist31 < shortestDistance) { + shortestDistance = dist31; + } + + } + + shortestDistance = sqrtf(shortestDistance); + + return shortestDistance; + + } + + float space_distances_shortest_points(const points_obj * points) { + + float shortestDistance; + float x1, y1, z1; + float x2, y2, z2; + float dist; + unsigned int iPoint; + unsigned int iPoint2; + + shortestDistance = +INFINITY; + + for (iPoint = 0; iPoint < points->nPoints; iPoint++) { + + x1 = points->array[iPoint*3+0]; + y1 = points->array[iPoint*3+1]; + z1 = points->array[iPoint*3+2]; + + for (iPoint2 = 0; iPoint2 < points->nPoints; iPoint2++) { + + if (iPoint != iPoint2) { + + x2 = points->array[iPoint2*3+0]; + y2 = points->array[iPoint2*3+1]; + z2 = points->array[iPoint2*3+2]; + + dist = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2); + + if (dist < shortestDistance) { + + shortestDistance = dist; + + } + + } + + } + + } + + shortestDistance = sqrtf(shortestDistance); + + return shortestDistance; + + } \ No newline at end of file diff --git a/src/init/space.h b/src/init/space.h new file mode 100644 index 0000000..d03bc5b --- /dev/null +++ b/src/init/space.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_INIT_SPACE +#define __ODAS_INIT_SPACE + + #include + #include + #include + #include "../signal/triangle.h" + #include "../signal/point.h" + + triangles_obj * space_triangles_level_zero(void); + + triangles_obj * space_triangles_level_next(const triangles_obj * triangles); + + triangles_obj * space_triangles_level_level(const unsigned int level); + + triangles_obj * space_triangles_points(const points_obj * points, const unsigned int index); + + points_obj * space_points_triangles(const triangles_obj * triangles); + + points_obj * space_points_fine(const points_obj * points, const unsigned int level); + + points_obj * space_sphere(const unsigned int level); + + points_obj * space_halfsphere(const unsigned int level); + + float space_distances_shortest_triangles(const triangles_obj * triangles); + + float space_distances_shortest_points(const points_obj * points); + +#endif \ No newline at end of file diff --git a/src/init/windowing.c b/src/init/windowing.c new file mode 100644 index 0000000..4ff6aa6 --- /dev/null +++ b/src/init/windowing.c @@ -0,0 +1,55 @@ + + #include "windowing.h" + + window_obj * windowing_hann(const unsigned int frameSize) { + + window_obj * obj; + unsigned int iSample; + + obj = window_construct_zero(frameSize); + + if ( frameSize == 1 ) { + + obj->array[0] = 1.0f; + + } + else { + + for ( iSample = 0; iSample < frameSize; iSample++ ) { + + obj->array[iSample] = 0.5f * ( 1.0f - cosf( 2 * M_PI * ( (float) iSample ) / ( (float) ( frameSize - 1 ) ) ) ); + + } + + + } + + return obj; + + } + + window_obj * windowing_roothann(const unsigned int frameSize) { + + window_obj * obj; + unsigned int iSample; + + obj = window_construct_zero(frameSize); + + if ( frameSize == 1 ) { + + obj->array[0] = 1.0f; + + } + else { + + for ( iSample = 0; iSample < frameSize; iSample++ ) { + + obj->array[iSample] = sqrtf( 0.5f * ( 1.0f - cosf( 2 * M_PI * ( (float) iSample ) / ( (float) ( frameSize - 1 ) ) ) ) ); + + } + + } + + return obj; + + } diff --git a/src/init/windowing.h b/src/init/windowing.h new file mode 100644 index 0000000..f9d028f --- /dev/null +++ b/src/init/windowing.h @@ -0,0 +1,14 @@ +#ifndef __ODAS_INIT_WINDOWING +#define __ODAS_INIT_WINDOWING + + #include + + #include "../signal/window.h" + + window_obj * windowing_hann(const unsigned int frameSize); + + window_obj * windowing_roothann(const unsigned int frameSize); + +#endif + + \ No newline at end of file diff --git a/src/injector/inj_targets.c b/src/injector/inj_targets.c new file mode 100644 index 0000000..ff0c878 --- /dev/null +++ b/src/injector/inj_targets.c @@ -0,0 +1,110 @@ + + #include "inj_targets.h" + + inj_targets_obj * inj_targets_construct(const inj_targets_cfg * inj_targets_config, const msg_hops_cfg * msg_hops_config, const msg_targets_cfg * msg_targets_config) { + + inj_targets_obj * obj; + + obj = (inj_targets_obj *) malloc(sizeof(inj_targets_obj)); + + obj->nTargets = msg_targets_config->nTargets; + obj->fS = msg_hops_config->fS; + + obj->timeStamp = 0; + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_targets_obj *) NULL; + + obj->targets = targets_clone(inj_targets_config->targets); + + return obj; + + } + + void inj_targets_destroy(inj_targets_obj * obj) { + + targets_destroy(obj->targets); + free((void *) obj); + + } + + void inj_targets_connect(inj_targets_obj * obj, msg_hops_obj * in, msg_targets_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void inj_targets_disconnect(inj_targets_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_targets_obj *) NULL; + + } + + int inj_targets_process(inj_targets_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + targets_copy(obj->out->targets, obj->targets); + obj->out->fS = obj->in->fS; + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_targets_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + inj_targets_cfg * inj_targets_cfg_construct(void) { + + inj_targets_cfg * cfg; + + cfg = (inj_targets_cfg *) malloc(sizeof(inj_targets_cfg)); + + cfg->nTargets = 0; + cfg->targets = NULL; + + return cfg; + + } + + void inj_targets_cfg_destroy(inj_targets_cfg * cfg) { + + if (cfg->targets != NULL) { + targets_destroy(cfg->targets); + } + + free((void *) cfg); + + } + + void inj_targets_cfg_printf(const inj_targets_cfg * cfg) { + + printf("nTargets = %u\n", cfg->nTargets); + + if (cfg->targets != NULL) { + + targets_printf(cfg->targets); + + } + else { + + printf("targets: NULL\n"); + + } + + + + } \ No newline at end of file diff --git a/src/injector/inj_targets.h b/src/injector/inj_targets.h new file mode 100644 index 0000000..bfcbfba --- /dev/null +++ b/src/injector/inj_targets.h @@ -0,0 +1,51 @@ +#ifndef __ODAS_INJECTOR_TARGETS +#define __ODAS_INJECTOR_TARGETS + + #include "../message/msg_hops.h" + #include "../message/msg_targets.h" + + #include "../general/format.h" + #include "../general/interface.h" + + #include + #include + #include + + typedef struct inj_targets_obj { + + unsigned long long timeStamp; + + unsigned int nTargets; + unsigned int fS; + + msg_hops_obj * in; + msg_targets_obj * out; + + targets_obj * targets; + + } inj_targets_obj; + + typedef struct inj_targets_cfg { + + unsigned int nTargets; + targets_obj * targets; + + } inj_targets_cfg; + + inj_targets_obj * inj_targets_construct(const inj_targets_cfg * inj_targets_config, const msg_hops_cfg * msg_hops_config, const msg_targets_cfg * msg_targets_config); + + void inj_targets_destroy(inj_targets_obj * obj); + + void inj_targets_connect(inj_targets_obj * obj, msg_hops_obj * in, msg_targets_obj * out); + + void inj_targets_disconnect(inj_targets_obj * obj); + + int inj_targets_process(inj_targets_obj * obj); + + inj_targets_cfg * inj_targets_cfg_construct(void); + + void inj_targets_cfg_destroy(inj_targets_cfg * cfg); + + void inj_targets_cfg_printf(const inj_targets_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/message/msg_categories.c b/src/message/msg_categories.c new file mode 100644 index 0000000..aec6139 --- /dev/null +++ b/src/message/msg_categories.c @@ -0,0 +1,81 @@ + + #include "msg_categories.h" + + msg_categories_obj * msg_categories_construct(const msg_categories_cfg * msg_categories_config) { + + msg_categories_obj * obj; + + obj = (msg_categories_obj *) malloc(sizeof(msg_categories_obj)); + + obj->timeStamp = 0; + obj->fS = msg_categories_config->fS; + obj->categories = categories_construct_zero(msg_categories_config->nChannels); + + return obj; + + } + + void msg_categories_destroy(msg_categories_obj * obj) { + + categories_destroy(obj->categories); + free((void *) obj); + + } + + void msg_categories_copy(msg_categories_obj * dest, const msg_categories_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + + categories_copy(dest->categories, src->categories); + + } + + void msg_categories_zero(msg_categories_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + categories_zero(obj->categories); + + } + + unsigned int msg_categories_isZero(const msg_categories_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_categories_cfg * msg_categories_cfg_construct(void) { + + msg_categories_cfg * cfg; + + cfg = (msg_categories_cfg *) malloc(sizeof(msg_categories_cfg)); + + cfg->nChannels = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_categories_cfg_destroy(msg_categories_cfg * msg_categories_config) { + + free((void *) msg_categories_config); + + } + + void msg_categories_cfg_printf(const msg_categories_cfg * msg_categories_config) { + + printf("nChannels = %u\n", msg_categories_config->nChannels); + printf("fS = %u\n", msg_categories_config->fS); + + } diff --git a/src/message/msg_categories.h b/src/message/msg_categories.h new file mode 100644 index 0000000..1ef1a2c --- /dev/null +++ b/src/message/msg_categories.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_MESSAGE_CATEGORIES +#define __ODAS_MESSAGE_CATEGORIES + + #include + #include "../signal/category.h" + + typedef struct msg_categories_obj { + + unsigned long long timeStamp; + unsigned int fS; + categories_obj * categories; + + } msg_categories_obj; + + typedef struct msg_categories_cfg { + + unsigned int nChannels; + unsigned int fS; + + } msg_categories_cfg; + + msg_categories_obj * msg_categories_construct(const msg_categories_cfg * msg_categories_config); + + void msg_categories_destroy(msg_categories_obj * obj); + + void msg_categories_copy(msg_categories_obj * dest, const msg_categories_obj * src); + + void msg_categories_zero(msg_categories_obj * obj); + + unsigned int msg_categories_isZero(const msg_categories_obj * obj); + + msg_categories_cfg * msg_categories_cfg_construct(void); + + void msg_categories_cfg_destroy(msg_categories_cfg * msg_categories_config); + + void msg_categories_cfg_printf(const msg_categories_cfg * msg_categories_config); + +#endif \ No newline at end of file diff --git a/src/message/msg_hops.c b/src/message/msg_hops.c new file mode 100644 index 0000000..779ee08 --- /dev/null +++ b/src/message/msg_hops.c @@ -0,0 +1,82 @@ + + #include "msg_hops.h" + + msg_hops_obj * msg_hops_construct(const msg_hops_cfg * msg_hops_config) { + + msg_hops_obj * obj; + + obj = (msg_hops_obj *) malloc(sizeof(msg_hops_obj)); + + obj->timeStamp = 0; + obj->fS = msg_hops_config->fS; + obj->hops = hops_construct_zero(msg_hops_config->nChannels, msg_hops_config->hopSize); + + return obj; + + } + + void msg_hops_destroy(msg_hops_obj * obj) { + + hops_destroy(obj->hops); + free((void *) obj); + + } + + void msg_hops_copy(msg_hops_obj * dest, const msg_hops_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + hops_copy(dest->hops, src->hops); + + } + + void msg_hops_zero(msg_hops_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + hops_zero(obj->hops); + + } + + unsigned int msg_hops_isZero(const msg_hops_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_hops_cfg * msg_hops_cfg_construct(void) { + + msg_hops_cfg * cfg; + + cfg = (msg_hops_cfg *) malloc(sizeof(msg_hops_cfg)); + + cfg->hopSize = 0; + cfg->nChannels = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_hops_cfg_destroy(msg_hops_cfg * msg_hops_config) { + + free((void *) msg_hops_config); + + } + + void msg_hops_cfg_printf(const msg_hops_cfg * msg_hops_config) { + + printf("hopSize = %u\n", msg_hops_config->hopSize); + printf("nChannels = %u\n", msg_hops_config->nChannels); + printf("fS = %u\n", msg_hops_config->fS); + + } diff --git a/src/message/msg_hops.h b/src/message/msg_hops.h new file mode 100644 index 0000000..1345dd1 --- /dev/null +++ b/src/message/msg_hops.h @@ -0,0 +1,40 @@ +#ifndef __ODAS_MESSAGE_HOPS +#define __ODAS_MESSAGE_HOPS + + #include + #include "../signal/hop.h" + #include "../utils/fifo.h" + + typedef struct msg_hops_obj { + + unsigned long long timeStamp; + unsigned int fS; + hops_obj * hops; + + } msg_hops_obj; + + typedef struct msg_hops_cfg { + + unsigned int hopSize; + unsigned int nChannels; + unsigned int fS; + + } msg_hops_cfg; + + msg_hops_obj * msg_hops_construct(const msg_hops_cfg * msg_hops_config); + + void msg_hops_destroy(msg_hops_obj * obj); + + void msg_hops_copy(msg_hops_obj * dest, const msg_hops_obj * src); + + void msg_hops_zero(msg_hops_obj * obj); + + unsigned int msg_hops_isZero(const msg_hops_obj * obj); + + msg_hops_cfg * msg_hops_cfg_construct(void); + + void msg_hops_cfg_destroy(msg_hops_cfg * msg_hops_config); + + void msg_hops_cfg_printf(const msg_hops_cfg * msg_hops_config); + +#endif \ No newline at end of file diff --git a/src/message/msg_pots.c b/src/message/msg_pots.c new file mode 100644 index 0000000..6852e51 --- /dev/null +++ b/src/message/msg_pots.c @@ -0,0 +1,80 @@ + + #include "msg_pots.h" + + msg_pots_obj * msg_pots_construct(const msg_pots_cfg * cfg) { + + msg_pots_obj * obj; + + obj = (msg_pots_obj *) malloc(sizeof(msg_pots_obj)); + + obj->timeStamp = 0; + obj->fS = cfg->fS; + obj->pots = pots_construct_zero(cfg->nPots); + + return obj; + + } + + void msg_pots_destroy(msg_pots_obj * obj) { + + pots_destroy(obj->pots); + free((void *) obj); + + } + + void msg_pots_copy(msg_pots_obj * dest, const msg_pots_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + pots_copy(dest->pots, src->pots); + + } + + void msg_pots_zero(msg_pots_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + pots_zero(obj->pots); + + } + + unsigned int msg_pots_isZero(const msg_pots_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_pots_cfg * msg_pots_cfg_construct(void) { + + msg_pots_cfg * cfg; + + cfg = (msg_pots_cfg *) malloc(sizeof(msg_pots_cfg)); + + cfg->nPots = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_pots_cfg_destroy(msg_pots_cfg * cfg) { + + free((void *) cfg); + + } + + void msg_pots_cfg_printf(const msg_pots_cfg * msg_pots_config) { + + printf("nPots = %u\n", msg_pots_config->nPots); + printf("fS = %u\n", msg_pots_config->fS); + + } \ No newline at end of file diff --git a/src/message/msg_pots.h b/src/message/msg_pots.h new file mode 100644 index 0000000..a016b67 --- /dev/null +++ b/src/message/msg_pots.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_MESSAGE_POTS +#define __ODAS_MESSAGE_POTS + + #include + #include "../signal/pot.h" + + typedef struct msg_pots_obj { + + unsigned long long timeStamp; + unsigned int fS; + pots_obj * pots; + + } msg_pots_obj; + + typedef struct msg_pots_cfg { + + unsigned int nPots; + unsigned int fS; + + } msg_pots_cfg; + + msg_pots_obj * msg_pots_construct(const msg_pots_cfg * cfg); + + void msg_pots_destroy(msg_pots_obj * obj); + + void msg_pots_copy(msg_pots_obj * dest, const msg_pots_obj * src); + + void msg_pots_zero(msg_pots_obj * obj); + + unsigned int msg_pots_isZero(const msg_pots_obj * obj); + + msg_pots_cfg * msg_pots_cfg_construct(void); + + void msg_pots_cfg_destroy(msg_pots_cfg * cfg); + + void msg_pots_cfg_printf(const msg_pots_cfg * msg_pots_config); + +#endif \ No newline at end of file diff --git a/src/message/msg_powers.c b/src/message/msg_powers.c new file mode 100644 index 0000000..6eff2b1 --- /dev/null +++ b/src/message/msg_powers.c @@ -0,0 +1,91 @@ + + #include "msg_powers.h" + + msg_powers_obj * msg_powers_construct(const msg_powers_cfg * msg_powers_config) { + + msg_powers_obj * obj; + + obj = (msg_powers_obj *) malloc(sizeof(msg_powers_obj)); + + obj->timeStamp = 0; + obj->fS = msg_powers_config->fS; + obj->envs = envs_construct_zero(msg_powers_config->nChannels, msg_powers_config->halfFrameSize); + + return obj; + + } + + void msg_powers_destroy(msg_powers_obj * obj) { + + envs_destroy(obj->envs); + free((void *) obj); + + } + + void msg_powers_copy(msg_powers_obj * dest, const msg_powers_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + envs_copy(dest->envs, src->envs); + + } + + void msg_powers_zero(msg_powers_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + envs_zero(obj->envs); + + } + + unsigned int msg_powers_isZero(const msg_powers_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_powers_cfg * msg_powers_cfg_construct(void) { + + msg_powers_cfg * cfg; + + cfg = (msg_powers_cfg *) malloc(sizeof(msg_powers_cfg)); + + cfg->halfFrameSize = 0; + cfg->nChannels = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_powers_cfg_destroy(msg_powers_cfg * msg_powers_config) { + + free((void *) msg_powers_config); + + } + + void msg_powers_cfg_printf(const msg_powers_cfg * msg_powers_config) { + + if (msg_powers_config != NULL) { + + printf("halfFrameSize = %u\n", msg_powers_config->halfFrameSize); + printf("nChannels = %u\n", msg_powers_config->nChannels); + printf("fS = %u\n", msg_powers_config->fS); + + } + else { + + printf("(null)\n"); + + } + + } \ No newline at end of file diff --git a/src/message/msg_powers.h b/src/message/msg_powers.h new file mode 100644 index 0000000..6c3635a --- /dev/null +++ b/src/message/msg_powers.h @@ -0,0 +1,40 @@ +#ifndef __ODAS_MESSAGE_POWERS +#define __ODAS_MESSAGE_POWERS + + #include + + #include "../signal/env.h" + + typedef struct msg_powers_obj { + + unsigned long long timeStamp; + unsigned int fS; + envs_obj * envs; + + } msg_powers_obj; + + typedef struct msg_powers_cfg { + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + } msg_powers_cfg; + + msg_powers_obj * msg_powers_construct(const msg_powers_cfg * msg_powers_config); + + void msg_powers_destroy(msg_powers_obj * obj); + + void msg_powers_copy(msg_powers_obj * dest, const msg_powers_obj * src); + + void msg_powers_zero(msg_powers_obj * obj); + + unsigned int msg_powers_isZero(const msg_powers_obj * obj); + + msg_powers_cfg * msg_powers_cfg_construct(void); + + void msg_powers_cfg_destroy(msg_powers_cfg * msg_powers_config); + + void msg_powers_cfg_printf(const msg_powers_cfg * msg_powers_config); + +#endif \ No newline at end of file diff --git a/src/message/msg_spectra.c b/src/message/msg_spectra.c new file mode 100644 index 0000000..a42a81e --- /dev/null +++ b/src/message/msg_spectra.c @@ -0,0 +1,91 @@ + + #include "msg_spectra.h" + + msg_spectra_obj * msg_spectra_construct(const msg_spectra_cfg * msg_spectra_config) { + + msg_spectra_obj * obj; + + obj = (msg_spectra_obj *) malloc(sizeof(msg_spectra_obj)); + + obj->timeStamp = 0; + obj->fS = msg_spectra_config->fS; + obj->freqs = freqs_construct_zero(msg_spectra_config->nChannels, msg_spectra_config->halfFrameSize); + + return obj; + + } + + void msg_spectra_destroy(msg_spectra_obj * obj) { + + freqs_destroy(obj->freqs); + free((void *) obj); + + } + + void msg_spectra_copy(msg_spectra_obj * dest, const msg_spectra_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + freqs_copy(dest->freqs, src->freqs); + + } + + void msg_spectra_zero(msg_spectra_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + freqs_zero(obj->freqs); + + } + + unsigned int msg_spectra_isZero(const msg_spectra_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_spectra_cfg * msg_spectra_cfg_construct(void) { + + msg_spectra_cfg * cfg; + + cfg = (msg_spectra_cfg *) malloc(sizeof(msg_spectra_cfg)); + + cfg->halfFrameSize = 0; + cfg->nChannels = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_spectra_cfg_destroy(msg_spectra_cfg * msg_spectra_config) { + + free((void *) msg_spectra_config); + + } + + void msg_spectra_cfg_printf(const msg_spectra_cfg * msg_spectra_config) { + + if (msg_spectra_config != NULL) { + + printf("halfFrameSize = %u\n", msg_spectra_config->halfFrameSize); + printf("nChannels = %u\n", msg_spectra_config->nChannels); + printf("fS = %u\n", msg_spectra_config->fS); + + } + else { + + printf("(null)\n"); + + } + + } \ No newline at end of file diff --git a/src/message/msg_spectra.h b/src/message/msg_spectra.h new file mode 100644 index 0000000..36e3d6b --- /dev/null +++ b/src/message/msg_spectra.h @@ -0,0 +1,40 @@ +#ifndef __ODAS_MESSAGE_SPECTRA +#define __ODAS_MESSAGE_SPECTRA + + #include + + #include "../signal/freq.h" + + typedef struct msg_spectra_obj { + + unsigned long long timeStamp; + unsigned int fS; + freqs_obj * freqs; + + } msg_spectra_obj; + + typedef struct msg_spectra_cfg { + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + } msg_spectra_cfg; + + msg_spectra_obj * msg_spectra_construct(const msg_spectra_cfg * msg_spectra_config); + + void msg_spectra_destroy(msg_spectra_obj * obj); + + void msg_spectra_copy(msg_spectra_obj * dest, const msg_spectra_obj * src); + + void msg_spectra_zero(msg_spectra_obj * obj); + + unsigned int msg_spectra_isZero(const msg_spectra_obj * obj); + + msg_spectra_cfg * msg_spectra_cfg_construct(void); + + void msg_spectra_cfg_destroy(msg_spectra_cfg * msg_spectra_config); + + void msg_spectra_cfg_printf(const msg_spectra_cfg * msg_spectra_config); + +#endif \ No newline at end of file diff --git a/src/message/msg_targets.c b/src/message/msg_targets.c new file mode 100644 index 0000000..10ba405 --- /dev/null +++ b/src/message/msg_targets.c @@ -0,0 +1,80 @@ + + #include "msg_targets.h" + + msg_targets_obj * msg_targets_construct(const msg_targets_cfg * cfg) { + + msg_targets_obj * obj; + + obj = (msg_targets_obj *) malloc(sizeof(msg_targets_obj)); + + obj->timeStamp = 0; + obj->fS = cfg->fS; + obj->targets = targets_construct_zero(cfg->nTargets); + + return obj; + + } + + void msg_targets_destroy(msg_targets_obj * obj) { + + targets_destroy(obj->targets); + free((void *) obj); + + } + + void msg_targets_copy(msg_targets_obj * dest, const msg_targets_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + targets_copy(dest->targets, src->targets); + + } + + void msg_targets_zero(msg_targets_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + targets_zero(obj->targets); + + } + + unsigned int msg_targets_isZero(const msg_targets_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_targets_cfg * msg_targets_cfg_construct(void) { + + msg_targets_cfg * cfg; + + cfg = (msg_targets_cfg *) malloc(sizeof(msg_targets_cfg)); + + cfg->nTargets = 0; + cfg->fS = 0; + + return cfg; + + } + + void msg_targets_cfg_destroy(msg_targets_cfg * cfg) { + + free((void *) cfg); + + } + + void msg_targets_cfg_printf(const msg_targets_cfg * msg_targets_config) { + + printf("nTargets = %u\n", msg_targets_config->nTargets); + printf("fS = %u\n", msg_targets_config->fS); + + } \ No newline at end of file diff --git a/src/message/msg_targets.h b/src/message/msg_targets.h new file mode 100644 index 0000000..c0feeee --- /dev/null +++ b/src/message/msg_targets.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_MESSAGE_TARGETS +#define __ODAS_MESSAGE_TARGETS + + #include + #include "../signal/target.h" + + typedef struct msg_targets_obj { + + unsigned long long timeStamp; + unsigned int fS; + targets_obj * targets; + + } msg_targets_obj; + + typedef struct msg_targets_cfg { + + unsigned int nTargets; + unsigned int fS; + + } msg_targets_cfg; + + msg_targets_obj * msg_targets_construct(const msg_targets_cfg * cfg); + + void msg_targets_destroy(msg_targets_obj * obj); + + void msg_targets_copy(msg_targets_obj * dest, const msg_targets_obj * src); + + void msg_targets_zero(msg_targets_obj * obj); + + unsigned int msg_targets_isZero(const msg_targets_obj * obj); + + msg_targets_cfg * msg_targets_cfg_construct(void); + + void msg_targets_cfg_destroy(msg_targets_cfg * cfg); + + void msg_targets_cfg_printf(const msg_targets_cfg * msg_targets_config); + +#endif \ No newline at end of file diff --git a/src/message/msg_tracks.c b/src/message/msg_tracks.c new file mode 100644 index 0000000..aa15a5b --- /dev/null +++ b/src/message/msg_tracks.c @@ -0,0 +1,79 @@ + + #include "msg_tracks.h" + + msg_tracks_obj * msg_tracks_construct(const msg_tracks_cfg * cfg) { + + msg_tracks_obj * obj; + + obj = (msg_tracks_obj *) malloc(sizeof(msg_tracks_obj)); + + obj->timeStamp = 0; + obj->fS = cfg->fS; + obj->tracks = tracks_construct_zero(cfg->nTracks); + + return obj; + + } + + void msg_tracks_destroy(msg_tracks_obj * obj) { + + tracks_destroy(obj->tracks); + free((void *) obj); + + } + + void msg_tracks_copy(msg_tracks_obj * dest, const msg_tracks_obj * src) { + + dest->timeStamp = src->timeStamp; + dest->fS = src->fS; + tracks_copy(dest->tracks, src->tracks); + + } + + void msg_tracks_zero(msg_tracks_obj * obj) { + + obj->timeStamp = 0; + obj->fS = 0; + tracks_zero(obj->tracks); + + } + + unsigned int msg_tracks_isZero(const msg_tracks_obj * obj) { + + unsigned int rtnValue; + + if (obj->timeStamp == 0) { + rtnValue = 1; + } + else { + rtnValue = 0; + } + + return rtnValue; + + } + + msg_tracks_cfg * msg_tracks_cfg_construct(void) { + + msg_tracks_cfg * cfg; + + cfg = (msg_tracks_cfg *) malloc(sizeof(msg_tracks_cfg)); + + cfg->nTracks = 0; + + return cfg; + + } + + void msg_tracks_cfg_destroy(msg_tracks_cfg * cfg) { + + free((void *) cfg); + + } + + void msg_tracks_cfg_printf(const msg_tracks_cfg * msg_tracks_config) { + + printf("nTracks = %u\n", msg_tracks_config->nTracks); + printf("fS = %u\n", msg_tracks_config->fS); + + } \ No newline at end of file diff --git a/src/message/msg_tracks.h b/src/message/msg_tracks.h new file mode 100644 index 0000000..8258136 --- /dev/null +++ b/src/message/msg_tracks.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_MESSAGE_TRACKS +#define __ODAS_MESSAGE_TRACKS + + #include + #include "../signal/track.h" + + typedef struct msg_tracks_obj { + + unsigned long long timeStamp; + unsigned int fS; + tracks_obj * tracks; + + } msg_tracks_obj; + + typedef struct msg_tracks_cfg { + + unsigned int nTracks; + unsigned int fS; + + } msg_tracks_cfg; + + msg_tracks_obj * msg_tracks_construct(const msg_tracks_cfg * cfg); + + void msg_tracks_destroy(msg_tracks_obj * obj); + + void msg_tracks_copy(msg_tracks_obj * dest, const msg_tracks_obj * src); + + void msg_tracks_zero(msg_tracks_obj * obj); + + unsigned int msg_tracks_isZero(const msg_tracks_obj * obj); + + msg_tracks_cfg * msg_tracks_cfg_construct(void); + + void msg_tracks_cfg_destroy(msg_tracks_cfg * cfg); + + void msg_tracks_cfg_printf(const msg_tracks_cfg * msg_tracks_config); + +#endif \ No newline at end of file diff --git a/src/module/mod_classify.c b/src/module/mod_classify.c new file mode 100644 index 0000000..fc8c0da --- /dev/null +++ b/src/module/mod_classify.c @@ -0,0 +1,136 @@ + + #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_tracks_cfg * msg_tracks_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); + + obj->in1 = (msg_hops_obj *) NULL; + obj->in2 = (msg_tracks_obj *) NULL; + obj->out = (msg_categories_obj *) NULL; + + 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); + + free((void *) obj); + + } + + int mod_classify_process(mod_classify_obj * obj) { + + int rtnValue; + + if (obj->in1->timeStamp != obj->in2->timeStamp) { + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + } + + if (msg_hops_isZero(obj->in1) == 0) { + + hop2frame_process(obj->hop2frame, obj->in1->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->in2->tracks, obj->out->categories); + + obj->out->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_categories_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_classify_connect(mod_classify_obj * obj, msg_hops_obj * in1, msg_tracks_obj * in2, msg_categories_obj * out) { + + obj->in1 = in1; + obj->in2 = in2; + obj->out = out; + + } + + void mod_classify_disconnect(mod_classify_obj * obj) { + + obj->in1 = (msg_hops_obj *) NULL; + obj->in2 = (msg_tracks_obj *) NULL; + obj->out = (msg_categories_obj *) NULL; + + } + + mod_classify_cfg * mod_classify_cfg_construct(void) { + + mod_classify_cfg * cfg; + + cfg = (mod_classify_cfg *) malloc(sizeof(mod_classify_cfg)); + + return cfg; + + } + + void mod_classify_cfg_destroy(mod_classify_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_classify_cfg_printf(const mod_classify_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_classify.h b/src/module/mod_classify.h new file mode 100644 index 0000000..f9d1009 --- /dev/null +++ b/src/module/mod_classify.h @@ -0,0 +1,74 @@ +#ifndef __ODAS_MODULE_CLASSIFY +#define __ODAS_MODULE_CLASSIFY + + #include + #include + + #include "../message/msg_hops.h" + #include "../message/msg_tracks.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 * in1; + msg_tracks_obj * in2; + 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_tracks_cfg * msg_tracks_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 * in1, msg_tracks_obj * in2, msg_categories_obj * out); + + void mod_classify_disconnect(mod_classify_obj * obj); + + mod_classify_cfg * mod_classify_cfg_construct(void); + + void mod_classify_cfg_destroy(mod_classify_cfg * cfg); + + void mod_classify_cfg_printf(const mod_classify_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_istft.c b/src/module/mod_istft.c new file mode 100644 index 0000000..e7411a7 --- /dev/null +++ b/src/module/mod_istft.c @@ -0,0 +1,89 @@ + + #include "mod_istft.h" + + mod_istft_obj * mod_istft_construct(const mod_istft_cfg * mod_istft_config, const msg_spectra_cfg * msg_spectra_config, const msg_hops_cfg * msg_hops_config) { + + mod_istft_obj * obj; + + obj = (mod_istft_obj *) malloc(sizeof(mod_istft_obj)); + + obj->freq2frame = freq2frame_construct_zero(2*(msg_spectra_config->halfFrameSize-1), msg_spectra_config->halfFrameSize); + obj->frames = frames_construct_zero(msg_hops_config->nChannels,2*(msg_spectra_config->halfFrameSize-1)); + obj->frame2hop = frame2hop_construct_zero(msg_hops_config->hopSize, 2*(msg_spectra_config->halfFrameSize-1), msg_hops_config->nChannels); + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void mod_istft_destroy(mod_istft_obj * obj) { + + freq2frame_destroy(obj->freq2frame); + frames_destroy(obj->frames); + frame2hop_destroy(obj->frame2hop); + + free((void *) obj); + + } + + int mod_istft_process(mod_istft_obj * obj) { + + int rtnValue; + + if (msg_spectra_isZero(obj->in) == 0) { + + freq2frame_process(obj->freq2frame, obj->in->freqs, obj->frames); + frame2hop_process(obj->frame2hop, obj->frames, obj->out->hops); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_hops_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_istft_connect(mod_istft_obj * obj, msg_spectra_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_istft_disconnect(mod_istft_obj * obj) { + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_istft_cfg * mod_istft_cfg_construct(void) { + + mod_istft_cfg * cfg; + + cfg = (mod_istft_cfg *) malloc(sizeof(mod_istft_cfg)); + + return cfg; + + } + + void mod_istft_cfg_destroy(mod_istft_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_istft_cfg_printf(const mod_istft_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_istft.h b/src/module/mod_istft.h new file mode 100644 index 0000000..fd0d9b0 --- /dev/null +++ b/src/module/mod_istft.h @@ -0,0 +1,42 @@ +#ifndef __ODAS_MODULE_ISTFT +#define __ODAS_MODULE_ISTFT + + #include "../system/freq2frame.h" + #include "../signal/frame.h" + #include "../system/frame2hop.h" + + #include "../message/msg_hops.h" + #include "../message/msg_spectra.h" + + typedef struct mod_istft_obj { + + freq2frame_obj * freq2frame; + frames_obj * frames; + frame2hop_obj * frame2hop; + + msg_spectra_obj * in; + msg_hops_obj * out; + + } mod_istft_obj; + + typedef struct mod_istft_cfg { + + } mod_istft_cfg; + + mod_istft_obj * mod_istft_construct(const mod_istft_cfg * mod_istft_config, const msg_spectra_cfg * msg_spectra_config, const msg_hops_cfg * msg_hops_config); + + void mod_istft_destroy(mod_istft_obj * obj); + + int mod_istft_process(mod_istft_obj * obj); + + void mod_istft_connect(mod_istft_obj * obj, msg_spectra_obj * in, msg_hops_obj * out); + + void mod_istft_disconnect(mod_istft_obj * obj); + + mod_istft_cfg * mod_istft_cfg_construct(void); + + void mod_istft_cfg_destroy(mod_istft_cfg * cfg); + + void mod_istft_cfg_printf(const mod_istft_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_mapping.c b/src/module/mod_mapping.c new file mode 100644 index 0000000..42e5d61 --- /dev/null +++ b/src/module/mod_mapping.c @@ -0,0 +1,97 @@ + + #include "mod_mapping.h" + + mod_mapping_obj * mod_mapping_construct(const mod_mapping_cfg * mod_mapping_config, const msg_hops_cfg * msg_hops_config) { + + mod_mapping_obj * obj; + unsigned int iLink; + + obj = (mod_mapping_obj *) malloc(sizeof(mod_mapping_obj)); + + obj->hop2hop_multiplex = hop2hop_multiplex_construct_zero(msg_hops_config->hopSize); + obj->links = links_clone(mod_mapping_config->links); + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void mod_mapping_destroy(mod_mapping_obj * obj) { + + links_destroy(obj->links); + hop2hop_multiplex_destroy(obj->hop2hop_multiplex); + free((void *) obj); + + } + + int mod_mapping_process(mod_mapping_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + hop2hop_multiplex_process(obj->hop2hop_multiplex, + obj->links, + obj->in->hops, + obj->out->hops); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_hops_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_mapping_connect(mod_mapping_obj * obj, msg_hops_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_mapping_disconnect(mod_mapping_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_mapping_cfg * mod_mapping_cfg_construct(void) { + + mod_mapping_cfg * cfg; + + cfg = (mod_mapping_cfg *) malloc(sizeof(mod_mapping_cfg)); + + cfg->links = (links_obj *) NULL; + + return cfg; + + } + + void mod_mapping_cfg_destroy(mod_mapping_cfg * cfg) { + + if (cfg->links != NULL) { + links_destroy(cfg->links); + } + + free((void *) cfg); + + } + + void mod_mapping_cfg_printf(const mod_mapping_cfg * cfg) { + + printf("links:"); links_printf(cfg->links); + + } \ No newline at end of file diff --git a/src/module/mod_mapping.h b/src/module/mod_mapping.h new file mode 100644 index 0000000..76c3abb --- /dev/null +++ b/src/module/mod_mapping.h @@ -0,0 +1,42 @@ +#ifndef __ODAS_MODULE_MAPPING +#define __ODAS_MODULE_MAPPING + + #include "../message/msg_hops.h" + #include "../message/msg_spectra.h" + + #include "../general/link.h" + #include "../system/hop2hop.h" + + typedef struct mod_mapping_obj { + + hop2hop_multiplex_obj * hop2hop_multiplex; + links_obj * links; + + msg_hops_obj * in; + msg_hops_obj * out; + + } mod_mapping_obj; + + typedef struct mod_mapping_cfg { + + links_obj * links; + + } mod_mapping_cfg; + + mod_mapping_obj * mod_mapping_construct(const mod_mapping_cfg * mod_mapping_config, const msg_hops_cfg * msg_hops_config); + + void mod_mapping_destroy(mod_mapping_obj * obj); + + int mod_mapping_process(mod_mapping_obj * obj); + + void mod_mapping_connect(mod_mapping_obj * obj, msg_hops_obj * in, msg_hops_obj * out); + + void mod_mapping_disconnect(mod_mapping_obj * obj); + + mod_mapping_cfg * mod_mapping_cfg_construct(void); + + void mod_mapping_cfg_destroy(mod_mapping_cfg * cfg); + + void mod_mapping_cfg_printf(const mod_mapping_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_noise.c b/src/module/mod_noise.c new file mode 100644 index 0000000..fbaf48a --- /dev/null +++ b/src/module/mod_noise.c @@ -0,0 +1,107 @@ + + #include "mod_noise.h" + + mod_noise_obj * mod_noise_construct(const mod_noise_cfg * mod_noise_config, const msg_spectra_cfg * msg_spectra_config, const msg_powers_cfg * msg_powers_config) { + + mod_noise_obj * obj; + + obj = (mod_noise_obj *) malloc(sizeof(mod_noise_obj)); + + obj->freq2env = freq2env_construct_zero(msg_spectra_config->halfFrameSize); + + obj->envs = envs_construct_zero(msg_powers_config->nChannels, + msg_powers_config->halfFrameSize); + + obj->env2env_mcra = env2env_mcra_construct_zero(msg_powers_config->nChannels, + msg_powers_config->halfFrameSize, + mod_noise_config->bSize, + mod_noise_config->alphaS, + mod_noise_config->L, + mod_noise_config->delta, + mod_noise_config->alphaD); + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_powers_obj *) NULL; + + return obj; + + } + + void mod_noise_destroy(mod_noise_obj * obj) { + + freq2env_destroy(obj->freq2env); + envs_destroy(obj->envs); + env2env_mcra_destroy(obj->env2env_mcra); + + free((void *) obj); + + } + + int mod_noise_process(mod_noise_obj * obj) { + + int rtnValue; + + if (msg_spectra_isZero(obj->in) == 0) { + + freq2env_process(obj->freq2env, + obj->in->freqs, + obj->envs); + + env2env_mcra_process(obj->env2env_mcra, + NULL, + obj->envs, + NULL, + obj->out->envs); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_powers_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_noise_connect(mod_noise_obj * obj, msg_spectra_obj * in, msg_powers_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_noise_disconnect(mod_noise_obj * obj) { + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_powers_obj *) NULL; + + } + + mod_noise_cfg * mod_noise_cfg_construct(void) { + + mod_noise_cfg * cfg; + + cfg = (mod_noise_cfg *) malloc(sizeof(mod_noise_cfg)); + + return cfg; + + } + + void mod_noise_cfg_destroy(mod_noise_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_noise_cfg_printf(const mod_noise_cfg * cfg) { + + + + } \ No newline at end of file diff --git a/src/module/mod_noise.h b/src/module/mod_noise.h new file mode 100644 index 0000000..f09438e --- /dev/null +++ b/src/module/mod_noise.h @@ -0,0 +1,46 @@ +#ifndef __ODAS_MODULE_NOISE +#define __ODAS_MODULE_NOISE + + #include "../system/freq2env.h" + #include "../system/env2env.h" + #include "../message/msg_spectra.h" + #include "../message/msg_powers.h" + + typedef struct mod_noise_obj { + + freq2env_obj * freq2env; + envs_obj * envs; + env2env_mcra_obj * env2env_mcra; + + msg_spectra_obj * in; + msg_powers_obj * out; + + } mod_noise_obj; + + typedef struct mod_noise_cfg { + + unsigned int bSize; + float alphaS; + unsigned int L; + float delta; + float alphaD; + + } mod_noise_cfg; + + mod_noise_obj * mod_noise_construct(const mod_noise_cfg * mod_noise_config, const msg_spectra_cfg * msg_spectra_config, const msg_powers_cfg * msg_powers_config); + + void mod_noise_destroy(mod_noise_obj * obj); + + int mod_noise_process(mod_noise_obj * obj); + + void mod_noise_connect(mod_noise_obj * obj, msg_spectra_obj * in, msg_powers_obj * out); + + void mod_noise_disconnect(mod_noise_obj * obj); + + mod_noise_cfg * mod_noise_cfg_construct(void); + + void mod_noise_cfg_destroy(mod_noise_cfg * cfg); + + void mod_noise_cfg_printf(const mod_noise_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_resample.c b/src/module/mod_resample.c new file mode 100644 index 0000000..07d0ee8 --- /dev/null +++ b/src/module/mod_resample.c @@ -0,0 +1,475 @@ + + #include "mod_resample.h" + + mod_resample_obj * mod_resample_construct(const mod_resample_cfg * mod_resample_config, const msg_hops_cfg * msg_hops_in_config, const msg_hops_cfg * msg_hops_out_config) { + + mod_resample_obj * obj; + + obj = (mod_resample_obj *) malloc(sizeof(mod_resample_obj)); + + obj->timeStamp = 0; + obj->noMorePush = 0; + + if (mod_resample_config->fSin == mod_resample_config->fSout) { + obj->type = 's'; + } + if (mod_resample_config->fSin > mod_resample_config->fSout) { + obj->type = 'd'; + } + if (mod_resample_config->fSin < mod_resample_config->fSout) { + obj->type = 'u'; + } + + obj->nChannels = msg_hops_in_config->nChannels; + obj->fSin = mod_resample_config->fSin; + obj->fSout = mod_resample_config->fSout; + obj->hopSizeIn = msg_hops_in_config->hopSize; + obj->hopSizeOut = msg_hops_out_config->hopSize; + obj->ratio = ((float) obj->fSout) / ((float) obj->fSin); + + switch (obj->type) { + + case 'd': + + obj->frameSize = obj->hopSizeIn * 2; + obj->halfFrameSize = obj->frameSize / 2 + 1; + obj->lowPassCut = (unsigned int) floorf(((float) (obj->frameSize/2)) * obj->ratio); + + obj->hop2hop = hop2hop_buffer_construct_zero(obj->nChannels, obj->hopSizeIn, obj->hopSizeOut, obj->ratio); + + obj->hop2frame = hop2frame_construct_zero(obj->hopSizeIn, obj->frameSize, obj->nChannels); + obj->framesAnalysis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2freq = frame2freq_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->freqsAnalysis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2freq_lowpass = freq2freq_lowpass_construct_zero(obj->halfFrameSize, obj->lowPassCut); + obj->freqsSynthesis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2frame = freq2frame_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->framesSynthesis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2hop = frame2hop_construct_zero(obj->hopSizeIn, obj->frameSize, obj->nChannels); + obj->hops = hops_construct_zero(obj->nChannels, obj->hopSizeIn); + + break; + + case 'u': + + obj->frameSize = obj->hopSizeOut * 2; + obj->halfFrameSize = obj->frameSize / 2 + 1; + obj->lowPassCut = (unsigned int) floorf(((float) (obj->frameSize/2)) / obj->ratio); + + obj->hop2hop = hop2hop_buffer_construct_zero(obj->nChannels, obj->hopSizeIn, obj->hopSizeOut, obj->ratio); + + obj->hop2frame = hop2frame_construct_zero(obj->hopSizeOut, obj->frameSize, obj->nChannels); + obj->framesAnalysis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2freq = frame2freq_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->freqsAnalysis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2freq_lowpass = freq2freq_lowpass_construct_zero(obj->halfFrameSize, obj-> lowPassCut); + obj->freqsSynthesis = freqs_construct_zero(obj->nChannels, obj->halfFrameSize); + obj->freq2frame = freq2frame_construct_zero(obj->frameSize, obj->halfFrameSize); + obj->framesSynthesis = frames_construct_zero(obj->nChannels, obj->frameSize); + obj->frame2hop = frame2hop_construct_zero(obj->hopSizeOut, obj->frameSize, obj->nChannels); + obj->hops = hops_construct_zero(obj->nChannels, obj->hopSizeOut); + + break; + + case 's': + + obj->frameSize = 0; + obj->halfFrameSize = 0; + obj->lowPassCut = 0; + + obj->hop2hop = hop2hop_buffer_construct_zero(obj->nChannels, obj->hopSizeIn, obj->hopSizeOut, obj->ratio); + + obj->hop2frame = (hop2frame_obj *) NULL; + obj->framesAnalysis = (frames_obj *) NULL; + obj->frame2freq = (frame2freq_obj *) NULL; + obj->freqsAnalysis = (freqs_obj *) NULL; + obj->freq2freq_lowpass = (freq2freq_lowpass_obj *) NULL; + obj->freqsSynthesis = (freqs_obj *) NULL; + obj->freq2frame = (freq2frame_obj *) NULL; + obj->framesSynthesis = (frames_obj *) NULL; + obj->frame2hop = (frame2hop_obj *) NULL; + obj->hops = (hops_obj *) NULL; + + break; + + } + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void mod_resample_destroy(mod_resample_obj * obj) { + + if (obj->hop2hop != NULL) { + hop2hop_buffer_destroy(obj->hop2hop); + } + + if (obj->hop2frame != NULL) { + hop2frame_destroy(obj->hop2frame); + } + + if (obj->framesAnalysis != NULL) { + frames_destroy(obj->framesAnalysis); + } + + if (obj->frame2freq != NULL) { + frame2freq_destroy(obj->frame2freq); + } + + if (obj->freqsAnalysis != NULL) { + freqs_destroy(obj->freqsAnalysis); + } + + if (obj->freq2freq_lowpass != NULL) { + freq2freq_lowpass_destroy(obj->freq2freq_lowpass); + } + + if (obj->freqsSynthesis != NULL) { + freqs_destroy(obj->freqsSynthesis); + } + + if (obj->freq2frame != NULL) { + freq2frame_destroy(obj->freq2frame); + } + + if (obj->framesSynthesis != NULL) { + frames_destroy(obj->framesSynthesis); + } + + if (obj->frame2hop != NULL) { + frame2hop_destroy(obj->frame2hop); + } + + if (obj->hops != NULL) { + hops_destroy(obj->hops); + } + + free((void *) obj); + + } + + int mod_resample_process_push(mod_resample_obj * obj) { + + int rtnValue; + + switch(obj->type) { + + case 'd': + + rtnValue = mod_resample_process_push_down(obj); + + break; + + case 'u': + + rtnValue = mod_resample_process_push_up(obj); + + break; + + case 's': + + rtnValue = mod_resample_process_push_same(obj); + + break; + + } + + return rtnValue; + + } + + int mod_resample_process_pop(mod_resample_obj * obj) { + + int rtnValue; + + switch(obj->type) { + + case 'd': + + rtnValue = mod_resample_process_pop_down(obj); + + break; + + case 'u': + + rtnValue = mod_resample_process_pop_up(obj); + + break; + + case 's': + + rtnValue = mod_resample_process_pop_same(obj); + + break; + + } + + return rtnValue; + + } + + int mod_resample_process_push_down(mod_resample_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + if (hop2hop_buffer_isFull(obj->hop2hop) == 0) { + + hop2frame_process(obj->hop2frame, + obj->in->hops, + obj->framesAnalysis); + + frame2freq_process(obj->frame2freq, + obj->framesAnalysis, + obj->freqsAnalysis); + + freq2freq_lowpass_process(obj->freq2freq_lowpass, + obj->freqsAnalysis, + obj->freqsSynthesis); + + freq2frame_process(obj->freq2frame, + obj->freqsSynthesis, + obj->framesSynthesis); + + frame2hop_process(obj->frame2hop, + obj->framesSynthesis, + obj->hops); + + hop2hop_buffer_push(obj->hop2hop, + obj->hops); + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + } + else { + + obj->noMorePush = 1; + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_resample_process_push_up(mod_resample_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + if (hop2hop_buffer_isFull(obj->hop2hop) == 0) { + + hop2hop_buffer_push(obj->hop2hop, + obj->in->hops); + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + } + else { + + obj->noMorePush = 1; + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_resample_process_push_same(mod_resample_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + if (hop2hop_buffer_isFull(obj->hop2hop) == 0) { + + hop2hop_buffer_push(obj->hop2hop, + obj->in->hops); + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + } + else { + + obj->noMorePush = 1; + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_resample_process_pop_down(mod_resample_obj * obj) { + + int rtnValue; + + if (hop2hop_buffer_isEmpty(obj->hop2hop) == 0) { + + hop2hop_buffer_pop(obj->hop2hop, + obj->out->hops); + + obj->timeStamp++; + obj->out->timeStamp = obj->timeStamp; + + rtnValue = 0; + + } + else { + + if (obj->noMorePush == 1) { + msg_hops_zero(obj->out); + } + + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_resample_process_pop_up(mod_resample_obj * obj) { + + int rtnValue; + + if (hop2hop_buffer_isEmpty(obj->hop2hop) == 0) { + + hop2hop_buffer_pop(obj->hop2hop, + obj->hops); + + hop2frame_process(obj->hop2frame, + obj->hops, + obj->framesAnalysis); + + frame2freq_process(obj->frame2freq, + obj->framesAnalysis, + obj->freqsAnalysis); + + freq2freq_lowpass_process(obj->freq2freq_lowpass, + obj->freqsAnalysis, + obj->freqsSynthesis); + + freq2frame_process(obj->freq2frame, + obj->freqsSynthesis, + obj->framesSynthesis); + + frame2hop_process(obj->frame2hop, + obj->framesSynthesis, + obj->out->hops); + + obj->timeStamp++; + obj->out->timeStamp = obj->timeStamp; + + rtnValue = 0; + + } + else { + + if (obj->noMorePush == 1) { + msg_hops_zero(obj->out); + } + + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_resample_process_pop_same(mod_resample_obj * obj) { + + int rtnValue; + + if (hop2hop_buffer_isEmpty(obj->hop2hop) == 0) { + + hop2hop_buffer_pop(obj->hop2hop, + obj->out->hops); + + obj->timeStamp++; + obj->out->timeStamp = obj->timeStamp; + + rtnValue = 0; + + } + else { + + if (obj->noMorePush == 1) { + msg_hops_zero(obj->out); + } + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_resample_connect(mod_resample_obj * obj, msg_hops_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_resample_disconnect(mod_resample_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_resample_cfg * mod_resample_cfg_construct(void) { + + mod_resample_cfg * cfg; + + cfg = (mod_resample_cfg *) malloc(sizeof(mod_resample_cfg)); + + cfg->fSin = 0; + cfg->fSout = 0; + + return cfg; + + } + + void mod_resample_cfg_destroy(mod_resample_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_resample_cfg_printf(const mod_resample_cfg * cfg) { + + printf("fSin = %u\n", cfg->fSin); + printf("fSout = %u\n", cfg->fSout); + + } diff --git a/src/module/mod_resample.h b/src/module/mod_resample.h new file mode 100644 index 0000000..f2b28b7 --- /dev/null +++ b/src/module/mod_resample.h @@ -0,0 +1,94 @@ +#ifndef __ODAS_MODULE_RS +#define __ODAS_MODULE_RS + + #include "../message/msg_hops.h" + + #include "../signal/hop.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + + #include "../system/hop2frame.h" + #include "../system/hop2hop.h" + #include "../system/frame2freq.h" + #include "../system/freq2freq.h" + #include "../system/freq2frame.h" + #include "../system/frame2hop.h" + + #include + #include + #include + + typedef struct mod_resample_obj { + + unsigned long long timeStamp; + char noMorePush; + + char type; + + unsigned int nChannels; + unsigned int fSin; + unsigned int fSout; + unsigned int hopSizeIn; + unsigned int hopSizeOut; + float ratio; + + unsigned int frameSize; + unsigned int halfFrameSize; + unsigned int lowPassCut; + + hop2hop_buffer_obj * hop2hop; + + hop2frame_obj * hop2frame; + frames_obj * framesAnalysis; + frame2freq_obj * frame2freq; + freqs_obj * freqsAnalysis; + freq2freq_lowpass_obj * freq2freq_lowpass; + freqs_obj * freqsSynthesis; + freq2frame_obj * freq2frame; + frames_obj * framesSynthesis; + frame2hop_obj * frame2hop; + hops_obj * hops; + + msg_hops_obj * in; + msg_hops_obj * out; + + } mod_resample_obj; + + typedef struct mod_resample_cfg { + + unsigned int fSin; + unsigned int fSout; + + } mod_resample_cfg; + + mod_resample_obj * mod_resample_construct(const mod_resample_cfg * mod_resample_config, const msg_hops_cfg * msg_hops_in_config, const msg_hops_cfg * msg_hops_out_config); + + void mod_resample_destroy(mod_resample_obj * obj); + + int mod_resample_process_push(mod_resample_obj * obj); + + int mod_resample_process_pop(mod_resample_obj * obj); + + int mod_resample_process_push_down(mod_resample_obj * obj); + + int mod_resample_process_push_up(mod_resample_obj * obj); + + int mod_resample_process_push_same(mod_resample_obj * obj); + + int mod_resample_process_pop_down(mod_resample_obj * obj); + + int mod_resample_process_pop_up(mod_resample_obj * obj); + + int mod_resample_process_pop_same(mod_resample_obj * obj); + + void mod_resample_connect(mod_resample_obj * obj, msg_hops_obj * in, msg_hops_obj * out); + + void mod_resample_disconnect(mod_resample_obj * obj); + + mod_resample_cfg * mod_resample_cfg_construct(void); + + void mod_resample_cfg_destroy(mod_resample_cfg * cfg); + + void mod_resample_cfg_printf(const mod_resample_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_ssl.c b/src/module/mod_ssl.c new file mode 100644 index 0000000..9db1b94 --- /dev/null +++ b/src/module/mod_ssl.c @@ -0,0 +1,336 @@ + + #include "mod_ssl.h" + + mod_ssl_obj * mod_ssl_construct(const mod_ssl_cfg * mod_ssl_config, const msg_spectra_cfg * msg_spectra_config, const msg_pots_cfg * msg_pots_config) { + + mod_ssl_obj * obj; + unsigned int iLevel; + unsigned int iPot; + + points_obj * points; + + obj = (mod_ssl_obj *) malloc(sizeof(mod_ssl_obj)); + + obj->nChannels = mod_ssl_config->mics->nChannels; + obj->nPairs = obj->nChannels * (obj->nChannels - 1) / 2; + obj->nPots = msg_pots_config->nPots; + obj->nLevels = mod_ssl_config->nLevels; + obj->frameSize = 2 * (msg_spectra_config->halfFrameSize - 1); + obj->halfFrameSize = msg_spectra_config->halfFrameSize; + obj->frameSizeInterp = obj->frameSize * mod_ssl_config->interpRate; + obj->halfFrameSizeInterp = (obj->halfFrameSize - 1) * mod_ssl_config->interpRate + 1; + obj->interpRate = mod_ssl_config->interpRate; + + obj->scans = scanning_init_scans(mod_ssl_config->mics, + mod_ssl_config->spatialfilter, + mod_ssl_config->nLevels, + mod_ssl_config->levels, + mod_ssl_config->samplerate->mu, + mod_ssl_config->soundspeed, + mod_ssl_config->nMatches, + obj->frameSize, + mod_ssl_config->deltas, + mod_ssl_config->probMin, + mod_ssl_config->nRefinedLevels, + mod_ssl_config->nThetas, + mod_ssl_config->gainMin, + mod_ssl_config->interpRate); + + obj->freq2freq_phasor = freq2freq_phasor_construct_zero(obj->halfFrameSize, + mod_ssl_config->epsilon); + + obj->phasors = freqs_construct_zero(mod_ssl_config->mics->nChannels, + msg_spectra_config->halfFrameSize); + + obj->freq2freq_product = freq2freq_product_construct_zero(obj->halfFrameSize); + + obj->products = freqs_construct_zero(mod_ssl_config->mics->nPairs, + msg_spectra_config->halfFrameSize); + + obj->freq2freq_interpolate = freq2freq_interpolate_construct_zero(obj->halfFrameSize, + obj->halfFrameSizeInterp); + + obj->productsInterp = freqs_construct_zero(mod_ssl_config->mics->nPairs, + obj->halfFrameSizeInterp); + + obj->freq2xcorr = freq2xcorr_construct_zero(obj->frameSizeInterp, + obj->halfFrameSizeInterp); + + obj->xcorrs = xcorrs_construct_zero(mod_ssl_config->mics->nPairs, + obj->frameSizeInterp); + + obj->xcorrsMax = xcorrs_construct_zero(mod_ssl_config->mics->nPairs, + obj->frameSizeInterp); + + obj->aimgs = (aimg_obj **) malloc(sizeof(aimg_obj *) * msg_pots_config->nPots); + + for (iLevel = 0; iLevel < mod_ssl_config->nLevels; iLevel++) { + + obj->aimgs[iLevel] = aimg_construct_zero(obj->scans->points[iLevel]->nPoints); + + } + + obj->xcorr2xcorr = xcorr2xcorr_construct_zero(obj->frameSizeInterp); + + obj->xcorr2aimg = (xcorr2aimg_obj **) malloc(sizeof(xcorr2aimg_obj *) * mod_ssl_config->nLevels); + + for (iLevel = 0; iLevel < mod_ssl_config->nLevels; iLevel++) { + + obj->xcorr2aimg[iLevel] = xcorr2aimg_construct_zero(obj->scans->points[iLevel]->nPoints); + + } + + obj->pots = pots_construct_zero(msg_pots_config->nPots); + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_pots_obj *) NULL; + + //obj->tmpFile = fopen("weights.bin","wb"); + + return obj; + + } + + void mod_ssl_destroy(mod_ssl_obj * obj) { + + unsigned int iLevel; + unsigned int iPot; + + //fclose(obj->tmpFile); + + scans_destroy(obj->scans); + + freq2freq_phasor_destroy(obj->freq2freq_phasor); + freq2freq_product_destroy(obj->freq2freq_product); + freq2freq_interpolate_destroy(obj->freq2freq_interpolate); + freqs_destroy(obj->phasors); + freqs_destroy(obj->products); + freqs_destroy(obj->productsInterp); + freq2xcorr_destroy(obj->freq2xcorr); + xcorrs_destroy(obj->xcorrs); + xcorrs_destroy(obj->xcorrsMax); + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + aimg_destroy(obj->aimgs[iLevel]); + } + + free((void *) obj->aimgs); + + xcorr2xcorr_destroy(obj->xcorr2xcorr); + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + xcorr2aimg_destroy(obj->xcorr2aimg[iLevel]); + } + + free((void *) obj->xcorr2aimg); + + pots_destroy(obj->pots); + + free((void *) obj); + + } + + int mod_ssl_process(mod_ssl_obj * obj) { + + int rtnValue; + unsigned int iPot; + unsigned int iLevel; + unsigned int iPoint; + + float maxValue; + unsigned int maxIndex; + + if (msg_spectra_isZero(obj->in) == 0) { + + freq2freq_phasor_process(obj->freq2freq_phasor, + obj->in->freqs, + obj->phasors); + + freq2freq_product_process(obj->freq2freq_product, + obj->phasors, + obj->phasors, + obj->scans->pairs, + obj->products); + + freq2freq_interpolate_process(obj->freq2freq_interpolate, + obj->products, + obj->productsInterp); + + freq2xcorr_process(obj->freq2xcorr, + obj->productsInterp, + obj->scans->pairs, + obj->xcorrs); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + if (iPot > 0) { + + xcorr2xcorr_process_reset(obj->xcorr2xcorr, + obj->scans->tdoas[obj->nLevels-1], + obj->scans->deltas[obj->nLevels-1], + obj->scans->pairs, + maxIndex, + obj->xcorrs); + + } + + maxIndex = 0; + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + + xcorr2xcorr_process_max(obj->xcorr2xcorr, + obj->xcorrs, + obj->scans->tdoas[iLevel], + obj->scans->deltas[iLevel], + obj->scans->pairs, + obj->xcorrsMax); + + xcorr2aimg_process(obj->xcorr2aimg[iLevel], + obj->scans->tdoas[iLevel], + obj->scans->indexes[iLevel], + obj->scans->spatialindexes[iLevel], + maxIndex, + obj->xcorrsMax, + obj->aimgs[iLevel]); + + maxValue = obj->aimgs[iLevel]->array[0]; + + for (iPoint = 0; iPoint < obj->aimgs[iLevel]->aimgSize; iPoint++) { + + if (obj->aimgs[iLevel]->array[iPoint] > maxValue) { + + maxValue = obj->aimgs[iLevel]->array[iPoint]; + maxIndex = iPoint; + + } + + } + + } + + obj->pots->array[iPot * 4 + 0] = obj->scans->points[obj->nLevels-1]->array[maxIndex * 3 + 0]; + obj->pots->array[iPot * 4 + 1] = obj->scans->points[obj->nLevels-1]->array[maxIndex * 3 + 1]; + obj->pots->array[iPot * 4 + 2] = obj->scans->points[obj->nLevels-1]->array[maxIndex * 3 + 2]; + obj->pots->array[iPot * 4 + 3] = maxValue * ((float) obj->interpRate); + + } + + memcpy(obj->out->pots->array, obj->pots->array, sizeof(float) * obj->pots->nPots * 4); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_pots_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_ssl_connect(mod_ssl_obj * obj, msg_spectra_obj * in, msg_pots_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_ssl_disconnect(mod_ssl_obj * obj) { + + obj->in = (msg_spectra_obj *) NULL; + obj->out = (msg_pots_obj *) NULL; + + } + + mod_ssl_cfg * mod_ssl_cfg_construct(void) { + + mod_ssl_cfg * cfg; + + cfg = (mod_ssl_cfg *) malloc(sizeof(mod_ssl_cfg)); + + cfg->mics = (mics_obj *) NULL; + cfg->samplerate = (samplerate_obj *) NULL; + cfg->soundspeed = (soundspeed_obj *) NULL; + cfg->spatialfilter = (spatialfilter_obj *) NULL; + + cfg->nLevels = 0;; + cfg->levels = (unsigned int *) NULL; + cfg->deltas = (unsigned int *) NULL; + cfg->nMatches = 0; + cfg->probMin = 0.0f; + cfg->nRefinedLevels = 0; + cfg->nThetas = 0; + cfg->gainMin = 0.0f; + + return cfg; + + } + + void mod_ssl_cfg_destroy(mod_ssl_cfg * cfg) { + + if (cfg->mics != NULL) { + mics_destroy(cfg->mics); + } + + if (cfg->samplerate != NULL) { + samplerate_destroy(cfg->samplerate); + } + + if (cfg->soundspeed != NULL) { + soundspeed_destroy(cfg->soundspeed); + } + + if (cfg->spatialfilter != NULL) { + spatialfilter_destroy(cfg->spatialfilter); + } + + if (cfg->levels != NULL) { + free((void *) cfg->levels); + } + + if (cfg->deltas != NULL) { + free((void *) cfg->deltas); + } + + free((void *) cfg); + + } + + void mod_ssl_cfg_printf(const mod_ssl_cfg * cfg) { + + unsigned int iLevel; + + mics_printf(cfg->mics); + samplerate_printf(cfg->samplerate); + soundspeed_printf(cfg->soundspeed); + spatialfilter_printf(cfg->spatialfilter); + + for (iLevel = 0; iLevel < cfg->nLevels; iLevel++) { + + if (iLevel == 0) { + + printf("levels = (%u): level = %u, delta = %d\n", iLevel, cfg->levels[iLevel], cfg->deltas[iLevel]); + + } + else { + + printf(" (%u): level = %u, delta = %d\n", iLevel, cfg->levels[iLevel], cfg->deltas[iLevel]); + + } + + + } + + printf("nMatches = %u\n", cfg->nMatches); + printf("probMin = %f\n", cfg->probMin); + printf("nRefinedLevels = %u\n", cfg->nRefinedLevels); + printf("nThetas = %u\n", cfg->nThetas); + printf("gainMin = %f\n", cfg->gainMin); + + } \ No newline at end of file diff --git a/src/module/mod_ssl.h b/src/module/mod_ssl.h new file mode 100644 index 0000000..74344f9 --- /dev/null +++ b/src/module/mod_ssl.h @@ -0,0 +1,104 @@ +#ifndef __ODAS_MODULE_SSL +#define __ODAS_MODULE_SSL + + #include + #include + + #include "../general/mic.h" + #include "../general/samplerate.h" + #include "../general/soundspeed.h" + #include "../general/spatialfilter.h" + + #include "../signal/aimg.h" + #include "../signal/env.h" + #include "../signal/freq.h" + #include "../signal/xcorr.h" + + #include "../system/env2env.h" + #include "../system/freq2env.h" + #include "../system/freq2freq.h" + #include "../system/freq2xcorr.h" + #include "../system/xcorr2aimg.h" + #include "../system/xcorr2xcorr.h" + + #include "../init/scanning.h" + + #include "../message/msg_spectra.h" + #include "../message/msg_powers.h" + #include "../message/msg_pots.h" + + + typedef struct mod_ssl_obj { + + unsigned int nChannels; + unsigned int nPairs; + unsigned int nPots; + unsigned int nLevels; + unsigned int frameSize; + unsigned int halfFrameSize; + unsigned int frameSizeInterp; + unsigned int halfFrameSizeInterp; + unsigned int interpRate; + + scans_obj * scans; + + freqs_obj * phasors; + freqs_obj * products; + freqs_obj * productsInterp; + xcorrs_obj * xcorrs; + xcorrs_obj * xcorrsMax; + + freq2env_obj * freq2env; + freq2freq_phasor_obj * freq2freq_phasor; + freq2freq_product_obj * freq2freq_product; + freq2freq_interpolate_obj * freq2freq_interpolate; + freq2xcorr_obj * freq2xcorr; + xcorr2xcorr_obj * xcorr2xcorr; + + aimg_obj ** aimgs; + xcorr2aimg_obj ** xcorr2aimg; + + pots_obj * pots; + + msg_spectra_obj * in; + msg_pots_obj * out; + + } mod_ssl_obj; + + typedef struct mod_ssl_cfg { + + mics_obj * mics; + samplerate_obj * samplerate; + soundspeed_obj * soundspeed; + spatialfilter_obj * spatialfilter; + + unsigned int interpRate; + float epsilon; + unsigned int nLevels; + unsigned int * levels; + signed int * deltas; + unsigned int nMatches; + float probMin; + unsigned int nRefinedLevels; + unsigned int nThetas; + float gainMin; + + } mod_ssl_cfg; + + mod_ssl_obj * mod_ssl_construct(const mod_ssl_cfg * mod_ssl_config, const msg_spectra_cfg * msg_spectra_config, const msg_pots_cfg * msg_pots_config); + + void mod_ssl_destroy(mod_ssl_obj * obj); + + int mod_ssl_process(mod_ssl_obj * obj); + + void mod_ssl_connect(mod_ssl_obj * obj, msg_spectra_obj * in, msg_pots_obj * out); + + void mod_ssl_disconnect(mod_ssl_obj * obj); + + mod_ssl_cfg * mod_ssl_cfg_construct(void); + + void mod_ssl_cfg_destroy(mod_ssl_cfg * cfg); + + void mod_ssl_cfg_printf(const mod_ssl_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_sss.c b/src/module/mod_sss.c new file mode 100644 index 0000000..c5ef5dc --- /dev/null +++ b/src/module/mod_sss.c @@ -0,0 +1,726 @@ + + #include "mod_sss.h" + + mod_sss_obj * mod_sss_construct(const mod_sss_cfg * mod_sss_config, const msg_tracks_cfg * msg_tracks_config, const msg_spectra_cfg * msg_spectra_config) { + + mod_sss_obj * obj; + + obj = (mod_sss_obj *) malloc(sizeof(mod_sss_obj)); + + obj->nSeps = msg_tracks_config->nTracks; + obj->nChannels = msg_spectra_config->nChannels; + obj->halfFrameSize = msg_spectra_config->halfFrameSize; + obj->mode_sep = mod_sss_config->mode_sep; + obj->mode_pf = mod_sss_config->mode_pf; + + switch(obj->mode_sep) { + + case 'd': + + obj->beampatterns_mics = directivity_beampattern_mics(mod_sss_config->mics, + mod_sss_config->nThetas); + + obj->beampatterns_spatialfilter = directivity_beampattern_spatialfilter(mod_sss_config->spatialfilter, + mod_sss_config->nThetas); + + obj->steers = steers_construct_zero(msg_spectra_config->halfFrameSize, + msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->gains = gains_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->masks = masks_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->tracksPrev = tracks_construct_zero(msg_tracks_config->nTracks); + + obj->tracksNow = tracks_construct_zero(msg_tracks_config->nTracks); + + obj->track2gain = track2gain_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + mod_sss_config->mics->direction, + mod_sss_config->spatialfilter->direction); + + obj->gain2mask = gain2mask_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + mod_sss_config->gainMin); + + obj->track2steer = track2steer_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize, + mod_sss_config->soundspeed->mu, + mod_sss_config->samplerate->mu, + mod_sss_config->mics->mu); + + obj->steer2demixing_ds = steer2demixing_ds_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize, + mod_sss_config->epsilon); + + obj->steer2demixing_gss = (steer2demixing_gss_obj *) NULL; + obj->steer2demixing_mvdr = (steer2demixing_mvdr_obj *) NULL; + + obj->demixingsPrev = demixings_construct_zero(msg_spectra_config->halfFrameSize, + msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->demixingsNow = demixings_construct_zero(msg_spectra_config->halfFrameSize, + msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->demixing2freq = demixing2freq_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize); + + break; + + case 'g': + + obj->beampatterns_mics = directivity_beampattern_mics(mod_sss_config->mics, + mod_sss_config->nThetas); + + obj->beampatterns_spatialfilter = directivity_beampattern_spatialfilter(mod_sss_config->spatialfilter, + mod_sss_config->nThetas); + + obj->steers = steers_construct_zero(msg_spectra_config->halfFrameSize, + msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->gains = gains_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->masks = masks_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->tracksPrev = tracks_construct_zero(msg_tracks_config->nTracks); + + obj->tracksNow = tracks_construct_zero(msg_tracks_config->nTracks); + + obj->track2gain = track2gain_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + mod_sss_config->mics->direction, + mod_sss_config->spatialfilter->direction); + + obj->gain2mask = gain2mask_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + mod_sss_config->gainMin); + + obj->track2steer = track2steer_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize, + mod_sss_config->soundspeed->mu, + mod_sss_config->samplerate->mu, + mod_sss_config->mics->mu); + + obj->steer2demixing_ds = (steer2demixing_ds_obj *) NULL; + obj->steer2demixing_gss = steer2demixing_gss_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize, + mod_sss_config->sep_gss_mu, + mod_sss_config->sep_gss_lambda, + mod_sss_config->epsilon); + obj->steer2demixing_mvdr = (steer2demixing_mvdr_obj *) NULL; + + obj->demixingsPrev = demixings_construct_zero(msg_spectra_config->halfFrameSize, + msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->demixingsNow = demixings_construct_zero(msg_spectra_config->halfFrameSize, + msg_tracks_config->nTracks, + msg_spectra_config->nChannels); + + obj->demixing2freq = demixing2freq_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize); + + break; + + case 'm': + + printf("MVDR not implemented yet.\n"); + exit(EXIT_FAILURE); + + break; + + default: + + printf("Invalid separation method.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->mode_pf) { + + case 'm': + + obj->freq2env = freq2env_construct_zero(msg_spectra_config->halfFrameSize); + + obj->noisys = envs_construct_zero(msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize); + + obj->demixing2env = demixing2env_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->nChannels, + msg_spectra_config->halfFrameSize); + + obj->noisesEst = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->env2env_mcra = env2env_mcra_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize, + mod_sss_config->pf_multi_bSize, + mod_sss_config->pf_multi_alphaS, + mod_sss_config->pf_multi_L, + mod_sss_config->pf_multi_delta, + mod_sss_config->pf_multi_alphaD); + + obj->noisesSep = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->env2env_interf = env2env_interf_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize, + mod_sss_config->pf_multi_eta, + mod_sss_config->pf_multi_alphaZ); + + obj->interfs = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->env2env_gainspeech = env2env_gainspeech_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize, + mod_sss_config->pf_multi_alphaPmin, + mod_sss_config->epsilon); + + obj->gainspeeches = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->snrs = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->vs = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->env2env_probspeech = env2env_probspeech_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize, + mod_sss_config->pf_multi_thetaWin, + mod_sss_config->pf_multi_alphaWin, + mod_sss_config->pf_multi_maxAbsenceProb, + mod_sss_config->pf_multi_Gmin, + mod_sss_config->pf_multi_winSizeLocal, + mod_sss_config->pf_multi_winSizeGlobal, + mod_sss_config->pf_multi_winSizeFrame); + + obj->probspeeches = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->env2env_gainall = env2env_gainall_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize, + mod_sss_config->pf_multi_Gmin); + + obj->gainalls = envs_construct_zero(msg_tracks_config->nTracks, + msg_spectra_config->halfFrameSize); + + obj->freq2freq_gain = freq2freq_gain_construct_zero(msg_spectra_config->halfFrameSize); + + break; + + default: + + printf("Invalid post-filtering method.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->in1 = (msg_spectra_obj *) NULL; + obj->in2 = (msg_powers_obj *) NULL; + obj->in3 = (msg_tracks_obj *) NULL; + obj->out1 = (msg_spectra_obj *) NULL; + obj->out2 = (msg_spectra_obj *) NULL; + + return obj; + + } + + void mod_sss_destroy(mod_sss_obj * obj) { + + switch(obj->mode_sep) { + + case 'd': + + beampatterns_destroy(obj->beampatterns_mics); + beampatterns_destroy(obj->beampatterns_spatialfilter); + steers_destroy(obj->steers); + gains_destroy(obj->gains); + masks_destroy(obj->masks); + tracks_destroy(obj->tracksPrev); + tracks_destroy(obj->tracksNow); + track2gain_destroy(obj->track2gain); + gain2mask_destroy(obj->gain2mask); + track2steer_destroy(obj->track2steer); + steer2demixing_ds_destroy(obj->steer2demixing_ds); + demixings_destroy(obj->demixingsPrev); + demixings_destroy(obj->demixingsNow); + demixing2freq_destroy(obj->demixing2freq); + + break; + + case 'g': + + beampatterns_destroy(obj->beampatterns_mics); + beampatterns_destroy(obj->beampatterns_spatialfilter); + steers_destroy(obj->steers); + gains_destroy(obj->gains); + masks_destroy(obj->masks); + tracks_destroy(obj->tracksPrev); + tracks_destroy(obj->tracksNow); + track2gain_destroy(obj->track2gain); + gain2mask_destroy(obj->gain2mask); + track2steer_destroy(obj->track2steer); + steer2demixing_gss_destroy(obj->steer2demixing_gss); + demixings_destroy(obj->demixingsPrev); + demixings_destroy(obj->demixingsNow); + demixing2freq_destroy(obj->demixing2freq); + + break; + + case 'm': + + printf("MVDR not implemented yet.\n"); + exit(EXIT_FAILURE); + + break; + + default: + + printf("Invalid separation method.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->mode_pf) { + + case 'm': + + freq2env_destroy(obj->freq2env); + envs_destroy(obj->noisys); + demixing2env_destroy(obj->demixing2env); + envs_destroy(obj->noisesEst); + env2env_mcra_destroy(obj->env2env_mcra); + envs_destroy(obj->noisesSep); + env2env_interf_destroy(obj->env2env_interf); + envs_destroy(obj->interfs); + env2env_gainspeech_destroy(obj->env2env_gainspeech); + envs_destroy(obj->gainspeeches); + envs_destroy(obj->snrs); + envs_destroy(obj->vs); + env2env_probspeech_destroy(obj->env2env_probspeech); + envs_destroy(obj->probspeeches); + env2env_gainall_destroy(obj->env2env_gainall); + envs_destroy(obj->gainalls); + freq2freq_gain_destroy(obj->freq2freq_gain); + + break; + + default: + + printf("Invalid post-filtering method.\n"); + exit(EXIT_FAILURE); + + break; + + } + + free((void *) obj); + + } + + int mod_sss_process(mod_sss_obj * obj) { + + int rtnValue1; + int rtnValue2; + int rtnValue; + + switch(obj->mode_sep) { + + case 'd': + + rtnValue1 = mod_sss_process_dds(obj); + + break; + + case 'g': + + rtnValue1 = mod_sss_process_dgss(obj); + + break; + + case 'm': + + rtnValue1 = mod_sss_process_dmvdr(obj); + + break; + + default: + + printf("Invalid separation method.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->mode_pf) { + + case 'm': + + rtnValue2 = mod_sss_process_mspf(obj); + + break; + + default: + + printf("Invalid post-filtering method.\n"); + exit(EXIT_FAILURE); + + break; + + } + + if (rtnValue1 != rtnValue2) { + printf("Return value mismatch.\n"); + exit(EXIT_FAILURE); + } + else { + rtnValue = rtnValue1; + } + + return rtnValue; + + } + + int mod_sss_process_dds(mod_sss_obj * obj) { + + int rtnValue; + + if ((obj->in1->timeStamp != obj->in2->timeStamp) || + (obj->in1->timeStamp != obj->in3->timeStamp)) { + + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + + } + + if (msg_spectra_isZero(obj->in1) == 0) { + + tracks_copy(obj->tracksPrev, + obj->tracksNow); + + tracks_copy(obj->tracksNow, + obj->in3->tracks); + + track2gain_process(obj->track2gain, + obj->beampatterns_mics, + obj->beampatterns_spatialfilter, + obj->tracksNow, + obj->gains); + + gain2mask_process(obj->gain2mask, + obj->gains, + obj->masks); + + track2steer_process(obj->track2steer, + obj->tracksNow, + obj->gains, + obj->masks, + obj->steers); + + demixings_copy(obj->demixingsPrev, + obj->demixingsNow); + + steer2demixing_ds_process(obj->steer2demixing_ds, + obj->tracksNow, + obj->steers, + obj->masks, + obj->demixingsNow); + + demixing2freq_process(obj->demixing2freq, + obj->tracksNow, + obj->demixingsNow, + obj->masks, + obj->in1->freqs, + obj->out1->freqs); + + obj->out1->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out1); + + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_sss_process_dgss(mod_sss_obj * obj) { + + int rtnValue; + + if ((obj->in1->timeStamp != obj->in2->timeStamp) || + (obj->in1->timeStamp != obj->in3->timeStamp)) { + + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + + } + + if (msg_spectra_isZero(obj->in1) == 0) { + + tracks_copy(obj->tracksPrev, + obj->tracksNow); + + tracks_copy(obj->tracksNow, + obj->in3->tracks); + + track2gain_process(obj->track2gain, + obj->beampatterns_mics, + obj->beampatterns_spatialfilter, + obj->tracksNow, + obj->gains); + + gain2mask_process(obj->gain2mask, + obj->gains, + obj->masks); + + track2steer_process(obj->track2steer, + obj->tracksNow, + obj->gains, + obj->masks, + obj->steers); + + demixings_copy(obj->demixingsPrev, + obj->demixingsNow); + + steer2demixing_gss_process(obj->steer2demixing_gss, + obj->tracksPrev, + obj->tracksNow, + obj->steers, + obj->masks, + obj->in1->freqs, + obj->demixingsPrev, + obj->demixingsNow); + + demixing2freq_process(obj->demixing2freq, + obj->tracksNow, + obj->demixingsNow, + obj->masks, + obj->in1->freqs, + obj->out1->freqs); + + obj->out1->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out1); + + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_sss_process_dmvdr(mod_sss_obj * obj) { + + int rtnValue; + + if ((obj->in1->timeStamp != obj->in2->timeStamp) || + (obj->in1->timeStamp != obj->in3->timeStamp)) { + + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + + } + + if (msg_spectra_isZero(obj->in1) == 0) { + + freqs_zero(obj->out1->freqs); + + obj->out1->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out1); + + rtnValue = -1; + + } + + return rtnValue; + + } + + int mod_sss_process_mspf(mod_sss_obj * obj) { + + int rtnValue; + + if ((obj->in1->timeStamp != obj->in2->timeStamp) || + (obj->in1->timeStamp != obj->in3->timeStamp)) { + + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + + } + + if (msg_spectra_isZero(obj->in1) == 0) { + + freq2env_process(obj->freq2env, + obj->out1->freqs, + obj->noisys); + + demixing2env_process(obj->demixing2env, + obj->in3->tracks, + obj->demixingsNow, + obj->masks, + obj->in2->envs, + obj->noisesEst); + + env2env_mcra_process(obj->env2env_mcra, + obj->in3->tracks, + obj->noisys, + obj->noisesEst, + obj->noisesSep); + + env2env_interf_process(obj->env2env_interf, + obj->in3->tracks, + obj->noisys, + obj->noisesSep, + obj->interfs); + + env2env_gainspeech_process(obj->env2env_gainspeech, + obj->in3->tracks, + obj->noisys, + obj->interfs, + obj->gainspeeches, + obj->snrs, + obj->vs); + + env2env_probspeech_process(obj->env2env_probspeech, + obj->in3->tracks, + obj->snrs, + obj->vs, + obj->probspeeches); + + env2env_gainall_process(obj->env2env_gainall, + obj->in3->tracks, + obj->gainspeeches, + obj->probspeeches, + obj->gainalls); + + freq2freq_gain_process(obj->freq2freq_gain, + obj->out1->freqs, + obj->gainalls, + obj->out2->freqs); + + obj->out2->timeStamp = obj->in1->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out2); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_sss_connect(mod_sss_obj * obj, msg_spectra_obj * in1, msg_powers_obj * in2, msg_tracks_obj * in3, msg_spectra_obj * out1, msg_spectra_obj * out2) { + + obj->in1 = in1; + obj->in2 = in2; + obj->in3 = in3; + obj->out1 = out1; + obj->out2 = out2; + + } + + void mod_sss_disconnect(mod_sss_obj * obj) { + + obj->in1 = (msg_spectra_obj *) NULL; + obj->in2 = (msg_powers_obj *) NULL; + obj->in3 = (msg_tracks_obj *) NULL; + obj->out1 = (msg_spectra_obj *) NULL; + obj->out2 = (msg_spectra_obj *) NULL; + + } + + mod_sss_cfg * mod_sss_cfg_construct(void) { + + mod_sss_cfg * cfg; + + cfg = (mod_sss_cfg *) malloc(sizeof(mod_sss_cfg)); + + cfg->mode_sep = 0x00; + cfg->mode_pf = 0x00; + + cfg->nThetas = 0; + cfg->gainMin = 0.0f; + + cfg->mics = (mics_obj *) NULL; + cfg->samplerate = (samplerate_obj *) NULL; + cfg->soundspeed = (soundspeed_obj *) NULL; + cfg->spatialfilter = (spatialfilter_obj *) NULL; + + return cfg; + + } + + void mod_sss_cfg_destroy(mod_sss_cfg * cfg) { + + if (cfg->mics != NULL) { + mics_destroy(cfg->mics); + } + + if (cfg->samplerate != NULL) { + samplerate_destroy(cfg->samplerate); + } + + if (cfg->soundspeed != NULL) { + soundspeed_destroy(cfg->soundspeed); + } + + if (cfg->spatialfilter != NULL) { + spatialfilter_destroy(cfg->spatialfilter); + } + + free((void *) cfg); + + } + + void mod_sss_cfg_printf(const mod_sss_cfg * cfg) { + + // Empty + + } \ No newline at end of file diff --git a/src/module/mod_sss.h b/src/module/mod_sss.h new file mode 100644 index 0000000..37d4de9 --- /dev/null +++ b/src/module/mod_sss.h @@ -0,0 +1,154 @@ +#ifndef __ODAS_MODULE_SSS +#define __ODAS_MODULE_SSS + + #include "../general/mic.h" + #include "../general/samplerate.h" + #include "../general/soundspeed.h" + #include "../general/spatialfilter.h" + + #include "../init/directivity.h" + + #include "../message/msg_powers.h" + #include "../message/msg_spectra.h" + #include "../message/msg_tracks.h" + + #include "../signal/beampattern.h" + #include "../signal/steer.h" + #include "../signal/gain.h" + #include "../signal/demixing.h" + #include "../signal/env.h" + + #include "../system/demixing2env.h" + #include "../system/demixing2freq.h" + #include "../system/env2env.h" + #include "../system/freq2env.h" + #include "../system/freq2freq.h" + #include "../system/gain2mask.h" + #include "../system/track2steer.h" + #include "../system/track2gain.h" + #include "../system/steer2demixing.h" + + #include + #include + + typedef struct mod_sss_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + + char mode_sep; + char mode_pf; + + beampatterns_obj * beampatterns_mics; + beampatterns_obj * beampatterns_spatialfilter; + steers_obj * steers; + gains_obj * gains; + masks_obj * masks; + + tracks_obj * tracksPrev; + tracks_obj * tracksNow; + + track2gain_obj * track2gain; + gain2mask_obj * gain2mask; + track2steer_obj * track2steer; + + steer2demixing_ds_obj * steer2demixing_ds; + steer2demixing_gss_obj * steer2demixing_gss; + steer2demixing_mvdr_obj * steer2demixing_mvdr; + + demixings_obj * demixingsPrev; + demixings_obj * demixingsNow; + + demixing2freq_obj * demixing2freq; + + freq2env_obj * freq2env; + envs_obj * noisys; + demixing2env_obj * demixing2env; + envs_obj * noisesEst; + env2env_mcra_obj * env2env_mcra; + envs_obj * noisesSep; + env2env_interf_obj * env2env_interf; + envs_obj * interfs; + env2env_gainspeech_obj * env2env_gainspeech; + envs_obj * gainspeeches; + envs_obj * snrs; + envs_obj * vs; + env2env_probspeech_obj * env2env_probspeech; + envs_obj * probspeeches; + env2env_gainall_obj * env2env_gainall; + envs_obj * gainalls; + freq2freq_gain_obj * freq2freq_gain; + + msg_spectra_obj * in1; + msg_powers_obj * in2; + msg_tracks_obj * in3; + msg_spectra_obj * out1; + msg_spectra_obj * out2; + + FILE * tmpFp; + + } mod_sss_obj; + + typedef struct mod_sss_cfg { + + char mode_sep; + char mode_pf; + + unsigned int nThetas; + float gainMin; + + float epsilon; + + mics_obj * mics; + samplerate_obj * samplerate; + soundspeed_obj * soundspeed; + spatialfilter_obj * spatialfilter; + + float sep_gss_lambda; + float sep_gss_mu; + + unsigned int pf_multi_bSize; + float pf_multi_alphaS; + unsigned int pf_multi_L; + float pf_multi_delta; + float pf_multi_alphaD; + + float pf_multi_eta; + float pf_multi_alphaZ; + float pf_multi_alphaPmin; + float pf_multi_thetaWin; + float pf_multi_alphaWin; + float pf_multi_maxAbsenceProb; + float pf_multi_Gmin; + unsigned int pf_multi_winSizeLocal; + unsigned int pf_multi_winSizeGlobal; + unsigned int pf_multi_winSizeFrame; + + } mod_sss_cfg; + + mod_sss_obj * mod_sss_construct(const mod_sss_cfg * mod_sss_config, const msg_tracks_cfg * msg_tracks_config, const msg_spectra_cfg * msg_spectra_config); + + void mod_sss_destroy(mod_sss_obj * obj); + + int mod_sss_process(mod_sss_obj * obj); + + int mod_sss_process_dds(mod_sss_obj * obj); + + int mod_sss_process_dgss(mod_sss_obj * obj); + + int mod_sss_process_dmvdr(mod_sss_obj * obj); + + int mod_sss_process_mspf(mod_sss_obj * obj); + + void mod_sss_connect(mod_sss_obj * obj, msg_spectra_obj * in1, msg_powers_obj * in2, msg_tracks_obj * in3, msg_spectra_obj * out1, msg_spectra_obj * out2); + + void mod_sss_disconnect(mod_sss_obj * obj); + + mod_sss_cfg * mod_sss_cfg_construct(void); + + void mod_sss_cfg_destroy(mod_sss_cfg * cfg); + + void mod_sss_cfg_printf(const mod_sss_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_sst.c b/src/module/mod_sst.c new file mode 100644 index 0000000..1e64ea9 --- /dev/null +++ b/src/module/mod_sst.c @@ -0,0 +1,1269 @@ + + #include "mod_sst.h" + + mod_sst_obj * mod_sst_construct(const mod_sst_cfg * mod_sst_config, const mod_ssl_cfg * mod_ssl_config, const msg_pots_cfg * msg_pots_config, const msg_targets_cfg * msg_targets_config, const msg_tracks_cfg * msg_tracks_config) { + + mod_sst_obj * obj; + + unsigned int iTrackMax; + points_obj * points; + beampatterns_obj * beampatterns_mics; + beampatterns_obj * beampatterns_spatialfilter; + spatialgains_obj * spatialgains; + spatialmasks_obj * spatialmasks; + spatialindexes_obj * spatialindexes; + unsigned int iPoint; + unsigned int nPointsActive; + float diffuse_cst; + float deltaT; + + obj = (mod_sst_obj *) malloc(sizeof(mod_sst_obj)); + + obj->nPots = msg_pots_config->nPots; + obj->nTracksMax = msg_tracks_config->nTracks; + obj->nTracks = 0; + obj->nTargetsMax = msg_targets_config->nTargets; + + obj->mode = mod_sst_config->mode; + obj->add = mod_sst_config->add; + + obj->mixtures = (mixture_obj **) malloc(sizeof(mixture_obj *) * (obj->nTracksMax+1)); + obj->coherences = (coherences_obj **) malloc(sizeof(coherences_obj *) * (obj->nTracksMax+1)); + obj->postprobs = (postprobs_obj **) malloc(sizeof(postprobs_obj *) * (obj->nTracksMax+1)); + + for (iTrackMax = 0; iTrackMax <= obj->nTracksMax; iTrackMax++) { + + obj->mixtures[iTrackMax] = mixture_construct_zero(obj->nPots, iTrackMax); + obj->coherences[iTrackMax] = coherences_construct_zero(obj->nPots, iTrackMax); + obj->postprobs[iTrackMax] = postprobs_construct_zero(obj->nPots, iTrackMax); + + } + + obj->ids = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracksMax); + memset(obj->ids, 0x00, sizeof(unsigned long long) * obj->nTracksMax); + obj->idsAdded = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracksMax); + memset(obj->idsAdded, 0x00, sizeof(unsigned long long) * obj->nTracksMax); + obj->idsRemoved = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracksMax); + memset(obj->idsRemoved, 0x00, sizeof(unsigned long long) * obj->nTracksMax); + + obj->tags = (char **) malloc(sizeof(char *) * obj->nTracksMax); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->tags[iTrackMax] = (char *) malloc(sizeof(char) * 256); + strcpy(obj->tags[iTrackMax],""); + + } + + obj->type = (char *) malloc(sizeof(char) * obj->nTracksMax); + memset(obj->type, 0x00, sizeof(char) * obj->nTracksMax); + + obj->kalmans = (kalman_obj **) malloc(sizeof(kalman_obj *) * obj->nTracksMax); + memset(obj->kalmans, 0x00, sizeof(kalman_obj *) * obj->nTracksMax); + obj->particles = (particles_obj **) malloc(sizeof(particles_obj *) * obj->nTracksMax); + memset(obj->particles, 0x00, sizeof(particles_obj *) * obj->nTracksMax); + + obj->sourceActivities = (float *) malloc(sizeof(float) * obj->nTracksMax); + memset(obj->sourceActivities, 0x00, sizeof(float) * obj->nTracksMax); + + obj->theta_new = mod_sst_config->theta_new; + obj->N_prob = mod_sst_config->N_prob; + obj->theta_prob = mod_sst_config->theta_prob; + obj->N_inactive = (unsigned int *) malloc(sizeof(unsigned int) * obj->nTracksMax); + + obj->theta_inactive = mod_sst_config->theta_inactive; + + obj->n_prob = (unsigned int *) malloc(sizeof(unsigned int) * obj->nTracksMax); + memset(obj->n_prob, 0x00, sizeof(unsigned int) * obj->nTracksMax); + obj->mean_prob = (float *) malloc(sizeof(float) * obj->nTracksMax); + memset(obj->mean_prob, 0x00, sizeof(float) * obj->nTracksMax); + obj->n_inactive = (unsigned int *) malloc(sizeof(unsigned int) * obj->nTracksMax); + memset(obj->n_inactive, 0x00, sizeof(unsigned int) * obj->nTracksMax); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->type[iTrackMax] = 'I'; + + switch(obj->mode) { + + case 'k': + + obj->kalmans[iTrackMax] = kalman_construct_zero(); + + break; + + case 'p': + + obj->particles[iTrackMax] = particles_construct_zero(mod_sst_config->nParticles); + + break; + + default: + + printf("Invalid type of filter\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->N_inactive[iTrackMax] = mod_sst_config->N_inactive[iTrackMax]; + + } + + points = space_sphere(mod_ssl_config->levels[mod_ssl_config->nLevels-1]); + beampatterns_mics = directivity_beampattern_mics(mod_ssl_config->mics, mod_ssl_config->nThetas); + beampatterns_spatialfilter = directivity_beampattern_spatialfilter(mod_ssl_config->spatialfilter, mod_ssl_config->nThetas); + spatialgains = directivity_spatialgains(mod_ssl_config->mics, beampatterns_mics, mod_ssl_config->spatialfilter, beampatterns_spatialfilter, points); + spatialmasks = directivity_spatialmasks(spatialgains, mod_ssl_config->gainMin); + spatialindexes = directivity_spatialindexes(spatialmasks); + + nPointsActive = 0; + + for (iPoint = 0; iPoint < spatialindexes->nPoints; iPoint++) { + + if (spatialindexes->count[iPoint] > 0) { + nPointsActive++; + } + + } + + diffuse_cst = 1.0f / (4.0f * M_PI * ((float) nPointsActive) / ((float) spatialindexes->nPoints)); + + points_destroy(points); + beampatterns_destroy(beampatterns_mics); + beampatterns_destroy(beampatterns_spatialfilter); + spatialgains_destroy(spatialgains); + spatialmasks_destroy(spatialmasks); + spatialindexes_destroy(spatialindexes); + + deltaT = ((float) mod_sst_config->hopSize) / ((float) msg_pots_config->fS); + + switch(obj->mode) { + + case 'k': + + obj->kalman2kalman_prob = kalman2kalman_construct(deltaT, + mod_sst_config->sigmaQ, + mod_sst_config->sigmaR_prob, + mod_sst_config->epsilon); + + obj->kalman2kalman_active = kalman2kalman_construct(deltaT, + mod_sst_config->sigmaQ, + mod_sst_config->sigmaR_active, + mod_sst_config->epsilon); + + obj->kalman2kalman_target = kalman2kalman_construct(deltaT, + mod_sst_config->sigmaQ, + mod_sst_config->sigmaR_target, + mod_sst_config->epsilon); + + obj->kalman2coherence_prob = kalman2coherence_construct(mod_sst_config->epsilon, + mod_sst_config->sigmaR_prob); + + obj->kalman2coherence_active = kalman2coherence_construct(mod_sst_config->epsilon, + mod_sst_config->sigmaR_active); + + obj->kalman2coherence_target = kalman2coherence_construct(mod_sst_config->epsilon, + mod_sst_config->sigmaR_target); + + obj->particle2particle_prob = NULL; + obj->particle2particle_active = NULL; + obj->particle2particle_target = NULL; + obj->particle2coherence_prob = NULL; + obj->particle2coherence_active = NULL; + obj->particle2coherence_target = NULL; + + break; + + case 'p': + + obj->kalman2kalman_prob = NULL; + obj->kalman2kalman_active = NULL; + obj->kalman2kalman_target = NULL; + obj->kalman2coherence_prob = NULL; + obj->kalman2coherence_active = NULL; + obj->kalman2coherence_target = NULL; + + obj->particle2particle_prob = particle2particle_construct(mod_sst_config->nParticles, + deltaT, + mod_sst_config->st_alpha, + mod_sst_config->st_beta, + mod_sst_config->st_ratio, + mod_sst_config->ve_alpha, + mod_sst_config->ve_beta, + mod_sst_config->ve_ratio, + mod_sst_config->ac_alpha, + mod_sst_config->ac_beta, + mod_sst_config->ac_ratio, + (double) mod_sst_config->epsilon, + mod_sst_config->sigmaR_prob, + mod_sst_config->Nmin); + + obj->particle2particle_active = particle2particle_construct(mod_sst_config->nParticles, + deltaT, + mod_sst_config->st_alpha, + mod_sst_config->st_beta, + mod_sst_config->st_ratio, + mod_sst_config->ve_alpha, + mod_sst_config->ve_beta, + mod_sst_config->ve_ratio, + mod_sst_config->ac_alpha, + mod_sst_config->ac_beta, + mod_sst_config->ac_ratio, + (double) mod_sst_config->epsilon, + mod_sst_config->sigmaR_active, + mod_sst_config->Nmin); + + obj->particle2particle_target = particle2particle_construct(mod_sst_config->nParticles, + deltaT, + mod_sst_config->st_alpha, + mod_sst_config->st_beta, + mod_sst_config->st_ratio, + mod_sst_config->ve_alpha, + mod_sst_config->ve_beta, + mod_sst_config->ve_ratio, + mod_sst_config->ac_alpha, + mod_sst_config->ac_beta, + mod_sst_config->ac_ratio, + (double) mod_sst_config->epsilon, + mod_sst_config->sigmaR_target, + mod_sst_config->Nmin); + + obj->particle2coherence_prob = particle2coherence_construct(mod_sst_config->sigmaR_prob); + + obj->particle2coherence_active = particle2coherence_construct(mod_sst_config->sigmaR_active); + + obj->particle2coherence_target = particle2coherence_construct(mod_sst_config->sigmaR_target); + + break; + + default: + + break; + + } + + obj->mixture2mixture = mixture2mixture_construct(mod_sst_config->active_gmm, + mod_sst_config->inactive_gmm, + diffuse_cst, + mod_sst_config->Pfalse, + mod_sst_config->Pnew, + mod_sst_config->Ptrack, + mod_sst_config->epsilon); + + obj->id = 0; + + obj->in1 = (msg_pots_obj *) NULL; + obj->in2 = (msg_targets_obj *) NULL; + obj->out = (msg_tracks_obj *) NULL; + + return obj; + + } + + void mod_sst_destroy(mod_sst_obj * obj) { + + unsigned int iTrackMax; + + for (iTrackMax = 0; iTrackMax <= obj->nTracksMax; iTrackMax++) { + + mixture_destroy(obj->mixtures[iTrackMax]); + coherences_destroy(obj->coherences[iTrackMax]); + postprobs_destroy(obj->postprobs[iTrackMax]); + + } + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->kalmans[iTrackMax] != NULL) { + + kalman_destroy(obj->kalmans[iTrackMax]); + + } + + if (obj->particles[iTrackMax] != NULL) { + + particles_destroy(obj->particles[iTrackMax]); + + } + + } + + free((void *) obj->mixtures); + free((void *) obj->coherences); + free((void *) obj->postprobs); + + free((void *) obj->ids); + free((void *) obj->idsAdded); + free((void *) obj->idsRemoved); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + free((void *) obj->tags[iTrackMax]); + } + free((void *) obj->tags); + + free((void *) obj->type); + + free((void *) obj->kalmans); + free((void *) obj->particles); + + free((void *) obj->sourceActivities); + + free((void *) obj->N_inactive); + free((void *) obj->n_prob); + free((void *) obj->mean_prob); + free((void *) obj->n_inactive); + + if (obj->kalman2kalman_prob != NULL) { + kalman2kalman_destroy(obj->kalman2kalman_prob); + } + if (obj->kalman2kalman_active != NULL) { + kalman2kalman_destroy(obj->kalman2kalman_active); + } + if (obj->kalman2kalman_target != NULL) { + kalman2kalman_destroy(obj->kalman2kalman_target); + } + if (obj->kalman2coherence_prob != NULL) { + kalman2coherence_destroy(obj->kalman2coherence_prob); + } + if (obj->kalman2coherence_active != NULL) { + kalman2coherence_destroy(obj->kalman2coherence_active); + } + if (obj->kalman2coherence_target != NULL) { + kalman2coherence_destroy(obj->kalman2coherence_target); + } + if (obj->particle2particle_prob != NULL) { + particle2particle_destroy(obj->particle2particle_prob); + } + if (obj->particle2particle_active != NULL) { + particle2particle_destroy(obj->particle2particle_active); + } + if (obj->particle2particle_target != NULL) { + particle2particle_destroy(obj->particle2particle_target); + } + if (obj->particle2coherence_prob != NULL) { + particle2coherence_destroy(obj->particle2coherence_prob); + } + if (obj->particle2coherence_active != NULL) { + particle2coherence_destroy(obj->particle2coherence_active); + } + if (obj->particle2coherence_target != NULL) { + particle2coherence_destroy(obj->particle2coherence_target); + } + + mixture2mixture_destroy(obj->mixture2mixture); + + free((void *) obj); + + } + + int mod_sst_process(mod_sst_obj * obj) { + + unsigned int iPot; + unsigned int iTrackMax; + unsigned int iTrack; + unsigned int iTargetMax; + float x,y,z; + float sourceActivity; + int rtnValue; + char targetFound; + + if (obj->in1->timeStamp != obj->in2->timeStamp) { + + printf("Time stamp mismatch.\n"); + exit(EXIT_FAILURE); + + } + + if (msg_pots_isZero(obj->in1) == 0) { + + // +----------------------------------------------------------------------+ + // | Update tracked sources from target sources | + // +----------------------------------------------------------------------+ + + // Add sources + + for (iTargetMax = 0; iTargetMax < obj->nTargetsMax; iTargetMax++) { + + targetFound = 0x00; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (strcmp(obj->in2->targets->tags[iTargetMax],obj->tags[iTrackMax])==0) { + + targetFound = 0x01; + break; + + } + + } + + if (targetFound == 0x00) { + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] == 0) { + + obj->id++; + obj->ids[iTrackMax] = obj->id; + strcpy(obj->tags[iTrackMax],obj->in2->targets->tags[iTargetMax]); + + switch(obj->mode) { + + case 'k': + + kalman2kalman_init_targets(obj->kalman2kalman_prob, + obj->in2->targets, + iTargetMax, + obj->kalmans[iTrackMax]); + + break; + + case 'p': + + particle2particle_init_targets(obj->particle2particle_prob, + obj->in2->targets, + iTargetMax, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->type[iTrackMax] = 'T'; + obj->n_prob[iTrackMax] = 0; + obj->mean_prob[iTrackMax] = 0.0f; + + break; + + } + + } + + } + + } + + // Remove sources + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (strcmp(obj->tags[iTrackMax],"dynamic") != 0) { + + targetFound = 0x00; + + for (iTargetMax = 0; iTargetMax < obj->nTargetsMax; iTargetMax++) { + + if (strcmp(obj->tags[iTrackMax],obj->in2->targets->tags[iTargetMax]) == 0) { + + targetFound = 0x01; + break; + + } + + } + + if (targetFound == 0x00) { + + obj->ids[iTrackMax] = 0; + strcpy(obj->tags[iTrackMax],""); + obj->type[iTrackMax] = 'I'; + obj->n_prob[iTrackMax] = 0; + obj->mean_prob[iTrackMax] = 0.0f; + + } + + } + + } + + // +----------------------------------------------------------------------+ + // | Count tracked sources | + // +----------------------------------------------------------------------+ + + obj->nTracks = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + obj->nTracks++; + + } + + } + + // +----------------------------------------------------------------------+ + // | Predict | + // +----------------------------------------------------------------------+ + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + switch(obj->mode) { + + case 'k': + + switch (obj->type[iTrackMax]) { + + case 'P': + + kalman2kalman_predict(obj->kalman2kalman_prob, + obj->kalmans[iTrackMax]); + + break; + + case 'A': + + kalman2kalman_predict(obj->kalman2kalman_active, + obj->kalmans[iTrackMax]); + + break; + + case 'T': + + kalman2kalman_predict_static(obj->kalman2kalman_target, + obj->kalmans[iTrackMax]); + + break; + + default: + + printf("Predict: Unknown state.\n"); + printf("%u, %c\n",iTrackMax,obj->type[iTrackMax]); + exit(EXIT_FAILURE); + + break; + + } + + break; + + case 'p': + + switch (obj->type[iTrackMax]) { + + case 'P': + + particle2particle_predict(obj->particle2particle_prob, + obj->particles[iTrackMax]); + + break; + + case 'A': + + particle2particle_predict(obj->particle2particle_active, + obj->particles[iTrackMax]); + + break; + + case 'T': + + particle2particle_predict_static(obj->particle2particle_target, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Predict: Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + } + + // +----------------------------------------------------------------------+ + // | Coherence | + // +----------------------------------------------------------------------+ + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + switch(obj->mode) { + + case 'k': + + switch (obj->type[iTrackMax]) { + + case 'P': + + kalman2coherence_process(obj->kalman2coherence_prob, + obj->kalmans[iTrackMax], + obj->in1->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + case 'A': + + kalman2coherence_process(obj->kalman2coherence_active, + obj->kalmans[iTrackMax], + obj->in1->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + case 'T': + + kalman2coherence_process(obj->kalman2coherence_target, + obj->kalmans[iTrackMax], + obj->in1->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + default: + + printf("Coherence: Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + case 'p': + + switch (obj->type[iTrackMax]) { + + case 'P': + + particle2coherence_process(obj->particle2coherence_prob, + obj->particles[iTrackMax], + obj->in1->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + case 'A': + + particle2coherence_process(obj->particle2coherence_active, + obj->particles[iTrackMax], + obj->in1->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + case 'T': + + particle2coherence_process(obj->particle2coherence_target, + obj->particles[iTrackMax], + obj->in1->pots, + iTrack, + obj->coherences[obj->nTracks]); + + break; + + default: + + printf("Coherence: Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + iTrack++; + + } + + } + + // +----------------------------------------------------------------------+ + // | Mixture | + // +----------------------------------------------------------------------+ + + mixture2mixture_process(obj->mixture2mixture, + obj->mixtures[obj->nTracks], + obj->in1->pots, + obj->coherences[obj->nTracks], + obj->postprobs[obj->nTracks]); + + // +----------------------------------------------------------------------+ + // | Update | + // +----------------------------------------------------------------------+ + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + switch(obj->mode) { + + case 'k': + + switch (obj->type[iTrackMax]) { + + case 'P': + + kalman2kalman_update(obj->kalman2kalman_prob, + obj->postprobs[obj->nTracks], + iTrack, + obj->in1->pots, + obj->kalmans[iTrackMax]); + + break; + + case 'A': + + kalman2kalman_update(obj->kalman2kalman_active, + obj->postprobs[obj->nTracks], + iTrack, + obj->in1->pots, + obj->kalmans[iTrackMax]); + + break; + + case 'T': + + kalman2kalman_update_static(obj->kalman2kalman_target, + obj->postprobs[obj->nTracks], + iTrack, + obj->in1->pots, + obj->kalmans[iTrackMax]); + + break; + + default: + + printf("Update: Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + case 'p': + + switch (obj->type[iTrackMax]) { + + case 'P': + + particle2particle_update(obj->particle2particle_prob, + obj->postprobs[obj->nTracks], + iTrack, + obj->in1->pots, + obj->particles[iTrackMax]); + + break; + + case 'A': + + particle2particle_update(obj->particle2particle_active, + obj->postprobs[obj->nTracks], + iTrack, + obj->in1->pots, + obj->particles[iTrackMax]); + + break; + + case 'T': + + particle2particle_update_static(obj->particle2particle_target, + obj->postprobs[obj->nTracks], + iTrack, + obj->in1->pots, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Update: Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + iTrack++; + + } + + } + + // +----------------------------------------------------------------------+ + // | Activity | + // +----------------------------------------------------------------------+ + + iTrack = 0; + memset(obj->sourceActivities, 0x00, sizeof(float) * obj->nTracksMax); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + sourceActivity = obj->postprobs[obj->nTracks]->arrayTrackTotal[iTrack]; + obj->sourceActivities[iTrackMax] = sourceActivity; + + // Update counters + + switch (obj->type[iTrackMax]) { + + case 'P': + + obj->n_prob[iTrackMax]++; + obj->mean_prob[iTrackMax] += sourceActivity; + + break; + + case 'A': + + if (sourceActivity >= obj->theta_inactive) { + obj->n_inactive[iTrackMax] = 0; + } + else { + obj->n_inactive[iTrackMax]++; + } + + break; + + case 'T': + + // No counter to update + + break; + + default: + + printf("Unknown state.\n"); + exit(EXIT_FAILURE); + + break; + + } + + iTrack++; + + } + + } + + // +----------------------------------------------------------------------+ + // | Transitions | + // +----------------------------------------------------------------------+ + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + if ((obj->type[iTrackMax] == 'P') && + (obj->n_prob[iTrackMax] == obj->N_prob) && + (obj->mean_prob[iTrackMax]/((float) obj->N_prob) >= obj->theta_prob)) { + + obj->type[iTrackMax] = 'A'; + obj->n_inactive[iTrackMax] = 0; + + } + + iTrack++; + + } + + } + + // +----------------------------------------------------------------------+ + // | Update tracked sources from potential sources | + // +----------------------------------------------------------------------+ + + // Only if the tracking is dynamic (i.e. sources may be created automatically) + + if (obj->add == 'd') { + + // Add sources + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->idsAdded[iTrackMax] = 0; + + } + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + if (obj->postprobs[obj->nTracks]->arrayNew[iPot] > obj->theta_new) { + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] == 0) { + + obj->id++; + obj->idsAdded[iTrackMax] = obj->id; + + switch(obj->mode) { + + case 'k': + + kalman2kalman_init_pots(obj->kalman2kalman_prob, + obj->in1->pots, + iPot, + obj->kalmans[iTrackMax]); + + break; + + case 'p': + + particle2particle_init_pots(obj->particle2particle_prob, + obj->in1->pots, + iPot, + obj->particles[iTrackMax]); + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->type[iTrackMax] = 'P'; + obj->n_prob[iTrackMax] = 0; + obj->mean_prob[iTrackMax] = 0.0f; + + break; + + } + + } + + } + + } + + // Remove source + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + obj->idsRemoved[iTrackMax] = 0; + + } + + iTrack = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + if ((obj->type[iTrackMax] == 'P') && + (obj->n_prob[iTrackMax] == obj->N_prob) && + (obj->mean_prob[iTrackMax]/((float) obj->N_prob) < obj->theta_prob)) { + + obj->idsRemoved[iTrackMax] = obj->ids[iTrackMax]; + + } + + if ((obj->type[iTrackMax] == 'A') && + (obj->n_inactive[iTrackMax] >= obj->N_inactive[obj->nTracks-1])) { + + obj->idsRemoved[iTrackMax] = obj->ids[iTrackMax]; + + } + + iTrack++; + + } + + } + + // Update IDs + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->idsAdded[iTrackMax] != 0) { + + obj->ids[iTrackMax] = obj->idsAdded[iTrackMax]; + strcpy(obj->tags[iTrackMax], "dynamic"); + + } + + if (obj->idsRemoved[iTrackMax] != 0) { + + obj->ids[iTrackMax] = 0; + strcpy(obj->tags[iTrackMax], ""); + + } + + } + + } + + // +----------------------------------------------------------------------+ + // | Count tracked sources | + // +----------------------------------------------------------------------+ + + obj->nTracks = 0; + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + obj->nTracks++; + + } + + } + + // +----------------------------------------------------------------------+ + // | Copy in tracking | + // +----------------------------------------------------------------------+ + + memset(obj->out->tracks->array, 0x00, sizeof(float) * obj->out->tracks->nTracks * 3); + memset(obj->out->tracks->ids, 0x00, sizeof(unsigned long long) * obj->out->tracks->nTracks); + + for (iTrackMax = 0; iTrackMax < obj->nTracksMax; iTrackMax++) { + + if (obj->ids[iTrackMax] != 0) { + + if ((obj->type[iTrackMax] == 'A') || (obj->type[iTrackMax] == 'T')) { + + switch(obj->mode) { + + case 'k': + + kalman2kalman_estimate(obj->kalman2kalman_active, + obj->kalmans[iTrackMax], + &x, + &y, + &z); + + break; + + case 'p': + + particle2particle_estimate(obj->particle2particle_active, + obj->particles[iTrackMax], + &x, + &y, + &z); + + break; + + default: + + printf("Invalid filter type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->out->tracks->array[iTrackMax * 3 + 0] = x; + obj->out->tracks->array[iTrackMax * 3 + 1] = y; + obj->out->tracks->array[iTrackMax * 3 + 2] = z; + obj->out->tracks->ids[iTrackMax] = obj->ids[iTrackMax]; + strcpy(obj->out->tracks->tags[iTrackMax],obj->tags[iTrackMax]); + obj->out->tracks->activity[iTrackMax] = obj->sourceActivities[iTrackMax]; + + } + + } + + } + + obj->out->timeStamp = obj->in2->timeStamp; + + rtnValue = 0; + + } + else { + + msg_tracks_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_sst_connect(mod_sst_obj * obj, msg_pots_obj * in1, msg_targets_obj * in2, msg_tracks_obj * out) { + + obj->in1 = in1; + obj->in2 = in2; + obj->out = out; + + } + + void mod_sst_disconnect(mod_sst_obj * obj) { + + obj->in1 = (msg_pots_obj *) NULL; + obj->in2 = (msg_targets_obj *) NULL; + obj->out = (msg_tracks_obj *) NULL; + + } + + mod_sst_cfg * mod_sst_cfg_construct(void) { + + mod_sst_cfg * cfg; + + cfg = (mod_sst_cfg *) malloc(sizeof(mod_sst_cfg)); + + cfg->mode = 0x00; + + cfg->hopSize = 0; + cfg->sigmaQ = 0.0f; + + cfg->nParticles = 0; + cfg->st_alpha = 0.0f; + cfg->st_beta = 0.0f; + cfg->st_ratio = 0.0f; + cfg->ve_alpha = 0.0f; + cfg->ve_beta = 0.0f; + cfg->ve_ratio = 0.0f; + cfg->ac_alpha = 0.0f; + cfg->ac_beta = 0.0f; + cfg->ac_ratio = 0.0f; + cfg->Nmin = 0.0f; + + cfg->epsilon = 0.0f; + cfg->sigmaR_prob = 0.0f; + cfg->sigmaR_active = 0.0f; + cfg->active_gmm = (gaussians_1d_obj *) NULL; + cfg->inactive_gmm = (gaussians_1d_obj *) NULL; + cfg->Pfalse = 0.0f; + cfg->Pnew = 0.0f; + cfg->Ptrack = 0.0f; + + cfg->theta_new = 0.0f; + cfg->N_prob = 0; + cfg->theta_prob = 0.0f; + cfg->N_inactive = (unsigned int *) NULL; + cfg->theta_inactive = 0.0f; + + return cfg; + + } + + void mod_sst_cfg_destroy(mod_sst_cfg * cfg) { + + if (cfg->active_gmm != NULL) { + gaussians_1d_destroy(cfg->active_gmm); + } + + if (cfg->inactive_gmm != NULL) { + gaussians_1d_destroy(cfg->inactive_gmm); + } + + if (cfg->N_inactive != NULL) { + free((void *) cfg->N_inactive); + } + + free((void *) cfg); + + } + + void mod_sst_cfg_printf(const mod_sst_cfg * cfg) { + + unsigned int iTrackMax; + + printf("mode = %c\n", cfg->mode); + printf("nTracksMax = %u\n", cfg->nTracksMax); + printf("hopSize = %u\n", cfg->hopSize); + printf("sigmaQ = %f\n", cfg->sigmaQ); + printf("nParticles = %u\n", cfg->nParticles); + printf("st_alpha = %f\n", cfg->st_alpha); + printf("st_beta = %f\n", cfg->st_beta); + printf("st_ratio = %f\n", cfg->st_ratio); + printf("ve_alpha = %f\n", cfg->ve_alpha); + printf("ve_beta = %f\n", cfg->ve_beta); + printf("ve_ratio = %f\n", cfg->ve_ratio); + printf("ac_alpha = %f\n", cfg->ac_alpha); + printf("ac_beta = %f\n", cfg->ac_beta); + printf("ac_ratio = %f\n", cfg->ac_ratio); + printf("Nmin = %f\n", cfg->Nmin); + printf("epsilon = %f\n", cfg->epsilon); + printf("sigmaR_prob = %f\n", cfg->sigmaR_prob); + printf("sigmaR_active = %f\n", cfg->sigmaR_active); + + printf("active_gmm:\n"); + gaussians_1d_printf(cfg->active_gmm); + + printf("inactive_gmm:\n"); + gaussians_1d_printf(cfg->inactive_gmm); + + printf("Pfalse = %f\n", cfg->Pfalse); + printf("Pnew = %f\n", cfg->Pnew); + printf("Ptrack = %f\n", cfg->Ptrack); + printf("theta_new = %f\n", cfg->theta_new); + printf("N_prob = %u\n", cfg->N_prob); + printf("theta_prob = %f\n", cfg->theta_prob); + + printf("N_inactive = ("); + for (iTrackMax = 0; iTrackMax < cfg->nTracksMax; iTrackMax++) { + + printf("%u",cfg->N_inactive[iTrackMax]); + + if (iTrackMax != (cfg->nTracksMax-1)) { + printf(", "); + } + + } + printf(")\n"); + + printf("theta_inactive = %f\n", cfg->theta_inactive); + + } \ No newline at end of file diff --git a/src/module/mod_sst.h b/src/module/mod_sst.h new file mode 100644 index 0000000..16cdf9e --- /dev/null +++ b/src/module/mod_sst.h @@ -0,0 +1,142 @@ +#ifndef __ODAS_MODULE_SST +#define __ODAS_MODULE_SST + + #include + #include + #include + #include + + #include "../general/mic.h" + + #include "../signal/coherence.h" + #include "../signal/kalman.h" + #include "../signal/mixture.h" + #include "../signal/particle.h" + + #include "../system/kalman2kalman.h" + #include "../system/particle2particle.h" + #include "../system/kalman2coherence.h" + #include "../system/particle2coherence.h" + #include "../system/mixture2mixture.h" + + #include "../message/msg_pots.h" + #include "../message/msg_targets.h" + #include "../message/msg_tracks.h" + #include "../module/mod_ssl.h" + + typedef struct mod_sst_obj { + + unsigned int nPots; + unsigned int nTracksMax; + unsigned int nTracks; + unsigned int nTargetsMax; + + char mode; + char add; + + mixture_obj ** mixtures; + coherences_obj ** coherences; + postprobs_obj ** postprobs; + + unsigned long long * ids; + unsigned long long * idsAdded; + unsigned long long * idsRemoved; + char ** tags; + + char * type; + + kalman_obj ** kalmans; + kalman2kalman_obj * kalman2kalman_prob; + kalman2kalman_obj * kalman2kalman_active; + kalman2kalman_obj * kalman2kalman_target; + kalman2coherence_obj * kalman2coherence_prob; + kalman2coherence_obj * kalman2coherence_active; + kalman2coherence_obj * kalman2coherence_target; + + particles_obj ** particles; + particle2particle_obj * particle2particle_prob; + particle2particle_obj * particle2particle_active; + particle2particle_obj * particle2particle_target; + particle2coherence_obj * particle2coherence_prob; + particle2coherence_obj * particle2coherence_active; + particle2coherence_obj * particle2coherence_target; + + mixture2mixture_obj * mixture2mixture; + + float * sourceActivities; + + float theta_new; + unsigned int N_prob; + float theta_prob; + unsigned int * N_inactive; + float theta_inactive; + + unsigned int * n_prob; + float * mean_prob; + unsigned int * n_inactive; + + unsigned long long id; + + msg_pots_obj * in1; + msg_targets_obj * in2; + msg_tracks_obj * out; + + } mod_sst_obj; + + typedef struct mod_sst_cfg { + + char mode; + char add; + + unsigned int nTracksMax; + unsigned int hopSize; + + float sigmaQ; + + unsigned int nParticles; + float st_alpha; + float st_beta; + float st_ratio; + float ve_alpha; + float ve_beta; + float ve_ratio; + float ac_alpha; + float ac_beta; + float ac_ratio; + float Nmin; + + float epsilon; + float sigmaR_active; + float sigmaR_prob; + float sigmaR_target; + gaussians_1d_obj * active_gmm; + gaussians_1d_obj * inactive_gmm; + float Pfalse; + float Pnew; + float Ptrack; + + float theta_new; + unsigned int N_prob; + float theta_prob; + unsigned int * N_inactive; + float theta_inactive; + + } mod_sst_cfg; + + mod_sst_obj * mod_sst_construct(const mod_sst_cfg * mod_sst_config, const mod_ssl_cfg * mod_ssl_config, const msg_pots_cfg * msg_pots_config, const msg_targets_cfg * msg_targets_config, const msg_tracks_cfg * msg_tracks_config); + + void mod_sst_destroy(mod_sst_obj * obj); + + int mod_sst_process(mod_sst_obj * obj); + + void mod_sst_connect(mod_sst_obj * obj, msg_pots_obj * in1, msg_targets_obj * in2, msg_tracks_obj * out); + + void mod_sst_disconnect(mod_sst_obj * obj); + + mod_sst_cfg * mod_sst_cfg_construct(void); + + void mod_sst_cfg_destroy(mod_sst_cfg * cfg); + + void mod_sst_cfg_printf(const mod_sst_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_stft.c b/src/module/mod_stft.c new file mode 100644 index 0000000..9916c8d --- /dev/null +++ b/src/module/mod_stft.c @@ -0,0 +1,90 @@ + + #include "mod_stft.h" + + mod_stft_obj * mod_stft_construct(const mod_stft_cfg * mod_stft_config, const msg_hops_cfg * msg_hops_config, const msg_spectra_cfg * msg_spectra_config) { + + mod_stft_obj * obj; + + obj = (mod_stft_obj *) malloc(sizeof(mod_stft_obj)); + + obj->hop2frame = hop2frame_construct_zero(msg_hops_config->hopSize, 2*(msg_spectra_config->halfFrameSize-1),msg_hops_config->nChannels); + obj->frames = frames_construct_zero(msg_hops_config->nChannels,2*(msg_spectra_config->halfFrameSize-1)); + obj->frame2freq = frame2freq_construct_zero(2*(msg_spectra_config->halfFrameSize-1), msg_spectra_config->halfFrameSize); + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + return obj; + + } + + void mod_stft_destroy(mod_stft_obj * obj) { + + hop2frame_destroy(obj->hop2frame); + frames_destroy(obj->frames); + frame2freq_destroy(obj->frame2freq); + + free((void *) obj); + + } + + int mod_stft_process(mod_stft_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + hop2frame_process(obj->hop2frame, obj->in->hops, obj->frames); + frame2freq_process(obj->frame2freq, obj->frames, obj->out->freqs); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_spectra_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_stft_connect(mod_stft_obj * obj, msg_hops_obj * in, msg_spectra_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_stft_disconnect(mod_stft_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_spectra_obj *) NULL; + + } + + mod_stft_cfg * mod_stft_cfg_construct(void) { + + mod_stft_cfg * cfg; + + cfg = (mod_stft_cfg *) malloc(sizeof(mod_stft_cfg)); + + return cfg; + + } + + void mod_stft_cfg_destroy(mod_stft_cfg * cfg) { + + free((void *) cfg); + + } + + + void mod_stft_cfg_printf(const mod_stft_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_stft.h b/src/module/mod_stft.h new file mode 100644 index 0000000..1e3822a --- /dev/null +++ b/src/module/mod_stft.h @@ -0,0 +1,41 @@ +#ifndef __ODAS_MODULE_STFT +#define __ODAS_MODULE_STFT + + #include "../system/hop2frame.h" + #include "../signal/frame.h" + #include "../system/frame2freq.h" + #include "../message/msg_hops.h" + #include "../message/msg_spectra.h" + + typedef struct mod_stft_obj { + + hop2frame_obj * hop2frame; + frames_obj * frames; + frame2freq_obj * frame2freq; + + msg_hops_obj * in; + msg_spectra_obj * out; + + } mod_stft_obj; + + typedef struct mod_stft_cfg { + + } mod_stft_cfg; + + mod_stft_obj * mod_stft_construct(const mod_stft_cfg * mod_stft_config, const msg_hops_cfg * msg_hops_config, const msg_spectra_cfg * msg_spectra_config); + + void mod_stft_destroy(mod_stft_obj * obj); + + int mod_stft_process(mod_stft_obj * obj); + + void mod_stft_connect(mod_stft_obj * obj, msg_hops_obj * in, msg_spectra_obj * out); + + void mod_stft_disconnect(mod_stft_obj * obj); + + mod_stft_cfg * mod_stft_cfg_construct(void); + + void mod_stft_cfg_destroy(mod_stft_cfg * cfg); + + void mod_stft_cfg_printf(const mod_stft_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/module/mod_volume.c b/src/module/mod_volume.c new file mode 100644 index 0000000..c45b62c --- /dev/null +++ b/src/module/mod_volume.c @@ -0,0 +1,81 @@ + + #include "mod_volume.h" + + mod_volume_obj * mod_volume_construct(const mod_volume_cfg * mod_volume_config, const msg_hops_cfg * msg_hops_config) { + + mod_volume_obj * obj; + + obj = (mod_volume_obj *) malloc(sizeof(mod_volume_obj)); + + obj->hop2hop_gain = hop2hop_gain_construct_zero(msg_hops_config->hopSize, mod_volume_config->gain); + + return obj; + + } + + void mod_volume_destroy(mod_volume_obj * obj) { + + hop2hop_gain_destroy(obj->hop2hop_gain); + + } + + int mod_volume_process(mod_volume_obj * obj) { + + int rtnValue; + + if (msg_hops_isZero(obj->in) == 0) { + + hop2hop_gain_process(obj->hop2hop_gain, + obj->in->hops, + obj->out->hops); + + obj->out->timeStamp = obj->in->timeStamp; + + rtnValue = 0; + + } + else { + + msg_hops_zero(obj->out); + + rtnValue = -1; + + } + + return rtnValue; + + } + + void mod_volume_connect(mod_volume_obj * obj, msg_hops_obj * in, msg_hops_obj * out) { + + obj->in = in; + obj->out = out; + + } + + void mod_volume_disconnect(mod_volume_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + obj->out = (msg_hops_obj *) NULL; + + } + + mod_volume_cfg * mod_volume_cfg_construct(void) { + + mod_volume_cfg * cfg; + + cfg = (mod_volume_cfg *) malloc(sizeof(mod_volume_cfg)); + + return cfg; + + } + + void mod_volume_cfg_destroy(mod_volume_cfg * cfg) { + + free((void *) cfg); + + } + + void mod_volume_cfg_printf(const mod_volume_cfg * cfg) { + + } \ No newline at end of file diff --git a/src/module/mod_volume.h b/src/module/mod_volume.h new file mode 100644 index 0000000..5653d49 --- /dev/null +++ b/src/module/mod_volume.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_MODULE_VOLUME +#define __ODAS_MODULE_VOLUME + + #include "../system/hop2hop.h" + #include "../message/msg_hops.h" + + typedef struct mod_volume_obj { + + hop2hop_gain_obj * hop2hop_gain; + + msg_hops_obj * in; + msg_hops_obj * out; + + } mod_volume_obj; + + typedef struct mod_volume_cfg { + + float gain; + + } mod_volume_cfg; + + mod_volume_obj * mod_volume_construct(const mod_volume_cfg * mod_volume_config, const msg_hops_cfg * msg_hops_config); + + void mod_volume_destroy(mod_volume_obj * obj); + + int mod_volume_process(mod_volume_obj * obj); + + void mod_volume_connect(mod_volume_obj * obj, msg_hops_obj * in, msg_hops_obj * out); + + void mod_volume_disconnect(mod_volume_obj * obj); + + mod_volume_cfg * mod_volume_cfg_construct(void); + + void mod_volume_cfg_destroy(mod_volume_cfg * cfg); + + void mod_volume_cfg_printf(const mod_volume_cfg * cfg); + +#endif \ No newline at end of file diff --git a/src/signal/acorr.c b/src/signal/acorr.c new file mode 100644 index 0000000..878411c --- /dev/null +++ b/src/signal/acorr.c @@ -0,0 +1,90 @@ + + #include "acorr.h" + + acorrs_obj * acorrs_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize) { + + acorrs_obj * obj; + unsigned int iSignal; + + obj = (acorrs_obj *) malloc(sizeof(acorrs_obj)); + + obj->nSignals = nSignals; + obj->halfFrameSize = halfFrameSize; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + + obj->array[iSignal] = (float *) malloc(sizeof(float) * halfFrameSize); + + } + + + return obj; + + } + + void acorrs_destroy(acorrs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + free((void *) obj->array[iSignal]); + + } + + free((void *) obj->array); + + free((void *) obj); + + } + + void acorrs_copy(acorrs_obj * dest, const acorrs_obj * src) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < src->nSignals; iSignal++) { + + memcpy(dest->array[iSignal],src->array[iSignal], sizeof(float) * src->halfFrameSize); + + } + + } + + void acorrs_zero(acorrs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + memset(obj->array[iSignal], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + void acorrs_printf(const acorrs_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + printf("%+1.5f ",obj->array[iSignal][iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->halfFrameSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } + + } diff --git a/src/signal/acorr.h b/src/signal/acorr.h new file mode 100644 index 0000000..20da778 --- /dev/null +++ b/src/signal/acorr.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SIGNAL_ACORR +#define __ODAS_SIGNAL_ACORR + + #include + #include + #include + + typedef struct acorrs_obj { + + unsigned int nSignals; + unsigned int halfFrameSize; + float ** array; + + } acorrs_obj; + + acorrs_obj * acorrs_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize); + + void acorrs_destroy(acorrs_obj * obj); + + void acorrs_copy(acorrs_obj * dest, const acorrs_obj * src); + + void acorrs_zero(acorrs_obj * obj); + + void acorrs_printf(const acorrs_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/aimg.c b/src/signal/aimg.c new file mode 100644 index 0000000..8c7f5c8 --- /dev/null +++ b/src/signal/aimg.c @@ -0,0 +1,42 @@ + + #include "aimg.h" + + aimg_obj * aimg_construct_zero(const unsigned int aimgSize) { + + aimg_obj * obj; + + obj = (aimg_obj *) malloc(sizeof(aimg_obj)); + + obj->aimgSize = aimgSize; + obj->array = (float *) malloc(sizeof(float) * aimgSize); + memset(obj->array, 0x00, aimgSize * sizeof(float)); + + return obj; + + } + + void aimg_destroy(aimg_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void aimg_printf(const aimg_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSample = 0; iSample < obj->aimgSize; iSample++) { + + printf("%+1.5f ",obj->array[iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->aimgSize)) { + printf("\n"); + } + + } + + printf("\n"); + + } \ No newline at end of file diff --git a/src/signal/aimg.h b/src/signal/aimg.h new file mode 100644 index 0000000..10ad4bc --- /dev/null +++ b/src/signal/aimg.h @@ -0,0 +1,21 @@ +#ifndef __ODAS_SIGNAL_AIMG +#define __ODAS_SIGNAL_AIMG + + #include + #include + #include + + typedef struct aimg_obj { + + unsigned int aimgSize; + float * array; + + } aimg_obj; + + aimg_obj * aimg_construct_zero(const unsigned int aimgSize); + + void aimg_destroy(aimg_obj * obj); + + void aimg_printf(const aimg_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/area.c b/src/signal/area.c new file mode 100644 index 0000000..79f43f7 --- /dev/null +++ b/src/signal/area.c @@ -0,0 +1,90 @@ + + #include "area.h" + + areas_obj * areas_construct_zero(const unsigned int nPointsDiscrete, const unsigned int nResolutionsPerDiscrete, const unsigned int nPairs) { + + areas_obj * obj; + + obj = (areas_obj *) malloc(sizeof(areas_obj)); + + obj->nPointsDiscrete = nPointsDiscrete; + obj->nResolutionsPerDiscrete = nResolutionsPerDiscrete; + obj->nPairs = nPairs; + + obj->array = (float *) malloc(sizeof(float) * nPointsDiscrete * nResolutionsPerDiscrete * nPairs); + memset(obj->array, 0x00, sizeof(float) * nPointsDiscrete * nResolutionsPerDiscrete * nPairs); + + return obj; + + } + + void areas_destroy(areas_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void areas_printf(const areas_obj * obj) { + + unsigned int iPointDiscrete; + unsigned int iResolutionPerDiscrete; + unsigned int iPair; + + printf("%u\n",obj->nPointsDiscrete); + printf("%u\n",obj->nResolutionsPerDiscrete); + printf("%u\n",obj->nPairs); + + for (iPointDiscrete = 0; iPointDiscrete < obj->nPointsDiscrete; iPointDiscrete++) { + + for (iResolutionPerDiscrete = 0; iResolutionPerDiscrete < obj->nResolutionsPerDiscrete; iResolutionPerDiscrete++) { + + printf("(%04u:%03u): ", iPointDiscrete, iResolutionPerDiscrete); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("%1.1E ",obj->array[iPointDiscrete * (obj->nResolutionsPerDiscrete * obj->nPairs) + iResolutionPerDiscrete * obj->nPairs + iPair]); + + } + + printf("\n"); + + } + + } + + } + + area_obj * area_construct_zero(const unsigned int nPairs) { + + area_obj * obj; + + obj = (area_obj *) malloc(sizeof(area_obj)); + + obj->nPairs = nPairs; + + obj->array = (float *) malloc(sizeof(float) * nPairs); + memset(obj->array, 0x00, sizeof(float) * nPairs); + + return obj; + + } + + void area_destroy(area_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void area_printf(const area_obj * obj) { + + unsigned int iPair; + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("(%03u): %+1.3f\n", iPair, obj->array[iPair]); + + } + + } diff --git a/src/signal/area.h b/src/signal/area.h new file mode 100644 index 0000000..1801a31 --- /dev/null +++ b/src/signal/area.h @@ -0,0 +1,38 @@ +#ifndef __ODAS_SIGNAL_AREA +#define __ODAS_SIGNAL_AREA + + #include + #include + #include + + typedef struct areas_obj { + + unsigned int nPointsDiscrete; + unsigned int nResolutionsPerDiscrete; + unsigned int nPairs; + + float * array; + + } areas_obj; + + typedef struct area_obj { + + unsigned int nPairs; + + float * array; + + } area_obj; + + areas_obj * areas_construct_zero(const unsigned int nPointsDiscrete, const unsigned int nResolutionsPerDiscrete, const unsigned int nPairs); + + void areas_destroy(areas_obj * obj); + + void areas_printf(const areas_obj * obj); + + area_obj * area_construct_zero(const unsigned int nPairs); + + void area_destroy(area_obj * obj); + + void area_printf(const area_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/assignation.c b/src/signal/assignation.c new file mode 100644 index 0000000..1469f98 --- /dev/null +++ b/src/signal/assignation.c @@ -0,0 +1,43 @@ + + #include "assignation.h" + + assignations_obj * assignations_construct_zero(const unsigned int nAssignations, const unsigned int nPots) { + + assignations_obj * obj; + + obj = (assignations_obj *) malloc(sizeof(assignations_obj)); + + obj->nAssignations = nAssignations; + obj->nPots = nPots; + obj->array = (signed int *) malloc(sizeof(signed int) * nAssignations * nPots); + memset(obj->array, 0x00, nAssignations * nPots * sizeof(signed int)); + + return obj; + + } + + void assignations_destroy(assignations_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void assignations_printf(const assignations_obj * obj) { + + unsigned int iAssignation; + unsigned int iPot; + + for (iAssignation = 0; iAssignation < obj->nAssignations; iAssignation++) { + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + printf("%+01d ",obj->array[iAssignation * obj->nPots + iPot]); + + } + + printf("\n"); + + } + + } diff --git a/src/signal/assignation.h b/src/signal/assignation.h new file mode 100644 index 0000000..2ceaffe --- /dev/null +++ b/src/signal/assignation.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_ASSIGNATION +#define __ODAS_SIGNAL_ASSIGNATION + + #include + #include + #include + + typedef struct assignations_obj { + + unsigned int nAssignations; + unsigned int nPots; + signed int * array; + + } assignations_obj; + + assignations_obj * assignations_construct_zero(const unsigned int nAssignations, const unsigned int nPots); + + void assignations_destroy(assignations_obj * obj); + + void assignations_printf(const assignations_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/beampattern.c b/src/signal/beampattern.c new file mode 100644 index 0000000..2e56289 --- /dev/null +++ b/src/signal/beampattern.c @@ -0,0 +1,54 @@ + + #include "beampattern.h" + + beampatterns_obj * beampatterns_construct_zero(const unsigned int nChannels, const unsigned int nThetas) { + + beampatterns_obj * obj; + + obj = (beampatterns_obj *) malloc(sizeof(beampatterns_obj)); + + obj->nChannels = nChannels; + obj->nThetas = nThetas; + + obj->minThetas = (float *) malloc(sizeof(float) * nChannels); + memset(obj->minThetas, 0x00, sizeof(float) * nChannels); + + obj->maxThetas = (float *) malloc(sizeof(float) * nChannels); + memset(obj->maxThetas, 0x00, sizeof(float) * nChannels); + + obj->deltaThetas = (float *) malloc(sizeof(float) * nChannels); + memset(obj->deltaThetas, 0x00, sizeof(float) * nChannels); + + obj->gains = (float *) malloc(sizeof(float) * nThetas * nChannels); + memset(obj->gains, 0x00, sizeof(float) * nThetas * nChannels); + + return obj; + + } + + void beampatterns_destroy(beampatterns_obj * obj) { + + free((void *) obj->minThetas); + free((void *) obj->maxThetas); + free((void *) obj->deltaThetas); + free((void *) obj->gains); + free((void *) obj); + + } + + void beampatterns_printf(const beampatterns_obj * obj) { + + unsigned int iChannel; + unsigned int iTheta; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + for (iTheta = 0; iTheta < obj->nThetas; iTheta++) { + + printf("(%02u,%04u): %1.3f\n", iChannel, iTheta, obj->gains[obj->nThetas * iChannel + iTheta]); + + } + + } + + } \ No newline at end of file diff --git a/src/signal/beampattern.h b/src/signal/beampattern.h new file mode 100644 index 0000000..a9cdabc --- /dev/null +++ b/src/signal/beampattern.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_SIGNAL_BEAMPATTERN +#define __ODAS_SIGNAL_BEAMPATTERN + + #include + #include + #include + + typedef struct beampatterns_obj { + + unsigned int nChannels; + unsigned int nThetas; + + float * minThetas; + float * maxThetas; + float * deltaThetas; + + float * gains; + + } beampatterns_obj; + + beampatterns_obj * beampatterns_construct_zero(const unsigned int nChannels, const unsigned int nThetas); + + void beampatterns_destroy(beampatterns_obj * obj); + + void beampatterns_printf(const beampatterns_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/category.c b/src/signal/category.c new file mode 100644 index 0000000..109b2ff --- /dev/null +++ b/src/signal/category.c @@ -0,0 +1,47 @@ + + #include "category.h" + + categories_obj * categories_construct_zero(const unsigned int nSignals) { + + categories_obj * obj; + + obj = (categories_obj *) malloc(sizeof(categories_obj)); + + obj->nSignals = nSignals; + obj->array = (char *) malloc(sizeof(char) * nSignals); + memset(obj->array, 0x00, sizeof(char) * nSignals); + + return obj; + + } + + void categories_destroy(categories_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + 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; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%02u): %c\n",iSignal,obj->array[iSignal]); + + } + + } \ No newline at end of file diff --git a/src/signal/category.h b/src/signal/category.h new file mode 100644 index 0000000..3a86a25 --- /dev/null +++ b/src/signal/category.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SIGNAL_CATEGORY +#define __ODAS_SIGNAL_CATEGORY + + #include + #include + #include + + typedef struct categories_obj { + + unsigned int nSignals; + char * array; + + } categories_obj; + + categories_obj * categories_construct_zero(const unsigned int nSignals); + + 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/signal/coherence.c b/src/signal/coherence.c new file mode 100644 index 0000000..5bfb677 --- /dev/null +++ b/src/signal/coherence.c @@ -0,0 +1,43 @@ + + #include "coherence.h" + + coherences_obj * coherences_construct_zero(const unsigned int nPots, const unsigned int nTracks) { + + coherences_obj * obj; + obj = (coherences_obj *) malloc(sizeof(coherences_obj)); + obj->nPots = nPots; + obj->nTracks = nTracks; + obj->array = (float *) malloc(sizeof(float) * nTracks * nPots); + memset(obj->array, 0x00, sizeof(float) * nTracks * nPots); + + return obj; + + } + + void coherences_destroy(coherences_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void coherences_printf(coherences_obj * obj) { + + unsigned int iTrack; + unsigned int iPot; + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + + printf("p(z|C,%u) = ",iTrack); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + printf("%+1.3e ",obj->array[iTrack * obj->nPots + iPot]); + + } + + printf("\n"); + + } + + } diff --git a/src/signal/coherence.h b/src/signal/coherence.h new file mode 100644 index 0000000..fa9b7eb --- /dev/null +++ b/src/signal/coherence.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_COHERENCE +#define __ODAS_SIGNAL_COHERENCE + + #include + #include + #include + + typedef struct coherences_obj { + + unsigned int nTracks; + unsigned int nPots; + float * array; + + } coherences_obj; + + coherences_obj * coherences_construct_zero(const unsigned int nTracks, const unsigned int nPots); + + void coherences_destroy(coherences_obj * obj); + + void coherences_printf(coherences_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/delta.c b/src/signal/delta.c new file mode 100644 index 0000000..1802a17 --- /dev/null +++ b/src/signal/delta.c @@ -0,0 +1,65 @@ + + #include "delta.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + deltas_obj * deltas_construct_zero(const unsigned int nPairs) { + + deltas_obj * obj; + + obj = (deltas_obj *) malloc(sizeof(deltas_obj)); + + obj->nPairs = nPairs; + obj->array = (unsigned int *) malloc(sizeof(unsigned int) * nPairs); + memset(obj->array, 0x00, sizeof(unsigned int) * nPairs); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + deltas_obj * deltas_clone(const deltas_obj * obj) { + + deltas_obj * clone; + + clone = (deltas_obj *) malloc(sizeof(deltas_obj)); + + clone->nPairs = obj->nPairs; + clone->array = (unsigned int *) malloc(sizeof(unsigned int) * obj->nPairs); + memcpy(clone->array, obj->array, sizeof(unsigned int) * obj->nPairs); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void deltas_destroy(deltas_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void deltas_printf(const deltas_obj * obj) { + + unsigned int iPair; + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("(%02u): %02u\n",iPair,obj->array[iPair]); + + } + + } \ No newline at end of file diff --git a/src/signal/delta.h b/src/signal/delta.h new file mode 100644 index 0000000..9159e96 --- /dev/null +++ b/src/signal/delta.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SIGNAL_DELTA +#define __ODAS_SIGNAL_DELTA + + #include + #include + #include + + typedef struct deltas_obj { + + unsigned int nPairs; + unsigned int * array; + + } deltas_obj; + + deltas_obj * deltas_construct_zero(const unsigned int nPairs); + + deltas_obj * deltas_clone(const deltas_obj * obj); + + void deltas_destroy(deltas_obj * obj); + + void deltas_printf(const deltas_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/demixing.c b/src/signal/demixing.c new file mode 100644 index 0000000..18a531e --- /dev/null +++ b/src/signal/demixing.c @@ -0,0 +1,95 @@ + + #include "demixing.h" + + demixings_obj * demixings_construct_zero(const unsigned int halfFrameSize, const unsigned int nSeps, const unsigned int nChannels) { + + demixings_obj * obj; + unsigned int iSep; + + obj = (demixings_obj *) malloc(sizeof(demixings_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + obj->array = (float **) malloc(sizeof(float *) * obj->nSeps); + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + obj->array[iSep] = (float *) malloc(sizeof(float) * obj->halfFrameSize * obj->nChannels * 2); + memset(obj->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize * obj->nChannels * 2); + + } + + return obj; + + } + + void demixings_destroy(demixings_obj * obj) { + + unsigned int iSep; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + free((void *) obj->array[iSep]); + + } + + free((void *) obj->array); + free((void *) obj); + + } + + void demixings_copy(demixings_obj * dest, const demixings_obj * src) { + + unsigned int iSep; + + for (iSep = 0; iSep < src->nSeps; iSep++) { + memcpy(dest->array[iSep], src->array[iSep], src->halfFrameSize * src->nChannels * 2 * sizeof(float)); + } + + } + + void demixings_zero(demixings_obj * obj) { + + unsigned int iSep; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + memset(obj->array[iSep], 0x00, obj->halfFrameSize * obj->nChannels * 2 * sizeof(float)); + } + + } + + void demixings_printf(const demixings_obj * obj) { + + unsigned int iBin; + unsigned int iSep; + unsigned int iChannel; + + float real; + float imag; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + printf("\nSource index: %u\n",iSep); + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + printf("(%03u): ",iBin); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + real = obj->array[iSep][iBin * obj->nChannels * 2 + iChannel * 2 + 0]; + imag = obj->array[iSep][iBin * obj->nChannels * 2 + iChannel * 2 + 1]; + + printf("(%+1.2f + %1.2fi) ", real, imag); + + } + + printf("\n"); + + } + + } + + } \ No newline at end of file diff --git a/src/signal/demixing.h b/src/signal/demixing.h new file mode 100644 index 0000000..58e0fe4 --- /dev/null +++ b/src/signal/demixing.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SIGNAL_DEMIXING +#define __ODAS_SIGNAL_DEMIXING + + #include + #include + #include + + typedef struct demixings_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + + float ** array; + + } demixings_obj; + + demixings_obj * demixings_construct_zero(const unsigned int halfFrameSize, const unsigned int nSeps, const unsigned int nChannels); + + void demixings_destroy(demixings_obj * obj); + + void demixings_copy(demixings_obj * dest, const demixings_obj * src); + + void demixings_zero(demixings_obj * obj); + + void demixings_printf(const demixings_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/env.c b/src/signal/env.c new file mode 100644 index 0000000..392b741 --- /dev/null +++ b/src/signal/env.c @@ -0,0 +1,101 @@ + + #include "env.h" + + envs_obj * envs_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize) { + + envs_obj * obj; + unsigned int iSignal; + + obj = (envs_obj *) malloc(sizeof(envs_obj)); + + obj->nSignals = nSignals; + obj->halfFrameSize = halfFrameSize; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->array[iSignal], 0x00, halfFrameSize * sizeof(float)); + } + + return obj; + + } + + envs_obj * envs_clone(const envs_obj * obj) { + + envs_obj * clone; + unsigned int iSignal; + + clone = (envs_obj *) malloc(sizeof(envs_obj)); + + clone->nSignals = obj->nSignals; + clone->halfFrameSize = obj->halfFrameSize; + + clone->array = (float **) malloc(sizeof(float *) * obj->nSignals); + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + clone->array[iSignal] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memcpy(clone->array[iSignal], obj->array[iSignal], obj->halfFrameSize * sizeof(float)); + } + + return clone; + + } + + void envs_copy(envs_obj * dest, const envs_obj * src) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < src->nSignals; iSignal++) { + memcpy(dest->array[iSignal], src->array[iSignal], src->halfFrameSize * sizeof(float)); + } + + } + + void envs_zero(envs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + memset(obj->array[iSignal], 0x00, obj->halfFrameSize * sizeof(float)); + } + + } + + void envs_destroy(envs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + free((void *) obj->array); + + free((void *) obj); + + } + + void envs_printf(const envs_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + printf("%+1.5f ", + obj->array[iSignal][iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->halfFrameSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/env.h b/src/signal/env.h new file mode 100644 index 0000000..7803ec2 --- /dev/null +++ b/src/signal/env.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SIGNAL_ENV +#define __ODAS_SIGNAL_ENV + + #include + #include + #include + + typedef struct envs_obj { + + unsigned int nSignals; + unsigned int halfFrameSize; + float ** array; + + } envs_obj; + + envs_obj * envs_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize); + + envs_obj * envs_clone(const envs_obj * obj); + + void envs_copy(envs_obj * dest, const envs_obj * src); + + void envs_zero(envs_obj * obj); + + void envs_destroy(envs_obj * obj); + + void envs_printf(const envs_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/frame.c b/src/signal/frame.c new file mode 100644 index 0000000..f80bdcd --- /dev/null +++ b/src/signal/frame.c @@ -0,0 +1,92 @@ + + #include "frame.h" + + frames_obj * frames_construct_zero(const unsigned int nSignals, const unsigned int frameSize) { + + frames_obj * obj; + unsigned int iSignal; + + obj = (frames_obj *) malloc(sizeof(frames_obj)); + + obj->nSignals = nSignals; + obj->frameSize = frameSize; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array[iSignal], 0x00, frameSize * sizeof(float)); + } + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + frames_obj * frames_clone(const frames_obj * obj) { + + frames_obj * clone; + unsigned int iSignal; + + clone = (frames_obj *) malloc(sizeof(frames_obj)); + + clone->nSignals = obj->nSignals; + clone->frameSize = obj->frameSize; + + clone->array = (float **) malloc(sizeof(float *) * obj->nSignals); + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + clone->array[iSignal] = (float *) malloc(sizeof(float) * obj->frameSize); + memcpy(clone->array[iSignal], obj->array[iSignal], obj->frameSize * sizeof(float)); + } + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void frames_destroy(frames_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + free((void *) obj->array); + + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void frames_printf(const frames_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + printf("%+1.5f ",obj->array[iSignal][iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->frameSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/frame.h b/src/signal/frame.h new file mode 100644 index 0000000..53264d0 --- /dev/null +++ b/src/signal/frame.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_SIGNAL_FRAME +#define __ODAS_SIGNAL_FRAME + + #include + #include + #include + + typedef struct frames_obj { + + unsigned int nSignals; + unsigned int frameSize; + float ** array; + + } frames_obj; + + frames_obj * frames_construct_zero(const unsigned int nSignals, const unsigned int frameSize); + + frames_obj * frames_clone(const frames_obj * obj); + + void frames_destroy(frames_obj * obj); + + void frames_printf(const frames_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/freq.c b/src/signal/freq.c new file mode 100644 index 0000000..14233b5 --- /dev/null +++ b/src/signal/freq.c @@ -0,0 +1,102 @@ + + #include "freq.h" + + freqs_obj * freqs_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize) { + + freqs_obj * obj; + unsigned int iSignal; + + obj = (freqs_obj *) malloc(sizeof(freqs_obj)); + + obj->nSignals = nSignals; + obj->halfFrameSize = halfFrameSize; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * halfFrameSize * 2); + memset(obj->array[iSignal], 0x00, halfFrameSize * 2 * sizeof(float)); + } + + return obj; + + } + + freqs_obj * freqs_clone(const freqs_obj * obj) { + + freqs_obj * clone; + unsigned int iSignal; + + clone = (freqs_obj *) malloc(sizeof(freqs_obj)); + + clone->nSignals = obj->nSignals; + clone->halfFrameSize = obj->halfFrameSize; + + clone->array = (float **) malloc(sizeof(float *) * obj->nSignals); + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + clone->array[iSignal] = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memcpy(clone->array[iSignal], obj->array[iSignal], obj->halfFrameSize * 2 * sizeof(float)); + } + + return clone; + + } + + void freqs_copy(freqs_obj * dest, const freqs_obj * src) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < src->nSignals; iSignal++) { + memcpy(dest->array[iSignal], src->array[iSignal], src->halfFrameSize * 2 * sizeof(float)); + } + + } + + void freqs_zero(freqs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + memset(obj->array[iSignal], 0x00, obj->halfFrameSize * 2 * sizeof(float)); + } + + } + + void freqs_destroy(freqs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + free((void *) obj->array); + + free((void *) obj); + + } + + void freqs_printf(const freqs_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + printf("(%+1.5f + %+1.5fj) ", + obj->array[iSignal][iSample*2 + 0], + obj->array[iSignal][iSample*2 + 1]); + + if ((((iSample+1) % 8) == 0) && ((iSample+1)!=obj->halfFrameSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/freq.h b/src/signal/freq.h new file mode 100644 index 0000000..10588c8 --- /dev/null +++ b/src/signal/freq.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SIGNAL_FREQ +#define __ODAS_SIGNAL_FREQ + + #include + #include + #include + + typedef struct freqs_obj { + + unsigned int nSignals; + unsigned int halfFrameSize; + float ** array; + + } freqs_obj; + + freqs_obj * freqs_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize); + + freqs_obj * freqs_clone(const freqs_obj * obj); + + void freqs_copy(freqs_obj * dest, const freqs_obj * src); + + void freqs_zero(freqs_obj * obj); + + void freqs_destroy(freqs_obj * obj); + + void freqs_printf(const freqs_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/gain.c b/src/signal/gain.c new file mode 100644 index 0000000..cd97a11 --- /dev/null +++ b/src/signal/gain.c @@ -0,0 +1,46 @@ + + #include "gain.h" + + gains_obj * gains_construct_zero(const unsigned int nSeps, const unsigned int nChannels) { + + gains_obj * obj; + + obj = (gains_obj *) malloc(sizeof(gains_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + + obj->array = (float *) malloc(sizeof(float) * nSeps * nChannels); + memset(obj->array, 0x00, sizeof(float) * nSeps * nChannels); + + return obj; + + } + + void gains_destroy(gains_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void gains_printf(const gains_obj * obj) { + + unsigned int iSep; + unsigned int iChannel; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + printf("(%02u): ",iSep); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + printf("%+1.3f ",obj->array[iSep * obj->nChannels + iChannel]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/gain.h b/src/signal/gain.h new file mode 100644 index 0000000..c49c521 --- /dev/null +++ b/src/signal/gain.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_GAIN +#define __ODAS_SIGNAL_GAIN + + #include + #include + #include + + typedef struct gains_obj { + + unsigned int nSeps; + unsigned int nChannels; + float * array; + + } gains_obj; + + gains_obj * gains_construct_zero(const unsigned int nSeps, const unsigned int nChannels); + + void gains_destroy(gains_obj * obj); + + void gains_printf(const gains_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/hop.c b/src/signal/hop.c new file mode 100644 index 0000000..be8263c --- /dev/null +++ b/src/signal/hop.c @@ -0,0 +1,100 @@ + + #include "hop.h" + + hops_obj * hops_construct_zero(const unsigned int nSignals, const unsigned int hopSize) { + + hops_obj * obj; + unsigned int iSignal; + + obj = (hops_obj *) malloc(sizeof(hops_obj)); + + obj->nSignals = nSignals; + obj->hopSize = hopSize; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * hopSize); + memset(obj->array[iSignal], 0x00, hopSize * sizeof(float)); + } + + return obj; + + } + + hops_obj * hops_clone(const hops_obj * obj) { + + hops_obj * clone; + unsigned int iSignal; + + clone = (hops_obj *) malloc(sizeof(hops_obj)); + + clone->nSignals = obj->nSignals; + clone->hopSize = obj->hopSize; + + clone->array = (float **) malloc(sizeof(float *) * obj->nSignals); + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + clone->array[iSignal] = (float *) malloc(sizeof(float) * obj->hopSize); + memcpy(clone->array[iSignal], obj->array[iSignal], obj->hopSize * sizeof(float)); + } + + return clone; + + } + + void hops_copy(hops_obj * dest, const hops_obj * src) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < src->nSignals; iSignal++) { + memcpy(dest->array[iSignal], src->array[iSignal], src->hopSize * sizeof(float)); + } + + } + + void hops_zero(hops_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + memset(obj->array[iSignal], 0x00, obj->hopSize * sizeof(float)); + } + + } + + void hops_destroy(hops_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + free((void *) obj->array); + + free((void *) obj); + + } + + void hops_printf(const hops_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + printf("%+1.5f ",obj->array[iSignal][iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->hopSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/hop.h b/src/signal/hop.h new file mode 100644 index 0000000..2a8e4e5 --- /dev/null +++ b/src/signal/hop.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SIGNAL_HOP +#define __ODAS_SIGNAL_HOP + + #include + #include + #include + + typedef struct hops_obj { + + unsigned int nSignals; + unsigned int hopSize; + float ** array; + + } hops_obj; + + hops_obj * hops_construct_zero(const unsigned int nSignals, const unsigned int hopSize); + + hops_obj * hops_clone(const hops_obj * obj); + + void hops_copy(hops_obj * dest, const hops_obj * src); + + void hops_zero(hops_obj * obj); + + void hops_destroy(hops_obj * obj); + + void hops_printf(const hops_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/impulse.c b/src/signal/impulse.c new file mode 100644 index 0000000..d8ff0bb --- /dev/null +++ b/src/signal/impulse.c @@ -0,0 +1,23 @@ + + #include "impulse.h" + + impulse_obj * impulse_construct(const unsigned int nCoefficients) { + + impulse_obj * obj; + + obj = (impulse_obj *) malloc(sizeof(impulse_obj)); + + obj->nCoefficients = nCoefficients; + obj->array = (float *) malloc(sizeof(float) * nCoefficients); + memset(obj->array, 0x00, sizeof(float) * nCoefficients); + + return obj; + + } + + void impulse_destroy(impulse_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } \ No newline at end of file diff --git a/src/signal/impulse.h b/src/signal/impulse.h new file mode 100644 index 0000000..5133621 --- /dev/null +++ b/src/signal/impulse.h @@ -0,0 +1,18 @@ +#ifndef __ODAS_SIGNAL_IMPULSE +#define __ODAS_SIGNAL_IMPULSE + + #include + #include + + typedef struct impulse_obj { + + float * array; + unsigned int nCoefficients; + + } impulse_obj; + + impulse_obj * impulse_construct(const unsigned int nCoefficients); + + void impulse_destroy(impulse_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/index.c b/src/signal/index.c new file mode 100644 index 0000000..1b1f019 --- /dev/null +++ b/src/signal/index.c @@ -0,0 +1,57 @@ + + #include "index.h" + + indexes_obj * indexes_construct_zero(const unsigned int nCoarses, const unsigned int nFines) { + + indexes_obj * obj; + + obj = (indexes_obj *) malloc(sizeof(indexes_obj)); + + obj->nCoarses = nCoarses; + obj->nFines = nFines; + obj->array = (unsigned int *) malloc(sizeof(unsigned int) * nCoarses * nFines); + memset(obj->array, 0x00, sizeof(unsigned int) * nCoarses * nFines); + obj->count = (unsigned int *) malloc(sizeof(unsigned int) * nCoarses); + memset(obj->count, 0x00, sizeof(unsigned int) * nCoarses); + + return obj; + + } + + void indexes_destroy(indexes_obj * obj) { + + free((void *) obj->array); + free((void *) obj->count); + free((void *) obj); + + } + + void indexes_printf(const indexes_obj * obj) { + + unsigned int iCoarse; + unsigned int iFine; + + for (iCoarse = 0; iCoarse < obj->nCoarses; iCoarse++) { + + printf("(%04u): ",iCoarse); + + if (obj->count[iCoarse] > 0) { + + for (iFine = 0; iFine < obj->count[iCoarse]; iFine++) { + + printf("%04u ",obj->array[iCoarse * obj->nFines + iFine]); + + } + + } + else { + + printf("-"); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/index.h b/src/signal/index.h new file mode 100644 index 0000000..891334a --- /dev/null +++ b/src/signal/index.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SIGNAL_INDEX +#define __ODAS_SIGNAL_INDEX + + #include + #include + #include + + typedef struct indexes_obj { + + unsigned int nCoarses; + unsigned int nFines; + unsigned int * array; + unsigned int * count; + + } indexes_obj; + + indexes_obj * indexes_construct_zero(const unsigned int nCoarses, const unsigned int nFines); + + void indexes_destroy(indexes_obj * obj); + + void indexes_printf(const indexes_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/kalman.c b/src/signal/kalman.c new file mode 100644 index 0000000..eb5cce2 --- /dev/null +++ b/src/signal/kalman.c @@ -0,0 +1,28 @@ + + #include "kalman.h" + + kalman_obj * kalman_construct_zero(void) { + + kalman_obj * obj; + + obj = (kalman_obj *) malloc(sizeof(kalman_obj)); + + obj->x_lm1lm1 = matrix_construct_zero(6,1); + obj->x_llm1 = matrix_construct_zero(6,1); + obj->P_lm1lm1 = matrix_construct_zero(6,6); + obj->P_llm1 = matrix_construct_zero(6,6); + + return obj; + + } + + void kalman_destroy(kalman_obj * obj) { + + matrix_destroy(obj->x_lm1lm1); + matrix_destroy(obj->x_llm1); + matrix_destroy(obj->P_lm1lm1); + matrix_destroy(obj->P_llm1); + + free((void *) obj); + + } diff --git a/src/signal/kalman.h b/src/signal/kalman.h new file mode 100644 index 0000000..4e2dade --- /dev/null +++ b/src/signal/kalman.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_KALMAN +#define __ODAS_SIGNAL_KALMAN + + #include + #include + + #include "../utils/matrix.h" + + typedef struct kalman_obj { + + matrix_obj * x_lm1lm1; + matrix_obj * x_llm1; + matrix_obj * P_lm1lm1; + matrix_obj * P_llm1; + + } kalman_obj; + + kalman_obj * kalman_construct_zero(void); + + void kalman_destroy(kalman_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/map.c b/src/signal/map.c new file mode 100644 index 0000000..dcc59c5 --- /dev/null +++ b/src/signal/map.c @@ -0,0 +1,46 @@ + + #include "map.h" + + maps_obj * maps_construct_zero(const unsigned int nCoarses, const unsigned int nFines) { + + maps_obj * obj; + + obj = (maps_obj *) malloc(sizeof(maps_obj)); + + obj->nCoarses = nCoarses; + obj->nFines = nFines; + + obj->array = (char *) malloc(sizeof(char) * nFines * nCoarses); + memset(obj->array, 0x00, sizeof(char) * nFines * nCoarses); + + return obj; + + } + + void maps_destroy(maps_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void maps_printf(const maps_obj * obj) { + + unsigned int iFine; + unsigned int iCoarse; + + for (iFine = 0; iFine < obj->nFines; iFine++) { + + printf("(%04u): ",iFine); + + for (iCoarse = 0; iCoarse < obj->nCoarses; iCoarse++) { + + printf("%01u",obj->array[iFine * obj->nCoarses + iCoarse]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/map.h b/src/signal/map.h new file mode 100644 index 0000000..9db88b3 --- /dev/null +++ b/src/signal/map.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_MAP +#define __ODAS_SIGNAL_MAP + + #include + #include + #include + + typedef struct maps_obj { + + unsigned int nCoarses; + unsigned int nFines; + char * array; + + } maps_obj; + + maps_obj * maps_construct_zero(const unsigned int nCoarses, const unsigned int nFines); + + void maps_destroy(maps_obj * obj); + + void maps_printf(const maps_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/mask.c b/src/signal/mask.c new file mode 100644 index 0000000..c8cdf94 --- /dev/null +++ b/src/signal/mask.c @@ -0,0 +1,46 @@ + + #include "mask.h" + + masks_obj * masks_construct_zero(const unsigned int nSeps, const unsigned int nChannels) { + + masks_obj * obj; + + obj = (masks_obj *) malloc(sizeof(masks_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + + obj->array = (char *) malloc(sizeof(char) * nSeps * nChannels); + memset(obj->array, 0x00, sizeof(char) * nSeps * nChannels); + + return obj; + + } + + void masks_destroy(masks_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void masks_printf(const masks_obj * obj) { + + unsigned int iSep; + unsigned int iChannel; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + printf("(%02u): ",iSep); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + printf("%d ",obj->array[iSep * obj->nChannels + iChannel]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/mask.h b/src/signal/mask.h new file mode 100644 index 0000000..6251889 --- /dev/null +++ b/src/signal/mask.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_MASK +#define __ODAS_SIGNAL_MASK + + #include + #include + #include + + typedef struct masks_obj { + + unsigned int nSeps; + unsigned int nChannels; + char * array; + + } masks_obj; + + masks_obj * masks_construct_zero(const unsigned int nSeps, const unsigned int nChannels); + + void masks_destroy(masks_obj * obj); + + void masks_printf(const masks_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/mixture.c b/src/signal/mixture.c new file mode 100644 index 0000000..6cc3f31 --- /dev/null +++ b/src/signal/mixture.c @@ -0,0 +1,128 @@ + + #include "mixture.h" + + mixture_obj * mixture_construct_zero(const unsigned int nPots, const unsigned int nTracks) { + + mixture_obj * obj; + + obj = (mixture_obj *) malloc(sizeof(mixture_obj)); + + obj->assignations = combining_generate(nPots, nTracks); + + obj->nPots = nPots; + obj->nTracks = nTracks; + obj->nTracksNewFalse = nTracks + 2; + obj->nCombinations = obj->assignations->nAssignations; + + obj->p_Ez_AICD = (float *) malloc(sizeof(float) * (3+nTracks) * obj->nPots ); + memset(obj->p_Ez_AICD, 0x00, sizeof(float) * (3+nTracks) * obj->nPots ); + + obj->p_Eszs_phics = (float *) malloc(sizeof(float) * obj->nTracksNewFalse * obj->nPots); + memset(obj->p_Eszs_phics, 0x00, sizeof(float) * obj->nTracksNewFalse * obj->nPots); + + obj->p_phics = (float *) malloc(sizeof(float) * obj->nTracksNewFalse * obj->nPots); + memset(obj->p_phics, 0x00, sizeof(float) * obj->nTracksNewFalse * obj->nPots); + + obj->p_Ez_phic = (float *) malloc(sizeof(float) * obj->nCombinations); + memset(obj->p_Ez_phic, 0x00, sizeof(float) * obj->nCombinations); + + obj->p_phic = (float *) malloc(sizeof(float) * obj->nCombinations); + memset(obj->p_phic, 0x00, sizeof(float) * obj->nCombinations); + + obj->p_phic_Ez = (float *) malloc(sizeof(float) * obj->nCombinations); + memset(obj->p_phic_Ez, 0x00, sizeof(float) * obj->nCombinations); + + return obj; + + } + + void mixture_destroy(mixture_obj * obj) { + + assignations_destroy(obj->assignations); + + free((void *) obj->p_Ez_AICD); + free((void *) obj->p_Eszs_phics); + free((void *) obj->p_phics); + free((void *) obj->p_Ez_phic); + free((void *) obj->p_phic); + free((void *) obj->p_phic_Ez); + + free((void *) obj); + + } + + void mixture_printf(const mixture_obj * obj) { + + unsigned int iTrack; + unsigned int iTrackNewFalse; + unsigned int iPot; + unsigned int iCombination; + + printf("p(E|A) = "); + for (iPot = 0; iPot < obj->nPots; iPot++) { + printf("%+1.3e ",obj->p_Ez_AICD[0 * obj->nPots + iPot]); + } + printf("\n"); + + printf("p(E|I) = "); + for (iPot = 0; iPot < obj->nPots; iPot++) { + printf("%+1.3e ",obj->p_Ez_AICD[1 * obj->nPots + iPot]); + } + printf("\n"); + + printf("p(z|D) = "); + for (iPot = 0; iPot < obj->nPots; iPot++) { + printf("%+1.3e ",obj->p_Ez_AICD[2 * obj->nPots + iPot]); + } + printf("\n"); + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + printf("p(z|C,%u) = ",iTrack); + for (iPot = 0; iPot < obj->nPots; iPot++) { + printf("%+1.3e ", obj->p_Ez_AICD[3 * obj->nPots + iPot]); + } + printf("\n"); + } + printf("\n"); + + printf("p(E,z|phi(s)):\n"); + for (iTrackNewFalse = 0; iTrackNewFalse < obj->nTracksNewFalse; iTrackNewFalse++) { + + printf(" phi = %d: ",iTrackNewFalse-2); + for (iPot = 0; iPot < obj->nPots; iPot++) { + printf("%+1.3e ",obj->p_Eszs_phics[iTrackNewFalse * obj->nPots + iPot]); + } + printf("\n"); + + } + printf("\n"); + + printf("p(phi(s)):\n"); + for (iTrackNewFalse = 0; iTrackNewFalse < obj->nTracksNewFalse; iTrackNewFalse++) { + + printf(" phi = %d: ",iTrackNewFalse-2); + for (iPot = 0; iPot < obj->nPots; iPot++) { + printf("%+1.3e ",obj->p_phics[iTrackNewFalse * obj->nPots + iPot]); + } + printf("\n"); + + } + printf("\n"); + + printf("p(E,z|phi), p(phi), p(phi|E,z):\n"); + + for (iCombination = 0; iCombination < obj->nCombinations; iCombination++) { + + printf(" "); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + printf("%+01d ",obj->assignations->array[iCombination * obj->nPots + iPot]); + + } + + printf(": %+1.3e %+1.3e %+1.3e\n",obj->p_Ez_phic[iCombination],obj->p_phic[iCombination],obj->p_phic_Ez[iCombination]); + + } + + } \ No newline at end of file diff --git a/src/signal/mixture.h b/src/signal/mixture.h new file mode 100644 index 0000000..d7469cf --- /dev/null +++ b/src/signal/mixture.h @@ -0,0 +1,35 @@ +#ifndef __ODAS_SIGNAL_MIXTURE +#define __ODAS_SIGNAL_MIXTURE + + #include + #include + #include + + #include "../signal/assignation.h" + #include "../init/combining.h" + + typedef struct mixture_obj { + + unsigned int nPots; + unsigned int nTracks; + unsigned int nTracksNewFalse; + unsigned int nCombinations; + + assignations_obj * assignations; + + float * p_Ez_AICD; + float * p_Eszs_phics; + float * p_phics; + float * p_Ez_phic; + float * p_phic; + float * p_phic_Ez; + + } mixture_obj; + + mixture_obj * mixture_construct_zero(const unsigned int nPots, const unsigned int nTracks); + + void mixture_destroy(mixture_obj * obj); + + void mixture_printf(const mixture_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/pair.c b/src/signal/pair.c new file mode 100644 index 0000000..12b7621 --- /dev/null +++ b/src/signal/pair.c @@ -0,0 +1,65 @@ + + #include "pair.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + pairs_obj * pairs_construct_zero(const unsigned int nPairs) { + + pairs_obj * obj; + + obj = (pairs_obj *) malloc(sizeof(pairs_obj)); + + obj->nPairs = nPairs; + obj->array = (char *) malloc(sizeof(char) * nPairs); + memset(obj->array, 0x00, sizeof(char) * nPairs); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + pairs_obj * pairs_clone(const pairs_obj * obj) { + + pairs_obj * clone; + + clone = (pairs_obj *) malloc(sizeof(pairs_obj)); + + clone->nPairs = obj->nPairs; + clone->array = (char *) malloc(sizeof(char) * obj->nPairs); + memcpy(clone->array, obj->array, sizeof(char) * obj->nPairs); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destroy | + // +----------------------------------------------------------+ + + void pairs_destroy(pairs_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void pairs_printf(const pairs_obj * obj) { + + unsigned int iPair; + + printf("nPairs: %u\n", obj->nPairs); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + printf("(%02u): %d\n", iPair, obj->array[iPair]); + } + + } \ No newline at end of file diff --git a/src/signal/pair.h b/src/signal/pair.h new file mode 100644 index 0000000..c0eabc5 --- /dev/null +++ b/src/signal/pair.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SIGNAL_PAIR +#define __ODAS_SIGNAL_PAIR + + #include + #include + #include + + typedef struct pairs_obj { + + unsigned int nPairs; + char * array; + + } pairs_obj; + + pairs_obj * pairs_construct_zero(const unsigned int nPairs); + + pairs_obj * pairs_clone(const pairs_obj * obj); + + void pairs_destroy(pairs_obj * obj); + + void pairs_printf(const pairs_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/particle.c b/src/signal/particle.c new file mode 100644 index 0000000..4caa5c4 --- /dev/null +++ b/src/signal/particle.c @@ -0,0 +1,49 @@ + + #include "particle.h" + + particles_obj * particles_construct_zero(const unsigned int nParticles) { + + particles_obj * obj; + + obj = (particles_obj *) malloc(sizeof(particles_obj)); + + obj->nParticles = nParticles; + + obj->array = (float *) malloc(sizeof(float) * 7 * nParticles); + memset(obj->array, 0x00, sizeof(float) * 7 * nParticles); + + obj->state = (unsigned char *) malloc(sizeof(unsigned char) * nParticles); + memset(obj->state, 0x00, sizeof(unsigned char) * nParticles); + + return obj; + + } + + void particles_destroy(particles_obj * obj) { + + free((void *) obj->array); + free((void *) obj->state); + free((void *) obj); + + } + + void particles_printf(const particles_obj * obj) { + + unsigned int iParticle; + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + printf("(%04u): x = (%+1.3f,%+1.3f,%+1.3f), v = (%+1.3f,%+1.3f,%+1.3f), w = %1.5f, s = %u\n", + iParticle, + obj->array[iParticle * 7 + 0], + obj->array[iParticle * 7 + 1], + obj->array[iParticle * 7 + 2], + obj->array[iParticle * 7 + 3], + obj->array[iParticle * 7 + 4], + obj->array[iParticle * 7 + 5], + obj->array[iParticle * 7 + 6], + obj->state[iParticle]); + + } + + } \ No newline at end of file diff --git a/src/signal/particle.h b/src/signal/particle.h new file mode 100644 index 0000000..3a08ff4 --- /dev/null +++ b/src/signal/particle.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_SIGNAL_PARTICLE +#define __ODAS_SIGNAL_PARTICLE + + #include + #include + #include + + typedef struct particles_obj { + + unsigned int nParticles; + float * array; + unsigned char * state; + + } particles_obj; + + particles_obj * particles_construct_zero(const unsigned int nParticles); + + void particles_destroy(particles_obj * obj); + + void particles_printf(const particles_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/pitch.c b/src/signal/pitch.c new file mode 100644 index 0000000..fa924ff --- /dev/null +++ b/src/signal/pitch.c @@ -0,0 +1,47 @@ + + #include "pitch.h" + + pitches_obj * pitches_construct_zero(const unsigned int nSignals) { + + pitches_obj * obj; + + obj = (pitches_obj *) malloc(sizeof(pitches_obj)); + + obj->nSignals = nSignals; + obj->array = (float *) malloc(sizeof(float) * nSignals); + memset(obj->array, 0x00, sizeof(float) * nSignals); + + return obj; + + } + + void pitches_destroy(pitches_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void pitches_copy(pitches_obj * dest, const pitches_obj * src) { + + memcpy(dest->array, src->array, sizeof(float) * src->nSignals); + + } + + void pitches_zero(pitches_obj * obj) { + + memset(obj->array, 0x00, sizeof(float) * obj->nSignals); + + } + + void pitches_printf(const pitches_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%02u): %1.5f\n",iSignal,obj->array[iSignal]); + + } + + } \ No newline at end of file diff --git a/src/signal/pitch.h b/src/signal/pitch.h new file mode 100644 index 0000000..0a46feb --- /dev/null +++ b/src/signal/pitch.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SIGNAL_PITCH +#define __ODAS_SIGNAL_PITCH + + #include + #include + #include + + typedef struct pitches_obj { + + unsigned int nSignals; + float * array; + + } pitches_obj; + + pitches_obj * pitches_construct_zero(const unsigned int nSignals); + + void pitches_destroy(pitches_obj * obj); + + void pitches_copy(pitches_obj * dest, const pitches_obj * src); + + void pitches_zero(pitches_obj * obj); + + void pitches_printf(const pitches_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/point.c b/src/signal/point.c new file mode 100644 index 0000000..ee68ae4 --- /dev/null +++ b/src/signal/point.c @@ -0,0 +1,69 @@ + + #include "point.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + points_obj * points_construct_zero(const unsigned int nPoints) { + + points_obj * obj; + + obj = (points_obj *) malloc(sizeof(points_obj)); + + obj->nPoints = nPoints; + obj->array = (float *) malloc(sizeof(float) * nPoints * 3); + memset(obj->array, 0x00, nPoints * 3 * sizeof(float)); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + points_obj * points_clone(const points_obj * obj) { + + points_obj * clone; + + clone = (points_obj *) malloc(sizeof(points_obj)); + + clone->nPoints = obj->nPoints; + clone->array = (float *) malloc(sizeof(float) * obj->nPoints * 3); + memcpy(clone->array, obj->array, obj->nPoints * 3 * sizeof(float)); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void points_destroy(points_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void points_printf(const points_obj * obj) { + + unsigned int iPoint; + + for (iPoint = 0; iPoint < obj->nPoints; iPoint++) { + + printf("(%04u): (%+1.3f,%+1.3f,%+1.3f)\n", + iPoint, + obj->array[iPoint * 3 + 0], + obj->array[iPoint * 3 + 1], + obj->array[iPoint * 3 + 2]); + + } + + } \ No newline at end of file diff --git a/src/signal/point.h b/src/signal/point.h new file mode 100644 index 0000000..c6ea0da --- /dev/null +++ b/src/signal/point.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SIGNAL_POINT +#define __ODAS_SIGNAL_POINT + + #include + #include + #include + + typedef struct points_obj { + + unsigned int nPoints; + float * array; + + } points_obj; + + points_obj * points_construct_zero(const unsigned int nPoints); + + points_obj * points_clone(const points_obj * obj); + + void points_destroy(points_obj * obj); + + void points_printf(const points_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/postprob.c b/src/signal/postprob.c new file mode 100644 index 0000000..2861cfd --- /dev/null +++ b/src/signal/postprob.c @@ -0,0 +1,64 @@ + + #include "postprob.h" + + postprobs_obj * postprobs_construct_zero(const unsigned int nPots, const unsigned int nTracks) { + + postprobs_obj * obj; + + obj = (postprobs_obj *) malloc(sizeof(postprobs_obj)); + + obj->nPots = nPots; + obj->nTracks = nTracks; + + obj->arrayNew = (float *) malloc(sizeof(float) * nPots); + memset(obj->arrayNew, 0x00, sizeof(float) * nPots); + + obj->arrayTrack = (float *) malloc(sizeof(float) * nTracks * nPots); + memset(obj->arrayTrack, 0x00, sizeof(float) * nTracks * nPots); + + obj->arrayTrackTotal = (float *) malloc(sizeof(float) * nTracks); + memset(obj->arrayTrackTotal, 0x00, sizeof(float) * nTracks); + + return obj; + + } + + void postprobs_destroy(postprobs_obj * obj) { + + free((void *) obj->arrayNew); + free((void *) obj->arrayTrack); + free((void *) obj->arrayTrackTotal); + free((void *) obj); + + } + + void postprobs_printf(const postprobs_obj * obj) { + + unsigned int iTrack; + unsigned int iPot; + + printf("p(new|E,z): "); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + printf("%+1.3e ",obj->arrayNew[iPot]); + + } + + printf("\n"); + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + + printf(" p(%u|E,z): ",iTrack); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + printf("%+1.3e ",obj->arrayTrack[iTrack * obj->nPots + iPot]); + + } + + printf("> %+1.3f\n",obj->arrayTrackTotal[iTrack]); + + } + + } \ No newline at end of file diff --git a/src/signal/postprob.h b/src/signal/postprob.h new file mode 100644 index 0000000..e70f7e0 --- /dev/null +++ b/src/signal/postprob.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SIGNAL_POSTPROB +#define __ODAS_SIGNAL_POSTPROB + + #include + #include + #include + + typedef struct postprobs_obj { + + unsigned int nTracks; + unsigned int nPots; + + float * arrayNew; + float * arrayTrack; + float * arrayTrackTotal; + + } postprobs_obj; + + postprobs_obj * postprobs_construct_zero(const unsigned int nPots, const unsigned int nTracks); + + void postprobs_destroy(postprobs_obj * obj); + + void postprobs_printf(const postprobs_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/pot.c b/src/signal/pot.c new file mode 100644 index 0000000..0fd7523 --- /dev/null +++ b/src/signal/pot.c @@ -0,0 +1,69 @@ + + #include "pot.h" + + pots_obj * pots_construct_zero(const unsigned int nPots) { + + pots_obj * obj; + + obj = (pots_obj *) malloc(sizeof(pots_obj)); + + obj->nPots = nPots; + obj->array = (float *) malloc(sizeof(float) * 4 * nPots); + memset(obj->array, 0x00, sizeof(float) * 4 * nPots); + + return obj; + + } + + pots_obj * pots_clone(const pots_obj * obj) { + + pots_obj * clone; + + clone = (pots_obj *) malloc(sizeof(pots_obj)); + + clone->nPots = obj->nPots; + clone->array = (float *) malloc(sizeof(float) * 4 * obj->nPots); + memcpy(clone->array, obj->array, sizeof(float) * 4 * obj->nPots); + + return clone; + + } + + void pots_copy(pots_obj * dest, const pots_obj * src) { + + dest->nPots = src->nPots; + + memcpy(dest->array, src->array, sizeof(float) * 4 * src->nPots); + + } + + void pots_zero(pots_obj * obj) { + + obj->nPots = 0; + memset(obj->array, 0x00, sizeof(float) * 4 * obj->nPots); + + } + + void pots_destroy(pots_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void pots_printf(const pots_obj * obj) { + + unsigned int iPot; + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + printf("(%02u): %+1.3f %+1.3f %+1.3f %+1.3f\n", + iPot, + obj->array[iPot * 4 + 0], + obj->array[iPot * 4 + 1], + obj->array[iPot * 4 + 2], + obj->array[iPot * 4 + 3]); + + } + + } diff --git a/src/signal/pot.h b/src/signal/pot.h new file mode 100644 index 0000000..1fff189 --- /dev/null +++ b/src/signal/pot.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_SIGNAL_POT +#define __ODAS_SIGNAL_POT + + #include + #include + #include + + typedef struct pots_obj { + + unsigned int nPots; + float * array; + + } pots_obj; + + pots_obj * pots_construct_zero(const unsigned int nPots); + + pots_obj * pots_clone(const pots_obj * obj); + + void pots_copy(pots_obj * dest, const pots_obj * src); + + void pots_zero(pots_obj * obj); + + void pots_destroy(pots_obj * obj); + + void pots_printf(const pots_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/scan.c b/src/signal/scan.c new file mode 100644 index 0000000..91c59d8 --- /dev/null +++ b/src/signal/scan.c @@ -0,0 +1,81 @@ + + #include "scan.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + scans_obj * scans_construct_null(const unsigned int nLevels) { + + scans_obj * obj; + + obj = (scans_obj *) malloc(sizeof(scans_obj)); + + obj->nLevels = nLevels; + + obj->points = (points_obj **) malloc(sizeof(points_obj *) * nLevels); + memset(obj->points, 0x00, sizeof(points_obj *) * nLevels); + + obj->tdoas = (tdoas_obj **) malloc(sizeof(tdoas_obj *) * nLevels); + memset(obj->tdoas, 0x00, sizeof(tdoas_obj *) * nLevels); + + obj->deltas = (deltas_obj **) malloc(sizeof(deltas_obj *) * nLevels); + memset(obj->deltas, 0x00, sizeof(deltas_obj *) * nLevels); + + obj->spatialindexes = (spatialindexes_obj **) malloc(sizeof(spatialindexes_obj *) * nLevels); + memset(obj->spatialindexes, 0x00, sizeof(spatialindexes_obj *) * nLevels); + + obj->pairs = (pairs_obj *) NULL; + + obj->indexes = (indexes_obj **) malloc(sizeof(indexes_obj *) * nLevels); + memset(obj->indexes, 0x00, sizeof(indexes_obj *) * nLevels); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void scans_destroy(scans_obj * obj) { + + unsigned int iLevel; + + for (iLevel = 0; iLevel < obj->nLevels; iLevel++) { + + if (obj->points[iLevel] != NULL) { + points_destroy(obj->points[iLevel]); + } + + if (obj->tdoas[iLevel] != NULL) { + tdoas_destroy(obj->tdoas[iLevel]); + } + + if (obj->deltas[iLevel] != NULL) { + deltas_destroy(obj->deltas[iLevel]); + } + + if (obj->spatialindexes[iLevel] != NULL) { + spatialindexes_destroy(obj->spatialindexes[iLevel]); + } + + if (obj->indexes[iLevel] != NULL) { + indexes_destroy(obj->indexes[iLevel]); + } + + } + + if (obj->pairs != NULL) { + pairs_destroy(obj->pairs); + } + + free((void *) obj->points); + free((void *) obj->tdoas); + free((void *) obj->deltas); + free((void *) obj->spatialindexes); + free((void *) obj->indexes); + + free((void *) obj); + + } diff --git a/src/signal/scan.h b/src/signal/scan.h new file mode 100644 index 0000000..5199f0b --- /dev/null +++ b/src/signal/scan.h @@ -0,0 +1,33 @@ +#ifndef __ODAS_SIGNAL_SCAN +#define __ODAS_SIGNAL_SCAN + + #include + #include + + #include "pair.h" + #include "point.h" + #include "tdoa.h" + #include "delta.h" + #include "index.h" + #include "spatialindex.h" + + //! Scan setup + typedef struct scans_obj { + + unsigned int nLevels; + + points_obj ** points; + tdoas_obj ** tdoas; + deltas_obj ** deltas; + spatialindexes_obj ** spatialindexes; + pairs_obj * pairs; + + indexes_obj ** indexes; + + } scans_obj; + + scans_obj * scans_construct_null(const unsigned int nLevels); + + void scans_destroy(scans_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/spatialgain.c b/src/signal/spatialgain.c new file mode 100644 index 0000000..bad6eb2 --- /dev/null +++ b/src/signal/spatialgain.c @@ -0,0 +1,78 @@ + + #include "spatialgain.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + spatialgains_obj * spatialgains_construct_zero(const unsigned int nChannels, const unsigned int nPoints) { + + spatialgains_obj * obj; + + obj = (spatialgains_obj *) malloc(sizeof(spatialgains_obj)); + + obj->nChannels = nChannels; + obj->nPoints = nPoints; + + obj->array = (float *) malloc(sizeof(float) * nChannels * nPoints); + memset(obj->array, 0x00, sizeof(float) * nChannels * nPoints); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + spatialgains_obj * spatialgains_clone(const spatialgains_obj * obj) { + + spatialgains_obj * clone; + + clone = (spatialgains_obj *) malloc(sizeof(spatialgains_obj)); + + clone->nChannels = obj->nChannels; + clone->nPoints = obj->nPoints; + + clone->array = (float *) malloc(sizeof(float) * obj->nChannels * obj->nPoints); + memcpy(clone->array, obj->array, sizeof(float) * obj->nChannels * obj->nPoints); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void spatialgains_destroy(spatialgains_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void spatialgains_printf(const spatialgains_obj * obj) { + + unsigned int iPoint; + unsigned int iChannel; + + for (iPoint = 0; iPoint < obj->nPoints; iPoint++) { + + printf("(%04u): ",iPoint); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + printf("%1.2f ",obj->array[iPoint * obj->nChannels + iChannel]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/spatialgain.h b/src/signal/spatialgain.h new file mode 100644 index 0000000..9ec8dbf --- /dev/null +++ b/src/signal/spatialgain.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SIGNAL_SPATIALGAIN +#define __ODAS_SIGNAL_SPATIALGAIN + + #include + #include + #include + + typedef struct spatialgains_obj { + + unsigned int nChannels; + unsigned int nPoints; + + float * array; + + } spatialgains_obj; + + spatialgains_obj * spatialgains_construct_zero(const unsigned int nChannels, const unsigned int nPoints); + + spatialgains_obj * spatialgains_clone(const spatialgains_obj * obj); + + void spatialgains_destroy(spatialgains_obj * obj); + + void spatialgains_printf(const spatialgains_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/spatialindex.c b/src/signal/spatialindex.c new file mode 100644 index 0000000..f2facf6 --- /dev/null +++ b/src/signal/spatialindex.c @@ -0,0 +1,95 @@ + + #include "spatialindex.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + spatialindexes_obj * spatialindexes_construct_zero(const unsigned int nPoints, const unsigned int nPairs) { + + spatialindexes_obj * obj; + + obj = (spatialindexes_obj *) malloc(sizeof(spatialindexes_obj)); + + obj->nPoints = nPoints; + obj->nPairs = nPairs; + + obj->array = (unsigned int *) malloc(sizeof(unsigned int) * nPoints * nPairs); + memset(obj->array, 0x00, sizeof(unsigned int) * nPoints * nPairs); + + obj->count = (unsigned int *) malloc(sizeof(unsigned int) * nPoints); + memset(obj->count, 0x00, sizeof(unsigned int) * nPoints); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + spatialindexes_obj * spatialindexes_clone(const spatialindexes_obj * obj) { + + spatialindexes_obj * clone; + + clone = (spatialindexes_obj *) malloc(sizeof(spatialindexes_obj)); + + clone->nPoints = obj->nPoints; + clone->nPairs = obj->nPairs; + + clone->array = (unsigned int *) malloc(sizeof(unsigned int) * obj->nPoints * obj->nPairs); + memcpy(clone->array, obj->array, sizeof(unsigned int) * obj->nPoints * obj->nPairs); + + clone->count = (unsigned int *) malloc(sizeof(unsigned int) * obj->nPoints); + memcpy(clone->count, obj->count, sizeof(unsigned int) * obj->nPoints); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void spatialindexes_destroy(spatialindexes_obj * obj) { + + free((void *) obj->array); + free((void *) obj->count); + + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void spatialindexes_printf(const spatialindexes_obj * obj) { + + unsigned int iPoint; + unsigned int iPair; + + for (iPoint = 0; iPoint < obj->nPoints; iPoint++) { + + printf("(%04u): ",iPoint); + + if (obj->count[iPoint] > 0) { + + for (iPair = 0; iPair < obj->count[iPoint]; iPair++) { + + printf("%03u ",obj->array[iPoint * obj->nPairs + iPair]); + + } + + } + else { + + printf("-"); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/spatialindex.h b/src/signal/spatialindex.h new file mode 100644 index 0000000..1ef38d9 --- /dev/null +++ b/src/signal/spatialindex.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SIGNAL_SPATIALINDEX +#define __ODAS_SIGNAL_SPATIALINDEX + + #include + #include + #include + + typedef struct spatialindexes_obj { + + unsigned int nPoints; + unsigned int nPairs; + + unsigned int * array; + unsigned int * count; + + } spatialindexes_obj; + + spatialindexes_obj * spatialindexes_construct_zero(const unsigned int nPoints, const unsigned int nPairs); + + spatialindexes_obj * spatialindexes_clone(const spatialindexes_obj * obj); + + void spatialindexes_destroy(spatialindexes_obj * obj); + + void spatialindexes_printf(const spatialindexes_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/spatialmask.c b/src/signal/spatialmask.c new file mode 100644 index 0000000..db0c185 --- /dev/null +++ b/src/signal/spatialmask.c @@ -0,0 +1,87 @@ + + #include "spatialmask.h" + + // +----------------------------------------------------------+ + // | Constructor | + // +----------------------------------------------------------+ + + spatialmasks_obj * spatialmasks_construct_zero(const unsigned int nPoints, const unsigned int nPairs) { + + spatialmasks_obj * obj; + + obj = (spatialmasks_obj *) malloc(sizeof(spatialmasks_obj)); + + obj->nPoints = nPoints; + obj->nPairs = nPairs; + + obj->array = (char *) malloc(sizeof(char) * nPoints * nPairs); + memset(obj->array, 0x00, sizeof(char) * nPoints * nPairs); + + return obj; + + } + + // +----------------------------------------------------------+ + // | Clone | + // +----------------------------------------------------------+ + + spatialmasks_obj * spatialmasks_clone(const spatialmasks_obj * obj) { + + spatialmasks_obj * clone; + + clone = (spatialmasks_obj *) malloc(sizeof(spatialmasks_obj)); + + clone->nPoints = obj->nPoints; + clone->nPairs = obj->nPairs; + + clone->array = (char *) malloc(sizeof(char) * obj->nPoints * obj->nPairs); + memcpy(clone->array, obj->array, sizeof(char) * obj->nPoints * obj->nPairs); + + return clone; + + } + + // +----------------------------------------------------------+ + // | Destructor | + // +----------------------------------------------------------+ + + void spatialmasks_destroy(spatialmasks_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + // +----------------------------------------------------------+ + // | Print | + // +----------------------------------------------------------+ + + void spatialmasks_printf(const spatialmasks_obj * obj) { + + unsigned int iPoint; + unsigned int iPair; + + for (iPoint = 0; iPoint < obj->nPoints; iPoint++) { + + printf("(%04u): ",iPoint); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + if (obj->array[iPoint * obj->nPairs + iPair] != 0x00) { + + printf("1"); + + } + else { + + printf("0"); + + } + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/spatialmask.h b/src/signal/spatialmask.h new file mode 100644 index 0000000..025e447 --- /dev/null +++ b/src/signal/spatialmask.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SIGNAL_SPATIALMASK +#define __ODAS_SIGNAL_SPATIALMASK + + #include + #include + #include + + typedef struct spatialmasks_obj { + + unsigned int nPoints; + unsigned int nPairs; + + char * array; + + } spatialmasks_obj; + + spatialmasks_obj * spatialmasks_construct_zero(const unsigned int nPoints, const unsigned int nPairs); + + spatialmasks_obj * spatialmasks_clone(const spatialmasks_obj * obj); + + void spatialmasks_destroy(spatialmasks_obj * obj); + + void spatialmasks_printf(const spatialmasks_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/steer.c b/src/signal/steer.c new file mode 100644 index 0000000..50394af --- /dev/null +++ b/src/signal/steer.c @@ -0,0 +1,85 @@ + + #include "steer.h" + + steers_obj * steers_construct_zero(const unsigned int halfFrameSize, const unsigned int nSeps, const unsigned int nChannels) { + + steers_obj * obj; + unsigned int iSep; + + obj = (steers_obj *) malloc(sizeof(steers_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + obj->array = (float **) malloc(sizeof(float *) * obj->nSeps); + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + obj->array[iSep] = (float *) malloc(sizeof(float) * obj->halfFrameSize * obj->nChannels * 2); + memset(obj->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize * obj->nChannels * 2); + + } + + return obj; + + } + + void steers_destroy(steers_obj * obj) { + + unsigned int iSep; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + free((void *) obj->array[iSep]); + + } + + free((void *) obj->array); + free((void *) obj); + + } + + void steers_copy(steers_obj * dest, const steers_obj * src) { + + unsigned int iSep; + + for (iSep = 0; iSep < src->nSeps; iSep++) { + memcpy(dest->array[iSep], src->array[iSep], src->halfFrameSize * src->nChannels * 2 * sizeof(float)); + } + + } + + void steers_printf(const steers_obj * obj) { + + unsigned int iBin; + unsigned int iSep; + unsigned int iChannel; + + float real; + float imag; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + printf("\nSource index: %u\n",iSep); + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + printf("(%03u): ",iBin); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + real = obj->array[iSep][iBin * obj->nChannels * 2 + iChannel * 2 + 0]; + imag = obj->array[iSep][iBin * obj->nChannels * 2 + iChannel * 2 + 1]; + + printf("(%+1.2f + %1.2fi) ", real, imag); + + } + + printf("\n"); + + } + + } + + } \ No newline at end of file diff --git a/src/signal/steer.h b/src/signal/steer.h new file mode 100644 index 0000000..8fab923 --- /dev/null +++ b/src/signal/steer.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SIGNAL_STEER +#define __ODAS_SIGNAL_STEER + + #include + #include + #include + + typedef struct steers_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + + float ** array; + + } steers_obj; + + steers_obj * steers_construct_zero(const unsigned int halfFrameSize, const unsigned int nSeps, const unsigned int nChannels); + + void steers_destroy(steers_obj * obj); + + void steers_copy(steers_obj * dest, const steers_obj * src); + + void steers_printf(const steers_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/target.c b/src/signal/target.c new file mode 100644 index 0000000..dad6466 --- /dev/null +++ b/src/signal/target.c @@ -0,0 +1,110 @@ + + #include "target.h" + + targets_obj * targets_construct_zero(const unsigned int nTargets) { + + targets_obj * obj; + unsigned int iTarget; + + obj = (targets_obj *) malloc(sizeof(targets_obj)); + + obj->nTargets = nTargets; + + obj->tags = (char **) malloc(sizeof(char *) * nTargets); + + for (iTarget = 0; iTarget < nTargets; iTarget++) { + + obj->tags[iTarget] = (char *) malloc(sizeof(char) * 256); + strcpy(obj->tags[iTarget], ""); + + } + + obj->array = (float *) malloc(sizeof(float) * 3 * nTargets); + memset(obj->array, 0x00, sizeof(float) * 3 * nTargets); + + return obj; + + } + + void targets_destroy(targets_obj * obj) { + + unsigned int iTarget; + + for (iTarget = 0; iTarget < obj->nTargets; iTarget++) { + free((void *) obj->tags[iTarget]); + } + free((void *) obj->tags); + + free((void *) obj->array); + free((void *) obj); + + } + + targets_obj * targets_clone(const targets_obj * obj) { + + targets_obj * clone; + unsigned int iTarget; + + clone = (targets_obj *) malloc(sizeof(targets_obj)); + + clone->nTargets = obj->nTargets; + clone->array = (float *) malloc(sizeof(float) * 3 * obj->nTargets); + memcpy(clone->array, obj->array, sizeof(float) * 3 * obj->nTargets); + + clone->tags = (char **) malloc(sizeof(char *) * obj->nTargets); + + for (iTarget = 0; iTarget < obj->nTargets; iTarget++) { + + clone->tags[iTarget] = (char *) malloc(sizeof(char) * 256); + strcpy(clone->tags[iTarget], obj->tags[iTarget]); + + } + + return clone; + + } + + void targets_copy(targets_obj * dest, const targets_obj * src) { + + unsigned int iTarget; + + dest->nTargets = src->nTargets; + memcpy(dest->array, src->array, sizeof(float) * 3 * src->nTargets); + + for (iTarget = 0; iTarget < src->nTargets; iTarget++) { + + strcpy(dest->tags[iTarget], src->tags[iTarget]); + + } + + } + + void targets_zero(targets_obj * obj) { + + unsigned int iTarget; + + memset(obj->array, 0x00, sizeof(float) * 3 * obj->nTargets); + + for (iTarget = 0; iTarget < obj->nTargets; iTarget++) { + + strcpy(obj->tags[iTarget], ""); + + } + + } + + void targets_printf(const targets_obj * obj) { + + unsigned int iTarget; + + for (iTarget = 0; iTarget < obj->nTargets; iTarget++) { + + printf("[%s]: %+1.3f %+1.3f %+1.3f\n", + obj->tags[iTarget], + obj->array[iTarget * 3 + 0], + obj->array[iTarget * 3 + 1], + obj->array[iTarget * 3 + 2]); + + } + + } \ No newline at end of file diff --git a/src/signal/target.h b/src/signal/target.h new file mode 100644 index 0000000..04a3d58 --- /dev/null +++ b/src/signal/target.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SIGNAL_TARGET +#define __ODAS_SIGNAL_TARGET + + #include + #include + #include + + typedef struct targets_obj { + + unsigned int nTargets; + char ** tags; + float * array; + + } targets_obj; + + targets_obj * targets_construct_zero(const unsigned int nTargets); + + void targets_destroy(targets_obj * obj); + + targets_obj * targets_clone(const targets_obj * obj); + + void targets_copy(targets_obj * dest, const targets_obj * src); + + void targets_zero(targets_obj * obj); + + void targets_printf(const targets_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/tau.c b/src/signal/tau.c new file mode 100644 index 0000000..15b112f --- /dev/null +++ b/src/signal/tau.c @@ -0,0 +1,51 @@ + + #include "tau.h" + + taus_obj * taus_construct_zero(const unsigned int nPoints, const unsigned int nPairs) { + + taus_obj * obj; + + obj = (taus_obj *) malloc(sizeof(taus_obj)); + + obj->nPoints = nPoints; + obj->nPairs = nPairs; + + obj->mu = (float *) malloc(sizeof(float) * nPoints * nPairs); + memset(obj->mu, 0x00, sizeof(float) * nPoints * nPairs); + + obj->sigma2 = (float *) malloc(sizeof(float) * nPoints * nPairs); + memset(obj->sigma2, 0x00, sizeof(float) * nPoints * nPairs); + + return obj; + + } + + void taus_destroy(taus_obj * obj) { + + free((void *) obj->mu); + free((void *) obj->sigma2); + + free((void *) obj); + + } + + void taus_printf(const taus_obj * obj) { + + unsigned int iPoint; + unsigned int iPair; + + for (iPoint = 0; iPoint < obj->nPoints; iPoint++) { + + printf("(%04u): ",iPoint); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("%03.3f (%03.3f) ",obj->mu[iPoint * obj->nPairs + iPair],obj->sigma2[iPoint * obj->nPairs + iPair]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/signal/tau.h b/src/signal/tau.h new file mode 100644 index 0000000..2b9118e --- /dev/null +++ b/src/signal/tau.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SIGNAL_TAU +#define __ODAS_SIGNAL_TAU + + #include + #include + #include + + typedef struct taus_obj { + + unsigned int nPoints; + unsigned int nPairs; + float * mu; + float * sigma2; + + } taus_obj; + + taus_obj * taus_construct_zero(const unsigned int nPoints, const unsigned int nPairs); + + void taus_destroy(taus_obj * obj); + + void taus_printf(const taus_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/tdoa.c b/src/signal/tdoa.c new file mode 100644 index 0000000..2b12ebf --- /dev/null +++ b/src/signal/tdoa.c @@ -0,0 +1,74 @@ + + #include "tdoa.h" + + tdoas_obj * tdoas_construct_zero(const unsigned int nPoints, const unsigned int nPairs) { + + tdoas_obj * obj; + + obj = (tdoas_obj *) malloc(sizeof(tdoas_obj)); + + obj->nPoints = nPoints; + obj->nPairs = nPairs; + + obj->array = (unsigned int *) malloc(sizeof(unsigned int) * nPoints * nPairs); + memset(obj->array, 0x00, sizeof(unsigned int) * nPoints * nPairs); + + obj->min = (unsigned int *) malloc(sizeof(unsigned int) * nPairs); + memset(obj->min, 0x00, sizeof(unsigned int) * nPairs); + + obj->max = (unsigned int *) malloc(sizeof(unsigned int) * nPairs); + memset(obj->max, 0x00, sizeof(unsigned int) * nPairs); + + return obj; + + } + + void tdoas_destroy(tdoas_obj * obj) { + + free((void *) obj->array); + free((void *) obj->min); + free((void *) obj->max); + free((void *) obj); + + } + + void tdoas_printf(const tdoas_obj * obj) { + + unsigned int iPoint; + unsigned int iPair; + + for (iPoint = 0; iPoint < obj->nPoints; iPoint++) { + + printf("(%04u): ",iPoint); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("%04u ",obj->array[iPoint * obj->nPairs + iPair]); + + } + + printf("\n"); + + } + + printf("(min): "); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("%04u ",obj->min[iPair]); + + } + + printf("\n"); + + printf("(max): "); + + for (iPair = 0; iPair < obj->nPairs; iPair++) { + + printf("%04u ",obj->max[iPair]); + + } + + printf("\n"); + + } diff --git a/src/signal/tdoa.h b/src/signal/tdoa.h new file mode 100644 index 0000000..fe90a2b --- /dev/null +++ b/src/signal/tdoa.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_SIGNAL_TDOA +#define __ODAS_SIGNAL_TDOA + + #include + #include + #include + + typedef struct tdoas_obj { + + unsigned int nPoints; + unsigned int nPairs; + unsigned int * array; + unsigned int * min; + unsigned int * max; + + } tdoas_obj; + + tdoas_obj * tdoas_construct_zero(const unsigned int nPoints, const unsigned int nPairs); + + void tdoas_destroy(tdoas_obj * obj); + + void tdoas_printf(const tdoas_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/track.c b/src/signal/track.c new file mode 100644 index 0000000..7049e2c --- /dev/null +++ b/src/signal/track.c @@ -0,0 +1,130 @@ + + #include "track.h" + + tracks_obj * tracks_construct_zero(const unsigned int nTracks) { + + tracks_obj * obj; + unsigned int iTrack; + + obj = (tracks_obj *) malloc(sizeof(tracks_obj)); + + obj->nTracks = nTracks; + obj->array = (float *) malloc(sizeof(float) * 3 * nTracks); + memset(obj->array, 0x00, sizeof(float) * 3 * nTracks); + obj->ids = (unsigned long long *) malloc(sizeof(unsigned long long) * nTracks); + memset(obj->ids, 0x00, sizeof(unsigned long long) * nTracks); + + obj->tags = (char **) malloc(sizeof(char *) * nTracks); + + for (iTrack = 0; iTrack < nTracks; iTrack++) { + + obj->tags[iTrack] = (char *) malloc(sizeof(char) * 256); + strcpy(obj->tags[iTrack], ""); + + } + + obj->activity = (float *) malloc(sizeof(float) * nTracks); + memset(obj->activity, 0x00, sizeof(float) * nTracks); + + return obj; + + } + + void tracks_destroy(tracks_obj * obj) { + + unsigned int iTrack; + + free((void *) obj->array); + free((void *) obj->ids); + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + free((void *) obj->tags[iTrack]); + } + free((void *) obj->tags); + + free((void *) obj->activity); + free((void *) obj); + + } + + tracks_obj * tracks_clone(const tracks_obj * obj) { + + tracks_obj * clone; + unsigned int iTrack; + + clone = (tracks_obj *) malloc(sizeof(tracks_obj)); + + clone->nTracks = obj->nTracks; + clone->array = (float *) malloc(sizeof(float) * 3 * obj->nTracks); + memcpy(clone->array, obj->array, sizeof(float) * 3 * obj->nTracks); + clone->ids = (unsigned long long *) malloc(sizeof(unsigned long long) * obj->nTracks); + memcpy(clone->ids, obj->ids, sizeof(unsigned long long) * obj->nTracks); + + clone->tags = (char **) malloc(sizeof(char *) * obj->nTracks); + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + + clone->tags[iTrack] = (char *) malloc(sizeof(char) * 256); + strcpy(clone->tags[iTrack], ""); + + } + + clone->activity = (float *) malloc(sizeof(float) * obj->nTracks); + memcpy(clone->activity, obj->activity, sizeof(float) * obj->nTracks); + + return clone; + + } + + void tracks_copy(tracks_obj * dest, const tracks_obj * src) { + + unsigned int iTrack; + + dest->nTracks = src->nTracks; + memcpy(dest->array, src->array, sizeof(float) * 3 * src->nTracks); + memcpy(dest->ids, src->ids, sizeof(unsigned long long) * src->nTracks); + + for (iTrack = 0; iTrack < src->nTracks; iTrack++) { + + strcpy(dest->tags[iTrack], src->tags[iTrack]); + + } + + memcpy(dest->activity, src->activity, sizeof(float) * src->nTracks); + + } + + void tracks_zero(tracks_obj * obj) { + + unsigned int iTrack; + + memset(obj->array, 0x00, sizeof(float) * 3 * obj->nTracks); + memset(obj->ids, 0x00, sizeof(unsigned long long) * obj->nTracks); + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + + strcpy(obj->tags[iTrack], ""); + + } + + memset(obj->activity, 0x00, sizeof(float) * obj->nTracks); + + } + + void tracks_printf(const tracks_obj * obj) { + + unsigned int iTrack; + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + + printf("(%04llu)-[%s]: %+1.3f %+1.3f %+1.3f - %1.3f\n", + obj->ids[iTrack], + obj->tags[iTrack], + obj->array[iTrack * 3 + 0], + obj->array[iTrack * 3 + 1], + obj->array[iTrack * 3 + 2], + obj->activity[iTrack]); + + } + + } \ No newline at end of file diff --git a/src/signal/track.h b/src/signal/track.h new file mode 100644 index 0000000..9986db2 --- /dev/null +++ b/src/signal/track.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_SIGNAL_TRACK +#define __ODAS_SIGNAL_TRACK + + #include + #include + #include + + typedef struct tracks_obj { + + unsigned int nTracks; + unsigned long long * ids; + char ** tags; + float * array; + float * activity; + + } tracks_obj; + + tracks_obj * tracks_construct_zero(const unsigned int nTracks); + + void tracks_destroy(tracks_obj * obj); + + tracks_obj * tracks_clone(const tracks_obj * obj); + + void tracks_copy(tracks_obj * dest, const tracks_obj * src); + + void tracks_zero(tracks_obj * obj); + + void tracks_printf(const tracks_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/triangle.c b/src/signal/triangle.c new file mode 100644 index 0000000..78d693c --- /dev/null +++ b/src/signal/triangle.c @@ -0,0 +1,45 @@ + + #include "triangle.h" + + triangles_obj * triangles_construct_zero(const unsigned int nTriangles) { + + triangles_obj * obj; + + obj = (triangles_obj *) malloc(sizeof(triangles_obj)); + + obj->nTriangles = nTriangles; + obj->array = (float *) malloc(sizeof(float) * nTriangles * 9); + memset(obj->array, nTriangles * 9, sizeof(float)); + + return obj; + + } + + void triangles_destroy(triangles_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void triangles_printf(const triangles_obj * obj) { + + unsigned int iTriangle; + + for (iTriangle = 0; iTriangle < obj->nTriangles; iTriangle++) { + + printf("(%04u): (%+1.3f,%+1.3f,%+1.3f) - (%+1.3f,%+1.3f,%+1.3f) - (%+1.3f,%+1.3f,%+1.3f)\n", + iTriangle, + obj->array[iTriangle * 9 + 0], + obj->array[iTriangle * 9 + 1], + obj->array[iTriangle * 9 + 2], + obj->array[iTriangle * 9 + 3], + obj->array[iTriangle * 9 + 4], + obj->array[iTriangle * 9 + 5], + obj->array[iTriangle * 9 + 6], + obj->array[iTriangle * 9 + 7], + obj->array[iTriangle * 9 + 8]); + + } + + } \ No newline at end of file diff --git a/src/signal/triangle.h b/src/signal/triangle.h new file mode 100644 index 0000000..a20b964 --- /dev/null +++ b/src/signal/triangle.h @@ -0,0 +1,21 @@ +#ifndef __ODAS_SIGNAL_TRIANGLE +#define __ODAS_SIGNAL_TRIANGLE + + #include + #include + #include + + typedef struct triangles_obj { + + unsigned nTriangles; + float * array; + + } triangles_obj; + + triangles_obj * triangles_construct_zero(const unsigned int nTriangles); + + void triangles_destroy(triangles_obj * obj); + + void triangles_printf(const triangles_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/window.c b/src/signal/window.c new file mode 100644 index 0000000..8d9022b --- /dev/null +++ b/src/signal/window.c @@ -0,0 +1,23 @@ + + #include "window.h" + + window_obj * window_construct_zero(const unsigned int frameSize) { + + window_obj * obj; + + obj = (window_obj *) malloc(sizeof(window_obj)); + + obj->frameSize = frameSize; + obj->array = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array, frameSize, sizeof(float)); + + return obj; + + } + + void window_destroy(window_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } \ No newline at end of file diff --git a/src/signal/window.h b/src/signal/window.h new file mode 100644 index 0000000..556a611 --- /dev/null +++ b/src/signal/window.h @@ -0,0 +1,18 @@ +#ifndef __ODAS_SIGNAL_WINDOW +#define __ODAS_SIGNAL_WINDOW + + #include + #include + + typedef struct window_obj { + + unsigned int frameSize; + float * array; + + } window_obj; + + window_obj * window_construct_zero(const unsigned int frameSize); + + void window_destroy(window_obj * obj); + +#endif \ No newline at end of file diff --git a/src/signal/xcorr.c b/src/signal/xcorr.c new file mode 100644 index 0000000..1799f7d --- /dev/null +++ b/src/signal/xcorr.c @@ -0,0 +1,100 @@ + + #include "xcorr.h" + + xcorrs_obj * xcorrs_construct_zero(const unsigned int nSignals, const unsigned int frameSize) { + + xcorrs_obj * obj; + unsigned int iSignal; + + obj = (xcorrs_obj *) malloc(sizeof(xcorrs_obj)); + + obj->nSignals = nSignals; + obj->frameSize = frameSize; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array[iSignal], 0x00, frameSize * sizeof(float)); + } + + return obj; + + } + + void xcorrs_destroy(xcorrs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + free((void *) obj->array); + + free((void *) obj); + + } + + void xcorrs_copy(xcorrs_obj * dest, const xcorrs_obj * src) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < src->nSignals; iSignal++) { + memcpy(dest->array[iSignal], src->array[iSignal], src->frameSize * sizeof(float)); + } + + } + + void xcorrs_zero(xcorrs_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + memset(obj->array[iSignal], 0x00, obj->frameSize * sizeof(float)); + } + + } + + void xcorrs_printf(const xcorrs_obj * obj) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + printf("%+1.5f ",obj->array[iSignal][iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->frameSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } + + } + + void xcorrs_printf_signal(const xcorrs_obj * obj, const unsigned int iSignal) { + + unsigned int iSample; + + printf("(%04u): ",iSignal); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + printf("%+1.5f ",obj->array[iSignal][iSample]); + + if ((((iSample+1) % 16) == 0) && ((iSample+1)!=obj->frameSize)) { + printf("\n "); + } + + } + + printf("\n"); + + } \ No newline at end of file diff --git a/src/signal/xcorr.h b/src/signal/xcorr.h new file mode 100644 index 0000000..fb9956f --- /dev/null +++ b/src/signal/xcorr.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SIGNAL_XCORR +#define __ODAS_SIGNAL_XCORR + + #include + #include + #include + + typedef struct xcorrs_obj { + + unsigned int nSignals; + unsigned int frameSize; + float ** array; + + } xcorrs_obj; + + xcorrs_obj * xcorrs_construct_zero(const unsigned int nSignals, const unsigned int frameSize); + + void xcorrs_destroy(xcorrs_obj * obj); + + void xcorrs_copy(xcorrs_obj * dest, const xcorrs_obj * src); + + void xcorrs_zero(xcorrs_obj * obj); + + void xcorrs_printf(const xcorrs_obj * obj); + + void xcorrs_printf_signal(const xcorrs_obj * obj, const unsigned int iSignal); + +#endif \ No newline at end of file diff --git a/src/sink/snk_categories.c b/src/sink/snk_categories.c new file mode 100644 index 0000000..49aa93e --- /dev/null +++ b/src/sink/snk_categories.c @@ -0,0 +1,391 @@ + + #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); + + if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_text_json)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_text_json)) || + ((obj->interface->type == interface_terminal) && (obj->format->type == format_text_json)))) { + + printf("Sink categories: Invalid interface and/or format.\n"); + exit(EXIT_FAILURE); + + } + + obj->buffer = (char *) malloc(sizeof(char) * 1024); + memset(obj->buffer, 0x00, sizeof(char) * 1024); + obj->bufferSize = 0; + + 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->buffer); + + 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; + + } + + void snk_categories_open(snk_categories_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_categories_open_interface_blackhole(obj); + + break; + + case interface_file: + + snk_categories_open_interface_file(obj); + + break; + + case interface_socket: + + snk_categories_open_interface_socket(obj); + + break; + + case interface_terminal: + + snk_categories_open_interface_terminal(obj); + + break; + + default: + + printf("Sink categories: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_categories_open_interface_blackhole(snk_categories_obj * obj) { + + // Empty + + } + + void snk_categories_open_interface_file(snk_categories_obj * obj) { + + obj->fp = fopen(obj->interface->fileName, "wb"); + + if (obj->fp == NULL) { + printf("Cannot open file %s\n",obj->interface->fileName); + exit(EXIT_FAILURE); + } + + } + + void snk_categories_open_interface_socket(snk_categories_obj * obj) { + + memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in)); + + obj->sserver.sin_family = AF_INET; + obj->sserver.sin_addr.s_addr = inet_addr(obj->interface->ip); + obj->sserver.sin_port = htons(obj->interface->port); + obj->sid = socket(AF_INET, SOCK_STREAM, 0); + + if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) { + + printf("Sink categories: Cannot connect to server\n"); + exit(EXIT_FAILURE); + + } + + } + + void snk_categories_open_interface_terminal(snk_categories_obj * obj) { + + // Empty + + } + + void snk_categories_close(snk_categories_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_categories_close_interface_blackhole(obj); + + break; + + case interface_file: + + snk_categories_close_interface_file(obj); + + break; + + case interface_socket: + + snk_categories_close_interface_socket(obj); + + break; + + case interface_terminal: + + snk_categories_close_interface_terminal(obj); + + break; + + default: + + printf("Sink categories: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_categories_close_interface_blackhole(snk_categories_obj * obj) { + + // Empty + + } + + void snk_categories_close_interface_file(snk_categories_obj * obj) { + + fclose(obj->fp); + + } + + void snk_categories_close_interface_socket(snk_categories_obj * obj) { + + close(obj->sid); + + } + + void snk_categories_close_interface_terminal(snk_categories_obj * obj) { + + // Empty + + } + + int snk_categories_process(snk_categories_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + switch(obj->format->type) { + + case format_text_json: + + snk_categories_process_format_text_json(obj); + + break; + + case format_undefined: + + snk_categories_process_format_undefined(obj); + + break; + + default: + + printf("Sink categories: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_categories_process_interface_blackhole(obj); + + break; + + case interface_file: + + snk_categories_process_interface_file(obj); + + break; + + case interface_socket: + + snk_categories_process_interface_socket(obj); + + break; + + case interface_terminal: + + snk_categories_process_interface_terminal(obj); + + break; + + default: + + printf("Sink categories: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void snk_categories_process_interface_blackhole(snk_categories_obj * obj) { + + // Empty + + } + + void snk_categories_process_interface_file(snk_categories_obj * obj) { + + fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp); + + } + + void snk_categories_process_interface_socket(snk_categories_obj * obj) { + + if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) { + printf("Sink categories: Could not send message.\n"); + exit(EXIT_FAILURE); + } + + } + + void snk_categories_process_interface_terminal(snk_categories_obj * obj) { + + printf("%s",obj->buffer); + + } + + void snk_categories_process_format_text_json(snk_categories_obj * obj) { + + unsigned int iChannel; + + obj->buffer[0] = 0x00; + + sprintf(obj->buffer,"%s{\n",obj->buffer); + sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp); + sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + switch(obj->in->categories->array[iChannel]) { + + case 0x01: + + sprintf(obj->buffer,"%s { \"category\": \"speech\" }",obj->buffer); + + break; + + case 0x00: + + sprintf(obj->buffer,"%s { \"category\": \"nonspeech\" }",obj->buffer); + + break; + + default: + + sprintf(obj->buffer,"%s { \"category\": \"undefined\" }",obj->buffer); + + break; + + } + + if (iChannel != (obj->nChannels - 1)) { + + sprintf(obj->buffer,"%s,",obj->buffer); + + } + + sprintf(obj->buffer,"%s\n",obj->buffer); + + } + + sprintf(obj->buffer,"%s ]\n",obj->buffer); + sprintf(obj->buffer,"%s}\n",obj->buffer); + + obj->bufferSize = strlen(obj->buffer); + + } + + void snk_categories_process_format_undefined(snk_categories_obj * obj) { + + obj->buffer[0] = 0x00; + obj->bufferSize = 0; + + } + + snk_categories_cfg * snk_categories_cfg_construct(void) { + + snk_categories_cfg * cfg; + + cfg = (snk_categories_cfg *) malloc(sizeof(snk_categories_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_categories_cfg_destroy(snk_categories_cfg * snk_categories_config) { + + if (snk_categories_config->format != NULL) { + format_destroy(snk_categories_config->format); + } + if (snk_categories_config->interface != NULL) { + interface_destroy(snk_categories_config->interface); + } + + free((void *) snk_categories_config); + + } \ No newline at end of file diff --git a/src/sink/snk_categories.h b/src/sink/snk_categories.h new file mode 100644 index 0000000..28cace3 --- /dev/null +++ b/src/sink/snk_categories.h @@ -0,0 +1,93 @@ +#ifndef __ODAS_SINK_CATEGORIES +#define __ODAS_SINK_CATEGORIES + + #include + #include + #include + #include + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_categories.h" + #include "../utils/pcm.h" + + typedef struct snk_categories_obj { + + unsigned long long timeStamp; + + unsigned int nChannels; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + char * buffer; + unsigned int bufferSize; + + FILE * fp; + + struct sockaddr_in sserver; + 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); + + void snk_categories_open(snk_categories_obj * obj); + + void snk_categories_open_interface_blackhole(snk_categories_obj * obj); + + void snk_categories_open_interface_file(snk_categories_obj * obj); + + void snk_categories_open_interface_socket(snk_categories_obj * obj); + + void snk_categories_open_interface_terminal(snk_categories_obj * obj); + + void snk_categories_close(snk_categories_obj * obj); + + void snk_categories_close_interface_blackhole(snk_categories_obj * obj); + + void snk_categories_close_interface_file(snk_categories_obj * obj); + + void snk_categories_close_interface_socket(snk_categories_obj * obj); + + void snk_categories_close_interface_terminal(snk_categories_obj * obj); + + int snk_categories_process(snk_categories_obj * obj); + + void snk_categories_process_interface_blackhole(snk_categories_obj * obj); + + void snk_categories_process_interface_file(snk_categories_obj * obj); + + void snk_categories_process_interface_socket(snk_categories_obj * obj); + + void snk_categories_process_interface_terminal(snk_categories_obj * obj); + + void snk_categories_process_format_text_json(snk_categories_obj * obj); + + void snk_categories_process_format_undefined(snk_categories_obj * obj); + + snk_categories_cfg * snk_categories_cfg_construct(void); + + void snk_categories_cfg_destroy(snk_categories_cfg * snk_categories_config); + +#endif \ No newline at end of file diff --git a/src/sink/snk_hops.c b/src/sink/snk_hops.c new file mode 100644 index 0000000..3f8f912 --- /dev/null +++ b/src/sink/snk_hops.c @@ -0,0 +1,446 @@ + + #include "snk_hops.h" + + snk_hops_obj * snk_hops_construct(const snk_hops_cfg * snk_hops_config, const msg_hops_cfg * msg_hops_config) { + + snk_hops_obj * obj; + + obj = (snk_hops_obj *) malloc(sizeof(snk_hops_obj)); + + obj->timeStamp = 0; + + obj->hopSize = msg_hops_config->hopSize; + obj->nChannels = msg_hops_config->nChannels; + obj->fS = snk_hops_config->fS; + + obj->format = format_clone(snk_hops_config->format); + obj->interface = interface_clone(snk_hops_config->interface); + + memset(obj->bytes, 0x00, 4 * sizeof(char)); + + if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int08)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int16)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int24)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int32)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int08)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int16)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int24)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_binary_int32)))) { + + printf("Sink hops: Invalid interface and/or format.\n"); + exit(EXIT_FAILURE); + + } + + obj->buffer = (char *) malloc(sizeof(char) * msg_hops_config->nChannels * msg_hops_config->hopSize * 4); + memset(obj->buffer, 0x00, sizeof(char) * msg_hops_config->nChannels * msg_hops_config->hopSize * 4); + obj->bufferSize = 0; + + obj->in = (msg_hops_obj *) NULL; + + return obj; + + } + + void snk_hops_destroy(snk_hops_obj * obj) { + + format_destroy(obj->format); + interface_destroy(obj->interface); + free((void *) obj->buffer); + + free((void *) obj); + + } + + void snk_hops_connect(snk_hops_obj * obj, msg_hops_obj * in) { + + obj->in = in; + + } + + void snk_hops_disconnect(snk_hops_obj * obj) { + + obj->in = (msg_hops_obj *) NULL; + + } + + void snk_hops_open(snk_hops_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_hops_open_interface_blackhole(obj); + + break; + + case interface_file: + + snk_hops_open_interface_file(obj); + + break; + + case interface_socket: + + snk_hops_open_interface_socket(obj); + + break; + + default: + + printf("Sink hops: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_hops_open_interface_blackhole(snk_hops_obj * obj) { + + // Empty + + } + + void snk_hops_open_interface_file(snk_hops_obj * obj) { + + obj->fp = fopen(obj->interface->fileName, "wb"); + + if (obj->fp == NULL) { + printf("Cannot open file %s\n",obj->interface->fileName); + exit(EXIT_FAILURE); + } + + } + + void snk_hops_open_interface_socket(snk_hops_obj * obj) { + + memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in)); + + obj->sserver.sin_family = AF_INET; + obj->sserver.sin_addr.s_addr = inet_addr(obj->interface->ip); + obj->sserver.sin_port = htons(obj->interface->port); + obj->sid = socket(AF_INET, SOCK_STREAM, 0); + + if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) { + + printf("Sink hops: Cannot connect to server\n"); + exit(EXIT_FAILURE); + + } + + } + + void snk_hops_close(snk_hops_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_hops_close_interface_blackhole(obj); + + break; + + case interface_file: + + snk_hops_close_interface_file(obj); + + break; + + case interface_socket: + + snk_hops_close_interface_socket(obj); + + break; + + default: + + printf("Sink hops: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_hops_close_interface_blackhole(snk_hops_obj * obj) { + + // Empty + + } + + void snk_hops_close_interface_file(snk_hops_obj * obj) { + + fclose(obj->fp); + + } + + void snk_hops_close_interface_socket(snk_hops_obj * obj) { + + close(obj->sid); + + } + + int snk_hops_process(snk_hops_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + switch(obj->format->type) { + + case format_binary_int08: + + snk_hops_process_format_binary_int08(obj); + + break; + + case format_binary_int16: + + snk_hops_process_format_binary_int16(obj); + + break; + + case format_binary_int24: + + snk_hops_process_format_binary_int24(obj); + + break; + + case format_binary_int32: + + snk_hops_process_format_binary_int32(obj); + + break; + + case format_undefined: + + snk_hops_process_format_undefined(obj); + + break; + + default: + + printf("Sink hops: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_hops_process_interface_blackhole(obj); + + break; + + case interface_file: + + snk_hops_process_interface_file(obj); + + break; + + case interface_socket: + + snk_hops_process_interface_socket(obj); + + break; + + default: + + printf("Sink hops: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void snk_hops_process_interface_blackhole(snk_hops_obj * obj) { + + // Emtpy + + } + + void snk_hops_process_interface_file(snk_hops_obj * obj) { + + fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp); + + } + + void snk_hops_process_interface_socket(snk_hops_obj * obj) { + + if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) { + printf("Sink hops: Could not send message.\n"); + exit(EXIT_FAILURE); + } + + } + + void snk_hops_process_format_binary_int08(snk_hops_obj * obj) { + + unsigned int iChannel; + unsigned int iSample; + float sample; + unsigned int nBytes; + unsigned int nBytesTotal; + + nBytes = 1; + nBytesTotal = 0; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + sample = obj->in->hops->array[iChannel][iSample]; + pcm_normalized2signedXXbits(sample, nBytes, obj->bytes); + memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes); + + nBytesTotal += nBytes; + + } + + } + + obj->bufferSize = nBytesTotal; + + } + + void snk_hops_process_format_binary_int16(snk_hops_obj * obj) { + + unsigned int iChannel; + unsigned int iSample; + float sample; + unsigned int nBytes; + unsigned int nBytesTotal; + + nBytes = 2; + nBytesTotal = 0; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + sample = obj->in->hops->array[iChannel][iSample]; + pcm_normalized2signedXXbits(sample, nBytes, obj->bytes); + memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes); + + nBytesTotal += nBytes; + + + } + + } + + obj->bufferSize = nBytesTotal; + + } + + void snk_hops_process_format_binary_int24(snk_hops_obj * obj) { + + unsigned int iChannel; + unsigned int iSample; + float sample; + unsigned int nBytes; + unsigned int nBytesTotal; + + nBytes = 3; + nBytesTotal = 0; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + sample = obj->in->hops->array[iChannel][iSample]; + pcm_normalized2signedXXbits(sample, nBytes, obj->bytes); + memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes); + + nBytesTotal += nBytes; + + } + + } + + obj->bufferSize = nBytesTotal; + + } + + void snk_hops_process_format_binary_int32(snk_hops_obj * obj) { + + unsigned int iChannel; + unsigned int iSample; + float sample; + unsigned int nBytes; + unsigned int nBytesTotal; + + nBytes = 4; + nBytesTotal = 0; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + sample = obj->in->hops->array[iChannel][iSample]; + pcm_normalized2signedXXbits(sample, nBytes, obj->bytes); + memcpy(&(obj->buffer[nBytesTotal]), &(obj->bytes[4-nBytes]), sizeof(char) * nBytes); + + nBytesTotal += nBytes; + + } + + } + + obj->bufferSize = nBytesTotal; + + } + + void snk_hops_process_format_undefined(snk_hops_obj * obj) { + + obj->buffer[0] = 0x00; + obj->bufferSize = 0; + + } + + snk_hops_cfg * snk_hops_cfg_construct(void) { + + snk_hops_cfg * cfg; + + cfg = (snk_hops_cfg *) malloc(sizeof(snk_hops_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_hops_cfg_destroy(snk_hops_cfg * snk_hops_config) { + + if (snk_hops_config->format != NULL) { + format_destroy(snk_hops_config->format); + } + if (snk_hops_config->interface != NULL) { + interface_destroy(snk_hops_config->interface); + } + + free((void *) snk_hops_config); + + } \ No newline at end of file diff --git a/src/sink/snk_hops.h b/src/sink/snk_hops.h new file mode 100644 index 0000000..1aec21f --- /dev/null +++ b/src/sink/snk_hops.h @@ -0,0 +1,96 @@ +#ifndef __ODAS_SINK_HOPS +#define __ODAS_SINK_HOPS + + #include + #include + #include + #include + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_hops.h" + #include "../utils/pcm.h" + + typedef struct snk_hops_obj { + + unsigned long long timeStamp; + + unsigned int hopSize; + unsigned int nChannels; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + char * buffer; + unsigned int bufferSize; + + FILE * fp; + + struct sockaddr_in sserver; + int sid; + + char bytes[4]; + + msg_hops_obj * in; + + } snk_hops_obj; + + typedef struct snk_hops_cfg { + + unsigned int fS; + format_obj * format; + interface_obj * interface; + + } snk_hops_cfg; + + snk_hops_obj * snk_hops_construct(const snk_hops_cfg * snk_hops_config, const msg_hops_cfg * msg_hops_config); + + void snk_hops_destroy(snk_hops_obj * obj); + + void snk_hops_connect(snk_hops_obj * obj, msg_hops_obj * in); + + void snk_hops_disconnect(snk_hops_obj * obj); + + void snk_hops_open(snk_hops_obj * obj); + + void snk_hops_open_interface_blackhole(snk_hops_obj * obj); + + void snk_hops_open_interface_file(snk_hops_obj * obj); + + void snk_hops_open_interface_socket(snk_hops_obj * obj); + + void snk_hops_close(snk_hops_obj * obj); + + void snk_hops_close_interface_blackhole(snk_hops_obj * obj); + + void snk_hops_close_interface_file(snk_hops_obj * obj); + + void snk_hops_close_interface_socket(snk_hops_obj * obj); + + int snk_hops_process(snk_hops_obj * obj); + + void snk_hops_process_interface_blackhole(snk_hops_obj * obj); + + void snk_hops_process_interface_file(snk_hops_obj * obj); + + void snk_hops_process_interface_socket(snk_hops_obj * obj); + + void snk_hops_process_format_binary_int08(snk_hops_obj * obj); + + void snk_hops_process_format_binary_int16(snk_hops_obj * obj); + + void snk_hops_process_format_binary_int24(snk_hops_obj * obj); + + void snk_hops_process_format_binary_int32(snk_hops_obj * obj); + + void snk_hops_process_format_undefined(snk_hops_obj * obj); + + snk_hops_cfg * snk_hops_cfg_construct(void); + + void snk_hops_cfg_destroy(snk_hops_cfg * snk_hops_config); + +#endif \ No newline at end of file diff --git a/src/sink/snk_pots.c b/src/sink/snk_pots.c new file mode 100644 index 0000000..aeba012 --- /dev/null +++ b/src/sink/snk_pots.c @@ -0,0 +1,388 @@ + + #include "snk_pots.h" + + snk_pots_obj * snk_pots_construct(const snk_pots_cfg * snk_pots_config, const msg_pots_cfg * msg_pots_config) { + + snk_pots_obj * obj; + + obj = (snk_pots_obj *) malloc(sizeof(snk_pots_obj)); + + obj->timeStamp = 0; + + obj->nPots = msg_pots_config->nPots; + obj->fS = snk_pots_config->fS; + + obj->format = format_clone(snk_pots_config->format); + obj->interface = interface_clone(snk_pots_config->interface); + + if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_float)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_text_json)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_text_json)) || + ((obj->interface->type == interface_terminal) && (obj->format->type == format_text_json)))) { + + printf("Sink pots: Invalid interface and/or format.\n"); + exit(EXIT_FAILURE); + + } + + obj->fp = (FILE *) NULL; + + obj->buffer = (char *) malloc(sizeof(char) * 1024); + memset(obj->buffer, 0x00, sizeof(char) * 1024); + obj->bufferSize = 0; + + obj->in = (msg_pots_obj *) NULL; + + return obj; + + } + + void snk_pots_destroy(snk_pots_obj * obj) { + + free((void *) obj->buffer); + + format_destroy(obj->format); + interface_destroy(obj->interface); + + free((void *) obj); + + } + + void snk_pots_connect(snk_pots_obj * obj, msg_pots_obj * in) { + + obj->in = in; + + } + + void snk_pots_disconnect(snk_pots_obj * obj) { + + obj->in = (msg_pots_obj *) NULL; + + } + + void snk_pots_open(snk_pots_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_pots_open_interface_blackhole(obj); + + break; + + case interface_file: + + snk_pots_open_interface_file(obj); + + break; + + case interface_socket: + + snk_pots_open_interface_socket(obj); + + break; + + case interface_terminal: + + snk_pots_open_interface_terminal(obj); + + break; + + default: + + printf("Sink pots: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_pots_open_interface_blackhole(snk_pots_obj * obj) { + + // Empty + + } + + void snk_pots_open_interface_file(snk_pots_obj * obj) { + + obj->fp = fopen(obj->interface->fileName, "wb"); + + if (obj->fp == NULL) { + printf("Cannot open file %s\n",obj->interface->fileName); + exit(EXIT_FAILURE); + } + + } + + void snk_pots_open_interface_socket(snk_pots_obj * obj) { + + memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in)); + + obj->sserver.sin_family = AF_INET; + obj->sserver.sin_addr.s_addr = inet_addr(obj->interface->ip); + obj->sserver.sin_port = htons(obj->interface->port); + obj->sid = socket(AF_INET, SOCK_STREAM, 0); + + if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) { + + printf("Sink pots: Cannot connect to server\n"); + exit(EXIT_FAILURE); + + } + + } + + void snk_pots_open_interface_terminal(snk_pots_obj * obj) { + + // Empty + + } + + void snk_pots_close(snk_pots_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_pots_close_interface_blackhole(obj); + + break; + + case interface_file: + + snk_pots_close_interface_file(obj); + + break; + + case interface_socket: + + snk_pots_close_interface_socket(obj); + + break; + + case interface_terminal: + + snk_pots_close_interface_terminal(obj); + + break; + + default: + + printf("Sink pots: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_pots_close_interface_blackhole(snk_pots_obj * obj) { + + // Empty + + } + + void snk_pots_close_interface_file(snk_pots_obj * obj) { + + fclose(obj->fp); + + } + + void snk_pots_close_interface_socket(snk_pots_obj * obj) { + + close(obj->sid); + + } + + void snk_pots_close_interface_terminal(snk_pots_obj * obj) { + + // Empty + + } + + int snk_pots_process(snk_pots_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + switch(obj->format->type) { + + case format_binary_float: + + snk_pots_process_format_binary_float(obj); + + break; + + case format_text_json: + + snk_pots_process_format_text_json(obj); + + break; + + case format_undefined: + + snk_pots_process_format_undefined(obj); + + break; + + default: + + printf("Sink pots: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_pots_process_interface_blackhole(obj); + + break; + + case interface_file: + + snk_pots_process_interface_file(obj); + + break; + + case interface_socket: + + snk_pots_process_interface_socket(obj); + + break; + + case interface_terminal: + + snk_pots_process_interface_terminal(obj); + + break; + + default: + + printf("Sink pots: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void snk_pots_process_interface_blackhole(snk_pots_obj * obj) { + + // Empty + + } + + void snk_pots_process_interface_file(snk_pots_obj * obj) { + + fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp); + + } + + void snk_pots_process_interface_socket(snk_pots_obj * obj) { + + if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) { + printf("Sink pots: Could not send message.\n"); + exit(EXIT_FAILURE); + } + + } + + void snk_pots_process_interface_terminal(snk_pots_obj * obj) { + + printf("%s",obj->buffer); + + } + + void snk_pots_process_format_binary_float(snk_pots_obj * obj) { + + memcpy(obj->buffer, obj->in->pots->array, sizeof(float) * 4 * obj->in->pots->nPots); + obj->bufferSize = sizeof(float) * 4 * obj->in->pots->nPots; + + } + + void snk_pots_process_format_text_json(snk_pots_obj * obj) { + + unsigned int iPot; + + obj->buffer[0] = 0x00; + + sprintf(obj->buffer,"%s{\n",obj->buffer); + sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp); + sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer); + + for (iPot = 0; iPot < obj->nPots; iPot++) { + + sprintf(obj->buffer,"%s { \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"E\": %1.3f }", obj->buffer, + obj->in->pots->array[iPot*4+0], obj->in->pots->array[iPot*4+1], obj->in->pots->array[iPot*4+2], obj->in->pots->array[iPot*4+3]); + + if (iPot != (obj->nPots - 1)) { + + sprintf(obj->buffer,"%s,",obj->buffer); + + } + + sprintf(obj->buffer,"%s\n",obj->buffer); + + } + + sprintf(obj->buffer,"%s ]\n",obj->buffer); + sprintf(obj->buffer,"%s}\n",obj->buffer); + + obj->bufferSize = strlen(obj->buffer); + + } + + void snk_pots_process_format_undefined(snk_pots_obj * obj) { + + obj->buffer[0] = 0x00; + obj->bufferSize = 0; + + } + + snk_pots_cfg * snk_pots_cfg_construct(void) { + + snk_pots_cfg * cfg; + + cfg = (snk_pots_cfg *) malloc(sizeof(snk_pots_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_pots_cfg_destroy(snk_pots_cfg * snk_pots_config) { + + if (snk_pots_config->format != NULL) { + format_destroy(snk_pots_config->format); + } + if (snk_pots_config->interface != NULL) { + interface_destroy(snk_pots_config->interface); + } + + free((void *) snk_pots_config); + + } \ No newline at end of file diff --git a/src/sink/snk_pots.h b/src/sink/snk_pots.h new file mode 100644 index 0000000..a26bfdc --- /dev/null +++ b/src/sink/snk_pots.h @@ -0,0 +1,94 @@ +#ifndef __ODAS_SINK_POTS +#define __ODAS_SINK_POTS + + #include + #include + #include + #include + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_pots.h" + + typedef struct snk_pots_obj { + + unsigned long long timeStamp; + + unsigned int nPots; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + char * buffer; + unsigned int bufferSize; + + FILE * fp; + + struct sockaddr_in sserver; + int sid; + + msg_pots_obj * in; + + } snk_pots_obj; + + typedef struct snk_pots_cfg { + + unsigned int fS; + format_obj * format; + interface_obj * interface; + + } snk_pots_cfg; + + snk_pots_obj * snk_pots_construct(const snk_pots_cfg * snk_pots_config, const msg_pots_cfg * msg_pots_config); + + void snk_pots_destroy(snk_pots_obj * obj); + + void snk_pots_connect(snk_pots_obj * obj, msg_pots_obj * in); + + void snk_pots_disconnect(snk_pots_obj * obj); + + void snk_pots_open(snk_pots_obj * obj); + + void snk_pots_open_interface_blackhole(snk_pots_obj * obj); + + void snk_pots_open_interface_file(snk_pots_obj * obj); + + void snk_pots_open_interface_socket(snk_pots_obj * obj); + + void snk_pots_open_interface_terminal(snk_pots_obj * obj); + + void snk_pots_close(snk_pots_obj * obj); + + void snk_pots_close_interface_blackhole(snk_pots_obj * obj); + + void snk_pots_close_interface_file(snk_pots_obj * obj); + + void snk_pots_close_interface_socket(snk_pots_obj * obj); + + void snk_pots_close_interface_terminal(snk_pots_obj * obj); + + int snk_pots_process(snk_pots_obj * obj); + + void snk_pots_process_interface_blackhole(snk_pots_obj * obj); + + void snk_pots_process_interface_file(snk_pots_obj * obj); + + void snk_pots_process_interface_socket(snk_pots_obj * obj); + + void snk_pots_process_interface_terminal(snk_pots_obj * obj); + + void snk_pots_process_format_binary_float(snk_pots_obj * obj); + + void snk_pots_process_format_text_json(snk_pots_obj * obj); + + void snk_pots_process_format_undefined(snk_pots_obj * obj); + + snk_pots_cfg * snk_pots_cfg_construct(void); + + void snk_pots_cfg_destroy(snk_pots_cfg * snk_pots_config); + +#endif \ No newline at end of file diff --git a/src/sink/snk_powers.c b/src/sink/snk_powers.c new file mode 100644 index 0000000..a69a8f8 --- /dev/null +++ b/src/sink/snk_powers.c @@ -0,0 +1,195 @@ + + #include "snk_powers.h" + + snk_powers_obj * snk_powers_construct(const snk_powers_cfg * snk_powers_config, const msg_powers_cfg * msg_powers_config) { + + snk_powers_obj * obj; + + obj = (snk_powers_obj *) malloc(sizeof(snk_powers_obj)); + + obj->halfFrameSize = msg_powers_config->halfFrameSize; + obj->nChannels = msg_powers_config->nChannels; + obj->fS = msg_powers_config->fS; + + obj->format = format_clone(snk_powers_config->format); + obj->interface = interface_clone(snk_powers_config->interface); + + if (!((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined))) { + + printf("Sink powers: Invalid interface and/or format.\n"); + exit(EXIT_FAILURE); + + } + + obj->in = (msg_powers_obj *) NULL; + + return obj; + + } + + void snk_powers_destroy(snk_powers_obj * obj) { + + format_destroy(obj->format); + interface_destroy(obj->interface); + + free((void *) obj); + + } + + void snk_powers_connect(snk_powers_obj * obj, msg_powers_obj * in) { + + obj->in = in; + + } + + void snk_powers_disconnect(snk_powers_obj * obj) { + + obj->in = (msg_powers_obj *) NULL; + + } + + void snk_powers_open(snk_powers_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_powers_open_interface_blackhole(obj); + + break; + + default: + + printf("Sink powers: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_powers_open_interface_blackhole(snk_powers_obj * obj) { + + // Empty + + } + + void snk_powers_close(snk_powers_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_powers_close_interface_blackhole(obj); + + break; + + default: + + printf("Sink powers: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_powers_close_interface_blackhole(snk_powers_obj * obj) { + + // Empty + + } + + int snk_powers_process(snk_powers_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + switch(obj->format->type) { + + case format_undefined: + + snk_powers_process_format_undefined(obj); + + break; + + default: + + printf("Sink powers: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_powers_process_interface_blackhole(obj); + + break; + + default: + + printf("Sink powers: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void snk_powers_process_interface_blackhole(snk_powers_obj * obj) { + + // Empty + + } + + void snk_powers_process_format_undefined(snk_powers_obj * obj) { + + // Empty + + } + + snk_powers_cfg * snk_powers_cfg_construct(void) { + + snk_powers_cfg * cfg; + + cfg = (snk_powers_cfg *) malloc(sizeof(snk_powers_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_powers_cfg_destroy(snk_powers_cfg * snk_powers_config) { + + if (snk_powers_config->format != NULL) { + format_destroy(snk_powers_config->format); + } + if (snk_powers_config->interface != NULL) { + interface_destroy(snk_powers_config->interface); + } + + free((void *) snk_powers_config); + + } \ No newline at end of file diff --git a/src/sink/snk_powers.h b/src/sink/snk_powers.h new file mode 100644 index 0000000..6e93e11 --- /dev/null +++ b/src/sink/snk_powers.h @@ -0,0 +1,66 @@ +#ifndef __ODAS_SINK_POWERS +#define __ODAS_SINK_POWERS + + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_powers.h" + + typedef struct snk_powers_obj { + + unsigned long long timeStamp; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + char * buffer; + unsigned int bufferSize; + + FILE * fp; + + msg_powers_obj * in; + + } snk_powers_obj; + + typedef struct snk_powers_cfg { + + unsigned int fS; + format_obj * format; + interface_obj * interface; + + } snk_powers_cfg; + + snk_powers_obj * snk_powers_construct(const snk_powers_cfg * snk_powers_config, const msg_powers_cfg * msg_powers_config); + + void snk_powers_destroy(snk_powers_obj * obj); + + void snk_powers_connect(snk_powers_obj * obj, msg_powers_obj * in); + + void snk_powers_disconnect(snk_powers_obj * obj); + + void snk_powers_open(snk_powers_obj * obj); + + void snk_powers_open_interface_blackhole(snk_powers_obj * obj); + + void snk_powers_close(snk_powers_obj * obj); + + void snk_powers_close_interface_blackhole(snk_powers_obj * obj); + + int snk_powers_process(snk_powers_obj * obj); + + void snk_powers_process_interface_blackhole(snk_powers_obj * obj); + + void snk_powers_process_format_undefined(snk_powers_obj * obj); + + snk_powers_cfg * snk_powers_cfg_construct(void); + + void snk_powers_cfg_destroy(snk_powers_cfg * snk_powers_config); + +#endif \ No newline at end of file diff --git a/src/sink/snk_spectra.c b/src/sink/snk_spectra.c new file mode 100644 index 0000000..aa88bb1 --- /dev/null +++ b/src/sink/snk_spectra.c @@ -0,0 +1,200 @@ + + #include "snk_spectra.h" + + snk_spectra_obj * snk_spectra_construct(const snk_spectra_cfg * snk_spectra_config, const msg_spectra_cfg * msg_spectra_config) { + + snk_spectra_obj * obj; + + obj = (snk_spectra_obj *) malloc(sizeof(snk_spectra_obj)); + + obj->halfFrameSize = msg_spectra_config->halfFrameSize; + obj->nChannels = msg_spectra_config->nChannels; + obj->fS = msg_spectra_config->fS; + + obj->format = format_clone(snk_spectra_config->format); + obj->interface = interface_clone(snk_spectra_config->interface); + + switch (obj->format->type) { + + case format_binary_float: break; + default: + + printf("Invalid format.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->in = (msg_spectra_obj *) NULL; + + return obj; + + } + + void snk_spectra_destroy(snk_spectra_obj * obj) { + + format_destroy(obj->format); + interface_destroy(obj->interface); + + free((void *) obj); + + } + + void snk_spectra_connect(snk_spectra_obj * obj, msg_spectra_obj * in) { + + obj->in = in; + + } + + void snk_spectra_disconnect(snk_spectra_obj * obj) { + + obj->in = (msg_spectra_obj *) NULL; + + } + + void snk_spectra_open(snk_spectra_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_spectra_open_interface_blackhole(obj); + + break; + + default: + + printf("Sink spectra: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_spectra_open_interface_blackhole(snk_spectra_obj * obj) { + + // Empty + + } + + void snk_spectra_close(snk_spectra_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_spectra_close_interface_blackhole(obj); + + break; + + default: + + printf("Sink spectra: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_spectra_close_interface_blackhole(snk_spectra_obj * obj) { + + // Empty + + } + + int snk_spectra_process(snk_spectra_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + switch(obj->format->type) { + + case format_undefined: + + snk_spectra_process_format_undefined(obj); + + break; + + default: + + printf("Sink spectra: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_spectra_process_interface_blackhole(obj); + + break; + + default: + + printf("Sink spectra: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void snk_spectra_process_interface_blackhole(snk_spectra_obj * obj) { + + // Empty + + } + + void snk_spectra_process_format_undefined(snk_spectra_obj * obj) { + + // Empty + + } + + snk_spectra_cfg * snk_spectra_cfg_construct(void) { + + snk_spectra_cfg * cfg; + + cfg = (snk_spectra_cfg *) malloc(sizeof(snk_spectra_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_spectra_cfg_destroy(snk_spectra_cfg * snk_spectra_config) { + + if (snk_spectra_config->format != NULL) { + format_destroy(snk_spectra_config->format); + } + if (snk_spectra_config->interface != NULL) { + interface_destroy(snk_spectra_config->interface); + } + + free((void *) snk_spectra_config); + + } \ No newline at end of file diff --git a/src/sink/snk_spectra.h b/src/sink/snk_spectra.h new file mode 100644 index 0000000..24f95d0 --- /dev/null +++ b/src/sink/snk_spectra.h @@ -0,0 +1,63 @@ +#ifndef __ODAS_SINK_SPECTRA +#define __ODAS_SINK_SPECTRA + + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_spectra.h" + + typedef struct snk_spectra_obj { + + unsigned long long timeStamp; + + unsigned int halfFrameSize; + unsigned int nChannels; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + FILE * fp; + + msg_spectra_obj * in; + + } snk_spectra_obj; + + typedef struct snk_spectra_cfg { + + unsigned int fS; + format_obj * format; + interface_obj * interface; + + } snk_spectra_cfg; + + snk_spectra_obj * snk_spectra_construct(const snk_spectra_cfg * snk_spectra_config, const msg_spectra_cfg * msg_spectra_config); + + void snk_spectra_destroy(snk_spectra_obj * obj); + + void snk_spectra_connect(snk_spectra_obj * obj, msg_spectra_obj * in); + + void snk_spectra_disconnect(snk_spectra_obj * obj); + + void snk_spectra_open(snk_spectra_obj * obj); + + void snk_spectra_open_interface_blackhole(snk_spectra_obj * obj); + + void snk_spectra_close(snk_spectra_obj * obj); + + void snk_spectra_close_interface_blackhole(snk_spectra_obj * obj); + + int snk_spectra_process(snk_spectra_obj * obj); + + void snk_spectra_process_interface_blackhole(snk_spectra_obj * obj); + + void snk_spectra_process_format_undefined(snk_spectra_obj * obj); + + snk_spectra_cfg * snk_spectra_cfg_construct(void); + + void snk_spectra_cfg_destroy(snk_spectra_cfg * snk_spectra_config); + +#endif \ No newline at end of file diff --git a/src/sink/snk_tracks.c b/src/sink/snk_tracks.c new file mode 100644 index 0000000..1980b21 --- /dev/null +++ b/src/sink/snk_tracks.c @@ -0,0 +1,383 @@ + + #include "snk_tracks.h" + + snk_tracks_obj * snk_tracks_construct(const snk_tracks_cfg * snk_tracks_config, const msg_tracks_cfg * msg_tracks_config) { + + snk_tracks_obj * obj; + + obj = (snk_tracks_obj *) malloc(sizeof(snk_tracks_obj)); + + obj->timeStamp = 0; + + obj->nTracks = msg_tracks_config->nTracks; + obj->fS = snk_tracks_config->fS; + + obj->format = format_clone(snk_tracks_config->format); + obj->interface = interface_clone(snk_tracks_config->interface); + + if (!(((obj->interface->type == interface_blackhole) && (obj->format->type == format_undefined)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_text_json)) || + ((obj->interface->type == interface_socket) && (obj->format->type == format_text_json)) || + ((obj->interface->type == interface_terminal) && (obj->format->type == format_text_json)))) { + + interface_printf(obj->interface); + format_printf(obj->format); + + printf("Sink tracks: Invalid interface and/or format.\n"); + exit(EXIT_FAILURE); + + } + + obj->fp = (FILE *) NULL; + + obj->buffer = (char *) malloc(sizeof(char) * 1024); + memset(obj->buffer, 0x00, sizeof(char) * 1024); + obj->bufferSize = 0; + + obj->in = (msg_tracks_obj *) NULL; + + return obj; + + } + + void snk_tracks_destroy(snk_tracks_obj * obj) { + + free((void *) obj->buffer); + + format_destroy(obj->format); + interface_destroy(obj->interface); + + free((void *) obj); + + } + + void snk_tracks_connect(snk_tracks_obj * obj, msg_tracks_obj * in) { + + obj->in = in; + + } + + void snk_tracks_disconnect(snk_tracks_obj * obj) { + + obj->in = (msg_tracks_obj *) NULL; + + } + + void snk_tracks_open(snk_tracks_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_tracks_open_interface_blackhole(obj); + + break; + + case interface_file: + + snk_tracks_open_interface_file(obj); + + break; + + case interface_socket: + + snk_tracks_open_interface_socket(obj); + + break; + + case interface_terminal: + + snk_tracks_open_interface_terminal(obj); + + break; + + default: + + printf("Sink tracks: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_tracks_open_interface_blackhole(snk_tracks_obj * obj) { + + // Empty + + } + + void snk_tracks_open_interface_file(snk_tracks_obj * obj) { + + obj->fp = fopen(obj->interface->fileName, "wb"); + + if (obj->fp == NULL) { + printf("Cannot open file %s\n",obj->interface->fileName); + exit(EXIT_FAILURE); + } + + } + + void snk_tracks_open_interface_socket(snk_tracks_obj * obj) { + + memset(&(obj->sserver), 0x00, sizeof(struct sockaddr_in)); + + obj->sserver.sin_family = AF_INET; + obj->sserver.sin_addr.s_addr = inet_addr(obj->interface->ip); + obj->sserver.sin_port = htons(obj->interface->port); + obj->sid = socket(AF_INET, SOCK_STREAM, 0); + + if ( (connect(obj->sid, (struct sockaddr *) &(obj->sserver), sizeof(obj->sserver))) < 0 ) { + + printf("Sink tracks: Cannot connect to server\n"); + exit(EXIT_FAILURE); + + } + + } + + void snk_tracks_open_interface_terminal(snk_tracks_obj * obj) { + + // Empty + + } + + void snk_tracks_close(snk_tracks_obj * obj) { + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_tracks_close_interface_blackhole(obj); + + break; + + case interface_file: + + snk_tracks_close_interface_file(obj); + + break; + + case interface_socket: + + snk_tracks_close_interface_socket(obj); + + break; + + case interface_terminal: + + snk_tracks_close_interface_terminal(obj); + + break; + + default: + + printf("Sink tracks: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void snk_tracks_close_interface_blackhole(snk_tracks_obj * obj) { + + // Empty + + } + + void snk_tracks_close_interface_file(snk_tracks_obj * obj) { + + fclose(obj->fp); + + } + + void snk_tracks_close_interface_socket(snk_tracks_obj * obj) { + + close(obj->sid); + + } + + void snk_tracks_close_interface_terminal(snk_tracks_obj * obj) { + + // Empty + + } + + int snk_tracks_process(snk_tracks_obj * obj) { + + int rtnValue; + + if (obj->in->timeStamp != 0) { + + switch(obj->format->type) { + + case format_text_json: + + snk_tracks_process_format_text_json(obj); + + break; + + case format_undefined: + + snk_tracks_process_format_undefined(obj); + + break; + + default: + + printf("Sink tracks: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_blackhole: + + snk_tracks_process_interface_blackhole(obj); + + break; + + case interface_file: + + snk_tracks_process_interface_file(obj); + + break; + + case interface_socket: + + snk_tracks_process_interface_socket(obj); + + break; + + case interface_terminal: + + snk_tracks_process_interface_terminal(obj); + + break; + + default: + + printf("Sink tracks: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void snk_tracks_process_interface_blackhole(snk_tracks_obj * obj) { + + // Empty + + } + + void snk_tracks_process_interface_file(snk_tracks_obj * obj) { + + fwrite(obj->buffer, sizeof(char), obj->bufferSize, obj->fp); + + } + + void snk_tracks_process_interface_socket(snk_tracks_obj * obj) { + + if (send(obj->sid, obj->buffer, obj->bufferSize, 0) < 0) { + printf("Sink tracks: Could not send message.\n"); + exit(EXIT_FAILURE); + } + + } + + void snk_tracks_process_interface_terminal(snk_tracks_obj * obj) { + + printf("%s",obj->buffer); + + } + + void snk_tracks_process_format_text_json(snk_tracks_obj * obj) { + + unsigned int iTrack; + + obj->buffer[0] = 0x00; + + sprintf(obj->buffer,"%s{\n",obj->buffer); + sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp); + sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer); + + for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { + + sprintf(obj->buffer,"%s { \"id\": %llu, \"tag\": \"%s\", \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"activity\": %1.3f }", + obj->buffer, + obj->in->tracks->ids[iTrack], + obj->in->tracks->tags[iTrack], + obj->in->tracks->array[iTrack*3+0], + obj->in->tracks->array[iTrack*3+1], + obj->in->tracks->array[iTrack*3+2], + obj->in->tracks->activity[iTrack]); + + if (iTrack != (obj->nTracks - 1)) { + + sprintf(obj->buffer,"%s,",obj->buffer); + + } + + sprintf(obj->buffer,"%s\n",obj->buffer); + + } + + sprintf(obj->buffer,"%s ]\n",obj->buffer); + sprintf(obj->buffer,"%s}\n",obj->buffer); + + obj->bufferSize = strlen(obj->buffer); + + } + + void snk_tracks_process_format_undefined(snk_tracks_obj * obj) { + + obj->buffer[0] = 0x00; + obj->bufferSize = 0; + + } + + snk_tracks_cfg * snk_tracks_cfg_construct(void) { + + snk_tracks_cfg * cfg; + + cfg = (snk_tracks_cfg *) malloc(sizeof(snk_tracks_cfg)); + + cfg->fS = 0; + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void snk_tracks_cfg_destroy(snk_tracks_cfg * snk_tracks_config) { + + if (snk_tracks_config->format != NULL) { + format_destroy(snk_tracks_config->format); + } + if (snk_tracks_config->interface != NULL) { + interface_destroy(snk_tracks_config->interface); + } + + free((void *) snk_tracks_config); + + } diff --git a/src/sink/snk_tracks.h b/src/sink/snk_tracks.h new file mode 100644 index 0000000..705b010 --- /dev/null +++ b/src/sink/snk_tracks.h @@ -0,0 +1,92 @@ +#ifndef __ODAS_SINK_TRACKS +#define __ODAS_SINK_TRACKS + + #include + #include + #include + #include + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_tracks.h" + + typedef struct snk_tracks_obj { + + unsigned long long timeStamp; + + unsigned int nTracks; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + char * buffer; + unsigned int bufferSize; + + FILE * fp; + + struct sockaddr_in sserver; + int sid; + + msg_tracks_obj * in; + + } snk_tracks_obj; + + typedef struct snk_tracks_cfg { + + unsigned int fS; + format_obj * format; + interface_obj * interface; + + } snk_tracks_cfg; + + snk_tracks_obj * snk_tracks_construct(const snk_tracks_cfg * snk_tracks_config, const msg_tracks_cfg * msg_tracks_config); + + void snk_tracks_destroy(snk_tracks_obj * obj); + + void snk_tracks_connect(snk_tracks_obj * obj, msg_tracks_obj * in); + + void snk_tracks_disconnect(snk_tracks_obj * obj); + + void snk_tracks_open(snk_tracks_obj * obj); + + void snk_tracks_open_interface_blackhole(snk_tracks_obj * obj); + + void snk_tracks_open_interface_file(snk_tracks_obj * obj); + + void snk_tracks_open_interface_socket(snk_tracks_obj * obj); + + void snk_tracks_open_interface_terminal(snk_tracks_obj * obj); + + void snk_tracks_close(snk_tracks_obj * obj); + + void snk_tracks_close_interface_blackhole(snk_tracks_obj * obj); + + void snk_tracks_close_interface_file(snk_tracks_obj * obj); + + void snk_tracks_close_interface_socket(snk_tracks_obj * obj); + + void snk_tracks_close_interface_terminal(snk_tracks_obj * obj); + + int snk_tracks_process(snk_tracks_obj * obj); + + void snk_tracks_process_interface_blackhole(snk_tracks_obj * obj); + + void snk_tracks_process_interface_file(snk_tracks_obj * obj); + + void snk_tracks_process_interface_socket(snk_tracks_obj * obj); + + void snk_tracks_process_interface_terminal(snk_tracks_obj * obj); + + void snk_tracks_process_format_text_json(snk_tracks_obj * obj); + + void snk_tracks_process_format_undefined(snk_tracks_obj * obj); + + snk_tracks_cfg * snk_tracks_cfg_construct(void); + + void snk_tracks_cfg_destroy(snk_tracks_cfg * snk_tracks_config); + +#endif \ No newline at end of file diff --git a/src/source/src_hops.c b/src/source/src_hops.c new file mode 100644 index 0000000..4697d6c --- /dev/null +++ b/src/source/src_hops.c @@ -0,0 +1,493 @@ + + #include "src_hops.h" + + src_hops_obj * src_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config) { + + src_hops_obj * obj; + unsigned int nBytes; + + obj = (src_hops_obj *) malloc(sizeof(src_hops_obj)); + + obj->timeStamp = 0; + + obj->hopSize = msg_hops_config->hopSize; + obj->nChannels = msg_hops_config->nChannels; + obj->fS = msg_hops_config->fS; + + obj->format = format_clone(src_hops_config->format); + obj->interface = interface_clone(src_hops_config->interface); + + memset(obj->bytes, 0x00, 4 * sizeof(char)); + + if (!(((obj->interface->type == interface_file) && (obj->format->type == format_binary_int08)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int16)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int24)) || + ((obj->interface->type == interface_file) && (obj->format->type == format_binary_int32)) || + ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int08)) || + ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int16)) || + ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int24)) || + ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)))) { + + printf("Source hops: Invalid interface and/or format.\n"); + exit(EXIT_FAILURE); + + } + + obj->buffer = (char *) malloc(sizeof(char) * obj->hopSize * obj->nChannels * 4); + memset(obj->buffer, 0x00, sizeof(char) * obj->hopSize * obj->nChannels * 4); + + switch (obj->format->type) { + + case format_binary_int08: obj->bufferSize = obj->hopSize * obj->nChannels * 1; break; + case format_binary_int16: obj->bufferSize = obj->hopSize * obj->nChannels * 2; break; + case format_binary_int24: obj->bufferSize = obj->hopSize * obj->nChannels * 3; break; + case format_binary_int32: obj->bufferSize = obj->hopSize * obj->nChannels * 4; break; + + } + + obj->out = (msg_hops_obj *) NULL; + + return obj; + + } + + void src_hops_destroy(src_hops_obj * obj) { + + free((void *) obj->buffer); + format_destroy(obj->format); + interface_destroy(obj->interface); + + free((void *) obj); + + } + + void src_hops_connect(src_hops_obj * obj, msg_hops_obj * out) { + + obj->out = out; + + } + + void src_hops_disconnect(src_hops_obj * obj) { + + obj->out = (msg_hops_obj *) NULL; + + } + + void src_hops_open(src_hops_obj * obj) { + + switch(obj->interface->type) { + + case interface_file: + + src_hops_open_interface_file(obj); + + break; + + case interface_soundcard: + + src_hops_open_interface_soundcard(obj); + + break; + + default: + + printf("Source hops: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void src_hops_open_interface_file(src_hops_obj * obj) { + + obj->fp = fopen(obj->interface->fileName, "rb"); + + if (obj->fp == NULL) { + printf("Cannot open file %s\n",obj->interface->fileName); + exit(EXIT_FAILURE); + } + + } + + void src_hops_open_interface_soundcard(src_hops_obj * obj) { + + snd_pcm_hw_params_t * hw_params; + snd_pcm_format_t format; + int err; + char * tmpStr; + + switch (obj->format->type) { + + case format_binary_int08: + + format = SND_PCM_FORMAT_S8; + + break; + + case format_binary_int16: + + format = SND_PCM_FORMAT_S16_LE; + + break; + + case format_binary_int24: + + format = SND_PCM_FORMAT_S24_LE; + + break; + + case format_binary_int32: + + format = SND_PCM_FORMAT_S32_LE; + + break; + + default: + + printf("Source hops: Invalid format.\n"); + exit(EXIT_FAILURE); + + break; + + } + + tmpStr = (char *) malloc(sizeof(char) * 1024); + sprintf(tmpStr, "hw:%u,%u", obj->interface->card, obj->interface->device); + + if ((err = snd_pcm_open(&(obj->ch), tmpStr, SND_PCM_STREAM_CAPTURE, 0)) < 0) { + printf("Source hops: Cannot open audio device %s: %s\n",tmpStr, snd_strerror(err)); + exit(EXIT_FAILURE); + } + + free((void *) tmpStr); + + if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) { + printf("Source hops: Cannot allocate hardware parameter structure: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + if ((err = snd_pcm_hw_params_any(obj->ch, hw_params)) < 0) { + printf("Source hops: Cannot initialize hardware parameter structure: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + if ((err = snd_pcm_hw_params_set_access(obj->ch, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { + printf("Source hops: Cannot set access type: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + if ((err = snd_pcm_hw_params_set_format(obj->ch, hw_params, format)) < 0) { + printf("Source hops: Cannot set sample format: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + if ((err = snd_pcm_hw_params_set_rate(obj->ch, hw_params, obj->fS, 0)) < 0) { + printf("Source hops: Cannot set sample rate: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + if ((err = snd_pcm_hw_params_set_channels(obj->ch, hw_params, obj->nChannels)) < 0) { + printf("Source hops: Cannot set channel count: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + if ((err = snd_pcm_hw_params(obj->ch, hw_params)) < 0) { + printf("Source hops: Cannot set parameters: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + snd_pcm_hw_params_free(hw_params); + + if ((err = snd_pcm_prepare(obj->ch)) < 0) { + printf("Source hops: Cannot prepare audio interface for use: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } + + } + + void src_hops_close(src_hops_obj * obj) { + + switch(obj->interface->type) { + + case interface_file: + + src_hops_close_interface_file(obj); + + break; + + case interface_soundcard: + + src_hops_close_interface_soundcard(obj); + + break; + + default: + + printf("Source hops: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + } + + void src_hops_close_interface_file(src_hops_obj * obj) { + + fclose(obj->fp); + + } + + void src_hops_close_interface_soundcard(src_hops_obj * obj) { + + snd_pcm_close(obj->ch); + + } + + int src_hops_process(src_hops_obj * obj) { + + int rtnValue; + + switch(obj->format->type) { + + case format_binary_int08: + + src_hops_process_format_binary_int08(obj); + + break; + + case format_binary_int16: + + src_hops_process_format_binary_int16(obj); + + break; + + case format_binary_int24: + + src_hops_process_format_binary_int24(obj); + + break; + + case format_binary_int32: + + src_hops_process_format_binary_int32(obj); + + break; + + default: + + printf("Source hops: Invalid format type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + switch(obj->interface->type) { + + case interface_file: + + rtnValue = src_hops_process_interface_file(obj); + + break; + + case interface_soundcard: + + rtnValue = src_hops_process_interface_soundcard(obj); + + break; + + default: + + printf("Source hops: Invalid interface type.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->timeStamp++; + obj->out->timeStamp = obj->timeStamp; + + return rtnValue; + + } + + int src_hops_process_interface_file(src_hops_obj * obj) { + + unsigned int nBytesTotal; + int rtnValue; + + nBytesTotal = fread(obj->buffer, sizeof(char), obj->bufferSize, obj->fp); + + if (nBytesTotal == obj->bufferSize) { + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + int src_hops_process_interface_soundcard(src_hops_obj * obj) { + + unsigned int nSamples; + int rtnValue; + int err; + + if (err = snd_pcm_readi(obj->ch, obj->buffer, obj->hopSize) > 0) { + + rtnValue = 0; + + } + else { + + rtnValue = -1; + + } + + return rtnValue; + + } + + void src_hops_process_format_binary_int08(src_hops_obj * obj) { + + unsigned int iSample; + unsigned int iChannel; + unsigned int nBytes; + float sample; + + nBytes = 1; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + memcpy(&(obj->bytes[4-nBytes]), + &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]), + sizeof(char) * nBytes); + + sample = pcm_signedXXbits2normalized(obj->bytes, nBytes); + + obj->out->hops->array[iChannel][iSample] = sample; + + } + + } + + } + + void src_hops_process_format_binary_int16(src_hops_obj * obj) { + + unsigned int iSample; + unsigned int iChannel; + unsigned int nBytes; + float sample; + + nBytes = 2; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + memcpy(&(obj->bytes[4-nBytes]), + &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]), + sizeof(char) * nBytes); + + sample = pcm_signedXXbits2normalized(obj->bytes, nBytes); + + obj->out->hops->array[iChannel][iSample] = sample; + + } + + } + + } + + void src_hops_process_format_binary_int24(src_hops_obj * obj) { + + unsigned int iSample; + unsigned int iChannel; + unsigned int nBytes; + float sample; + + nBytes = 3; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + memcpy(&(obj->bytes[4-nBytes]), + &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]), + sizeof(char) * nBytes); + + sample = pcm_signedXXbits2normalized(obj->bytes, nBytes); + + obj->out->hops->array[iChannel][iSample] = sample; + + } + + } + + } + + void src_hops_process_format_binary_int32(src_hops_obj * obj) { + + unsigned int iSample; + unsigned int iChannel; + unsigned int nBytes; + float sample; + + nBytes = 4; + + for (iSample = 0; iSample < obj->hopSize; iSample++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + memcpy(&(obj->bytes[4-nBytes]), + &(obj->buffer[(iSample * obj->nChannels + iChannel) * nBytes]), + sizeof(char) * nBytes); + + sample = pcm_signedXXbits2normalized(obj->bytes, nBytes); + + obj->out->hops->array[iChannel][iSample] = sample; + + } + + } + + } + + src_hops_cfg * src_hops_cfg_construct(void) { + + src_hops_cfg * cfg; + + cfg = (src_hops_cfg *) malloc(sizeof(src_hops_cfg)); + + cfg->format = (format_obj *) NULL; + cfg->interface = (interface_obj *) NULL; + + return cfg; + + } + + void src_hops_cfg_destroy(src_hops_cfg * src_hops_config) { + + if (src_hops_config->format != NULL) { + format_destroy(src_hops_config->format); + } + if (src_hops_config->interface != NULL) { + interface_destroy(src_hops_config->interface); + } + + free((void *) src_hops_config); + + } diff --git a/src/source/src_hops.h b/src/source/src_hops.h new file mode 100644 index 0000000..5857435 --- /dev/null +++ b/src/source/src_hops.h @@ -0,0 +1,83 @@ +#ifndef __ODAS_SOURCE_HOPS +#define __ODAS_SOURCE_HOPS + + #include + #include + #include + #include + + #include "../general/format.h" + #include "../general/interface.h" + #include "../message/msg_hops.h" + #include "../signal/hop.h" + #include "../utils/pcm.h" + + typedef struct src_hops_obj { + + unsigned long long timeStamp; + + unsigned int hopSize; + unsigned int nChannels; + unsigned int fS; + + format_obj * format; + interface_obj * interface; + + FILE * fp; + snd_pcm_t * ch; + + char * buffer; + unsigned int bufferSize; + + char bytes[4]; + + msg_hops_obj * out; + + } src_hops_obj; + + typedef struct src_hops_cfg { + + format_obj * format; + interface_obj * interface; + + } src_hops_cfg; + + src_hops_obj * src_hops_construct(const src_hops_cfg * src_hops_config, const msg_hops_cfg * msg_hops_config); + + void src_hops_destroy(src_hops_obj * obj); + + void src_hops_connect(src_hops_obj * obj, msg_hops_obj * out); + + void src_hops_disconnect(src_hops_obj * obj); + + void src_hops_open(src_hops_obj * obj); + + void src_hops_open_interface_file(src_hops_obj * obj); + + void src_hops_open_interface_soundcard(src_hops_obj * obj); + + void src_hops_close(src_hops_obj * obj); + + void src_hops_close_interface_file(src_hops_obj * obj); + + void src_hops_close_interface_soundcard(src_hops_obj * obj); + + int src_hops_process(src_hops_obj * obj); + + int src_hops_process_interface_file(src_hops_obj * obj); + + int src_hops_process_interface_soundcard(src_hops_obj * obj); + + void src_hops_process_format_binary_int08(src_hops_obj * obj); + + void src_hops_process_format_binary_int16(src_hops_obj * obj); + + void src_hops_process_format_binary_int24(src_hops_obj * obj); + + void src_hops_process_format_binary_int32(src_hops_obj * obj); + + src_hops_cfg * src_hops_cfg_construct(void); + + void src_hops_cfg_destroy(src_hops_cfg * src_hops_config); + +#endif \ No newline at end of file diff --git a/src/system/acorr2pitch.c b/src/system/acorr2pitch.c new file mode 100644 index 0000000..81ad2ac --- /dev/null +++ b/src/system/acorr2pitch.c @@ -0,0 +1,106 @@ + + #include "acorr2pitch.h" + + acorr2pitch_obj * acorr2pitch_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize, const unsigned int winSize) { + + acorr2pitch_obj * obj; + + obj = (acorr2pitch_obj *) malloc(sizeof(acorr2pitch_obj)); + + obj->nSignals = nSignals; + obj->halfFrameSize = halfFrameSize; + obj->winSize = winSize; + + return obj; + + } + + void acorr2pitch_destroy(acorr2pitch_obj * obj) { + + free((void *) obj); + + } + + void acorr2pitch_process(acorr2pitch_obj * obj, const acorrs_obj * acorrs, pitches_obj * pitches) { + + unsigned int iSignal; + + signed int iBin; + signed int iWin; + signed int iSample; + + float peakValue; + float nextValue; + + float maxValue; + unsigned int maxIndex; + char isPeak; + char peakFound; + + unsigned int peakPrev; + unsigned int peakNow; + unsigned int peakNext; + float RPrev; + float RNow; + float RNext; + + 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 * ((signed int) (obj->winSize)); iWin <= ((signed int) (obj->winSize)); iWin++) { + + iSample = iBin + iWin; + nextValue = acorrs->array[iSignal][iSample]; + + if ((iWin != 0) && (peakValue <= nextValue)) { + + isPeak = 0x00; + break; + + } + + } + + if (isPeak == 0x01) { + + if (peakValue > maxValue) { + + maxValue = peakValue; + maxIndex = iBin; + + peakFound = 0x01; + + } + + } + + } + + 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; + + } + + } + + } \ No newline at end of file diff --git a/src/system/acorr2pitch.h b/src/system/acorr2pitch.h new file mode 100644 index 0000000..abf9b91 --- /dev/null +++ b/src/system/acorr2pitch.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_SYSTEM_ACORR2PITCH +#define __ODAS_SYSTEM_ACORR2PITCH + + #include "../signal/acorr.h" + #include "../signal/pitch.h" + + #include + + typedef struct acorr2pitch_obj { + + unsigned int nSignals; + unsigned int halfFrameSize; + unsigned int frameSize; + unsigned int winSize; + + } acorr2pitch_obj; + + acorr2pitch_obj * acorr2pitch_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize, const unsigned int winSize); + + void acorr2pitch_destroy(acorr2pitch_obj * obj); + + void acorr2pitch_process(acorr2pitch_obj * obj, const acorrs_obj * acorrs, pitches_obj * pitches); + +#endif \ No newline at end of file diff --git a/src/system/demixing2env.c b/src/system/demixing2env.c new file mode 100644 index 0000000..a8f0d16 --- /dev/null +++ b/src/system/demixing2env.c @@ -0,0 +1,82 @@ + + #include "demixing2env.h" + + demixing2env_obj * demixing2env_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize) { + + demixing2env_obj * obj; + + obj = (demixing2env_obj *) malloc(sizeof(demixing2env_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + return obj; + + } + + void demixing2env_destroy(demixing2env_obj * obj) { + + free((void *) obj); + + } + + void demixing2env_process(demixing2env_obj * obj, const tracks_obj * tracks, const demixings_obj * demixings, const masks_obj * masks, const envs_obj * envsChannel, envs_obj * envsSeparated) { + + unsigned int iSep; + unsigned int iChannel; + unsigned int iBin; + + unsigned int iSampleSC; + unsigned int iSampleBC; + unsigned int iSampleB; + + float X2; + float Wreal; + float Wimag; + float W2; + float Y2; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + memset(envsSeparated->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleSC = iSep * obj->nChannels + iChannel; + + if (masks->array[iSampleSC] == 1) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleB = iBin; + + X2 = envsChannel->array[iChannel][iSampleB]; + + Wreal = demixings->array[iSep][iSampleBC * 2 + 0]; + Wimag = demixings->array[iSep][iSampleBC * 2 + 1]; + W2 = Wreal * Wreal + Wimag * Wimag; + + Y2 = W2 * X2; + + envsSeparated->array[iSep][iSampleB] += Y2; + + } + + } + + } + + } + else { + + memset(envsSeparated->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + } \ No newline at end of file diff --git a/src/system/demixing2env.h b/src/system/demixing2env.h new file mode 100644 index 0000000..ddada11 --- /dev/null +++ b/src/system/demixing2env.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SYSTEM_DEMIXING2ENV +#define __ODAS_SYSTEM_DEMIXING2ENV + + #include + #include + #include + #include + + #include "../signal/demixing.h" + #include "../signal/env.h" + #include "../signal/mask.h" + #include "../signal/track.h" + + typedef struct demixing2env_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + + } demixing2env_obj; + + demixing2env_obj * demixing2env_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize); + + void demixing2env_destroy(demixing2env_obj * obj); + + void demixing2env_process(demixing2env_obj * obj, const tracks_obj * tracks, const demixings_obj * demixings, const masks_obj * masks, const envs_obj * envsChannel, envs_obj * envsSeparated); + +#endif \ No newline at end of file diff --git a/src/system/demixing2freq.c b/src/system/demixing2freq.c new file mode 100644 index 0000000..e21fb6c --- /dev/null +++ b/src/system/demixing2freq.c @@ -0,0 +1,85 @@ + + #include "demixing2freq.h" + + demixing2freq_obj * demixing2freq_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize) { + + demixing2freq_obj * obj; + + obj = (demixing2freq_obj *) malloc(sizeof(demixing2freq_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + return obj; + + } + + void demixing2freq_destroy(demixing2freq_obj * obj) { + + free((void *) obj); + + } + + void demixing2freq_process(demixing2freq_obj * obj, const tracks_obj * tracks, const demixings_obj * demixings, const masks_obj * masks, const freqs_obj * freqsChannel, freqs_obj * freqsSeparated) { + + unsigned int iSep; + unsigned int iChannel; + unsigned int iBin; + + unsigned int iSampleSC; + unsigned int iSampleBC; + unsigned int iSampleB; + + float Xreal; + float Ximag; + float Wreal; + float Wimag; + float Yreal; + float Yimag; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + memset(freqsSeparated->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize * 2); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleSC = iSep * obj->nChannels + iChannel; + + if (masks->array[iSampleSC] == 1) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleB = iBin; + + Xreal = freqsChannel->array[iChannel][iSampleB * 2 + 0]; + Ximag = freqsChannel->array[iChannel][iSampleB * 2 + 1]; + + Wreal = demixings->array[iSep][iSampleBC * 2 + 0]; + Wimag = demixings->array[iSep][iSampleBC * 2 + 1]; + + Yreal = Wreal * Xreal - Wimag * Ximag; + Yimag = Wreal * Ximag + Wimag * Xreal; + + freqsSeparated->array[iSep][iSampleB * 2 + 0] += Yreal; + freqsSeparated->array[iSep][iSampleB * 2 + 1] += Yimag; + + } + + } + + } + + } + else { + + memset(freqsSeparated->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize * 2); + + } + + } + + } \ No newline at end of file diff --git a/src/system/demixing2freq.h b/src/system/demixing2freq.h new file mode 100644 index 0000000..708f443 --- /dev/null +++ b/src/system/demixing2freq.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SYSTEM_DEMIXING2FREQ +#define __ODAS_SYSTEM_DEMIXING2FREQ + + #include + #include + #include + #include + + #include "../signal/demixing.h" + #include "../signal/freq.h" + #include "../signal/mask.h" + #include "../signal/track.h" + + typedef struct demixing2freq_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + + } demixing2freq_obj; + + demixing2freq_obj * demixing2freq_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize); + + void demixing2freq_destroy(demixing2freq_obj * obj); + + void demixing2freq_process(demixing2freq_obj * obj, const tracks_obj * tracks, const demixings_obj * demixings, const masks_obj * masks, const freqs_obj * freqsChannel, freqs_obj * freqsSeparated); + +#endif \ No newline at end of file diff --git a/src/system/env2env.c b/src/system/env2env.c new file mode 100644 index 0000000..3a49ea8 --- /dev/null +++ b/src/system/env2env.c @@ -0,0 +1,1264 @@ + + #include "env2env.h" + + env2env_mcra_obj * env2env_mcra_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const unsigned int bSize, const float alphaS, const unsigned int L, const float delta, const float alphaD) { + + env2env_mcra_obj * obj; + unsigned int n; + unsigned int iChannel; + float bTotal; + + obj = (env2env_mcra_obj *) malloc(sizeof(env2env_mcra_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + obj->bSize = bSize; + obj->alphaS = alphaS; + obj->L = L; + obj->delta = delta; + obj->alphaD = alphaD; + + obj->idsPrev = (unsigned long long *) malloc(sizeof(unsigned long long) * nChannels); + memset(obj->idsPrev, 0x00, sizeof(unsigned long long) * nChannels); + obj->l = (unsigned int *) malloc(sizeof(unsigned int) * nChannels); + memset(obj->l, 0x00, sizeof(unsigned int) * nChannels); + + obj->b = (float *) malloc(sizeof(float) * bSize); + for (n = 0; n < obj->bSize; n++) { + obj->b[n] = 0.5f * (1.0f * cosf(2.0f * M_PI * ((float) (n + 1)) / ((float) (obj->bSize + 1)))); + bTotal += (float) (obj->b[n]); + } + for (n = 0; n < obj->bSize; n++) { + obj->b[n] /= bTotal; + } + + obj->Sf = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->S = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->SPrev = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->Smin = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->SminPrev = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->Stmp = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->StmpPrev = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->lambdaD = (float **) malloc(sizeof(float *) * obj->nChannels); + obj->lambdaDnext = (float **) malloc(sizeof(float *) * obj->nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + obj->Sf[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->Sf[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->S[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->S[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->SPrev[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->SPrev[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->Smin[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->Smin[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->SminPrev[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->SminPrev[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->Stmp[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->Stmp[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->StmpPrev[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->StmpPrev[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->lambdaD[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->lambdaD[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->lambdaDnext[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->lambdaDnext[iChannel], 0x00, sizeof(float) * halfFrameSize); + + } + + return obj; + + } + + void env2env_mcra_destroy(env2env_mcra_obj * obj) { + + unsigned iChannel; + + free((void *) obj->idsPrev); + free((void *) obj->l); + free((void *) obj->b); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + free((void *) obj->Sf[iChannel]); + free((void *) obj->S[iChannel]); + free((void *) obj->SPrev[iChannel]); + free((void *) obj->Smin[iChannel]); + free((void *) obj->SminPrev[iChannel]); + free((void *) obj->Stmp[iChannel]); + free((void *) obj->StmpPrev[iChannel]); + free((void *) obj->lambdaD[iChannel]); + free((void *) obj->lambdaDnext[iChannel]); + + } + + free((void *) obj->Sf); + free((void *) obj->S); + free((void *) obj->SPrev); + free((void *) obj->Smin); + free((void *) obj->SminPrev); + free((void *) obj->Stmp); + free((void *) obj->StmpPrev); + free((void *) obj->lambdaD); + free((void *) obj->lambdaDnext); + + free((void *) obj); + + } + + void env2env_mcra_process(env2env_mcra_obj * obj, const tracks_obj * tracks, const envs_obj * noisys, const envs_obj * estNoises, envs_obj * noises) { + + unsigned int iChannel; + unsigned int iBin; + signed int iSample; + signed int iBinWrapped; + float sample; + + char doProcess; + char doReset; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (tracks != NULL) { + + if (tracks->ids[iChannel] != 0) { + + if (obj->idsPrev[iChannel] != 0) { + + doProcess = 0x01; + doReset = 0x00; + + } + else { + + doProcess = 0x01; + doReset = 0x01; + + } + + } + else { + + doProcess = 0x00; + doReset = 0x00; + + } + + obj->idsPrev[iChannel] = tracks->ids[iChannel]; + + } + else { + + doProcess = 0x01; + doReset = 0x00; + + } + + if (doReset == 0x01) { + + obj->l[iChannel] = 0; + + if (estNoises != NULL) { + + memcpy(obj->Sf[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->S[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->SPrev[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->Smin[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->SminPrev[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->Stmp[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->StmpPrev[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->lambdaD[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->lambdaDnext[iChannel], estNoises->array[iChannel], sizeof(float) * obj->halfFrameSize); + + } + else { + + memset(obj->Sf[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->S[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->SPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->Smin[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->SminPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->Stmp[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->StmpPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->lambdaD[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->lambdaDnext[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + if (doProcess == 0x01) { + + // N-1 + // +-- + // Sf_l[k] = > b[n] |X_l[k+n-(N-1)/2]|^2 + // +-- + // n=0 + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + sample = 0.0f; + + for (iSample = 0; iSample < obj->bSize; iSample++) { + + iBinWrapped = ((signed int) iBin) + iSample - ((signed int) ((obj->bSize-1)/2)); + + if (iBinWrapped < 0) { + iBinWrapped = -1 * iBinWrapped; + } + if (iBinWrapped >= ((signed int) obj->halfFrameSize)) { + iBinWrapped = 2*(obj->halfFrameSize-1) - iBinWrapped; + } + + sample += obj->b[iSample] * noisys->array[iChannel][iBinWrapped]; + + } + + obj->Sf[iChannel][iBin] = sample; + + } + + // + // S_l[k] = (1 - alphaS) * S_l-1[k] + alphaS * Sf_l[k] + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->S[iChannel][iBin] = (1 - obj->alphaS) * obj->SPrev[iChannel][iBin] + obj->alphaS * obj->Sf[iChannel][iBin]; + + } + + // \ + // Smin_l[k] = min{Smin_l-1[k],S_l[k]} | l < L + // Stmp_l[k] = min{Stmp_l-1[k],S_l[k]} | + // / + // \ + // Smin_l[k] = min{Stmp_l-1[k],S_l[k]} | l = L + // Stmp_l[k] = S_l[k] | + // / + + if (obj->l[iChannel] <= obj->L) { + + // Smin_l[k] = min{Smin_l-1[k],S_l[k]} + // Stmp_l[k] = min{Stmp_l-1[k],S_l[k]} + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + if (obj->SminPrev[iChannel][iBin] < obj->S[iChannel][iBin]) { + obj->Smin[iChannel][iBin] = obj->SminPrev[iChannel][iBin]; + } + else { + obj->Smin[iChannel][iBin] = obj->S[iChannel][iBin]; + } + + if (obj->StmpPrev[iChannel][iBin] < obj->S[iChannel][iBin]) { + obj->Stmp[iChannel][iBin] = obj->StmpPrev[iChannel][iBin]; + } + else { + obj->Stmp[iChannel][iBin] = obj->S[iChannel][iBin]; + } + + } + + // Count frames + + (obj->l[iChannel])++; + + } + else { + + // Smin_l[k] = min{Stmp_l-1[k],S_l[k]} + // Stmp_l[k] = S_l[k] + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + if (obj->StmpPrev[iChannel][iBin] < obj->S[iChannel][iBin]) { + obj->Smin[iChannel][iBin] = obj->StmpPrev[iChannel][iBin]; + } + else { + obj->Smin[iChannel][iBin] = obj->S[iChannel][iBin]; + } + + obj->Stmp[iChannel][iBin] = obj->S[iChannel][iBin]; + + } + + // Reset frame counter + + obj->l[iChannel] = 0; + + } + + // \ + // | S_l[k] < Smin_l[k] * delta + // lambdaD_l+1[k] = (1-alphaD) * lambdaD_l[k] + alphaD * |Y_l[k]|^2 | lambdaD_l[k] > |Y_l[k]|^2 + // | + // / + // + // lambdaD_l+1[k] = lambdaD_l[k] otherwise + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + if ((obj->S[iChannel][iBin] < (obj->Smin[iChannel][iBin] * obj->delta)) || (obj->lambdaD[iChannel][iBin] > obj->S[iChannel][iBin])) { + + obj->lambdaDnext[iChannel][iBin] = (1.0f - obj->alphaD) * obj->lambdaD[iChannel][iBin] + obj->alphaD * obj->S[iChannel][iBin]; + + } + + } + + + // Copy to output + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + noises->array[iChannel][iBin] = obj->lambdaDnext[iChannel][iBin]; + + } + + // Smin_l-1 = Smin_l + // S_l-1 = S_l + // Stmp_l-1 = Stmp_l + // lambdaD_l = lambdaD_l+1 + + memcpy(obj->SminPrev[iChannel], obj->Smin[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->SPrev[iChannel], obj->S[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->StmpPrev[iChannel], obj->Stmp[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->lambdaD[iChannel], obj->lambdaDnext[iChannel], sizeof(float) * obj->halfFrameSize); + + } + + } + + } + + env2env_weight_obj * env2env_weight_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float alphaD, const float epsilon) { + + env2env_weight_obj * obj; + unsigned int iChannel; + + obj = (env2env_weight_obj *) malloc(sizeof(env2env_weight_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + obj->alphaD = alphaD; + obj->epsilon = epsilon; + + obj->XPrev = (float **) malloc(sizeof(float *) * nChannels); + obj->xi = (float **) malloc(sizeof(float *) * nChannels); + obj->zetaPrev = (float **) malloc(sizeof(float *) * nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + obj->XPrev[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->XPrev[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->xi[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->xi[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->zetaPrev[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->zetaPrev[iChannel], 0x00, sizeof(float) * halfFrameSize); + + } + + return obj; + + } + + void env2env_weight_destroy(env2env_weight_obj * obj) { + + unsigned int iChannel; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + free((void *) obj->XPrev[iChannel]); + free((void *) obj->xi[iChannel]); + free((void *) obj->zetaPrev[iChannel]); + + } + + free((void *) obj->XPrev); + free((void *) obj->xi); + free((void *) obj->zetaPrev); + + } + + void env2env_weight_process(env2env_weight_obj * obj, const tracks_obj * tracks, const envs_obj * noisys, const envs_obj * noises, envs_obj * weights) { + + unsigned int iChannel; + unsigned int iBin; + + char doProcess; + char doReset; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (tracks != NULL) { + + if (tracks->ids[iChannel] != 0) { + + doProcess = 0x01; + doReset = 0x00; + + } + else { + + doProcess = 0x00; + doReset = 0x01; + + } + + } + else { + + doProcess = 0x01; + doReset = 0x00; + + } + + if (doReset == 0x01) { + + memset(obj->XPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->xi[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->zetaPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + if (doProcess == 0x01) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->xi[iChannel][iBin] = ((1 - obj->alphaD) * obj->zetaPrev[iChannel][iBin] * obj->XPrev[iChannel][iBin] + obj->alphaD * noisys->array[iChannel][iBin]) / (noises->array[iChannel][iBin] + obj->epsilon); + weights->array[iChannel][iBin] = obj->xi[iChannel][iBin] / (obj->xi[iChannel][iBin] + 1.0f); + + obj->XPrev[iChannel][iBin] = noisys->array[iChannel][iBin]; + obj->zetaPrev[iChannel][iBin] = weights->array[iChannel][iBin]; + + } + + } + + } + + } + + env2env_interf_obj * env2env_interf_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float eta, const float alphaZ) { + + env2env_interf_obj * obj; + unsigned int iChannel; + + obj = (env2env_interf_obj *) malloc(sizeof(env2env_interf_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + obj->eta = eta; + obj->alphaZ = alphaZ; + + obj->Zs = (float **) malloc(sizeof(float *) * nChannels); + obj->ZsPrev = (float **) malloc(sizeof(float *) * nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + obj->Zs[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->Zs[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->ZsPrev[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->ZsPrev[iChannel], 0x00, sizeof(float) * halfFrameSize); + + } + + return obj; + + } + + void env2env_interf_destroy(env2env_interf_obj * obj) { + + unsigned int iChannel; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + free((void *) obj->Zs[iChannel]); + free((void *) obj->ZsPrev[iChannel]); + + } + + free((void *) obj->Zs); + free((void *) obj->ZsPrev); + + free((void *) obj); + + } + + void env2env_interf_process(env2env_interf_obj * obj, const tracks_obj * tracks, const envs_obj * seps, const envs_obj * noises, envs_obj * interfs) { + + unsigned int iChannel1; + unsigned int iChannel2; + unsigned int iChannel; + unsigned int iBin; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (tracks->ids[iChannel] != 0) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->Zs[iChannel][iBin] = (1.0f - obj->alphaZ) * obj->ZsPrev[iChannel][iBin] + obj->alphaZ * seps->array[iChannel][iBin]; + + } + + memcpy(obj->ZsPrev[iChannel], obj->Zs[iChannel], sizeof(float)*obj->halfFrameSize); + + } + else { + + memset(obj->Zs[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->ZsPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + for (iChannel1 = 0; iChannel1 < obj->nChannels; iChannel1++) { + + if (tracks->ids[iChannel1] != 0) { + + memset(interfs->array[iChannel1], 0x00, sizeof(float) * obj->halfFrameSize); + + for (iChannel2 = 0; iChannel2 < obj->nChannels; iChannel2++) { + + if (tracks->ids[iChannel2] != 0) { + + if (iChannel1 != iChannel2) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + interfs->array[iChannel1][iBin] += obj->Zs[iChannel2][iBin] * obj->eta; + + } + + } + + } + + } + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + interfs->array[iChannel1][iBin] += noises->array[iChannel1][iBin]; + + } + + } + else { + + memset(interfs->array[iChannel1], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + } + + env2env_gainspeech_obj * env2env_gainspeech_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float alphaPmin, const float epsilon) { + + env2env_gainspeech_obj * obj; + unsigned int iChannel; + + obj = (env2env_gainspeech_obj *) malloc(sizeof(env2env_gainspeech_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + obj->alphaPmin = alphaPmin; + obj->epsilon = epsilon; + + obj->gamma = (float **) malloc(sizeof(float *) * nChannels); + obj->alphaP = (float **) malloc(sizeof(float *) * nChannels); + obj->xi = (float **) malloc(sizeof(float *) * nChannels); + obj->GH1 = (float **) malloc(sizeof(float *) * nChannels); + obj->v = (float **) malloc(sizeof(float *) * nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + obj->gamma[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->gamma[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->alphaP[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->alphaP[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->xi[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->xi[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->GH1[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->GH1[iChannel], 0x00, sizeof(float) * halfFrameSize); + obj->v[iChannel] = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->v[iChannel], 0x00, sizeof(float) * halfFrameSize); + + } + + obj->transcendental = transcendental_construct_zero(0.0f, 5.0f, 5001); + + return obj; + + } + + void env2env_gainspeech_destroy(env2env_gainspeech_obj * obj) { + + unsigned int iChannel; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + free((void *) obj->gamma[iChannel]); + free((void *) obj->alphaP[iChannel]); + free((void *) obj->xi[iChannel]); + free((void *) obj->GH1[iChannel]); + free((void *) obj->v[iChannel]); + + } + + free((void *) obj->gamma); + free((void *) obj->alphaP); + free((void *) obj->xi); + free((void *) obj->GH1); + free((void *) obj->v); + + transcendental_destroy(obj->transcendental); + + free((void *) obj); + + } + + void env2env_gainspeech_process(env2env_gainspeech_obj * obj, const tracks_obj * tracks, const envs_obj * seps, const envs_obj * noises, envs_obj * gains, envs_obj * snrs, envs_obj * vs) { + + unsigned int iChannel; + unsigned int iBin; + float xi_over_xi_plus_1; + float max_gamma_minus_1_vs_0; + float GH1_2; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (tracks->ids[iChannel] != 0) { + + // + // gamma_l[k] = |Y_l(k)|^2 / (lambda_l[k] + epsilon) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->gamma[iChannel][iBin] = seps->array[iChannel][iBin] / (noises->array[iChannel][iBin] + obj->epsilon); + + } + + // + // alphaP_l[k] = min{(xi_l-1[k] / (xi_l-1[k] + 1))^2 + alphaPmin, 1.0} + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + xi_over_xi_plus_1 = obj->xi[iChannel][iBin] / (obj->xi[iChannel][iBin] + 1.0f); + + obj->alphaP[iChannel][iBin] = xi_over_xi_plus_1 * xi_over_xi_plus_1 + obj->alphaPmin; + + if (obj->alphaP[iChannel][iBin] > 1.0f) { + obj->alphaP[iChannel][iBin] = 1.0f; + } + + } + + // + // xi_l[k] = (1 - alphaP_l[k]) * (GH1_l-1[k])^2 * gamma_l[k] + alphaP_l[k] * max{gamma_l[k]-1,0} + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + if ((obj->gamma[iChannel][iBin] - 1.0f) < 0.0f) { + max_gamma_minus_1_vs_0 = 0.0f; + } + else { + max_gamma_minus_1_vs_0 = obj->gamma[iChannel][iBin] - 1.0f; + } + + GH1_2 = obj->GH1[iChannel][iBin] * obj->GH1[iChannel][iBin]; + + obj->xi[iChannel][iBin] = (1.0f - obj->alphaP[iChannel][iBin]) * GH1_2 * obj->gamma[iChannel][iBin] + obj->alphaP[iChannel][iBin] * max_gamma_minus_1_vs_0; + + } + + // + // v_l[k] = gamma_l[k] * xi_l[k] / (xi_l[k] + 1) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->v[iChannel][iBin] = obj->gamma[iChannel][iBin] * obj->xi[iChannel][iBin] / (obj->xi[iChannel][iBin] + 1.0f); + + } + + // + // GH1_l[k] = (xi_l[k] / (xi_l[k] + 1)) * fcn(v_l[k]) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->GH1[iChannel][iBin] = (obj->xi[iChannel][iBin] / (obj->xi[iChannel][iBin] + 1.0f)) * transcendental_process(obj->transcendental, obj->v[iChannel][iBin]); + + if (obj->GH1[iChannel][iBin] > 1.0f) { + obj->GH1[iChannel][iBin] = 1.0f; + } + + } + + memcpy(gains->array[iChannel],obj->GH1[iChannel],sizeof(float) * obj->halfFrameSize); + memcpy(snrs->array[iChannel],obj->xi[iChannel],sizeof(float) * obj->halfFrameSize); + memcpy(vs->array[iChannel],obj->v[iChannel],sizeof(float) * obj->halfFrameSize); + + } + else { + + memset(obj->gamma[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->alphaP[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->xi[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->GH1[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->v[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + memset(gains->array[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(snrs->array[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(vs->array[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + } + + env2env_probspeech_obj * env2env_probspeech_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float theta, const float alpha, const float maxAbsenceProb, const float Gmin, const unsigned int winSizeLocal, const unsigned int winSizeGlobal, const unsigned int winSizeFrame) { + + env2env_probspeech_obj * obj; + unsigned int iSample; + unsigned int iChannel; + signed int iSampleShifted; + unsigned int iSampleWrapped; + float total; + + obj = (env2env_probspeech_obj *) malloc(sizeof(env2env_probspeech_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + obj->frameSize = (halfFrameSize-1) * 2; + obj->theta = theta; + obj->alpha = alpha; + obj->maxAbsenceProb = maxAbsenceProb; + obj->Gmin = Gmin; + obj->winSizeLocal = winSizeLocal; + obj->winSizeGlobal = winSizeGlobal; + obj->winSizeFrame = winSizeFrame; + + obj->fft = fft_construct(obj->frameSize); + + obj->winLocal = (float *) malloc(sizeof(float) * winSizeLocal); + memset(obj->winLocal, 0x00, sizeof(float) * winSizeLocal); + obj->winGlobal = (float *) malloc(sizeof(float) * winSizeGlobal); + memset(obj->winGlobal, 0x00, sizeof(float) * winSizeGlobal); + obj->winFrame = (float *) malloc(sizeof(float) * winSizeFrame); + memset(obj->winFrame, 0x00, sizeof(float) * winSizeFrame); + + if ( winSizeLocal == 1 ) { + obj->winLocal[0] = 1.0f; + } + else { + total = 0.0f; + for ( iSample = 0; iSample < winSizeLocal; iSample++ ) { + obj->winLocal[iSample] = 0.5f * ( 1.0f - cosf( 2 * M_PI * ( (float) (iSample+1) ) / ( (float) ( (winSizeLocal+2) - 1 ) ) ) ); + total += obj->winLocal[iSample]; + } + for ( iSample = 0; iSample < winSizeLocal; iSample++ ) { + obj->winLocal[iSample] /= total; + } + } + + if ( winSizeGlobal == 1 ) { + obj->winGlobal[0] = 1.0f; + } + else { + total = 0.0f; + for ( iSample = 0; iSample < winSizeGlobal; iSample++ ) { + obj->winGlobal[iSample] = 0.5f * ( 1.0f - cosf( 2 * M_PI * ( (float) (iSample+1) ) / ( (float) ( (winSizeGlobal+2) - 1 ) ) ) ); + total += obj->winGlobal[iSample]; + } + for ( iSample = 0; iSample < winSizeGlobal; iSample++ ) { + obj->winGlobal[iSample] /= total; + + } + } + + if ( winSizeFrame == 1 ) { + obj->winFrame[0] = 1.0f; + } + else { + total = 0.0f; + for ( iSample = 0; iSample < winSizeFrame; iSample++ ) { + obj->winFrame[iSample] = 0.5f * ( 1.0f - cosf( 2 * M_PI * ( (float) (iSample+1) ) / ( (float) ( (winSizeFrame+2) - 1 ) ) ) ); + total += obj->winFrame[iSample]; + } + for ( iSample = 0; iSample < winSizeFrame; iSample++ ) { + obj->winFrame[iSample] /= total; + } + } + + obj->winLocalShifted = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->winLocalShifted, 0x00, sizeof(float) * obj->frameSize); + obj->winGlobalShifted = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->winGlobalShifted, 0x00, sizeof(float) * obj->frameSize); + obj->winFrameShifted = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->winFrameShifted, 0x00, sizeof(float) * obj->frameSize); + + for (iSample = 0; iSample < obj->winSizeLocal; iSample++) { + + iSampleShifted = iSample - (obj->winSizeLocal / 2); + + if (iSampleShifted < 0) { + iSampleWrapped = (unsigned int) (iSampleShifted + obj->frameSize); + } + else { + iSampleWrapped = (unsigned int) (iSampleShifted); + } + + obj->winLocalShifted[iSampleWrapped] = obj->winLocal[iSample]; + + } + + for (iSample = 0; iSample < obj->winSizeGlobal; iSample++) { + + iSampleShifted = iSample - (obj->winSizeGlobal / 2); + + if (iSampleShifted < 0) { + iSampleWrapped = (unsigned int) (iSampleShifted + obj->frameSize); + } + else { + iSampleWrapped = (unsigned int) (iSampleShifted); + } + + obj->winGlobalShifted[iSampleWrapped] = obj->winGlobal[iSample]; + + } + + for (iSample = 0; iSample < obj->winSizeFrame; iSample++) { + + iSampleShifted = iSample - (obj->winSizeFrame / 2); + + if (iSampleShifted < 0) { + iSampleWrapped = (unsigned int) (iSampleShifted + obj->frameSize); + } + else { + iSampleWrapped = (unsigned int) (iSampleShifted); + } + + obj->winFrameShifted[iSampleWrapped] = obj->winFrame[iSample]; + + } + + obj->winLocalShiftedFreq = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->winLocalShiftedFreq, 0x00, sizeof(float) * obj->halfFrameSize * 2); + obj->winGlobalShiftedFreq = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->winGlobalShiftedFreq, 0x00, sizeof(float) * obj->halfFrameSize * 2); + obj->winFrameShiftedFreq = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->winFrameShiftedFreq, 0x00, sizeof(float) * obj->halfFrameSize * 2); + + fft_r2c(obj->fft, obj->winLocalShifted, obj->winLocalShiftedFreq); + fft_r2c(obj->fft, obj->winGlobalShifted, obj->winGlobalShiftedFreq); + fft_r2c(obj->fft, obj->winFrameShifted, obj->winFrameShiftedFreq); + + obj->xiTime = (float **) malloc(sizeof(float *) * nChannels); + obj->xiFreq = (float **) malloc(sizeof(float *) * nChannels); + + obj->xiSmoothedLocalFreq = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedGlobalFreq = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedFrameFreq = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedLocalTime = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedGlobalTime = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedFrameTime = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedLocal = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedGlobal = (float **) malloc(sizeof(float *) * nChannels); + obj->xiSmoothedFrame = (float **) malloc(sizeof(float *) * nChannels); + + obj->zetaLocal = (float **) malloc(sizeof(float *) * nChannels); + obj->zetaLocalPrev = (float **) malloc(sizeof(float *) * nChannels); + obj->zetaGlobal = (float **) malloc(sizeof(float *) * nChannels); + obj->zetaGlobalPrev = (float **) malloc(sizeof(float *) * nChannels); + obj->zetaFrame = (float **) malloc(sizeof(float *) * nChannels); + obj->zetaFramePrev = (float **) malloc(sizeof(float *) * nChannels); + + obj->PLocal = (float **) malloc(sizeof(float *) * nChannels); + obj->PGlobal = (float **) malloc(sizeof(float *) * nChannels); + obj->PFrame = (float **) malloc(sizeof(float *) * nChannels); + + obj->q = (float **) malloc(sizeof(float *) * nChannels); + obj->p = (float **) malloc(sizeof(float *) * nChannels); + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + obj->xiTime[iChannel] = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->xiTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + obj->xiFreq[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + + obj->xiSmoothedLocalFreq[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiSmoothedLocalFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + obj->xiSmoothedGlobalFreq[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiSmoothedGlobalFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + obj->xiSmoothedFrameFreq[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiSmoothedFrameFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + obj->xiSmoothedLocalTime[iChannel] = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->xiSmoothedLocalTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + obj->xiSmoothedGlobalTime[iChannel] = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->xiSmoothedGlobalTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + obj->xiSmoothedFrameTime[iChannel] = (float *) malloc(sizeof(float) * obj->frameSize); + memset(obj->xiSmoothedFrameTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + obj->xiSmoothedLocal[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->xiSmoothedLocalTime[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->xiSmoothedGlobal[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->xiSmoothedGlobalTime[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->xiSmoothedFrame[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->xiSmoothedFrameTime[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + obj->zetaLocal[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->zetaLocal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->zetaLocalPrev[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->zetaLocalPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->zetaGlobal[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->zetaGlobal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->zetaGlobalPrev[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->zetaGlobalPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->zetaFrame[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->zetaFrame[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->zetaFramePrev[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->zetaFramePrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + obj->PLocal[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->PLocal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->PGlobal[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->PGlobal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->PFrame[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->PFrame[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + obj->q[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->q[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + obj->p[iChannel] = (float *) malloc(sizeof(float) * obj->halfFrameSize); + memset(obj->p[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + return obj; + + } + + void env2env_probspeech_destroy(env2env_probspeech_obj * obj) { + + unsigned int iChannel; + + fft_destroy(obj->fft); + + free((void *) obj->winLocal); + free((void *) obj->winGlobal); + free((void *) obj->winFrame); + + free((void *) obj->winLocalShifted); + free((void *) obj->winGlobalShifted); + free((void *) obj->winFrameShifted); + + free((void *) obj->winLocalShiftedFreq); + free((void *) obj->winGlobalShiftedFreq); + free((void *) obj->winFrameShiftedFreq); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + free((void *) obj->xiTime[iChannel]); + free((void *) obj->xiFreq[iChannel]); + + free((void *) obj->xiSmoothedLocalFreq[iChannel]); + free((void *) obj->xiSmoothedGlobalFreq[iChannel]); + free((void *) obj->xiSmoothedFrameFreq[iChannel]); + free((void *) obj->xiSmoothedLocalTime[iChannel]); + free((void *) obj->xiSmoothedGlobalTime[iChannel]); + free((void *) obj->xiSmoothedFrameTime[iChannel]); + free((void *) obj->xiSmoothedLocal[iChannel]); + free((void *) obj->xiSmoothedGlobal[iChannel]); + free((void *) obj->xiSmoothedFrame[iChannel]); + + free((void *) obj->zetaLocal[iChannel]); + free((void *) obj->zetaLocalPrev[iChannel]); + free((void *) obj->zetaGlobal[iChannel]); + free((void *) obj->zetaGlobalPrev[iChannel]); + free((void *) obj->zetaFrame[iChannel]); + free((void *) obj->zetaFramePrev[iChannel]); + + free((void *) obj->PLocal[iChannel]); + free((void *) obj->PGlobal[iChannel]); + free((void *) obj->PFrame[iChannel]); + + free((void *) obj->q[iChannel]); + free((void *) obj->p[iChannel]); + + } + + free((void *) obj->xiTime); + free((void *) obj->xiFreq); + + free((void *) obj->xiSmoothedLocalFreq); + free((void *) obj->xiSmoothedGlobalFreq); + free((void *) obj->xiSmoothedFrameFreq); + free((void *) obj->xiSmoothedLocalTime); + free((void *) obj->xiSmoothedGlobalTime); + free((void *) obj->xiSmoothedFrameTime); + free((void *) obj->xiSmoothedLocal); + free((void *) obj->xiSmoothedGlobal); + free((void *) obj->xiSmoothedFrame); + + free((void *) obj->zetaLocal); + free((void *) obj->zetaLocalPrev); + free((void *) obj->zetaGlobal); + free((void *) obj->zetaGlobalPrev); + free((void *) obj->zetaFrame); + free((void *) obj->zetaFramePrev); + + free((void *) obj->PLocal); + free((void *) obj->PGlobal); + free((void *) obj->PFrame); + + free((void *) obj->q); + free((void *) obj->p); + + free((void *) obj); + + } + + void env2env_probspeech_process(env2env_probspeech_obj * obj, const tracks_obj * tracks, const envs_obj * snrs, const envs_obj * vs, envs_obj * probspeechs) { + + unsigned int iChannel; + unsigned int iBin; + + float hLocalReal; + float hLocalImag; + float hGlobalReal; + float hGlobalImag; + float hFrameReal; + float hFrameImag; + float xiReal; + float xiImag; + + float hLocalxiReal; + float hLocalxiImag; + float hGlobalxiReal; + float hGlobalxiImag; + float hFramexiReal; + float hFramexiImag; + + float theta_zeta; + float PLocalGlobalFrame; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (tracks->ids[iChannel] != 0) { + + // + // Circular convolution with local, global and frame windows + // + + obj->xiTime[iChannel][0] = snrs->array[iChannel][0]; + obj->xiTime[iChannel][obj->halfFrameSize-1] = snrs->array[iChannel][obj->halfFrameSize-1]; + + for (iBin = 1; iBin < (obj->halfFrameSize-1); iBin++) { + + obj->xiTime[iChannel][iBin] = snrs->array[iChannel][iBin]; + obj->xiTime[iChannel][obj->frameSize-iBin] = snrs->array[iChannel][iBin]; + + } + + fft_r2c(obj->fft, obj->xiTime[iChannel], obj->xiFreq[iChannel]); + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + hLocalReal = obj->winLocalShiftedFreq[iBin*2+0]; + hLocalImag = obj->winLocalShiftedFreq[iBin*2+1]; + hGlobalReal = obj->winGlobalShiftedFreq[iBin*2+0]; + hGlobalImag = obj->winGlobalShiftedFreq[iBin*2+1]; + hFrameReal = obj->winFrameShiftedFreq[iBin*2+0]; + hFrameImag = obj->winFrameShiftedFreq[iBin*2+1]; + xiReal = obj->xiFreq[iChannel][iBin*2+0]; + xiImag = obj->xiFreq[iChannel][iBin*2+1]; + + hLocalxiReal = hLocalReal * xiReal - hLocalImag * xiImag; + hLocalxiImag = hLocalReal * xiImag + hLocalImag * xiReal; + hGlobalxiReal = hGlobalReal * xiReal - hGlobalImag * xiImag; + hGlobalxiImag = hGlobalReal * xiImag + hGlobalImag * xiReal; + hFramexiReal = hFrameReal * xiReal - hFrameImag * xiImag; + hFramexiImag = hFrameReal * xiImag + hFrameImag * xiReal; + + obj->xiSmoothedLocalFreq[iChannel][iBin*2+0] = hLocalxiReal; + obj->xiSmoothedLocalFreq[iChannel][iBin*2+1] = hLocalxiImag; + obj->xiSmoothedGlobalFreq[iChannel][iBin*2+0] = hGlobalxiReal; + obj->xiSmoothedGlobalFreq[iChannel][iBin*2+1] = hGlobalxiImag; + obj->xiSmoothedFrameFreq[iChannel][iBin*2+0] = hFramexiReal; + obj->xiSmoothedFrameFreq[iChannel][iBin*2+1] = hFramexiImag; + + } + + fft_c2r(obj->fft, obj->xiSmoothedLocalFreq[iChannel], obj->xiSmoothedLocalTime[iChannel]); + fft_c2r(obj->fft, obj->xiSmoothedGlobalFreq[iChannel], obj->xiSmoothedGlobalTime[iChannel]); + fft_c2r(obj->fft, obj->xiSmoothedFrameFreq[iChannel], obj->xiSmoothedFrameTime[iChannel]); + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->xiSmoothedLocal[iChannel][iBin] = obj->xiSmoothedLocalTime[iChannel][iBin]; + obj->xiSmoothedGlobal[iChannel][iBin] = obj->xiSmoothedGlobalTime[iChannel][iBin]; + obj->xiSmoothedFrame[iChannel][iBin] = obj->xiSmoothedFrameTime[iChannel][iBin]; + + } + + // + // zeta_l(k) = (1 - alpha) * zeta_l-1(k) + alpha * xiSmoothed_l(k) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->zetaLocal[iChannel][iBin] = (1.0f - obj->alpha) * obj->zetaLocalPrev[iChannel][iBin] + obj->alpha * obj->xiSmoothedLocal[iChannel][iBin]; + obj->zetaGlobal[iChannel][iBin] = (1.0f - obj->alpha) * obj->zetaGlobalPrev[iChannel][iBin] + obj->alpha * obj->xiSmoothedGlobal[iChannel][iBin]; + obj->zetaFrame[iChannel][iBin] = (1.0f - obj->alpha) * obj->zetaFramePrev[iChannel][iBin] + obj->alpha * obj->xiSmoothedFrame[iChannel][iBin]; + + } + + memcpy(obj->zetaLocalPrev[iChannel], obj->zetaLocal[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->zetaGlobalPrev[iChannel], obj->zetaGlobal[iChannel], sizeof(float) * obj->halfFrameSize); + memcpy(obj->zetaFramePrev[iChannel], obj->zetaFrame[iChannel], sizeof(float) * obj->halfFrameSize); + + // + // P_l(k) = 1 / (1 + (theta/zeta_l(k))^2) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + theta_zeta = obj->theta/obj->zetaLocal[iChannel][iBin]; + obj->PLocal[iChannel][iBin] = 1.0f / (1.0f + (theta_zeta*theta_zeta)); + + theta_zeta = obj->theta/obj->zetaGlobal[iChannel][iBin]; + obj->PGlobal[iChannel][iBin] = 1.0f / (1.0f + (theta_zeta*theta_zeta)); + + theta_zeta = obj->theta/obj->zetaFrame[iChannel][iBin]; + obj->PFrame[iChannel][iBin] = 1.0f / (1.0f + (theta_zeta*theta_zeta)); + + } + + // + // q_l(k) = min(1-Plocal_l(k)*Pglobal_l(k)*Pframe_l(k)) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + PLocalGlobalFrame = obj->PLocal[iChannel][iBin] * obj->PGlobal[iChannel][iBin] * obj->PFrame[iChannel][iBin]; + + if ((1.0f - PLocalGlobalFrame) > 0.9f) { + obj->q[iChannel][iBin] = 0.9; + } + else { + obj->q[iChannel][iBin] = 1.0f - PLocalGlobalFrame; + } + + } + + // + // p_l(k) = (1 + (q_l(k) / (1 - q_l(k)) * (1 + xi_l(k)) * exp(-v_l(k))) + // + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->p[iChannel][iBin] = 1.0f / (1.0f + (obj->q[iChannel][iBin] / (1.0f - obj->q[iChannel][iBin])) * (1.0f + snrs->array[iChannel][iBin]) * expf(-1.0f * vs->array[iChannel][iBin])); + + } + + memcpy(probspeechs->array[iChannel],obj->p[iChannel],sizeof(float) * obj->halfFrameSize); + + } + else { + + memset(obj->xiTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + memset(obj->xiFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + + memset(obj->xiSmoothedLocalFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiSmoothedGlobalFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiSmoothedFrameFreq[iChannel], 0x00, sizeof(float) * obj->halfFrameSize * 2); + memset(obj->xiSmoothedLocalTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + memset(obj->xiSmoothedGlobalTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + memset(obj->xiSmoothedFrameTime[iChannel], 0x00, sizeof(float) * obj->frameSize); + memset(obj->xiSmoothedLocalTime[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->xiSmoothedGlobalTime[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->xiSmoothedFrameTime[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + memset(obj->zetaLocal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->zetaLocalPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->zetaGlobal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->zetaGlobalPrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->zetaFrame[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->zetaFramePrev[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + memset(obj->PLocal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->PGlobal[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->PFrame[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + memset(obj->q[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + memset(obj->p[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + memset(probspeechs->array[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + } + + env2env_gainall_obj * env2env_gainall_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float Gmin) { + + env2env_gainall_obj * obj; + + obj = (env2env_gainall_obj *) malloc(sizeof(env2env_gainall_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + obj->Gmin = Gmin; + + return obj; + + } + + void env2env_gainall_destroy(env2env_gainall_obj * obj) { + + free((void *) obj); + + } + + void env2env_gainall_process(env2env_gainall_obj * obj, const tracks_obj * tracks, const envs_obj * gainspeeches, const envs_obj * probspeeches, envs_obj * gainalls) { + + unsigned int iChannel; + unsigned int iBin; + + float expr1; + float expr2; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (tracks->ids[iChannel] != 0) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + expr1 = powf(gainspeeches->array[iChannel][iBin], probspeeches->array[iChannel][iBin]); + expr2 = powf(obj->Gmin, (1.0f - probspeeches->array[iChannel][iBin])); + + gainalls->array[iChannel][iBin] = expr1 * expr2; + + } + + } + else { + + memset(gainalls->array[iChannel], 0x00, sizeof(float) * obj->halfFrameSize); + + } + + } + + } \ No newline at end of file diff --git a/src/system/env2env.h b/src/system/env2env.h new file mode 100644 index 0000000..6d115e0 --- /dev/null +++ b/src/system/env2env.h @@ -0,0 +1,188 @@ +#ifndef __ODAS_SYSTEM_ENV2ENV +#define __ODAS_SYSTEM_ENV2ENV + + #include + #include + #include + + #include "../signal/env.h" + #include "../signal/track.h" + #include "../utils/fft.h" + #include "../utils/transcendental.h" + + typedef struct env2env_mcra_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + + unsigned int bSize; + float alphaS; + unsigned int L; + float delta; + float alphaD; + + unsigned long long * idsPrev; + unsigned int * l; + + float * b; + float ** S; + float ** Smin; + float ** SminPrev; + float ** SPrev; + float ** Stmp; + float ** StmpPrev; + float ** Sf; + float ** lambdaD; + float ** lambdaDnext; + + } env2env_mcra_obj; + + typedef struct env2env_weight_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + + float alphaD; + float epsilon; + + float ** XPrev; + float ** xi; + float ** zetaPrev; + + } env2env_weight_obj; + + typedef struct env2env_interf_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + + float eta; + float alphaZ; + + float ** Zs; + float ** ZsPrev; + + } env2env_interf_obj; + + typedef struct env2env_gainspeech_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + + float alphaPmin; + float epsilon; + + float ** gamma; + float ** alphaP; + float ** xi; + float ** GH1; + float ** v; + + transcendental_obj * transcendental; + + } env2env_gainspeech_obj; + + typedef struct env2env_probspeech_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + unsigned int frameSize; + + float theta; + float alpha; + float maxAbsenceProb; + float Gmin; + + unsigned int winSizeLocal; + unsigned int winSizeGlobal; + unsigned int winSizeFrame; + + fft_obj * fft; + + float * winLocal; + float * winGlobal; + float * winFrame; + + float * winLocalShifted; + float * winGlobalShifted; + float * winFrameShifted; + + float * winLocalShiftedFreq; + float * winGlobalShiftedFreq; + float * winFrameShiftedFreq; + + float ** xiTime; + float ** xiFreq; + + float ** xiSmoothedLocalFreq; + float ** xiSmoothedGlobalFreq; + float ** xiSmoothedFrameFreq; + float ** xiSmoothedLocalTime; + float ** xiSmoothedGlobalTime; + float ** xiSmoothedFrameTime; + float ** xiSmoothedLocal; + float ** xiSmoothedGlobal; + float ** xiSmoothedFrame; + + float ** zetaLocal; + float ** zetaLocalPrev; + float ** zetaGlobal; + float ** zetaGlobalPrev; + float ** zetaFrame; + float ** zetaFramePrev; + + float ** PLocal; + float ** PGlobal; + float ** PFrame; + + float ** q; + float ** p; + + } env2env_probspeech_obj; + + typedef struct env2env_gainall_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + + float Gmin; + + } env2env_gainall_obj; + + env2env_mcra_obj * env2env_mcra_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const unsigned int bSize, const float alphaS, const unsigned int L, const float delta, const float alphaD); + + void env2env_mcra_destroy(env2env_mcra_obj * obj); + + void env2env_mcra_process(env2env_mcra_obj * obj, const tracks_obj * tracks, const envs_obj * noisys, const envs_obj * estNoises, envs_obj * noises); + + env2env_weight_obj * env2env_weight_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float alphaD, const float epsilon); + + void env2env_weight_destroy(env2env_weight_obj * obj); + + void env2env_weight_process(env2env_weight_obj * obj, const tracks_obj * tracks, const envs_obj * noisys, const envs_obj * noises, envs_obj * weights); + + env2env_interf_obj * env2env_interf_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float eta, const float alphaZ); + + void env2env_interf_destroy(env2env_interf_obj * obj); + + void env2env_interf_process(env2env_interf_obj * obj, const tracks_obj * tracks, const envs_obj * seps, const envs_obj * noises, envs_obj * interfs); + + env2env_gainspeech_obj * env2env_gainspeech_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float alphaPmin, const float epsilon); + + void env2env_gainspeech_destroy(env2env_gainspeech_obj * obj); + + void env2env_gainspeech_process(env2env_gainspeech_obj * obj, const tracks_obj * tracks, const envs_obj * seps, const envs_obj * noises, envs_obj * gains, envs_obj * snrs, envs_obj * vs); + + env2env_probspeech_obj * env2env_probspeech_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float theta, const float alpha, const float maxAbsenceProb, const float Gmin, const unsigned int winSizeLocal, const unsigned int winSizeGlobal, const unsigned int winSizeFrame); + + void env2env_probspeech_destroy(env2env_probspeech_obj * obj); + + void env2env_probspeech_process(env2env_probspeech_obj * obj, const tracks_obj * tracks, const envs_obj * snrs, const envs_obj * vs, envs_obj * probspeechs); + + env2env_gainall_obj * env2env_gainall_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize, const float Gmin); + + void env2env_gainall_destroy(env2env_gainall_obj * obj); + + void env2env_gainall_process(env2env_gainall_obj * obj, const tracks_obj * tracks, const envs_obj * gainspeeches, const envs_obj * probspeeches, envs_obj * gainalls); + +#endif \ No newline at end of file diff --git a/src/system/frame2freq.c b/src/system/frame2freq.c new file mode 100644 index 0000000..beb8253 --- /dev/null +++ b/src/system/frame2freq.c @@ -0,0 +1,51 @@ + + #include "frame2freq.h" + + frame2freq_obj * frame2freq_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize) { + + frame2freq_obj * obj; + + obj = (frame2freq_obj *) malloc(sizeof(frame2freq_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = halfFrameSize; + + obj->win = windowing_roothann(frameSize); + obj->frame = (float *) malloc(sizeof(float) * frameSize); + memset(obj->frame, 0x00, sizeof(float) * frameSize); + obj->fft = fft_construct(frameSize); + + return obj; + + } + + void frame2freq_destroy(frame2freq_obj * obj) { + + window_destroy(obj->win); + free((void *) obj->frame); + fft_destroy(obj->fft); + + free((void *) obj); + + } + + void frame2freq_process(frame2freq_obj * obj, const frames_obj * frames, freqs_obj * freqs) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < frames->nSignals; iSignal++) { + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + obj->frame[iSample] = obj->win->array[iSample] * frames->array[iSignal][iSample]; + + } + + fft_r2c(obj->fft, + obj->frame, + freqs->array[iSignal]); + + } + + } \ No newline at end of file diff --git a/src/system/frame2freq.h b/src/system/frame2freq.h new file mode 100644 index 0000000..a485602 --- /dev/null +++ b/src/system/frame2freq.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_SYSTEM_FRAME2FREQ +#define __ODAS_SYSTEM_FRAME2FREQ + + #include + + #include "../init/windowing.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/window.h" + #include "../utils/fft.h" + + typedef struct frame2freq_obj { + + unsigned int frameSize; + unsigned int halfFrameSize; + + window_obj * win; + float * frame; + + fft_obj * fft; + + } frame2freq_obj; + + frame2freq_obj * frame2freq_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize); + + void frame2freq_destroy(frame2freq_obj * obj); + + void frame2freq_process(frame2freq_obj * obj, const frames_obj * frames, freqs_obj * freqs); + +#endif \ No newline at end of file diff --git a/src/system/frame2hop.c b/src/system/frame2hop.c new file mode 100644 index 0000000..c60c036 --- /dev/null +++ b/src/system/frame2hop.c @@ -0,0 +1,67 @@ + + #include "frame2hop.h" + + frame2hop_obj * frame2hop_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals) { + + frame2hop_obj * obj; + unsigned int iSignal; + + obj = (frame2hop_obj *) malloc(sizeof(frame2hop_obj)); + + obj->hopSize = hopSize; + obj->frameSize = frameSize; + obj->nSignals = nSignals; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array[iSignal], 0x00, sizeof(float) * frameSize); + } + + return obj; + + } + + void frame2hop_destroy(frame2hop_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + + free((void *) obj->array); + + free((void *) obj); + + } + + void frame2hop_process(frame2hop_obj * obj, const frames_obj * frames, hops_obj * hops) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + memmove(&(obj->array[iSignal][0]), + &(obj->array[iSignal][obj->hopSize]), + sizeof(float) * (obj->frameSize - obj->hopSize)); + + memset(&(obj->array[iSignal][obj->frameSize - obj->hopSize]), + 0x00, + sizeof(float) * (obj->hopSize)); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + obj->array[iSignal][iSample] += frames->array[iSignal][iSample]; + + } + + memcpy(&(hops->array[iSignal][0]), + &(obj->array[iSignal][0]), + sizeof(float) * obj->hopSize); + + } + + } \ No newline at end of file diff --git a/src/system/frame2hop.h b/src/system/frame2hop.h new file mode 100644 index 0000000..a24a745 --- /dev/null +++ b/src/system/frame2hop.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SYSTEM_FRAME2HOP +#define __ODAS_SYSTEM_FRAME2HOP + + #include + #include + + #include "../signal/hop.h" + #include "../signal/frame.h" + + typedef struct frame2hop_obj { + + unsigned int hopSize; + unsigned int frameSize; + unsigned int nSignals; + + float ** array; + + } frame2hop_obj; + + frame2hop_obj * frame2hop_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals); + + void frame2hop_destroy(frame2hop_obj * obj); + + void frame2hop_process(frame2hop_obj * obj, const frames_obj * frames, hops_obj * hops); + +#endif \ No newline at end of file diff --git a/src/system/freq2acorr.c b/src/system/freq2acorr.c new file mode 100644 index 0000000..7ce715a --- /dev/null +++ b/src/system/freq2acorr.c @@ -0,0 +1,62 @@ + + #include "freq2acorr.h" + + freq2acorr_obj * freq2acorr_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize) { + + freq2acorr_obj * obj; + + obj = (freq2acorr_obj *) malloc(sizeof(freq2acorr_obj)); + + obj->nSignals = nSignals; + obj->halfFrameSize = halfFrameSize; + obj->frameSize = (halfFrameSize-1)*2; + + obj->arrayIn = (float *) malloc(sizeof(float) * obj->halfFrameSize * 2); + obj->arrayOut = (float *) malloc(sizeof(float) * obj->frameSize); + + obj->fft = fft_construct(obj->frameSize); + + return obj; + + } + + void freq2acorr_destroy(freq2acorr_obj * obj) { + + 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; + float Ypwr; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + 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]; + Ypwr = Yreal * Yreal + Yimag * Yimag; + + obj->arrayIn[iBin * 2 + 0] = Ypwr; + obj->arrayIn[iBin * 2 + 1] = 0.0f; + + } + + fft_c2r(obj->fft, obj->arrayIn, obj->arrayOut); + + memcpy(acorrs->array[iSignal], obj->arrayOut, sizeof(float) * obj->halfFrameSize); + + } + + } \ No newline at end of file diff --git a/src/system/freq2acorr.h b/src/system/freq2acorr.h new file mode 100644 index 0000000..d2941b3 --- /dev/null +++ b/src/system/freq2acorr.h @@ -0,0 +1,31 @@ +#ifndef __ODAS_SYSTEM_FREQ2ACORR +#define __ODAS_SYSTEM_FREQ2ACORR + + #include + #include + #include + + #include "../signal/acorr.h" + #include "../signal/freq.h" + #include "../utils/fft.h" + + typedef struct freq2acorr_obj { + + unsigned int nSignals; + unsigned int halfFrameSize; + unsigned int frameSize; + + float * arrayIn; + float * arrayOut; + + fft_obj * fft; + + } freq2acorr_obj; + + freq2acorr_obj * freq2acorr_construct_zero(const unsigned int nSignals, const unsigned int halfFrameSize); + + void freq2acorr_destroy(freq2acorr_obj * obj); + + void freq2acorr_process(freq2acorr_obj * obj, const freqs_obj * freqs, acorrs_obj * acorrs); + +#endif \ No newline at end of file diff --git a/src/system/freq2env.c b/src/system/freq2env.c new file mode 100644 index 0000000..0e58cc3 --- /dev/null +++ b/src/system/freq2env.c @@ -0,0 +1,46 @@ + + #include "freq2env.h" + + freq2env_obj * freq2env_construct_zero(const unsigned int halfFrameSize) { + + freq2env_obj * obj; + + obj = (freq2env_obj *) malloc(sizeof(freq2env_obj)); + + obj->halfFrameSize = halfFrameSize; + + return obj; + + } + + void freq2env_destroy(freq2env_obj * obj) { + + free((void *) obj); + + } + + void freq2env_process(freq2env_obj * obj, const freqs_obj * freqs, envs_obj * envs) { + + unsigned int iSignal; + unsigned int iBin; + + float Xreal; + float Ximag; + float X2; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + Xreal = freqs->array[iSignal][iBin * 2 + 0]; + Ximag = freqs->array[iSignal][iBin * 2 + 1]; + + X2 = Xreal * Xreal + Ximag * Ximag; + + envs->array[iSignal][iBin] = X2; + + } + + } + + } \ No newline at end of file diff --git a/src/system/freq2env.h b/src/system/freq2env.h new file mode 100644 index 0000000..49035e5 --- /dev/null +++ b/src/system/freq2env.h @@ -0,0 +1,21 @@ +#ifndef __ODAS_SYSTEM_FREQ2ENV +#define __ODAS_SYSTEM_FREQ2ENV + + #include + + #include "../signal/freq.h" + #include "../signal/env.h" + + typedef struct freq2env_obj { + + unsigned int halfFrameSize; + + } freq2env_obj; + + freq2env_obj * freq2env_construct_zero(const unsigned int halfFrameSize); + + void freq2env_destroy(freq2env_obj * obj); + + void freq2env_process(freq2env_obj * obj, const freqs_obj * freqs, envs_obj * envs); + +#endif \ No newline at end of file diff --git a/src/system/freq2frame.c b/src/system/freq2frame.c new file mode 100644 index 0000000..8898cad --- /dev/null +++ b/src/system/freq2frame.c @@ -0,0 +1,51 @@ + + #include "freq2frame.h" + + freq2frame_obj * freq2frame_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize) { + + freq2frame_obj * obj; + + obj = (freq2frame_obj *) malloc(sizeof(freq2frame_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = halfFrameSize; + + obj->win = windowing_roothann(frameSize); + obj->frame = (float *) malloc(sizeof(float) * frameSize); + memset(obj->frame, 0x00, sizeof(float) * frameSize); + obj->fft = fft_construct(frameSize); + + return obj; + + } + + void freq2frame_destroy(freq2frame_obj * obj) { + + window_destroy(obj->win); + free((void *) obj->frame); + fft_destroy(obj->fft); + + free((void *) obj); + + } + + void freq2frame_process(freq2frame_obj * obj, const freqs_obj * freqs, frames_obj * frames) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < frames->nSignals; iSignal++) { + + fft_c2r(obj->fft, + freqs->array[iSignal], + obj->frame); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + frames->array[iSignal][iSample] = obj->win->array[iSample] * obj->frame[iSample]; + + } + + } + + } \ No newline at end of file diff --git a/src/system/freq2frame.h b/src/system/freq2frame.h new file mode 100644 index 0000000..43981de --- /dev/null +++ b/src/system/freq2frame.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_SYSTEM_FREQ2FRAME +#define __ODAS_SYSTEM_FREQ2FRAME + + #include + + #include "../init/windowing.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/window.h" + #include "../utils/fft.h" + + typedef struct freq2frame_obj { + + unsigned int frameSize; + unsigned int halfFrameSize; + + window_obj * win; + float * frame; + + fft_obj * fft; + + } freq2frame_obj; + + freq2frame_obj * freq2frame_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize); + + void freq2frame_destroy(freq2frame_obj * obj); + + void freq2frame_process(freq2frame_obj * obj, const freqs_obj * freqs, frames_obj * frames); + +#endif \ No newline at end of file diff --git a/src/system/freq2freq.c b/src/system/freq2freq.c new file mode 100644 index 0000000..d018c57 --- /dev/null +++ b/src/system/freq2freq.c @@ -0,0 +1,256 @@ + + #include "freq2freq.h" + + freq2freq_phasor_obj * freq2freq_phasor_construct_zero(const unsigned int halfFrameSize, const float epsilon) { + + freq2freq_phasor_obj * obj; + + obj = (freq2freq_phasor_obj *) malloc(sizeof(freq2freq_phasor_obj)); + + obj->halfFrameSize = halfFrameSize; + obj->epsilon = epsilon; + + return obj; + + } + + void freq2freq_phasor_destroy(freq2freq_phasor_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_phasor_process(freq2freq_phasor_obj * obj, const freqs_obj * freqs, freqs_obj * phasors) { + + unsigned int iSignal, iSample; + float real, imag; + float magnitude; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + for (iSample = 0; iSample < freqs->halfFrameSize; iSample++) { + + real = freqs->array[iSignal][iSample * 2 + 0]; + imag = freqs->array[iSignal][iSample * 2 + 1]; + magnitude = sqrtf(real*real+imag*imag) + obj->epsilon; + + phasors->array[iSignal][iSample * 2 + 0] = real / magnitude; + phasors->array[iSignal][iSample * 2 + 1] = imag / magnitude; + + } + + } + + } + + freq2freq_weightedphasor_obj * freq2freq_weightedphasor_construct_zero(const unsigned int halfFrameSize, const float epsilon) { + + freq2freq_weightedphasor_obj * obj; + + obj = (freq2freq_weightedphasor_obj *) malloc(sizeof(freq2freq_weightedphasor_obj)); + + obj->halfFrameSize = halfFrameSize; + obj->epsilon = epsilon; + + return obj; + + } + + void freq2freq_weightedphasor_destroy(freq2freq_weightedphasor_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_weightedphasor_process(freq2freq_weightedphasor_obj * obj, const freqs_obj * freqs, const envs_obj * weights, freqs_obj * weightedphasors) { + + unsigned int iSignal, iSample; + float real, imag; + float magnitude; + float weight; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + for (iSample = 0; iSample < freqs->halfFrameSize; iSample++) { + + real = freqs->array[iSignal][iSample * 2 + 0]; + imag = freqs->array[iSignal][iSample * 2 + 1]; + magnitude = sqrtf(real*real+imag*imag) + obj->epsilon; + weight = weights->array[iSignal][iSample]; + + weightedphasors->array[iSignal][iSample * 2 + 0] = weight * real / magnitude; + weightedphasors->array[iSignal][iSample * 2 + 1] = weight * imag / magnitude; + + } + + } + + } + + freq2freq_product_obj * freq2freq_product_construct_zero(const unsigned int halfFrameSize) { + + freq2freq_product_obj * obj; + + obj = (freq2freq_product_obj *) malloc(sizeof(freq2freq_product_obj)); + + obj->halfFrameSize = halfFrameSize; + + return obj; + + } + + void freq2freq_product_destroy(freq2freq_product_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_product_process(freq2freq_product_obj * obj, const freqs_obj * freqs1, const freqs_obj * freqs2, const pairs_obj * pairs, freqs_obj * freqs12) { + + unsigned int iSignal1, iSignal2, iSignal12, iSample; + float real1, imag1; + float real2, imag2; + + iSignal12 = 0; + + for (iSignal1 = 0; iSignal1 < freqs1->nSignals; iSignal1++) { + + for (iSignal2 = (iSignal1+1); iSignal2 < freqs2->nSignals; iSignal2++) { + + if (pairs->array[iSignal12] == 0x01) { + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + real1 = freqs1->array[iSignal1][iSample * 2 + 0]; + imag1 = freqs1->array[iSignal1][iSample * 2 + 1]; + real2 = freqs2->array[iSignal2][iSample * 2 + 0]; + imag2 = freqs2->array[iSignal2][iSample * 2 + 1]; + + freqs12->array[iSignal12][iSample * 2 + 0] = real1 * real2 + imag1 * imag2; + freqs12->array[iSignal12][iSample * 2 + 1] = imag1 * real2 - imag2 * real1; + + } + + } + + iSignal12++; + + } + + } + + } + + freq2freq_lowpass_obj * freq2freq_lowpass_construct_zero(const unsigned int halfFrameSize, const unsigned int lowPassCut) { + + freq2freq_lowpass_obj * obj; + + obj = (freq2freq_lowpass_obj *) malloc(sizeof(freq2freq_lowpass_obj)); + + obj->halfFrameSize = halfFrameSize; + obj->lowPassCut = lowPassCut; + + return obj; + + } + + void freq2freq_lowpass_destroy(freq2freq_lowpass_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_lowpass_process(freq2freq_lowpass_obj * obj, const freqs_obj * freqsAllPass, freqs_obj * freqsLowPass) { + + unsigned int iSignal; + + freqs_zero(freqsLowPass); + + for (iSignal = 0; iSignal < freqsAllPass->nSignals; iSignal++) { + + memcpy(freqsLowPass->array[iSignal], freqsAllPass->array[iSignal], sizeof(float) * 2 * obj->lowPassCut); + + } + + } + + freq2freq_interpolate_obj * freq2freq_interpolate_construct_zero(const unsigned int halfFrameSize, const unsigned int halfFrameSizeInterp) { + + freq2freq_interpolate_obj * obj; + + obj = (freq2freq_interpolate_obj *) malloc(sizeof(freq2freq_interpolate_obj)); + + obj->halfFrameSize = halfFrameSize; + obj->halfFrameSizeInterp = halfFrameSizeInterp; + + return obj; + + } + + void freq2freq_interpolate_destroy(freq2freq_interpolate_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_interpolate_process(freq2freq_interpolate_obj * obj, const freqs_obj * freqs, const freqs_obj * freqsInterp) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + memset(freqsInterp->array[iSignal], 0x00, sizeof(float) * 2 * obj->halfFrameSizeInterp); + memcpy(freqsInterp->array[iSignal], freqs->array[iSignal], sizeof(float) * 2 * obj->halfFrameSize); + + } + + } + + freq2freq_gain_obj * freq2freq_gain_construct_zero(const unsigned int halfFrameSize) { + + freq2freq_gain_obj * obj; + + obj = (freq2freq_gain_obj *) malloc(sizeof(freq2freq_gain_obj)); + + obj->halfFrameSize = halfFrameSize; + + return obj; + + } + + void freq2freq_gain_destroy(freq2freq_gain_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_gain_process(freq2freq_gain_obj * obj, const freqs_obj * freqsIn, const envs_obj * envsIn, freqs_obj * freqsOut) { + + unsigned int iSignal; + unsigned int iSample; + + float xReal; + float xImag; + float g; + float yReal; + float yImag; + + for (iSignal = 0; iSignal < freqsIn->nSignals; iSignal++) { + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + xReal = freqsIn->array[iSignal][iSample*2+0]; + xImag = freqsIn->array[iSignal][iSample*2+1]; + g = envsIn->array[iSignal][iSample]; + + yReal = g * xReal; + yImag = g * xImag; + + freqsOut->array[iSignal][iSample*2+0] = yReal; + freqsOut->array[iSignal][iSample*2+1] = yImag; + + } + + } + + } diff --git a/src/system/freq2freq.h b/src/system/freq2freq.h new file mode 100644 index 0000000..101b342 --- /dev/null +++ b/src/system/freq2freq.h @@ -0,0 +1,88 @@ +#ifndef __ODAS_SYSTEM_FREQ2FREQ +#define __ODAS_SYSTEM_FREQ2FREQ + + #include + #include + + #include "../signal/freq.h" + #include "../signal/env.h" + #include "../signal/pair.h" + #include "../signal/track.h" + + typedef struct freq2freq_phasor_obj { + + unsigned int halfFrameSize; + float epsilon; + + } freq2freq_phasor_obj; + + typedef struct freq2freq_weightedphasor_obj { + + unsigned int halfFrameSize; + float epsilon; + + } freq2freq_weightedphasor_obj; + + typedef struct freq2freq_product_obj { + + unsigned int halfFrameSize; + + } freq2freq_product_obj; + + typedef struct freq2freq_lowpass_obj { + + unsigned int halfFrameSize; + unsigned int lowPassCut; + + } freq2freq_lowpass_obj; + + typedef struct freq2freq_interpolate_obj { + + unsigned halfFrameSize; + unsigned halfFrameSizeInterp; + + } freq2freq_interpolate_obj; + + typedef struct freq2freq_gain_obj { + + unsigned int halfFrameSize; + + } freq2freq_gain_obj; + + freq2freq_phasor_obj * freq2freq_phasor_construct_zero(const unsigned int halfFrameSize, const float epsilon); + + void freq2freq_phasor_destroy(freq2freq_phasor_obj * obj); + + void freq2freq_phasor_process(freq2freq_phasor_obj * obj, const freqs_obj * freqs, freqs_obj * phasors); + + freq2freq_weightedphasor_obj * freq2freq_weightedphasor_construct_zero(const unsigned int halfFrameSize, const float epsilon); + + void freq2freq_weightedphasor_destroy(freq2freq_weightedphasor_obj * obj); + + void freq2freq_weightedphasor_process(freq2freq_weightedphasor_obj * obj, const freqs_obj * freqs, const envs_obj * weights, freqs_obj * weightedphasors); + + freq2freq_product_obj * freq2freq_product_construct_zero(const unsigned int halfFrameSize); + + void freq2freq_product_destroy(freq2freq_product_obj * obj); + + void freq2freq_product_process(freq2freq_product_obj * obj, const freqs_obj * freqs1, const freqs_obj * freqs2, const pairs_obj * pairs, freqs_obj * freqs12); + + freq2freq_lowpass_obj * freq2freq_lowpass_construct_zero(const unsigned int halfFrameSize, const unsigned int lowPassCut); + + void freq2freq_lowpass_destroy(freq2freq_lowpass_obj * obj); + + void freq2freq_lowpass_process(freq2freq_lowpass_obj * obj, const freqs_obj * freqsAllPass, freqs_obj * freqsLowPass); + + freq2freq_interpolate_obj * freq2freq_interpolate_construct_zero(const unsigned int halfFrameSize, const unsigned int halfFrameSizeInterp); + + void freq2freq_interpolate_destroy(freq2freq_interpolate_obj * obj); + + void freq2freq_interpolate_process(freq2freq_interpolate_obj * obj, const freqs_obj * freqs, const freqs_obj * freqsInterp); + + freq2freq_gain_obj * freq2freq_gain_construct_zero(const unsigned int halfFrameSize); + + void freq2freq_gain_destroy(freq2freq_gain_obj * obj); + + void freq2freq_gain_process(freq2freq_gain_obj * obj, const freqs_obj * freqsIn, const envs_obj * envsIn, freqs_obj * freqsOut); + +#endif \ No newline at end of file diff --git a/src/system/freq2xcorr.c b/src/system/freq2xcorr.c new file mode 100644 index 0000000..84da9b2 --- /dev/null +++ b/src/system/freq2xcorr.c @@ -0,0 +1,53 @@ + + #include "freq2xcorr.h" + + freq2xcorr_obj * freq2xcorr_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize) { + + freq2xcorr_obj * obj; + + obj = (freq2xcorr_obj *) malloc(sizeof(freq2xcorr_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = halfFrameSize; + + obj->frame = (float *) malloc(sizeof(float) * halfFrameSize * 2); + memset(obj->frame,0x00,sizeof(float)* halfFrameSize * 2); + + obj->fft = fft_construct(frameSize); + + return obj; + + } + + void freq2xcorr_destroy(freq2xcorr_obj * obj) { + + fft_destroy(obj->fft); + free((void *) obj->frame); + + free((void *) obj); + + } + + void freq2xcorr_process(freq2xcorr_obj * obj, const freqs_obj * freqs, const pairs_obj * pairs, xcorrs_obj * xcorrs) { + + unsigned int iSignal; + unsigned int iSample; + unsigned int iSampleSrc; + unsigned int iSampleDest; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + if (pairs->array[iSignal] == 0x01) { + + fft_c2r(obj->fft, + freqs->array[iSignal], + obj->frame); + + memcpy(&(xcorrs->array[iSignal][0]),&(obj->frame[obj->frameSize/2]),(obj->frameSize/2)*sizeof(float)); + memcpy(&(xcorrs->array[iSignal][obj->frameSize/2]),&(obj->frame[0]),(obj->frameSize/2)*sizeof(float)); + + } + + } + + } \ No newline at end of file diff --git a/src/system/freq2xcorr.h b/src/system/freq2xcorr.h new file mode 100644 index 0000000..5f61f33 --- /dev/null +++ b/src/system/freq2xcorr.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SYSTEM_FREQ2XCORR +#define __ODAS_SYSTEM_FREQ2XCORR + + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/pair.h" + #include "../signal/tdoa.h" + #include "../signal/xcorr.h" + #include "../utils/fft.h" + + typedef struct freq2xcorr_obj { + + unsigned int frameSize; + unsigned int halfFrameSize; + + float * frame; + + fft_obj * fft; + + } freq2xcorr_obj; + + freq2xcorr_obj * freq2xcorr_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize); + + void freq2xcorr_destroy(freq2xcorr_obj * obj); + + void freq2xcorr_process(freq2xcorr_obj * obj, const freqs_obj * freqs, const pairs_obj * pairs, xcorrs_obj * xcorrs); + +#endif \ No newline at end of file diff --git a/src/system/gain2mask.c b/src/system/gain2mask.c new file mode 100644 index 0000000..1f7767c --- /dev/null +++ b/src/system/gain2mask.c @@ -0,0 +1,44 @@ + + #include "gain2mask.h" + + gain2mask_obj * gain2mask_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float gainMin) { + + gain2mask_obj * obj; + + obj = (gain2mask_obj *) malloc(sizeof(gain2mask_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->gainMin = gainMin; + + return obj; + + } + + void gain2mask_destroy(gain2mask_obj * obj) { + + free((void *) obj); + + } + + void gain2mask_process(gain2mask_obj * obj, const gains_obj * gains, masks_obj * masks) { + + unsigned int iSep; + unsigned int iChannel; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (gains->array[iSep * obj->nChannels + iChannel] >= obj->gainMin) { + masks->array[iSep * obj->nChannels + iChannel] = 0x01; + } + else { + masks->array[iSep * obj->nChannels + iChannel] = 0x00; + } + + } + + } + + } diff --git a/src/system/gain2mask.h b/src/system/gain2mask.h new file mode 100644 index 0000000..4ce68de --- /dev/null +++ b/src/system/gain2mask.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_SYSTEM_GAIN2MASK +#define __ODAS_SYSTEM_GAIN2MASK + + #include "../signal/gain.h" + #include "../signal/mask.h" + + #include + #include + + typedef struct gain2mask_obj { + + unsigned int nSeps; + unsigned int nChannels; + float gainMin; + + } gain2mask_obj; + + gain2mask_obj * gain2mask_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float gainMin); + + void gain2mask_destroy(gain2mask_obj * obj); + + void gain2mask_process(gain2mask_obj * obj, const gains_obj * gains, masks_obj * masks); + +#endif \ No newline at end of file diff --git a/src/system/hop2frame.c b/src/system/hop2frame.c new file mode 100644 index 0000000..60d7240 --- /dev/null +++ b/src/system/hop2frame.c @@ -0,0 +1,59 @@ + + #include "hop2frame.h" + + hop2frame_obj * hop2frame_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals) { + + hop2frame_obj * obj; + unsigned int iSignal; + + obj = (hop2frame_obj *) malloc(sizeof(hop2frame_obj)); + + obj->hopSize = hopSize; + obj->frameSize = frameSize; + obj->nSignals = nSignals; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array[iSignal], 0x00, sizeof(float) * frameSize); + } + + return obj; + + } + + void hop2frame_destroy(hop2frame_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + + free((void *) obj->array); + free((void *) obj); + + } + + void hop2frame_process(hop2frame_obj * obj, const hops_obj * hops, frames_obj * frames) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < hops->nSignals; iSignal++) { + + memmove(&(obj->array[iSignal][0]), + &(obj->array[iSignal][obj->hopSize]), + sizeof(float) * (obj->frameSize-obj->hopSize)); + + memcpy(&(obj->array[iSignal][(obj->frameSize-obj->hopSize)]), + &(hops->array[iSignal][0]), + sizeof(float) * obj->hopSize); + + memcpy(frames->array[iSignal], + obj->array[iSignal], + sizeof(float) * obj->frameSize); + + } + + } \ No newline at end of file diff --git a/src/system/hop2frame.h b/src/system/hop2frame.h new file mode 100644 index 0000000..f2edbd3 --- /dev/null +++ b/src/system/hop2frame.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SYSTEM_HOP2FRAME +#define __ODAS_SYSTEM_HOP2FRAME + + #include + #include + + #include "../signal/hop.h" + #include "../signal/frame.h" + + typedef struct hop2frame_obj { + + unsigned int hopSize; + unsigned int frameSize; + unsigned int nSignals; + + float ** array; + + } hop2frame_obj; + + hop2frame_obj * hop2frame_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals); + + void hop2frame_destroy(hop2frame_obj * obj); + + void hop2frame_process(hop2frame_obj * obj, const hops_obj * hops, frames_obj * frames); + +#endif \ No newline at end of file diff --git a/src/system/hop2hop.c b/src/system/hop2hop.c new file mode 100644 index 0000000..f4a3ba3 --- /dev/null +++ b/src/system/hop2hop.c @@ -0,0 +1,268 @@ + + #include "hop2hop.h" + + hop2hop_multiplex_obj * hop2hop_multiplex_construct_zero(const unsigned int hopSize) { + + hop2hop_multiplex_obj * obj; + + obj = (hop2hop_multiplex_obj *) malloc(sizeof(hop2hop_multiplex_obj)); + + obj->hopSize = hopSize; + + return obj; + + } + + void hop2hop_multiplex_destroy(hop2hop_multiplex_obj * obj) { + + free((void *) obj); + + } + + void hop2hop_multiplex_process(hop2hop_multiplex_obj * obj, const links_obj * links, const hops_obj * src, hops_obj * dest) { + + unsigned int iLink; + + for (iLink = 0; iLink < links->nLinks; iLink++) { + + if (links->array[iLink] == 0) { + + memset(dest->array[iLink], 0x00, sizeof(float) * obj->hopSize); + + } + else { + + memcpy(dest->array[iLink], src->array[links->array[iLink]-1], sizeof(float) * obj->hopSize); + + } + + } + + } + + hop2hop_buffer_obj * hop2hop_buffer_construct_zero(const unsigned int nSignals, const unsigned int hopSizeIn, const unsigned int hopSizeOut, const float ratio) { + + hop2hop_buffer_obj * obj; + unsigned int iSignal; + + obj = (hop2hop_buffer_obj *) malloc(sizeof(hop2hop_buffer_obj)); + + obj->nSignals = nSignals; + obj->hopSizeIn = hopSizeIn; + obj->hopSizeOut = hopSizeOut; + obj->intervalIn = (float) hopSizeIn; + obj->intervalOut = ((float) hopSizeOut) / ratio; + obj->intervalSize = 0.0f; + obj->ratio = ratio; + obj->delta = 1.0f / ratio; + + if (obj->intervalIn >= obj->intervalOut) { + + obj->bufferSize = (unsigned int) ceilf(2.0f * obj->intervalIn); + + } + else { + + obj->bufferSize = (unsigned int) ceilf(2.0f * obj->intervalOut); + + } + + obj->iRead = 0.0f; + obj->iWrite = 0.0f; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + obj->array[iSignal] = (float *) malloc(sizeof(float) * obj->bufferSize); + memset(obj->array[iSignal], 0x00, sizeof(float) * obj->bufferSize); + + } + + return obj; + + } + + void hop2hop_buffer_destroy(hop2hop_buffer_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + + free((void *) obj->array); + free((void *) obj); + + } + + void hop2hop_buffer_push(hop2hop_buffer_obj * obj, const hops_obj * hops) { + + unsigned int iWriteInt; + + unsigned int iHop1; + unsigned int iBuffer1; + unsigned int nSamples1; + unsigned int iHop2; + unsigned int iBuffer2; + unsigned int nSamples2; + + unsigned int iSignal; + + if ((obj->intervalSize + obj->intervalIn) <= ((float) obj->bufferSize)) { + + iWriteInt = (unsigned int) obj->iWrite; + + if ((obj->iWrite + obj->intervalIn) <= ((float) obj->bufferSize)) { + + iHop1 = 0; + iBuffer1 = iWriteInt; + nSamples1 = (unsigned int) obj->intervalIn; + + iHop2 = 0; + iBuffer2 = 0; + nSamples2 = 0; + + } + else { + + iHop1 = 0; + iBuffer1 = iWriteInt; + nSamples1 = (obj->bufferSize - iWriteInt); + + iHop2 = (obj->bufferSize - iWriteInt); + iBuffer2 = 0; + nSamples2 = obj->intervalIn - (obj->bufferSize - iWriteInt); + + } + + for (iSignal = 0; iSignal < hops->nSignals; iSignal++) { + + memcpy(&(obj->array[iSignal][iBuffer1]), + &(hops->array[iSignal][iHop1]), + nSamples1 * sizeof(float)); + + memcpy(&(obj->array[iSignal][iBuffer2]), + &(hops->array[iSignal][iHop2]), + nSamples2 * sizeof(float)); + + } + + obj->intervalSize += (float) obj->intervalIn; + + obj->iWrite += (float) obj->intervalIn; + obj->iWrite = fmod(obj->iWrite, (float) obj->bufferSize); + + } + + } + + void hop2hop_buffer_pop(hop2hop_buffer_obj * obj, hops_obj * hops) { + + unsigned int iSample; + unsigned int iReadFloor; + unsigned int iReadCeil; + float yFloor; + float yCeil; + float yDelta; + float xDelta; + + unsigned int iSignal; + + if (obj->intervalOut <= obj->intervalSize) { + + for (iSample = 0; iSample < obj->hopSizeOut; iSample++) { + + iReadFloor = (unsigned int) floorf(obj->iRead); + iReadCeil = (iReadFloor + 1) % obj->bufferSize; + + xDelta = obj->iRead - floorf(obj->iRead); + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + yFloor = obj->array[iSignal][iReadFloor]; + yCeil = obj->array[iSignal][iReadCeil]; + yDelta = yCeil - yFloor; + + hops->array[iSignal][iSample] = xDelta * yDelta + yFloor; + + } + + obj->iRead += obj->delta; + obj->iRead = fmod(obj->iRead, (float) obj->bufferSize); + + } + + obj->intervalSize -= (float) obj->intervalOut; + + } + + } + + char hop2hop_buffer_isFull(hop2hop_buffer_obj * obj) { + + char rtnValue; + + rtnValue = 0; + + if ((obj->intervalSize + obj->intervalIn) > ((float) obj->bufferSize)) { + + rtnValue = 1; + + } + + return rtnValue; + + } + + char hop2hop_buffer_isEmpty(hop2hop_buffer_obj * obj) { + + char rtnValue; + + rtnValue = 0; + + if (obj->intervalOut > obj->intervalSize) { + + rtnValue = 1; + + } + + return rtnValue; + + } + + hop2hop_gain_obj * hop2hop_gain_construct_zero(const unsigned int hopSize, const float gain) { + + hop2hop_gain_obj * obj; + + obj = (hop2hop_gain_obj *) malloc(sizeof(hop2hop_gain_obj)); + + obj->hopSize = hopSize; + obj->gain = gain; + + return obj; + + } + + void hop2hop_gain_destroy(hop2hop_gain_obj * obj) { + + free((void *) obj); + + } + + void hop2hop_gain_process(hop2hop_gain_obj * obj, const hops_obj * src, hops_obj * dest) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < src->nSignals; iSignal++) { + + for (iSample = 0; iSample < src->hopSize; iSample++) { + + dest->array[iSignal][iSample] = obj->gain * src->array[iSignal][iSample]; + + } + + } + + } \ No newline at end of file diff --git a/src/system/hop2hop.h b/src/system/hop2hop.h new file mode 100644 index 0000000..78ab649 --- /dev/null +++ b/src/system/hop2hop.h @@ -0,0 +1,67 @@ +#ifndef __ODAS_SYSTEM_HOP2HOP +#define __ODAS_SYSTEM_HOP2HOP + + #include + #include + #include + + #include "../signal/hop.h" + #include "../general/link.h" + + typedef struct hop2hop_multiplex_obj { + + unsigned int hopSize; + + } hop2hop_multiplex_obj; + + typedef struct hop2hop_buffer_obj { + + unsigned int nSignals; + unsigned int hopSizeIn; + unsigned int hopSizeOut; + float intervalIn; + float intervalOut; + float intervalSize; + unsigned int bufferSize; + float ratio; + float delta; + + float iWrite; + float iRead; + + float ** array; + + } hop2hop_buffer_obj; + + typedef struct hop2hop_gain_obj { + + unsigned int hopSize; + float gain; + + } hop2hop_gain_obj; + + hop2hop_multiplex_obj * hop2hop_multiplex_construct_zero(const unsigned int hopSize); + + void hop2hop_multiplex_destroy(hop2hop_multiplex_obj * obj); + + void hop2hop_multiplex_process(hop2hop_multiplex_obj * obj, const links_obj * links, const hops_obj * src, hops_obj * dest); + + hop2hop_buffer_obj * hop2hop_buffer_construct_zero(const unsigned int nSignals, const unsigned int hopSizeIn, const unsigned int hopSizeOut, const float ratio); + + void hop2hop_buffer_destroy(hop2hop_buffer_obj * obj); + + void hop2hop_buffer_push(hop2hop_buffer_obj * obj, const hops_obj * hops); + + void hop2hop_buffer_pop(hop2hop_buffer_obj * obj, hops_obj * hops); + + char hop2hop_buffer_isFull(hop2hop_buffer_obj * obj); + + char hop2hop_buffer_isEmpty(hop2hop_buffer_obj * obj); + + hop2hop_gain_obj * hop2hop_gain_construct_zero(const unsigned int hopSize, const float gain); + + void hop2hop_gain_destroy(hop2hop_gain_obj * obj); + + void hop2hop_gain_process(hop2hop_gain_obj * obj, const hops_obj * src, hops_obj * dest); + +#endif \ No newline at end of file diff --git a/src/system/kalman2coherence.c b/src/system/kalman2coherence.c new file mode 100644 index 0000000..26796ff --- /dev/null +++ b/src/system/kalman2coherence.c @@ -0,0 +1,171 @@ + + #include "kalman2coherence.h" + + kalman2coherence_obj * kalman2coherence_construct(const float epsilon, const float sigmaR) { + + kalman2coherence_obj * obj; + + obj = (kalman2coherence_obj *) malloc(sizeof(kalman2coherence_obj)); + + obj->epsilon = epsilon; + + obj->H = matrix_construct_zero(3,6); + obj->H->array[0*obj->H->nCols+0] = 1.0f; + obj->H->array[1*obj->H->nCols+1] = 1.0f; + obj->H->array[2*obj->H->nCols+2] = 1.0f; + + obj->Ht = matrix_construct_zero(6,3); + obj->Ht->array[0*obj->Ht->nCols+0] = 1.0f; + obj->Ht->array[1*obj->Ht->nCols+1] = 1.0f; + obj->Ht->array[2*obj->Ht->nCols+2] = 1.0f; + + obj->mu_t = matrix_construct_zero(3,1); + obj->mu_t_t = matrix_construct_zero(1,3); + obj->mu_s = matrix_construct_zero(3,1); + obj->mu_s_t = matrix_construct_zero(1,3); + obj->mu_st = matrix_construct_zero(3,1); + obj->mu_st_t = matrix_construct_zero(1,3); + + obj->HP = matrix_construct_zero(3,6); + obj->sigma_epsilon = matrix_construct_zero(3,3); + + obj->sigma_t = matrix_construct_zero(3,3); + obj->sigma_s = matrix_construct_zero(3,3); + obj->sigma_st = matrix_construct_zero(3,3); + + obj->sigma_t_epsilon = matrix_construct_zero(3,3); + obj->sigma_t_inv = matrix_construct_zero(3,3); + obj->sigma_s_inv = matrix_construct_zero(3,3); + obj->sigma_st_inv = matrix_construct_zero(3,3); + + obj->sigma_t_inv_mu_t = matrix_construct_zero(3,1); + obj->sigma_s_inv_mu_s = matrix_construct_zero(3,1); + obj->sigma_st_inv_mu_st = matrix_construct_zero(3,1); + + obj->mu_t_t_sigma_t_inv_mu_t = matrix_construct_zero(1,1); + obj->mu_s_t_sigma_s_inv_mu_s = matrix_construct_zero(1,1); + obj->mu_st_t_sigma_st_inv_mu_st = matrix_construct_zero(1,1); + + obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s = matrix_construct_zero(3,1); + + obj->sigma_s->array[0*obj->sigma_s->nCols+0] = sigmaR*sigmaR; + obj->sigma_s->array[1*obj->sigma_s->nCols+1] = sigmaR*sigmaR; + obj->sigma_s->array[2*obj->sigma_s->nCols+2] = sigmaR*sigmaR; + + obj->sigma_epsilon->array[0*obj->sigma_epsilon->nCols+0] = epsilon; + obj->sigma_epsilon->array[1*obj->sigma_epsilon->nCols+1] = epsilon; + obj->sigma_epsilon->array[2*obj->sigma_epsilon->nCols+2] = epsilon; + + matrix_inv(obj->sigma_s_inv, obj->sigma_s); + + return obj; + + } + + void kalman2coherence_destroy(kalman2coherence_obj * obj) { + + matrix_destroy(obj->H); + matrix_destroy(obj->Ht); + + matrix_destroy(obj->mu_t); + matrix_destroy(obj->mu_t_t); + matrix_destroy(obj->mu_s); + matrix_destroy(obj->mu_s_t); + matrix_destroy(obj->mu_st); + matrix_destroy(obj->mu_st_t); + + matrix_destroy(obj->HP); + matrix_destroy(obj->sigma_epsilon); + + matrix_destroy(obj->sigma_t); + matrix_destroy(obj->sigma_s); + matrix_destroy(obj->sigma_st); + + matrix_destroy(obj->sigma_t_epsilon); + matrix_destroy(obj->sigma_t_inv); + matrix_destroy(obj->sigma_s_inv); + matrix_destroy(obj->sigma_st_inv); + + matrix_destroy(obj->sigma_t_inv_mu_t); + matrix_destroy(obj->sigma_s_inv_mu_s); + matrix_destroy(obj->sigma_st_inv_mu_st); + + matrix_destroy(obj->mu_t_t_sigma_t_inv_mu_t); + matrix_destroy(obj->mu_s_t_sigma_s_inv_mu_s); + matrix_destroy(obj->mu_st_t_sigma_st_inv_mu_st); + + matrix_destroy(obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s); + + free((void *) obj); + + } + + void kalman2coherence_process(kalman2coherence_obj * obj, const kalman_obj * kalman, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences) { + + unsigned int iPot; + float B1, B2, B3, B4; + float weight; + + // Compute mu_t + matrix_mul(obj->mu_t, obj->H, kalman->x_llm1); + matrix_transpose(obj->mu_t_t, obj->mu_t); + + // Compute sigma_t + matrix_mul(obj->HP, obj->H, kalman->P_llm1); + matrix_mul(obj->sigma_t, obj->HP, obj->Ht); + matrix_add(obj->sigma_t_epsilon, obj->sigma_t, obj->sigma_epsilon); + + // Compute sigma_t^-1 + matrix_inv(obj->sigma_t_inv, obj->sigma_t_epsilon); + + // Compute sigma_t^-1 * mu_t + matrix_mul(obj->sigma_t_inv_mu_t, obj->sigma_t_inv, obj->mu_t); + + // Compute B3 + matrix_mul(obj->mu_t_t_sigma_t_inv_mu_t, obj->mu_t_t, obj->sigma_t_inv_mu_t); + B3 = obj->mu_t_t_sigma_t_inv_mu_t->array[0*(obj->mu_t_t_sigma_t_inv_mu_t->nCols)+0]; + + for (iPot = 0; iPot < pots->nPots; iPot++) { + + // Compute mu_s + obj->mu_s->array[0*(obj->mu_s->nCols)+0] = pots->array[iPot*4+0]; + obj->mu_s->array[1*(obj->mu_s->nCols)+0] = pots->array[iPot*4+1]; + obj->mu_s->array[2*(obj->mu_s->nCols)+0] = pots->array[iPot*4+2]; + matrix_transpose(obj->mu_s_t, obj->mu_s); + + // Compute sigma_st^-1 + matrix_add(obj->sigma_st_inv, obj->sigma_s_inv, obj->sigma_t_inv); + + // Compute sigma_st + matrix_inv(obj->sigma_st, obj->sigma_st_inv); + + // Compute sigma_s^-1 * mu_s + matrix_mul(obj->sigma_s_inv_mu_s, obj->sigma_s_inv, obj->mu_s); + + // Compute (sigma_t^-1 * mu_t + sigma_s^-1 * mu_s) + matrix_add(obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s, obj->sigma_t_inv_mu_t, obj->sigma_s_inv_mu_s); + + // Compute mu_st = sigma_st * (sigma_t^-1 * mu_t + sigma_s^-1 * mu_s) + matrix_mul(obj->mu_st, obj->sigma_st, obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s); + matrix_transpose(obj->mu_st_t, obj->mu_st); + + // Compute B1 + B1 = logf(matrix_det(obj->sigma_st)) - logf(8.0f * M_PI * M_PI * M_PI * matrix_det(obj->sigma_t) * matrix_det(obj->sigma_s)); + + // Compute B2 + matrix_mul(obj->sigma_st_inv_mu_st, obj->sigma_st_inv, obj->mu_st); + matrix_mul(obj->mu_st_t_sigma_st_inv_mu_st, obj->mu_st_t, obj->sigma_st_inv_mu_st); + B2 = obj->mu_st_t_sigma_st_inv_mu_st->array[0*(obj->mu_st_t_sigma_st_inv_mu_st->nCols)+0]; + + // Compute B4 + matrix_mul(obj->mu_s_t_sigma_s_inv_mu_s, obj->mu_s_t, obj->sigma_s_inv_mu_s); + B4 = obj->mu_s_t_sigma_s_inv_mu_s->array[0*(obj->mu_s_t_sigma_s_inv_mu_s->nCols)+0]; + + // Compute weight + weight = expf(0.5f * (B1+B2-B3-B4)); + + coherences->array[iTrack * pots->nPots + iPot] = weight; + + } + + } \ No newline at end of file diff --git a/src/system/kalman2coherence.h b/src/system/kalman2coherence.h new file mode 100644 index 0000000..0aac38c --- /dev/null +++ b/src/system/kalman2coherence.h @@ -0,0 +1,57 @@ +#ifndef __ODAS_SYSTEM_KALMAN2PRIOR +#define __ODAS_SYSTEM_KALMAN2PRIOR + + #include + #include + + #include "../signal/coherence.h" + #include "../signal/kalman.h" + #include "../signal/pot.h" + #include "../utils/matrix.h" + + typedef struct kalman2coherence_obj { + + float epsilon; + + matrix_obj * H; + matrix_obj * Ht; + + matrix_obj * mu_t; + matrix_obj * mu_t_t; + matrix_obj * mu_s; + matrix_obj * mu_s_t; + matrix_obj * mu_st; + matrix_obj * mu_st_t; + + matrix_obj * HP; + matrix_obj * sigma_epsilon; + + matrix_obj * sigma_t; + matrix_obj * sigma_s; + matrix_obj * sigma_st; + + matrix_obj * sigma_t_epsilon; + matrix_obj * sigma_t_inv; + matrix_obj * sigma_s_inv; + matrix_obj * sigma_st_inv; + + matrix_obj * sigma_t_inv_mu_t; + matrix_obj * sigma_s_inv_mu_s; + matrix_obj * sigma_st_inv_mu_st; + + matrix_obj * mu_t_t_sigma_t_inv_mu_t; + matrix_obj * mu_s_t_sigma_s_inv_mu_s; + matrix_obj * mu_st_t_sigma_st_inv_mu_st; + + matrix_obj * sigma_t_inv_mu_t_sigma_s_inv_mu_s; + + } kalman2coherence_obj; + + kalman2coherence_obj * kalman2coherence_construct(const float epsilon, const float sigmaR); + + void kalman2coherence_destroy(kalman2coherence_obj * obj); + + void kalman2coherence_process(kalman2coherence_obj * obj, const kalman_obj * kalman, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences); + + +#endif \ No newline at end of file diff --git a/src/system/kalman2kalman.c b/src/system/kalman2kalman.c new file mode 100644 index 0000000..e470f55 --- /dev/null +++ b/src/system/kalman2kalman.c @@ -0,0 +1,249 @@ + + #include "kalman2kalman.h" + + kalman2kalman_obj * kalman2kalman_construct(const float deltaT, const float sigmaQ, const float sigmaR, const float epsilon) { + + kalman2kalman_obj * obj; + + obj = (kalman2kalman_obj *) malloc(sizeof(kalman2kalman_obj)); + + obj->deltaT = deltaT; + obj->sigmaQ = sigmaQ; + obj->sigmaR = sigmaR; + obj->epsilon = epsilon; + + obj->F = matrix_construct_zero(6,6); + obj->Ft = matrix_construct_zero(6,6); + obj->Q = matrix_construct_zero(6,6); + obj->H = matrix_construct_zero(3,6); + obj->Ht = matrix_construct_zero(6,3); + obj->R = matrix_construct_zero(3,3); + + obj->F->array[0*(obj->F->nCols)+0] = 1.0f; + obj->F->array[0*(obj->F->nCols)+3] = deltaT; + obj->F->array[1*(obj->F->nCols)+1] = 1.0f; + obj->F->array[1*(obj->F->nCols)+4] = deltaT; + obj->F->array[2*(obj->F->nCols)+2] = 1.0f; + obj->F->array[2*(obj->F->nCols)+5] = deltaT; + obj->F->array[3*(obj->F->nCols)+3] = 1.0f; + obj->F->array[4*(obj->F->nCols)+4] = 1.0f; + obj->F->array[5*(obj->F->nCols)+5] = 1.0f; + + obj->Ft->array[0*(obj->Ft->nCols)+0] = 1.0f; + obj->Ft->array[3*(obj->Ft->nCols)+0] = deltaT; + obj->Ft->array[1*(obj->Ft->nCols)+1] = 1.0f; + obj->Ft->array[4*(obj->Ft->nCols)+1] = deltaT; + obj->Ft->array[2*(obj->Ft->nCols)+2] = 1.0f; + obj->Ft->array[5*(obj->Ft->nCols)+2] = deltaT; + obj->Ft->array[3*(obj->Ft->nCols)+3] = 1.0f; + obj->Ft->array[4*(obj->Ft->nCols)+4] = 1.0f; + obj->Ft->array[5*(obj->Ft->nCols)+5] = 1.0f; + + obj->Q->array[3*(obj->Q->nCols)+3] = sigmaQ*sigmaQ; + obj->Q->array[4*(obj->Q->nCols)+4] = sigmaQ*sigmaQ; + obj->Q->array[5*(obj->Q->nCols)+5] = sigmaQ*sigmaQ; + + obj->H->array[0*(obj->H->nCols)+0] = 1.0f; + obj->H->array[1*(obj->H->nCols)+1] = 1.0f; + obj->H->array[2*(obj->H->nCols)+2] = 1.0f; + + obj->Ht->array[0*(obj->Ht->nCols)+0] = 1.0f; + obj->Ht->array[1*(obj->Ht->nCols)+1] = 1.0f; + obj->Ht->array[2*(obj->Ht->nCols)+2] = 1.0f; + + obj->R->array[0*(obj->R->nCols)+0] = sigmaR*sigmaR; + obj->R->array[1*(obj->R->nCols)+1] = sigmaR*sigmaR; + obj->R->array[2*(obj->R->nCols)+2] = sigmaR*sigmaR; + + obj->FP = matrix_construct_zero(6,6); + obj->FPFt = matrix_construct_zero(6,6); + + obj->K = matrix_construct_zero(6,3); + obj->PHt = matrix_construct_zero(6,3); + obj->HP = matrix_construct_zero(3,6); + obj->HPHt = matrix_construct_zero(3,3); + obj->HPHt_R = matrix_construct_zero(3,3); + obj->HPHt_Rinv = matrix_construct_zero(3,3); + obj->Hx = matrix_construct_zero(3,1); + obj->z = matrix_construct_zero(3,1); + obj->z_Hx = matrix_construct_zero(3,1); + obj->Kz_Hx = matrix_construct_zero(6,1); + obj->pKz_Hx = matrix_construct_zero(6,1); + obj->KHP = matrix_construct_zero(6,6); + obj->pKHP = matrix_construct_zero(6,6); + + return obj; + + } + + void kalman2kalman_destroy(kalman2kalman_obj * obj) { + + matrix_destroy(obj->F); + matrix_destroy(obj->Ft); + matrix_destroy(obj->Q); + matrix_destroy(obj->H); + matrix_destroy(obj->Ht); + matrix_destroy(obj->R); + + matrix_destroy(obj->FP); + matrix_destroy(obj->FPFt); + + matrix_destroy(obj->K); + matrix_destroy(obj->PHt); + matrix_destroy(obj->HP); + matrix_destroy(obj->HPHt); + matrix_destroy(obj->HPHt_R); + matrix_destroy(obj->HPHt_Rinv); + matrix_destroy(obj->Hx); + matrix_destroy(obj->z); + matrix_destroy(obj->z_Hx); + matrix_destroy(obj->Kz_Hx); + matrix_destroy(obj->pKz_Hx); + matrix_destroy(obj->KHP); + matrix_destroy(obj->pKHP); + + free((void *) obj); + + } + + void kalman2kalman_init_pots(kalman2kalman_obj * obj, const pots_obj * pots, const unsigned int iPot, kalman_obj * kalman) { + + matrix_copy_zero(kalman->x_llm1); + matrix_copy_zero(kalman->x_lm1lm1); + matrix_copy_zero(kalman->P_llm1); + matrix_copy_zero(kalman->P_lm1lm1); + + kalman->P_lm1lm1->array[0*(kalman->P_lm1lm1->nCols)+0] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[1*(kalman->P_lm1lm1->nCols)+1] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[2*(kalman->P_lm1lm1->nCols)+2] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[3*(kalman->P_lm1lm1->nCols)+3] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[4*(kalman->P_lm1lm1->nCols)+4] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[5*(kalman->P_lm1lm1->nCols)+5] = obj->sigmaQ * obj->sigmaQ; + + kalman->x_lm1lm1->array[0*(kalman->x_lm1lm1->nCols)+0] = pots->array[iPot * 4 + 0]; + kalman->x_lm1lm1->array[1*(kalman->x_lm1lm1->nCols)+0] = pots->array[iPot * 4 + 1]; + kalman->x_lm1lm1->array[2*(kalman->x_lm1lm1->nCols)+0] = pots->array[iPot * 4 + 2]; + + } + + void kalman2kalman_init_targets(kalman2kalman_obj * obj, const targets_obj * targets, const unsigned int iTarget, kalman_obj * kalman) { + + matrix_copy_zero(kalman->x_llm1); + matrix_copy_zero(kalman->x_lm1lm1); + matrix_copy_zero(kalman->P_llm1); + matrix_copy_zero(kalman->P_lm1lm1); + + kalman->P_lm1lm1->array[0*(kalman->P_lm1lm1->nCols)+0] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[1*(kalman->P_lm1lm1->nCols)+1] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[2*(kalman->P_lm1lm1->nCols)+2] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[3*(kalman->P_lm1lm1->nCols)+3] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[4*(kalman->P_lm1lm1->nCols)+4] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[5*(kalman->P_lm1lm1->nCols)+5] = obj->sigmaQ * obj->sigmaQ; + + kalman->x_lm1lm1->array[0*(kalman->x_lm1lm1->nCols)+0] = targets->array[iTarget * 3 + 0]; + kalman->x_lm1lm1->array[1*(kalman->x_lm1lm1->nCols)+0] = targets->array[iTarget * 3 + 1]; + kalman->x_lm1lm1->array[2*(kalman->x_lm1lm1->nCols)+0] = targets->array[iTarget * 3 + 2]; + + } + + void kalman2kalman_predict(kalman2kalman_obj * obj, kalman_obj * kalman) { + + float xx, xy, xz; + float vx, vy, vz; + float norm, norm2, proj; + + matrix_mul(kalman->x_llm1, obj->F, kalman->x_lm1lm1); + matrix_mul(obj->FP, obj->F, kalman->P_lm1lm1); + matrix_mul(obj->FPFt, obj->FP, obj->Ft); + matrix_add(kalman->P_llm1, obj->FPFt, obj->Q); + + xx = kalman->x_llm1->array[0*(kalman->x_llm1->nCols)+0]; + xy = kalman->x_llm1->array[1*(kalman->x_llm1->nCols)+0]; + xz = kalman->x_llm1->array[2*(kalman->x_llm1->nCols)+0]; + vx = kalman->x_llm1->array[3*(kalman->x_llm1->nCols)+0]; + vy = kalman->x_llm1->array[4*(kalman->x_llm1->nCols)+0]; + vz = kalman->x_llm1->array[5*(kalman->x_llm1->nCols)+0]; + + norm2 = xx*xx + xy*xy + xz*xz; + norm = sqrtf(norm2); + proj = xx*vx + xy*vy + xz*vz; + + kalman->x_llm1->array[0*(kalman->x_llm1->nCols)+0] = xx / (norm + obj->epsilon); + kalman->x_llm1->array[1*(kalman->x_llm1->nCols)+0] = xy / (norm + obj->epsilon); + kalman->x_llm1->array[2*(kalman->x_llm1->nCols)+0] = xz / (norm + obj->epsilon); + kalman->x_llm1->array[3*(kalman->x_llm1->nCols)+0] = vx - xx * proj / (norm2 + obj->epsilon); + kalman->x_llm1->array[4*(kalman->x_llm1->nCols)+0] = vy - xy * proj / (norm2 + obj->epsilon); + kalman->x_llm1->array[5*(kalman->x_llm1->nCols)+0] = vz - xz * proj / (norm2 + obj->epsilon); + + } + + void kalman2kalman_predict_static(kalman2kalman_obj * obj, kalman_obj * kalman) { + + matrix_copy_matrix(kalman->x_llm1, kalman->x_lm1lm1); + matrix_copy_matrix(kalman->P_llm1, kalman->P_lm1lm1); + + } + + void kalman2kalman_update(kalman2kalman_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, kalman_obj * kalman) { + + unsigned int iPot; + float maxValue; + unsigned int maxIndex; + float updateFactor; + + // Find potential source with max prob + + maxValue = postprobs->arrayTrack[iTrack * postprobs->nPots]; + maxIndex = 0; + + for (iPot = 1; iPot < postprobs->nPots; iPot++) { + + if (maxValue < postprobs->arrayTrack[iTrack * postprobs->nPots + iPot]) { + maxValue = postprobs->arrayTrack[iTrack * postprobs->nPots + iPot]; + maxIndex = iPot; + } + + } + + obj->z->array[0*(obj->z->nCols)+0] = pots->array[maxIndex * 4 + 0]; + obj->z->array[1*(obj->z->nCols)+0] = pots->array[maxIndex * 4 + 1]; + obj->z->array[2*(obj->z->nCols)+0] = pots->array[maxIndex * 4 + 2]; + + // Compute K + matrix_mul(obj->HP, obj->H, kalman->P_llm1); + matrix_mul(obj->HPHt, obj->HP, obj->Ht); + matrix_add(obj->HPHt_R, obj->HPHt, obj->R); + matrix_inv(obj->HPHt_Rinv, obj->HPHt_R); + matrix_mul(obj->PHt, kalman->P_llm1, obj->Ht); + matrix_mul(obj->K, obj->PHt, obj->HPHt_Rinv); + + updateFactor = postprobs->arrayTrackTotal[iTrack]; + + // Update x + matrix_mul(obj->Hx, obj->H, kalman->x_llm1); + matrix_sub(obj->z_Hx, obj->z, obj->Hx); + matrix_mul(obj->Kz_Hx, obj->K, obj->z_Hx); + matrix_scale(obj->pKz_Hx, obj->Kz_Hx, updateFactor); + matrix_add(kalman->x_lm1lm1, kalman->x_llm1, obj->pKz_Hx); + + // Update P + matrix_mul(obj->KHP, obj->K, obj->HP); + matrix_scale(obj->pKHP, obj->KHP, updateFactor); + matrix_sub(kalman->P_lm1lm1, kalman->P_llm1, obj->pKHP); + + } + + void kalman2kalman_update_static(kalman2kalman_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, kalman_obj * kalman) { + + matrix_copy_matrix(kalman->x_lm1lm1, kalman->x_llm1); + matrix_copy_matrix(kalman->P_lm1lm1, kalman->P_llm1); + + } + + void kalman2kalman_estimate(kalman2kalman_obj * obj, const kalman_obj * kalman, float * x, float * y, float * z) { + + *x = kalman->x_lm1lm1->array[0*(kalman->x_lm1lm1->nCols)+0]; + *y = kalman->x_lm1lm1->array[1*(kalman->x_lm1lm1->nCols)+0]; + *z = kalman->x_lm1lm1->array[2*(kalman->x_lm1lm1->nCols)+0]; + + } \ No newline at end of file diff --git a/src/system/kalman2kalman.h b/src/system/kalman2kalman.h new file mode 100644 index 0000000..7fd9717 --- /dev/null +++ b/src/system/kalman2kalman.h @@ -0,0 +1,66 @@ +#ifndef __ODAS_SYSTEM_KALMAN2KALMAN +#define __ODAS_SYSTEM_KALMAN2KALMAN + + #include + #include + #include + + #include "../signal/postprob.h" + #include "../signal/kalman.h" + #include "../signal/pot.h" + #include "../signal/target.h" + #include "../utils/matrix.h" + + typedef struct kalman2kalman_obj { + + float epsilon; + + float deltaT; + float sigmaQ; + float sigmaR; + + matrix_obj * F; + matrix_obj * Ft; + matrix_obj * Q; + matrix_obj * H; + matrix_obj * Ht; + matrix_obj * R; + + matrix_obj * FP; + matrix_obj * FPFt; + + matrix_obj * K; + matrix_obj * PHt; + matrix_obj * HP; + matrix_obj * HPHt; + matrix_obj * HPHt_R; + matrix_obj * HPHt_Rinv; + matrix_obj * Hx; + matrix_obj * z; + matrix_obj * z_Hx; + matrix_obj * Kz_Hx; + matrix_obj * pKz_Hx; + matrix_obj * KHP; + matrix_obj * pKHP; + + } kalman2kalman_obj; + + kalman2kalman_obj * kalman2kalman_construct(const float deltaT, const float sigmaQ, const float sigmaR, const float epsilon); + + void kalman2kalman_destroy(kalman2kalman_obj * obj); + + void kalman2kalman_init_pots(kalman2kalman_obj * obj, const pots_obj * pots, const unsigned int iPot, kalman_obj * kalman); + + void kalman2kalman_init_targets(kalman2kalman_obj * obj, const targets_obj * targets, const unsigned int iTarget, kalman_obj * kalman); + + void kalman2kalman_predict(kalman2kalman_obj * obj, kalman_obj * kalman); + + void kalman2kalman_predict_static(kalman2kalman_obj * obj, kalman_obj * kalman); + + void kalman2kalman_update(kalman2kalman_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, kalman_obj * kalman); + + void kalman2kalman_update_static(kalman2kalman_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, kalman_obj * kalman); + + void kalman2kalman_estimate(kalman2kalman_obj * obj, const kalman_obj * kalman, float * x, float * y, float * z); + +#endif \ No newline at end of file diff --git a/src/system/mixture2mixture.c b/src/system/mixture2mixture.c new file mode 100644 index 0000000..0c86710 --- /dev/null +++ b/src/system/mixture2mixture.c @@ -0,0 +1,230 @@ + + #include "mixture2mixture.h" + + mixture2mixture_obj * mixture2mixture_construct(const gaussians_1d_obj * active_gmm, const gaussians_1d_obj * inactive_gmm, const float diffuse_cst, const float Pfalse, const float Pnew, const float Ptrack, const float epsilon) { + + mixture2mixture_obj * obj; + + obj = (mixture2mixture_obj *) malloc(sizeof(mixture2mixture_obj)); + + obj->active = gaussians_1d_construct_gaussians(active_gmm); + obj->inactive = gaussians_1d_construct_gaussians(inactive_gmm); + obj->diffuse = diffuse_cst; + + obj->Pfalse = Pfalse; + obj->Pnew = Pnew; + obj->Ptrack = Ptrack; + obj->epsilon = epsilon; + + return obj; + + } + + void mixture2mixture_destroy(mixture2mixture_obj * obj) { + + gaussians_1d_destroy(obj->active); + gaussians_1d_destroy(obj->inactive); + + free((void *) obj); + + } + + void mixture2mixture_process(mixture2mixture_obj * obj, mixture_obj * mixture, const pots_obj * pots, const coherences_obj * coherences, postprobs_obj * postprobs) { + + unsigned int iPot; + unsigned int iTrack; + unsigned int iTrackNewFalse; + unsigned int iCombination; + + signed int t; + float total; + unsigned char match; + + // Compute likelihood + + // p(E^s_l|A), p(E^s_l|I) & p(z^s_l|D) + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + mixture->p_Ez_AICD[0 * pots->nPots + iPot] = gaussians_1d_eval(obj->active, pots->array[iPot * 4 + 3]); + mixture->p_Ez_AICD[1 * pots->nPots + iPot] = gaussians_1d_eval(obj->inactive, pots->array[iPot * 4 + 3]); + mixture->p_Ez_AICD[2 * pots->nPots + iPot] = obj->diffuse; + + } + + // p(z^s_l|C,t) + + for (iTrack = 0; iTrack < mixture->nTracks; iTrack++) { + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + mixture->p_Ez_AICD[(3 + iTrack) * pots->nPots + iPot] = coherences->array[iTrack * mixture->nPots + iPot]; + + } + + } + + // p(E^s_l,z^s_l|phis_c) + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + for (iTrackNewFalse = 0; iTrackNewFalse < mixture->nTracksNewFalse; iTrackNewFalse++) { + + t = (((signed int) iTrackNewFalse) - 2); + + if (t == -2) { + + mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot] = mixture->p_Ez_AICD[1 * pots->nPots + iPot] * mixture->p_Ez_AICD[2 * pots->nPots + iPot]; + + } + else if (t == -1) { + + mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot] = mixture->p_Ez_AICD[0 * pots->nPots + iPot] * mixture->p_Ez_AICD[2 * pots->nPots + iPot]; + + } + else { + + mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot] = mixture->p_Ez_AICD[0 * pots->nPots + iPot] * mixture->p_Ez_AICD[(t + 3) * pots->nPots + iPot]; + + } + + } + + } + + // Prior probabilities + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + for (iTrackNewFalse = 0; iTrackNewFalse < mixture->nTracksNewFalse; iTrackNewFalse++) { + + t = (((signed int) iTrackNewFalse) - 2); + + if (t == -2) { + + mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot] = obj->Pfalse; + + } + else if (t == -1) { + + mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot] = obj->Pnew; + + } + else { + + mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot] = obj->Ptrack; + + } + + } + + } + + // Posterior probabilities + + total = obj->epsilon; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + mixture->p_Ez_phic[iCombination] = 1.0f; + mixture->p_phic[iCombination] = 1.0f; + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + t = mixture->assignations->array[iCombination * mixture->nPots + iPot]; + iTrackNewFalse = (unsigned int) (t + 2); + + mixture->p_Ez_phic[iCombination] *= mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot]; + mixture->p_phic[iCombination] *= mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot]; + + } + + mixture->p_phic_Ez[iCombination] = mixture->p_Ez_phic[iCombination] * mixture->p_phic[iCombination]; + + total += mixture->p_phic_Ez[iCombination]; + + } + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + mixture->p_phic_Ez[iCombination] /= total; + + } + + // Tracking - Potential probabilities + + for (iTrack = 0; iTrack < mixture->nTracks; iTrack++) { + + t = ((signed int) iTrack); + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + postprobs->arrayTrack[iTrack * mixture->nPots + iPot] = 0.0f; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + if (mixture->assignations->array[iCombination * mixture->nPots + iPot] == t) { + + postprobs->arrayTrack[iTrack * mixture->nPots + iPot] += mixture->p_phic_Ez[iCombination]; + + } + + } + + } + + } + + // New probabilities + + postprobs->arrayNew[0] = 0.0f; + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + postprobs->arrayNew[iPot] = 0.0f; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + if (mixture->assignations->array[iCombination * mixture->nPots + iPot] == -1) { + + postprobs->arrayNew[iPot] += mixture->p_phic_Ez[iCombination]; + + } + + } + + } + + // Tracking probabilities + + for (iTrack = 0; iTrack < mixture->nTracks; iTrack++) { + + t = ((signed int) iTrack); + postprobs->arrayTrackTotal[iTrack] = 0.0f; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + match = 0; + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + if (mixture->assignations->array[iCombination * mixture->nPots + iPot] == t) { + + match = 1; + break; + + } + + } + + if (match == 1) { + + postprobs->arrayTrackTotal[iTrack] += mixture->p_phic_Ez[iCombination]; + + } + + } + + } + + } \ No newline at end of file diff --git a/src/system/mixture2mixture.h b/src/system/mixture2mixture.h new file mode 100644 index 0000000..f3dec07 --- /dev/null +++ b/src/system/mixture2mixture.h @@ -0,0 +1,33 @@ +#ifndef __ODAS_SYSTEM_MIXTURE2MIXTURE +#define __ODAS_SYSTEM_MIXTURE2MIXTURE + + #include + #include + #include + + #include "../utils/gaussian.h" + #include "../signal/coherence.h" + #include "../signal/mixture.h" + #include "../signal/pot.h" + #include "../signal/postprob.h" + + typedef struct mixture2mixture_obj { + + gaussians_1d_obj * active; + gaussians_1d_obj * inactive; + float diffuse; + + float Pfalse; + float Pnew; + float Ptrack; + float epsilon; + + } mixture2mixture_obj; + + mixture2mixture_obj * mixture2mixture_construct(const gaussians_1d_obj * active_gmm, const gaussians_1d_obj * inactive_gmm, const float diffuse_cst, const float Pfalse, const float Pnew, const float Ptrack, const float epsilon); + + void mixture2mixture_destroy(mixture2mixture_obj * obj); + + void mixture2mixture_process(mixture2mixture_obj * obj, mixture_obj * mixture, const pots_obj * pots, const coherences_obj * coherences, postprobs_obj * postprobs); + +#endif \ No newline at end of file diff --git a/src/system/particle2coherence.c b/src/system/particle2coherence.c new file mode 100644 index 0000000..ea040e9 --- /dev/null +++ b/src/system/particle2coherence.c @@ -0,0 +1,68 @@ + + #include "particle2coherence.h" + + particle2coherence_obj * particle2coherence_construct(const float sigmaR) { + + particle2coherence_obj * obj; + + obj = (particle2coherence_obj *) malloc(sizeof(particle2coherence_obj)); + + obj->sigmaR = sigmaR; + obj->expScale = 1.0f / (sigmaR*sigmaR*sigmaR * powf(2*M_PI,(3.0f/2.0f))); + obj->expFactor = -1.0f / (2.0f * sigmaR * sigmaR); + + return obj; + + } + + void particle2coherence_destroy(particle2coherence_obj * obj) { + + free((void *) obj); + + } + + void particle2coherence_process(particle2coherence_obj * obj, const particles_obj * particles, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences) { + + unsigned int iPot; + unsigned int iParticle; + + float total; + float x1, y1, z1; + float x2, y2, z2, w2; + float dx, dy, dz; + float scale, factor; + float expr; + + scale = obj->expScale; + factor = obj->expFactor; + + for (iPot = 0; iPot < pots->nPots; iPot++) { + + x1 = pots->array[iPot * 4 + 0]; + y1 = pots->array[iPot * 4 + 1]; + z1 = pots->array[iPot * 4 + 2]; + + total = 0.0f; + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + x2 = particles->array[iParticle * 7 + 0]; + y2 = particles->array[iParticle * 7 + 1]; + z2 = particles->array[iParticle * 7 + 2]; + w2 = particles->array[iParticle * 7 + 6]; + + dx = x1 - x2; + dy = y1 - y2; + dz = z1 - z2; + + total += w2 * expf(factor * (dx*dx + dy*dy + dz*dz)); + + } + + total *= scale; + + coherences->array[iTrack * coherences->nPots + iPot] = total; + + } + + } \ No newline at end of file diff --git a/src/system/particle2coherence.h b/src/system/particle2coherence.h new file mode 100644 index 0000000..ea59c42 --- /dev/null +++ b/src/system/particle2coherence.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SYSTEM_PARTICLE2COHERENCE +#define __ODAS_SYSTEM_PARTICLE2COHERENCE + + #include "../utils/gaussian.h" + #include "../signal/particle.h" + #include "../signal/coherence.h" + #include "../signal/pot.h" + + typedef struct particle2coherence_obj { + + float sigmaR; + float expScale; + float expFactor; + + } particle2coherence_obj; + + particle2coherence_obj * particle2coherence_construct(const float sigmaR); + + void particle2coherence_destroy(particle2coherence_obj * obj); + + void particle2coherence_process(particle2coherence_obj * obj, const particles_obj * particles, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences); + +#endif \ No newline at end of file diff --git a/src/system/particle2particle.c b/src/system/particle2particle.c new file mode 100644 index 0000000..a76d622 --- /dev/null +++ b/src/system/particle2particle.c @@ -0,0 +1,293 @@ + + #include "particle2particle.h" + + particle2particle_obj * particle2particle_construct(const unsigned int nParticles, const float deltaT, const float st_alpha, const float st_beta, const float st_ratio, const float ve_alpha, const float ve_beta, const float ve_ratio, const float ac_alpha, const float ac_beta, const float ac_ratio, const double epsilon, const float sigmaR, const float Nmin) { + + particle2particle_obj * obj; + unsigned int iState; + + obj = (particle2particle_obj *) malloc(sizeof(particle2particle_obj)); + + obj->nParticles = nParticles; + obj->deltaT = deltaT; + + obj->alphas[0] = st_alpha; + obj->alphas[1] = ve_alpha; + obj->alphas[2] = ac_alpha; + obj->betas[0] = st_beta; + obj->betas[1] = ve_beta; + obj->betas[2] = ac_beta; + obj->ratios[0] = st_ratio; + obj->ratios[1] = ve_ratio; + obj->ratios[2] = ac_ratio; + + for (iState = 0; iState < 3; iState++) { + + obj->as[iState] = expf(-1.0f * obj->alphas[iState] * deltaT); + obj->bs[iState] = obj->betas[iState] * sqrtf(1.0f - obj->as[iState] * obj->as[iState]); + + } + + obj->rnd_ratio = random_construct_zero(3); + random_pdf(obj->rnd_ratio, obj->ratios); + obj->indexes_ratio = (unsigned int *) malloc(sizeof(unsigned int) * nParticles); + + obj->pdf_weight = (float *) malloc(sizeof(float) * nParticles); + obj->indexes_weight = (unsigned int *) malloc(sizeof(unsigned int) * nParticles); + obj->rnd_weight = random_construct_zero(nParticles); + + obj->realisation_normal = (float *) malloc(sizeof(float) * nParticles * 3); + obj->normaloff = normaloff_construct_rnd(epsilon, 10000); + + obj->epsilon = epsilon; + obj->Nmin = Nmin; + + obj->sigmaR = sigmaR; + obj->expScale = 1.0f / (sigmaR*sigmaR*sigmaR * powf(2*M_PI,(3.0f/2.0f))); + obj->expFactor = -1.0f / (2.0f * obj->sigmaR * obj->sigmaR); + + obj->sum_P_p_x_O = (float *) malloc(sizeof(float) * nParticles); + obj->particles = particles_construct_zero(nParticles); + + return obj; + + } + + void particle2particle_destroy(particle2particle_obj * obj) { + + random_destroy(obj->rnd_ratio); + free((void *) obj->indexes_ratio); + + free((void *) obj->pdf_weight); + free((void *) obj->indexes_weight); + random_destroy(obj->rnd_weight); + + free((void *) obj->realisation_normal); + normaloff_destroy(obj->normaloff); + + free((void *) obj->sum_P_p_x_O); + particles_destroy(obj->particles); + + free((void *) obj); + + } + + void particle2particle_init_pots(particle2particle_obj * obj, const pots_obj * pots, const unsigned int iPot, particles_obj * particles) { + + unsigned int iParticle; + + random_generate(obj->rnd_ratio, obj->nParticles, obj->indexes_ratio); + + memset(particles->array, 0x00, sizeof(float) * 7 * obj->nParticles); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 0] = pots->array[iPot * 4 + 0]; + particles->array[iParticle * 7 + 1] = pots->array[iPot * 4 + 1]; + particles->array[iParticle * 7 + 2] = pots->array[iPot * 4 + 2]; + particles->array[iParticle * 7 + 6] = (1.0f / ((float) obj->nParticles)); + + particles->state[iParticle] = (unsigned char) (obj->indexes_ratio[iParticle]); + + } + + } + + void particle2particle_init_targets(particle2particle_obj * obj, const targets_obj * targets, const unsigned int iTarget, particles_obj * particles) { + + unsigned int iParticle; + + random_generate(obj->rnd_ratio, obj->nParticles, obj->indexes_ratio); + + memset(particles->array, 0x00, sizeof(float) * 7 * obj->nParticles); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 0] = targets->array[iTarget * 3 + 0]; + particles->array[iParticle * 7 + 1] = targets->array[iTarget * 3 + 1]; + particles->array[iParticle * 7 + 2] = targets->array[iTarget * 3 + 2]; + particles->array[iParticle * 7 + 6] = (1.0f / ((float) obj->nParticles)); + + particles->state[iParticle] = (unsigned char) (obj->indexes_ratio[iParticle]); + + } + + } + + void particle2particle_predict(particle2particle_obj * obj, particles_obj * particles) { + + unsigned int iParticle; + float a, b; + + normaloff_generate(obj->normaloff, obj->nParticles * 3, obj->realisation_normal); + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + a = obj->as[particles->state[iParticle]]; + b = obj->bs[particles->state[iParticle]]; + + particles->array[iParticle * 7 + 3] = a * particles->array[iParticle * 7 + 3] + b * obj->realisation_normal[iParticle * 3 + 0]; + particles->array[iParticle * 7 + 4] = a * particles->array[iParticle * 7 + 4] + b * obj->realisation_normal[iParticle * 3 + 1]; + particles->array[iParticle * 7 + 5] = a * particles->array[iParticle * 7 + 5] + b * obj->realisation_normal[iParticle * 3 + 2]; + + particles->array[iParticle * 7 + 0] = particles->array[iParticle * 7 + 0] + obj->deltaT * particles->array[iParticle * 7 + 3]; + particles->array[iParticle * 7 + 1] = particles->array[iParticle * 7 + 1] + obj->deltaT * particles->array[iParticle * 7 + 4]; + particles->array[iParticle * 7 + 2] = particles->array[iParticle * 7 + 2] + obj->deltaT * particles->array[iParticle * 7 + 5]; + + } + + } + + void particle2particle_predict_static(particle2particle_obj * obj, particles_obj * particles) { + + // Do nothing: keep old particles distribution + + } + + void particle2particle_update(particle2particle_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, particles_obj * particles) { + + unsigned int iParticle; + unsigned int iPot; + float x1, y1, z1; + float x2, y2, z2; + float dx, dy, dz; + float scale, factor; + float postprob; + float expr, value; + float uniform, alpha, oneminusalpha, alphanorm; + float p_x_O; + + float total_sum_P_p_x_O; + float total_w; + + float Neff; + + // Compute sum{P_q,j * p(O_q|x_j,i)}, and normalize + + memset(obj->sum_P_p_x_O, 0x00, sizeof(float) * obj->nParticles); + + total_sum_P_p_x_O = obj->epsilon; + scale = obj->expScale; + factor = obj->expFactor; + + for (iPot = 0; iPot < pots->nPots; iPot++) { + + x1 = pots->array[iPot * 4 + 0]; + y1 = pots->array[iPot * 4 + 1]; + z1 = pots->array[iPot * 4 + 2]; + + postprob = postprobs->arrayTrack[iTrack * pots->nPots + iPot]; + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + x2 = particles->array[iParticle * 7 + 0]; + y2 = particles->array[iParticle * 7 + 1]; + z2 = particles->array[iParticle * 7 + 2]; + + dx = x1 - x2; + dy = y1 - y2; + dz = z1 - z2; + + // We don't need the scale since we normalize + expr = expf(factor * (dx*dx + dy*dy + dz*dz)); + value = postprob * expr; + + obj->sum_P_p_x_O[iParticle] += value; + total_sum_P_p_x_O += value; + + } + + } + + // Compute p(x_j,i|O) and update weights + + uniform = (1.0f/((float) obj->nParticles)); + alpha = postprobs->arrayTrackTotal[iTrack]; + oneminusalpha = (1.0f - alpha); + alphanorm = alpha / total_sum_P_p_x_O; + + total_w = obj->epsilon; + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + p_x_O = oneminusalpha * uniform + alphanorm * obj->sum_P_p_x_O[iParticle]; + particles->array[iParticle * 7 + 6] *= p_x_O; + total_w += particles->array[iParticle * 7 + 6]; + + } + + Neff = obj->epsilon; + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 6] /= total_w; + Neff += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 6]; + + } + + // Resample if needed + + Neff = 1.0f / Neff; + + if (Neff < (obj->Nmin * (float) obj->nParticles)) { + + memcpy(obj->particles->array, particles->array, sizeof(float) * 7 * obj->nParticles); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + obj->pdf_weight[iParticle] = obj->particles->array[iParticle * 7 + 6]; + + } + + random_pdf(obj->rnd_weight, obj->pdf_weight); + random_generate(obj->rnd_weight, obj->nParticles, obj->indexes_weight); + random_generate(obj->rnd_ratio, obj->nParticles, obj->indexes_ratio); + uniform = (1.0f/((float) obj->nParticles)); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 0] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 0]; + particles->array[iParticle * 7 + 1] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 1]; + particles->array[iParticle * 7 + 2] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 2]; + particles->array[iParticle * 7 + 3] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 3]; + particles->array[iParticle * 7 + 4] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 4]; + particles->array[iParticle * 7 + 5] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 5]; + + particles->state[iParticle] = (unsigned char) obj->indexes_ratio[iParticle]; + + particles->array[iParticle * 7 + 6] = uniform; + + } + + } + + } + + void particle2particle_update_static(particle2particle_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, particles_obj * particles) { + + // Do nothing: keep old particles distribution + + } + + void particle2particle_estimate(const particle2particle_obj * obj, const particles_obj * particles, float * x, float * y, float * z) { + + unsigned int iParticle; + float xTotal, yTotal, zTotal; + + xTotal = 0.0f; + yTotal = 0.0f; + zTotal = 0.0f; + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + xTotal += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 0]; + yTotal += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 1]; + zTotal += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 2]; + + } + + *x = xTotal; + *y = yTotal; + *z = zTotal; + + } \ No newline at end of file diff --git a/src/system/particle2particle.h b/src/system/particle2particle.h new file mode 100644 index 0000000..e545757 --- /dev/null +++ b/src/system/particle2particle.h @@ -0,0 +1,63 @@ +#ifndef __ODAS_SYSTEM_PARTICLE2PARTICLE +#define __ODAS_SYSTEM_PARTICLE2PARTICLE + + #include "../utils/gaussian.h" + #include "../utils/random.h" + #include "../signal/particle.h" + #include "../signal/postprob.h" + #include "../signal/pot.h" + #include "../signal/target.h" + + typedef struct particle2particle_obj { + + unsigned int nParticles; + float deltaT; + + float alphas[3]; + float betas[3]; + float as[3]; + float bs[3]; + float ratios[3]; + + float sigmaR; + float expScale; + float expFactor; + + float * pdf_ratio; + unsigned int * indexes_ratio; + random_obj * rnd_ratio; + + float * pdf_weight; + unsigned int * indexes_weight; + random_obj * rnd_weight; + + float * realisation_normal; + double epsilon; + normaloff_obj * normaloff; + + float * sum_P_p_x_O; + particles_obj * particles; + + float Nmin; + + } particle2particle_obj; + + particle2particle_obj * particle2particle_construct(const unsigned int nParticles, const float deltaT, const float st_alpha, const float st_beta, const float st_ratio, const float ve_alpha, const float ve_beta, const float ve_ratio, const float ac_alpha, const float ac_beta, const float ac_ratio, const double epsilon, const float sigmaR, const float Nmin); + + void particle2particle_destroy(particle2particle_obj * obj); + + void particle2particle_init_pots(particle2particle_obj * obj, const pots_obj * pots, const unsigned int iPot, particles_obj * particles); + + void particle2particle_init_targets(particle2particle_obj * obj, const targets_obj * targets, const unsigned int iTarget, particles_obj * particles); + + void particle2particle_predict(particle2particle_obj * obj, particles_obj * particles); + + void particle2particle_predict_static(particle2particle_obj * obj, particles_obj * particles); + + void particle2particle_update(particle2particle_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, particles_obj * particles); + + void particle2particle_update_static(particle2particle_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, particles_obj * particles); + + void particle2particle_estimate(const particle2particle_obj * obj, const particles_obj * particles, float * x, float * y, float * z); + +#endif \ No newline at end of file diff --git a/src/system/pitch2category.c b/src/system/pitch2category.c new file mode 100644 index 0000000..19e938e --- /dev/null +++ b/src/system/pitch2category.c @@ -0,0 +1,158 @@ + + #include "pitch2category.h" + + pitch2category_obj * pitch2category_construct_zero(const unsigned int nSeps, const float tauMin, const float tauMax, const float deltaTauMax, const float alpha, const float gamma, const float phiMin, const float r0) { + + pitch2category_obj * obj; + + obj = (pitch2category_obj *) malloc(sizeof(pitch2category_obj)); + + obj->nSeps = nSeps; + + obj->tauMin = tauMin; + obj->tauMax = tauMax; + obj->deltaTauMax = deltaTauMax; + obj->alpha = alpha; + obj->gamma = gamma; + obj->phiMin = phiMin; + obj->r0 = r0; + + obj->tausNow = (float *) malloc(sizeof(float) * nSeps); + memset(obj->tausNow, 0x00, sizeof(float) * nSeps); + + obj->tausPrev = (float *) malloc(sizeof(float) * nSeps); + memset(obj->tausPrev, 0x00, sizeof(float) * nSeps); + + obj->deltaTausNow = (float *) malloc(sizeof(float) * nSeps); + memset(obj->deltaTausNow, 0x00, sizeof(float) * nSeps); + + obj->deltaTausPrev = (float *) malloc(sizeof(float) * nSeps); + memset(obj->deltaTausPrev, 0x00, sizeof(float) * nSeps); + + obj->phisNow = (float *) malloc(sizeof(float) * nSeps); + memset(obj->phisNow, 0x00, sizeof(float) * nSeps); + + obj->phisPrev = (float *) malloc(sizeof(float) * nSeps); + memset(obj->phisPrev, 0x00, sizeof(float) * nSeps); + + obj->vs = (float *) malloc(sizeof(float) * nSeps); + memset(obj->vs, 0x00, sizeof(float) * nSeps); + + obj->rs = (float *) malloc(sizeof(float) * nSeps); + memset(obj->rs, 0x00, sizeof(float) * nSeps); + + obj->categories = (char *) malloc(sizeof(char) * nSeps); + memset(obj->categories, 0x00, sizeof(char) * nSeps); + + return obj; + + } + + void pitch2category_destroy(pitch2category_obj * obj) { + + free((void *) obj->tausNow); + free((void *) obj->tausPrev); + free((void *) obj->deltaTausNow); + free((void *) obj->deltaTausPrev); + free((void *) obj->phisNow); + free((void *) obj->phisPrev); + free((void *) obj->vs); + free((void *) obj->rs); + free((void *) obj->categories); + + free((void *) obj); + + } + + void pitch2category_process(pitch2category_obj * obj, const pitches_obj * pitches, const tracks_obj * tracks, categories_obj * categories) { + + unsigned int iSep; + float deltaPitch; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + if (obj->categories[iSep] != 0x01) { + + // tau_i + obj->tausNow[iSep] = pitches->array[iSep]; + + // delta_tau_i + obj->deltaTausNow[iSep] = obj->tausNow[iSep] - obj->tausPrev[iSep]; + + // phi_i + if ((fabs(obj->deltaTausNow[iSep]) < obj->deltaTauMax) && (fabs(obj->deltaTausPrev[iSep]) < obj->deltaTauMax)) { + + obj->phisNow[iSep] = (1 - obj->alpha) * obj->phisPrev[iSep] + obj->alpha * obj->deltaTausNow[iSep]; + + } + else if ((fabs(obj->deltaTausNow[iSep]) < obj->deltaTauMax) && (fabs(obj->deltaTausPrev[iSep]) >= obj->deltaTauMax)) { + + obj->phisNow[iSep] = obj->deltaTausNow[iSep]; + + } + else { + + obj->phisNow[iSep] = 0.0f; + + } + + // v_i + if ((obj->tausNow[iSep] >= obj->tauMin) && (obj->tausNow[iSep] <= obj->tauMax) && fabs(obj->phisNow[iSep]) > obj->phiMin) { + + obj->vs[iSep] = 1.0f; + + } + else { + + obj->vs[iSep] = 0.0f; + + } + + // r_i + obj->rs[iSep] = (1.0f - obj->gamma) * obj->rs[iSep] + obj->gamma * obj->vs[iSep]; + + // Classify + + if (obj->rs[iSep] > obj->r0) { + + // Speech + obj->categories[iSep] = 0x01; + + } + else { + + // Non speech + obj->categories[iSep] = 0x00; + + } + + // tau_i-1 = tau_i + memcpy(obj->tausPrev, obj->tausNow, sizeof(float) * obj->nSeps); + + // delta_tau_i-1 = delta_tau_i + memcpy(obj->deltaTausPrev, obj->deltaTausNow, sizeof(float) * obj->nSeps); + + // phi_i-1 = phi_i + memcpy(obj->phisPrev, obj->phisNow, sizeof(float) * obj->nSeps); + + } + + categories->array[iSep] = obj->categories[iSep]; + + } + else { + + obj->tausNow[iSep] = 0.0f; + obj->deltaTausNow[iSep] = 0.0f; + obj->phisNow[iSep] = 0.0f; + obj->vs[iSep] = 0.0f; + obj->rs[iSep] = 0.0f; + obj->categories[iSep] = 0x00; + + } + + } + + } \ No newline at end of file diff --git a/src/system/pitch2category.h b/src/system/pitch2category.h new file mode 100644 index 0000000..842dfbc --- /dev/null +++ b/src/system/pitch2category.h @@ -0,0 +1,43 @@ +#ifndef __ODAS_SYSTEM_PITCH2CATEGORY +#define __ODAS_SYSTEM_PITCH2CATEGORY + + #include + #include + #include + #include + + #include "../signal/category.h" + #include "../signal/pitch.h" + #include "../signal/track.h" + + typedef struct pitch2category_obj { + + unsigned int nSeps; + + float tauMin; + float tauMax; + float deltaTauMax; + float alpha; + float gamma; + float phiMin; + float r0; + + float * tausNow; + float * tausPrev; + float * deltaTausNow; + float * deltaTausPrev; + float * phisNow; + float * phisPrev; + float * vs; + float * rs; + char * categories; + + } pitch2category_obj; + + pitch2category_obj * pitch2category_construct_zero(const unsigned int nSeps, const float tauMin, const float tauMax, const float deltaTauMax, const float alpha, const float gamma, const float phiMin, const float r0); + + void pitch2category_destroy(pitch2category_obj * obj); + + void pitch2category_process(pitch2category_obj * obj, const pitches_obj * pitches, const tracks_obj * tracks, categories_obj * categories); + +#endif \ No newline at end of file diff --git a/src/system/steer2demixing.c b/src/system/steer2demixing.c new file mode 100644 index 0000000..b8e1a4d --- /dev/null +++ b/src/system/steer2demixing.c @@ -0,0 +1,672 @@ + + #include "steer2demixing.h" + + int count = 0; + + steer2demixing_ds_obj * steer2demixing_ds_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float epsilon) { + + steer2demixing_ds_obj * obj; + + obj = (steer2demixing_ds_obj *) malloc(sizeof(steer2demixing_ds_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + obj->epsilon = epsilon; + + obj->gains2 = (float *) malloc(sizeof(float) * halfFrameSize); + memset(obj->gains2, 0x00, sizeof(float) * halfFrameSize); + + return obj; + + } + + void steer2demixing_ds_destroy(steer2demixing_ds_obj * obj) { + + free((void *) obj->gains2); + free((void *) obj); + + } + + void steer2demixing_ds_process(steer2demixing_ds_obj * obj, const tracks_obj * tracks, const steers_obj * steers, const masks_obj * masks, demixings_obj * demixings) { + + unsigned int iSep; + unsigned int iChannel; + unsigned int iBin; + unsigned int iSampleSC; + unsigned int iSampleBC; + + char mask; + float Areal; + float Aimag; + float gain2; + float Wreal; + float Wimag; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + memset(obj->gains2, 0x00, sizeof(float) * obj->halfFrameSize); + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + obj->gains2[iBin] = obj->epsilon; + + } + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleSC = iSep * obj->nChannels + iChannel; + mask = masks->array[iSampleSC]; + + if (mask == 1) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + + Areal = steers->array[iSep][iSampleBC * 2 + 0]; + Aimag = steers->array[iSep][iSampleBC * 2 + 1]; + + gain2 = Areal * Areal + Aimag * Aimag; + + obj->gains2[iBin] += gain2; + + } + + } + + } + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleSC = iSep * obj->nChannels + iChannel; + mask = masks->array[iSampleSC]; + + if (mask == 1) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + + Areal = steers->array[iSep][iSampleBC * 2 + 0]; + Aimag = steers->array[iSep][iSampleBC * 2 + 1]; + + Wreal = Areal / obj->gains2[iBin]; + Wimag = -1.0f * Aimag / obj->gains2[iBin]; + + demixings->array[iSep][iSampleBC * 2 + 0] = Wreal; + demixings->array[iSep][iSampleBC * 2 + 1] = Wimag; + + } + + } + else { + + demixings->array[iSep][iSampleBC * 2 + 0] = 0.0f; + demixings->array[iSep][iSampleBC * 2 + 1] = 0.0f; + + } + + } + + } + + } + + } + + + steer2demixing_gss_obj * steer2demixing_gss_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float mu, const float lambda, const float epsilon) { + + steer2demixing_gss_obj * obj; + unsigned int iSep; + + obj = (steer2demixing_gss_obj *) malloc(sizeof(steer2demixing_gss_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + obj->mu = mu; + obj->lambda = lambda; + obj->epsilon = epsilon; + + obj->X = cmatrix_construct_zero(nChannels, 1); + obj->XH = cmatrix_construct_zero(1, nChannels); + + obj->Y = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->YH = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->Ryy = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->E = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->A = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->AH = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->Wn = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->Wnp1 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ1 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ2 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + + obj->dJ1_EY = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ1_4EY = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ1_4EYXH = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + + obj->dJ2_WA = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ2_WAmI = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ2_2WAmI = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->dJ2_2WAmIAH = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + + obj->alpha_dJ1 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->alpha_dJ1_p_dJ2 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->mu_alpha_dJ1_p_dJ2 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->one_m_lambda_mu_Wn = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + obj->one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2 = (cmatrix_obj **) malloc(sizeof(cmatrix_obj *) * nSeps); + + for (iSep = 0; iSep < nSeps; iSep++) { + + obj->Y[iSep] = cmatrix_construct_zero((iSep+1), 1); + obj->YH[iSep] = cmatrix_construct_zero(1, (iSep+1)); + obj->Ryy[iSep] = cmatrix_construct_zero((iSep+1), (iSep+1)); + obj->E[iSep] = cmatrix_construct_zero((iSep+1), (iSep+1)); + obj->A[iSep] = cmatrix_construct_zero(nChannels, (iSep+1)); + obj->AH[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->Wn[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->Wnp1[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->dJ1[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->dJ2[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + + obj->dJ1_EY[iSep] = cmatrix_construct_zero((iSep+1), 1); + obj->dJ1_4EY[iSep] = cmatrix_construct_zero((iSep+1), 1); + obj->dJ1_4EYXH[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + + obj->dJ2_WA[iSep] = cmatrix_construct_zero((iSep+1), (iSep+1)); + obj->dJ2_WAmI[iSep] = cmatrix_construct_zero((iSep+1), (iSep+1)); + obj->dJ2_2WAmI[iSep] = cmatrix_construct_zero((iSep+1), (iSep+1)); + obj->dJ2_2WAmIAH[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + + obj->alpha_dJ1[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->alpha_dJ1_p_dJ2[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->mu_alpha_dJ1_p_dJ2[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->one_m_lambda_mu_Wn[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + obj->one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2[iSep] = cmatrix_construct_zero((iSep+1), nChannels); + + } + + return obj; + + } + + void steer2demixing_gss_destroy(steer2demixing_gss_obj * obj) { + + unsigned int iSep; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + cmatrix_destroy(obj->Y[iSep]); + cmatrix_destroy(obj->YH[iSep]); + cmatrix_destroy(obj->Ryy[iSep]); + cmatrix_destroy(obj->E[iSep]); + cmatrix_destroy(obj->A[iSep]); + cmatrix_destroy(obj->AH[iSep]); + cmatrix_destroy(obj->Wn[iSep]); + cmatrix_destroy(obj->Wnp1[iSep]); + cmatrix_destroy(obj->dJ1[iSep]); + cmatrix_destroy(obj->dJ2[iSep]); + + cmatrix_destroy(obj->dJ1_EY[iSep]); + cmatrix_destroy(obj->dJ1_4EY[iSep]); + cmatrix_destroy(obj->dJ1_4EYXH[iSep]); + + cmatrix_destroy(obj->dJ2_WA[iSep]); + cmatrix_destroy(obj->dJ2_WAmI[iSep]); + cmatrix_destroy(obj->dJ2_2WAmI[iSep]); + cmatrix_destroy(obj->dJ2_2WAmIAH[iSep]); + + cmatrix_destroy(obj->alpha_dJ1[iSep]); + cmatrix_destroy(obj->alpha_dJ1_p_dJ2[iSep]); + cmatrix_destroy(obj->mu_alpha_dJ1_p_dJ2[iSep]); + cmatrix_destroy(obj->one_m_lambda_mu_Wn[iSep]); + cmatrix_destroy(obj->one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2[iSep]); + + } + + free((void *) obj->Y); + free((void *) obj->YH); + free((void *) obj->Ryy); + free((void *) obj->E); + free((void *) obj->A); + free((void *) obj->AH); + free((void *) obj->Wn); + free((void *) obj->Wnp1); + free((void *) obj->dJ1); + free((void *) obj->dJ2); + + free((void *) obj->dJ1_EY); + free((void *) obj->dJ1_4EY); + free((void *) obj->dJ1_4EYXH); + + free((void *) obj->dJ2_WA); + free((void *) obj->dJ2_WAmI); + free((void *) obj->dJ2_2WAmI); + free((void *) obj->dJ2_2WAmIAH); + + free((void *) obj->alpha_dJ1); + free((void *) obj->alpha_dJ1_p_dJ2); + free((void *) obj->mu_alpha_dJ1_p_dJ2); + free((void *) obj->one_m_lambda_mu_Wn); + free((void *) obj->one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2); + + cmatrix_destroy(obj->XH); + cmatrix_destroy(obj->X); + + free((void *) obj); + + } + + void steer2demixing_gss_process(steer2demixing_gss_obj * obj, const tracks_obj * tracksPrev, const tracks_obj * tracks, const steers_obj * steers, const masks_obj * masks, const freqs_obj * freqs, const demixings_obj * demixingsPrev, demixings_obj * demixings) { + + unsigned int iSep; + unsigned int iBin; + unsigned int iChannel; + unsigned int nActiveSources; + unsigned int iActiveSource; + unsigned int iSampleSC; + unsigned int iSampleBC; + unsigned int iSampleAC; + unsigned int iSampleCA; + + float Areal; + float Aimag; + float Wreal; + float Wimag; + float gain2; + float Xreal; + float Ximag; + float X2; + float Rxx2; + float alpha; + + nActiveSources = 0; + + // Count the number of active sources + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + nActiveSources++; + + } + + } + + //freqs_printf(freqs); + + if (nActiveSources > 0) { + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + // + // Compute X[k] and X^H[k] + // + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + + obj->X->real[iChannel] = freqs->array[iChannel][iBin*2+0]; + obj->X->imag[iChannel] = freqs->array[iChannel][iBin*2+1]; + obj->XH->real[iChannel] = freqs->array[iChannel][iBin*2+0]; + obj->XH->imag[iChannel] = -1.0f * freqs->array[iChannel][iBin*2+1]; + + } + + // + // Compute W_n[k], and add new sources is needed + // + + iActiveSource = 0; + + cmatrix_zero(obj->Wn[nActiveSources-1]); + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + if (tracks->ids[iSep] == tracksPrev->ids[iSep]) { + + // If the source was previously active, load the corresponding demixing terms + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleAC = iActiveSource * obj->nChannels + iChannel; + + Wreal = demixingsPrev->array[iSep][iSampleBC * 2 + 0]; + Wimag = demixingsPrev->array[iSep][iSampleBC * 2 + 1]; + + obj->Wn[nActiveSources-1]->real[iSampleAC] = Wreal; + obj->Wn[nActiveSources-1]->imag[iSampleAC] = Wimag; + + } + + } + else { + + // Otherwise instantiate with terms of a weighted delay and sum beamformer + + gain2 = obj->epsilon; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleSC = iSep * obj->nChannels + iChannel; + iSampleAC = iActiveSource * obj->nChannels + iChannel; + + if (masks->array[iSampleSC] == 1) { + + Areal = steers->array[iSep][iSampleBC * 2 + 0]; + Aimag = steers->array[iSep][iSampleBC * 2 + 1]; + + gain2 += Areal * Areal + Aimag * Aimag; + + } + + } + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleSC = iSep * obj->nChannels + iChannel; + iSampleAC = iActiveSource * obj->nChannels + iChannel; + + if (masks->array[iSampleSC] == 1) { + + Areal = steers->array[iSep][iSampleBC * 2 + 0]; + Aimag = steers->array[iSep][iSampleBC * 2 + 1]; + + Wreal = Areal / gain2; + Wimag = -1.0f * Aimag / gain2; + + obj->Wn[nActiveSources-1]->real[iSampleAC] = Wreal; + obj->Wn[nActiveSources-1]->imag[iSampleAC] = Wimag; + + } + + } + + } + + iActiveSource++; + + } + + } + + // + // Compute Y[k] = Wn[k]X[k] + // + + cmatrix_mul(obj->Y[nActiveSources-1], + obj->Wn[nActiveSources-1], + obj->X); + + // + // Compute Y^H[k] + // + + cmatrix_hermitian(obj->YH[nActiveSources-1], + obj->Y[nActiveSources-1]); + + // + // Compute Ryy[k] = Y[k] Y[k]^H + // + + cmatrix_mul(obj->Ryy[nActiveSources-1], + obj->Y[nActiveSources-1], + obj->YH[nActiveSources-1]); + + // + // Compute E[k] = Ryy[k] - diag{Ryy[k]} + // + + cmatrix_copy_cmatrix(obj->E[nActiveSources-1], + obj->Ryy[nActiveSources-1]); + + for (iActiveSource = 0; iActiveSource < nActiveSources; iActiveSource++) { + + obj->E[nActiveSources-1]->real[iActiveSource * nActiveSources + iActiveSource] = 0.0f; + obj->E[nActiveSources-1]->imag[iActiveSource * nActiveSources + iActiveSource] = 0.0f; + + } + + // + // Compute A[k] and A^H[k] + // + + iActiveSource = 0; + + cmatrix_zero(obj->A[nActiveSources-1]); + cmatrix_zero(obj->AH[nActiveSources-1]); + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleSC = iSep * obj->nChannels + iChannel; + iSampleCA = iChannel * nActiveSources + iActiveSource; + iSampleAC = iActiveSource * obj->nChannels + iChannel; + + if (masks->array[iSampleSC] == 1) { + + Areal = steers->array[iSep][iSampleBC * 2 + 0]; + Aimag = steers->array[iSep][iSampleBC * 2 + 1]; + + obj->A[nActiveSources-1]->real[iSampleCA] = Areal; + obj->A[nActiveSources-1]->imag[iSampleCA] = Aimag; + + obj->AH[nActiveSources-1]->real[iSampleAC] = Areal; + obj->AH[nActiveSources-1]->imag[iSampleAC] = -1.0f * Aimag; + + } + + } + + iActiveSource++; + + } + + } + + // + // Compute dJ1[k] = 4{E[k]Wn[k]X[k]}X^H[k] = 4{E[k]Y[k]}X^H[k] + // + + // E[k]Y[k] + + cmatrix_mul(obj->dJ1_EY[nActiveSources-1], + obj->E[nActiveSources-1], + obj->Y[nActiveSources-1]); + + // 4E[k]Y[k] + + cmatrix_scale(obj->dJ1_4EY[nActiveSources-1], + obj->dJ1_EY[nActiveSources-1], + 4.0f); + + // 4E[k]Y[k]X^H[k] + + cmatrix_mul(obj->dJ1_4EYXH[nActiveSources-1], + obj->dJ1_4EY[nActiveSources-1], + obj->XH); + + // Copy + + cmatrix_copy_cmatrix(obj->dJ1[nActiveSources-1], + obj->dJ1_4EYXH[nActiveSources-1]); + + // + // Compute dJ2[k] = 2{W[k]A[k]-I}A^H[k] + // + + // W[k]A[k] + + cmatrix_mul(obj->dJ2_WA[nActiveSources-1], + obj->Wn[nActiveSources-1], + obj->A[nActiveSources-1]); + + // W[k]A[k] - I + + cmatrix_copy_cmatrix(obj->dJ2_WAmI[nActiveSources-1], + obj->dJ2_WA[nActiveSources-1]); + + for (iActiveSource = 0; iActiveSource < nActiveSources; iActiveSource++) { + obj->dJ2_WAmI[nActiveSources-1]->real[iActiveSource * nActiveSources + iActiveSource] -= 1.0f; + } + + // 2{W[k]A[k]-I} + + cmatrix_scale(obj->dJ2_2WAmI[nActiveSources-1], + obj->dJ2_WAmI[nActiveSources-1], + 2.0f); + + // 2{W[k]A[k]-I}A^H[k] + + cmatrix_mul(obj->dJ2_2WAmIAH[nActiveSources-1], + obj->dJ2_2WAmI[nActiveSources-1], + obj->AH[nActiveSources-1]); + + // Copy + + cmatrix_copy_cmatrix(obj->dJ2[nActiveSources-1], + obj->dJ2_2WAmIAH[nActiveSources-1]); + + + //if (iBin == 10) { + // cmatrix_printf(obj->AH[nActiveSources-1]); + //} + + // + // Compute ||Rxx||^2 = ||X[k]X^H[k]||^2 = (||X[k]||^2)^2 + // + + X2 = 0.0f; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + Xreal = obj->X->real[iChannel]; + Ximag = obj->X->imag[iChannel]; + + X2 += Xreal * Xreal + Ximag * Ximag; + + } + + Rxx2 = X2 * X2; + + // + // Compute alpha = 1 / ||Rxx||^2 + // + + alpha = 1.0f / (Rxx2 + obj->epsilon); + + // + // Compute W_n+1[k] = (1 - lambda * mu) * W_n[k] - mu * {alpha * dJ1 + dJ2} + // + + // alpha * dJ1 + + cmatrix_scale(obj->alpha_dJ1[nActiveSources-1], + obj->dJ1[nActiveSources-1], + alpha); + + // alpha * dJ1 + dJ2 + + cmatrix_add(obj->alpha_dJ1_p_dJ2[nActiveSources-1], + obj->alpha_dJ1[nActiveSources-1], + obj->dJ2[nActiveSources-1]); + + // mu * (alpha * dJ1 + dJ2) + + cmatrix_scale(obj->mu_alpha_dJ1_p_dJ2[nActiveSources-1], + obj->alpha_dJ1_p_dJ2[nActiveSources-1], + 1.0f * obj->mu); + + // (1 - lambda * mu) * Wn + + cmatrix_scale(obj->one_m_lambda_mu_Wn[nActiveSources-1], + obj->Wn[nActiveSources-1], + (1.0f - obj->lambda * obj->mu)); + + // (1 - lambda * mu) * Wn[k] - mu * {alpha * dJ1[k] + dJ2[k]} + + cmatrix_sub(obj->one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2[nActiveSources-1], + obj->one_m_lambda_mu_Wn[nActiveSources-1], + obj->mu_alpha_dJ1_p_dJ2[nActiveSources-1]); + + // Copy + + cmatrix_copy_cmatrix(obj->Wnp1[nActiveSources-1], + obj->one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2[nActiveSources-1]); + + // + // Copy to demixing + // + + iActiveSource = 0; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + iSampleAC = iActiveSource * obj->nChannels + iChannel; + + Wreal = obj->Wnp1[nActiveSources-1]->real[iSampleAC]; + Wimag = obj->Wnp1[nActiveSources-1]->imag[iSampleAC]; + + demixings->array[iSep][iSampleBC * 2 + 0] = Wreal; + demixings->array[iSep][iSampleBC * 2 + 1] = Wimag; + + } + + iActiveSource++; + + } + + } + + } + + } + + // count++; + + //if (count == 1) { + // exit(EXIT_SUCCESS); + //} + + } + + steer2demixing_mvdr_obj * steer2demixing_mvdr_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float alpha, const float sigma, const unsigned int deltaK) { + + // Not implemented yet + + } + + void steer2demixing_mvdr_destroy(steer2demixing_mvdr_obj * obj) { + + // Not implemented yet + + } + + void steer2demixing_mvdr_process(steer2demixing_mvdr_obj * obj, const tracks_obj * tracks, const steers_obj * steers, const masks_obj * masks, const freqs_obj * freqs, demixings_obj * demixings) { + + // Not implemented yet + + } + diff --git a/src/system/steer2demixing.h b/src/system/steer2demixing.h new file mode 100644 index 0000000..f95c765 --- /dev/null +++ b/src/system/steer2demixing.h @@ -0,0 +1,95 @@ +#ifndef __ODAS_SYSTEM_STEER2DEMIXING +#define __ODAS_SYSTEM_STEER2DEMIXING + + #include + #include + #include + #include + + #include "../signal/demixing.h" + #include "../signal/freq.h" + #include "../signal/mask.h" + #include "../signal/steer.h" + #include "../signal/track.h" + + #include "../utils/cmatrix.h" + + typedef struct steer2demixing_ds_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + float epsilon; + + float * gains2; + + } steer2demixing_ds_obj; + + typedef struct steer2demixing_gss_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + float epsilon; + + float mu; + float lambda; + + cmatrix_obj * X; + cmatrix_obj * XH; + + cmatrix_obj ** Y; + cmatrix_obj ** YH; + cmatrix_obj ** Ryy; + cmatrix_obj ** E; + cmatrix_obj ** A; + cmatrix_obj ** AH; + cmatrix_obj ** Wn; + cmatrix_obj ** Wnp1; + cmatrix_obj ** dJ1; + cmatrix_obj ** dJ2; + + cmatrix_obj ** dJ1_EY; + cmatrix_obj ** dJ1_4EY; + cmatrix_obj ** dJ1_4EYXH; + + cmatrix_obj ** dJ2_WA; + cmatrix_obj ** dJ2_WAmI; + cmatrix_obj ** dJ2_2WAmI; + cmatrix_obj ** dJ2_2WAmIAH; + + cmatrix_obj ** alpha_dJ1; + cmatrix_obj ** alpha_dJ1_p_dJ2; + cmatrix_obj ** mu_alpha_dJ1_p_dJ2; + cmatrix_obj ** one_m_lambda_mu_Wn; + cmatrix_obj ** one_m_lambda_mu_Wn_m_mu_alpha_dJ1_p_dJ2; + + } steer2demixing_gss_obj; + + typedef struct steer2demixing_mvdr_obj { + + } steer2demixing_mvdr_obj; + + + steer2demixing_ds_obj * steer2demixing_ds_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float epsilon); + + void steer2demixing_ds_destroy(steer2demixing_ds_obj * obj); + + void steer2demixing_ds_process(steer2demixing_ds_obj * obj, const tracks_obj * tracks, const steers_obj * steers, const masks_obj * masks, demixings_obj * demixings); + + + steer2demixing_gss_obj * steer2demixing_gss_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float mu, const float lambda, const float epsilon); + + void steer2demixing_gss_destroy(steer2demixing_gss_obj * obj); + + void steer2demixing_gss_process(steer2demixing_gss_obj * obj, const tracks_obj * tracksPrev, const tracks_obj * tracks, const steers_obj * steers, const masks_obj * masks, const freqs_obj * freqs, const demixings_obj * demixingsPrev, demixings_obj * demixings); + + + steer2demixing_mvdr_obj * steer2demixing_mvdr_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float alpha, const float sigma, const unsigned int deltaK); + + void steer2demixing_mvdr_destroy(steer2demixing_mvdr_obj * obj); + + void steer2demixing_mvdr_process(steer2demixing_mvdr_obj * obj, const tracks_obj * tracks, const steers_obj * steers, const masks_obj * masks, const freqs_obj * freqs, demixings_obj * demixings); + + +#endif \ No newline at end of file diff --git a/src/system/track2gain.c b/src/system/track2gain.c new file mode 100644 index 0000000..78d761c --- /dev/null +++ b/src/system/track2gain.c @@ -0,0 +1,116 @@ + + #include "track2gain.h" + + track2gain_obj * track2gain_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float * directions, const float * direction) { + + track2gain_obj * obj; + + obj = (track2gain_obj *) malloc(sizeof(track2gain_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + + obj->directions = (float *) malloc(sizeof(float) * nChannels * 3); + memcpy(obj->directions, directions, sizeof(float) * nChannels * 3); + + obj->direction = (float *) malloc(sizeof(float) * 3); + memcpy(obj->direction, direction, sizeof(float) * 3); + + return obj; + + } + + void track2gain_destroy(track2gain_obj * obj) { + + free((void *) obj->directions); + free((void *) obj->direction); + free((void *) obj); + + } + + void track2gain_process(track2gain_obj * obj, const beampatterns_obj * beampatterns_mics, const beampatterns_obj * beampatterns_spatialfilter, const tracks_obj * tracks, gains_obj * gains) { + + unsigned int iSep; + unsigned int iChannel; + + unsigned int iThetaMic; + unsigned int iThetaFilter; + + float ux, uy, uz; + float uNorm; + float dx, dy, dz; + float dNorm; + float sx, sy, sz; + float sNorm; + + float projMic; + float projFilter; + float thetaMic; + float thetaFilter; + float gainMic; + float gainFilter; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + ux = tracks->array[iSep * 3 + 0]; + uy = tracks->array[iSep * 3 + 1]; + uz = tracks->array[iSep * 3 + 2]; + + uNorm = sqrtf(ux * ux + uy * uy + uz * uz); + + sx = obj->direction[0]; + sy = obj->direction[1]; + sz = obj->direction[2]; + + sNorm = sqrtf(sx * sx + sy * sy + sz * sz); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + dx = obj->directions[iChannel * 3 + 0]; + dy = obj->directions[iChannel * 3 + 1]; + dz = obj->directions[iChannel * 3 + 2]; + + dNorm = sqrtf(dx * dx + dy * dy + dz * dz); + + projMic = dx * ux + dy * uy + dz * uz; + projFilter = sx * ux + sy * uy + sz * uz; + + thetaMic = (360.0f/(2.0f * M_PI)) * acosf(projMic / (dNorm * uNorm)); + thetaFilter = (360.0f/(2.0f * M_PI)) * acosf(projFilter / (sNorm * uNorm)); + + iThetaMic = roundf((thetaMic - beampatterns_mics->minThetas[iChannel]) / (beampatterns_mics->deltaThetas[iChannel]) + beampatterns_mics->minThetas[iChannel]); + iThetaFilter = roundf((thetaFilter - beampatterns_spatialfilter->minThetas[0]) / (beampatterns_spatialfilter->deltaThetas[0]) + beampatterns_spatialfilter->minThetas[0]); + + if (iThetaMic < 0) { + iThetaMic = 0; + } + if (iThetaMic >= beampatterns_mics->nThetas) { + iThetaMic = beampatterns_mics->nThetas - 1; + } + + if (iThetaFilter < 0) { + iThetaFilter = 0; + } + if (iThetaFilter >= beampatterns_spatialfilter->nThetas) { + iThetaFilter = beampatterns_spatialfilter->nThetas - 1; + } + + gainMic = beampatterns_mics->gains[iChannel * beampatterns_mics->nThetas + iThetaMic]; + gainFilter = beampatterns_spatialfilter->gains[iThetaFilter]; + + gains->array[iSep * obj->nChannels + iChannel] = gainMic * gainFilter; + + } + + } + else { + + memset(&(gains->array[iSep * obj->nChannels]), 0x00, sizeof(float) * obj->nChannels); + + } + + } + + } \ No newline at end of file diff --git a/src/system/track2gain.h b/src/system/track2gain.h new file mode 100644 index 0000000..d6e2dda --- /dev/null +++ b/src/system/track2gain.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SYSTEM_TRACK2GAIN +#define __ODAS_SYSTEM_TRACK2GAIN + + #include "../signal/beampattern.h" + #include "../signal/track.h" + #include "../signal/gain.h" + + #include + #include + #include + + typedef struct track2gain_obj { + + unsigned int nSeps; + unsigned int nChannels; + float * directions; + float * direction; + + } track2gain_obj; + + track2gain_obj * track2gain_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float * directions, const float * direction); + + void track2gain_destroy(track2gain_obj * obj); + + void track2gain_process(track2gain_obj * obj, const beampatterns_obj * beampatterns_mics, const beampatterns_obj * beampatterns_spatialfilter, const tracks_obj * tracks, gains_obj * gains); + + +#endif \ No newline at end of file diff --git a/src/system/track2steer.c b/src/system/track2steer.c new file mode 100644 index 0000000..19c8bde --- /dev/null +++ b/src/system/track2steer.c @@ -0,0 +1,106 @@ + + #include "track2steer.h" + + track2steer_obj * track2steer_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float c, const unsigned int fS, const float * mics) { + + track2steer_obj * obj; + unsigned int iBin; + + obj = (track2steer_obj *) malloc(sizeof(track2steer_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + obj->c = c; + obj->fS = fS; + + obj->mics = (float *) malloc(sizeof(float) * nChannels * 3); + memcpy(obj->mics, mics, sizeof(float) * nChannels * 3); + + obj->factor = (float *) malloc(sizeof(float) * halfFrameSize); + + for (iBin = 0; iBin < halfFrameSize; iBin++) { + + obj->factor[iBin] = -2.0f * M_PI * ((float) iBin) / ((float) ((halfFrameSize-1) * 2)); + + } + + obj->speed = ((float) obj->fS) / obj->c; + + return obj; + + } + + void track2steer_destroy(track2steer_obj * obj) { + + unsigned int iBin; + + free((void *) obj->factor); + free((void *) obj->mics); + + free((void *) obj); + + } + + void track2steer_process(track2steer_obj * obj, const tracks_obj * tracks, const gains_obj * gains, const masks_obj * masks, steers_obj * steers) { + + unsigned int iSep; + unsigned int iBin; + unsigned int iChannel; + + float dist; + float delay; + float gain; + char mask; + + float Areal; + float Aimag; + + unsigned int iSampleSC; + unsigned int iSampleBC; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + iSampleSC = iSep * obj->nChannels + iChannel; + mask = masks->array[iSampleSC]; + + if (mask == 1) { + + dist = tracks->array[iSep * 3 + 0] * obj->mics[iChannel * 3 + 0] + + tracks->array[iSep * 3 + 1] * obj->mics[iChannel * 3 + 1] + + tracks->array[iSep * 3 + 2] * obj->mics[iChannel * 3 + 2]; + + delay = -1.0f * obj->speed * dist; + + gain = gains->array[iSampleSC]; + + for (iBin = 0; iBin < obj->halfFrameSize; iBin++) { + + iSampleBC = iBin * obj->nChannels + iChannel; + + Areal = gain * cosf(obj->factor[iBin] * delay); + Aimag = gain * sinf(obj->factor[iBin] * delay); + + steers->array[iSep][iSampleBC * 2 + 0] = Areal; + steers->array[iSep][iSampleBC * 2 + 1] = Aimag; + + } + + } + + } + + } + else { + + memset(steers->array[iSep], 0x00, sizeof(float) * obj->halfFrameSize * obj->nChannels * 2); + + } + + } + + } \ No newline at end of file diff --git a/src/system/track2steer.h b/src/system/track2steer.h new file mode 100644 index 0000000..c77fa18 --- /dev/null +++ b/src/system/track2steer.h @@ -0,0 +1,34 @@ +#ifndef __ODAS_SYSTEM_TRACK2STEER +#define __ODAS_SYSTEM_TRACK2STEER + + #include + #include + #include + #include + + #include "../signal/gain.h" + #include "../signal/mask.h" + #include "../signal/track.h" + #include "../signal/steer.h" + + typedef struct track2steer_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int halfFrameSize; + float c; + unsigned int fS; + float * mics; + + float * factor; + float speed; + + } track2steer_obj; + + track2steer_obj * track2steer_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int halfFrameSize, const float c, const unsigned int fS, const float * mics); + + void track2steer_destroy(track2steer_obj * obj); + + void track2steer_process(track2steer_obj * obj, const tracks_obj * tracks, const gains_obj * gains, const masks_obj * masks, steers_obj * steers); + +#endif \ No newline at end of file diff --git a/src/system/xcorr2aimg.c b/src/system/xcorr2aimg.c new file mode 100644 index 0000000..d1fd4ce --- /dev/null +++ b/src/system/xcorr2aimg.c @@ -0,0 +1,52 @@ + + #include "xcorr2aimg.h" + + xcorr2aimg_obj * xcorr2aimg_construct_zero(const unsigned int aimgSize) { + + xcorr2aimg_obj * obj; + + obj = (xcorr2aimg_obj *) malloc(sizeof(xcorr2aimg_obj)); + + obj->aimgSize = aimgSize; + + return obj; + + } + + void xcorr2aimg_destroy(xcorr2aimg_obj * obj) { + + free((void *) obj); + + } + + void xcorr2aimg_process(xcorr2aimg_obj * obj, const tdoas_obj * tdoas, const indexes_obj * indexes, const spatialindexes_obj * spatialindexes, const unsigned int iCoarse, const xcorrs_obj * xcorrs, aimg_obj * aimg) { + + unsigned int iSpatialIndex; + unsigned int iPair; + unsigned int iFine; + unsigned int iPoint; + unsigned int tau; + + memset(aimg->array, 0x00, sizeof(float) * aimg->aimgSize); + + for (iFine = 0; iFine < indexes->count[iCoarse]; iFine++) { + + iPoint = indexes->array[iCoarse * indexes->nFines + iFine]; + + for (iSpatialIndex = 0; iSpatialIndex < spatialindexes->count[iPoint]; iSpatialIndex++) { + + iPair = spatialindexes->array[iPoint * spatialindexes->nPairs + iSpatialIndex]; + + tau = tdoas->array[iPoint * tdoas->nPairs + iPair]; + + aimg->array[iPoint] += xcorrs->array[iPair][tau]; + + } + + aimg->array[iPoint] /= ((float) spatialindexes->count[iPoint]); + + } + + + + } \ No newline at end of file diff --git a/src/system/xcorr2aimg.h b/src/system/xcorr2aimg.h new file mode 100644 index 0000000..8e44810 --- /dev/null +++ b/src/system/xcorr2aimg.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SYSTEM_XCORR2AIMG +#define __ODAS_SYSTEM_XCORR2AIMG + + #include + + #include "../signal/tdoa.h" + #include "../signal/index.h" + #include "../signal/xcorr.h" + #include "../signal/aimg.h" + #include "../signal/spatialindex.h" + + //! Update the states of the particle filter + typedef struct xcorr2aimg_obj { + + unsigned int aimgSize; ///< Number of points scanned. + + } xcorr2aimg_obj; + + xcorr2aimg_obj * xcorr2aimg_construct_zero(const unsigned int aimgSize); + + void xcorr2aimg_destroy(xcorr2aimg_obj * obj); + + void xcorr2aimg_process(xcorr2aimg_obj * obj, const tdoas_obj * tdoas, const indexes_obj * indexes, const spatialindexes_obj * spatialindexes, const unsigned int iCoarse, const xcorrs_obj * xcorrs, aimg_obj * aimg); + +#endif \ No newline at end of file diff --git a/src/system/xcorr2xcorr.c b/src/system/xcorr2xcorr.c new file mode 100644 index 0000000..6f149ab --- /dev/null +++ b/src/system/xcorr2xcorr.c @@ -0,0 +1,119 @@ + + #include "xcorr2xcorr.h" + + xcorr2xcorr_obj * xcorr2xcorr_construct_zero(const unsigned int frameSize) { + + xcorr2xcorr_obj * obj; + + obj = (xcorr2xcorr_obj *) malloc(sizeof(xcorr2xcorr_obj)); + + obj->frameSize = frameSize; + + return obj; + + } + + void xcorr2xcorr_destroy(xcorr2xcorr_obj * obj) { + + free((void *) obj); + + } + + void xcorr2xcorr_process_max(xcorr2xcorr_obj * obj, const xcorrs_obj * xcorrs, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, xcorrs_obj * xcorrsMax) { + + unsigned int iSignal; + unsigned int iSampleMax; + unsigned int iSampleMaxLeft; + unsigned int iSampleMaxRight; + unsigned int iSample; + unsigned int delta; + float maxValue; + + for (iSignal = 0; iSignal < xcorrs->nSignals; iSignal++) { + + if (pairs->array[iSignal] == 0x01) { + + delta = deltas->array[iSignal]; + iSampleMaxLeft = tdoas->min[iSignal]; + iSampleMaxRight = tdoas->max[iSignal]; + + for (iSampleMax = iSampleMaxLeft; iSampleMax <= iSampleMaxRight; iSampleMax++) { + + maxValue = xcorrs->array[iSignal][iSampleMax]; + + for (iSample = (iSampleMax-delta); iSample <= (iSampleMax+delta); iSample++) { + + if (xcorrs->array[iSignal][iSample] > maxValue) { + + maxValue = xcorrs->array[iSignal][iSample]; + + } + + } + + xcorrsMax->array[iSignal][iSampleMax] = maxValue; + + } + + } + + } + + } + + void xcorr2xcorr_process_reset(xcorr2xcorr_obj * obj, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, const unsigned int iPoint, xcorrs_obj * xcorrs) { + + unsigned int iSignal; + + signed int iMiddle; + float vMiddle; + signed int iLeft; + float vLeft; + signed int iRight; + float vRight; + + unsigned int iSample; + unsigned int nSamples; + unsigned int delta; + + for (iSignal = 0; iSignal < xcorrs->nSignals; iSignal++) { + + if (pairs->array[iSignal] == 0x01) { + + iMiddle = tdoas->array[iPoint * tdoas->nPairs + iSignal]; + vMiddle = xcorrs->array[iSignal][iMiddle]; + + for (iLeft = (iMiddle-1); iLeft >= 0; iLeft--) { + + vLeft = xcorrs->array[iSignal][iLeft]; + + if (vLeft > vMiddle) { + break; + } + + xcorrs->array[iSignal][iLeft] = 0.0f; + + } + for (iRight = (iMiddle+1); iRight < obj->frameSize; iRight++) { + + vRight = xcorrs->array[iSignal][iRight]; + + if (vRight > vMiddle) { + break; + } + + xcorrs->array[iSignal][iRight] = 0.0f; + + } + + delta = deltas->array[iSignal]; + iSample = tdoas->array[iPoint * tdoas->nPairs + iSignal] - delta; + nSamples = 2 * delta + 1; + + memset(&(xcorrs->array[iSignal][iSample]), 0x00, sizeof(float) * nSamples); + + } + + } + + } diff --git a/src/system/xcorr2xcorr.h b/src/system/xcorr2xcorr.h new file mode 100644 index 0000000..365a9e6 --- /dev/null +++ b/src/system/xcorr2xcorr.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SYSTEM_XCORR +#define __ODAS_SYSTEM_XCORR + + #include + #include + + #include "../signal/delta.h" + #include "../signal/xcorr.h" + #include "../signal/tdoa.h" + #include "../signal/pair.h" + + typedef struct xcorr2xcorr_obj { + + unsigned int frameSize; ///< Number of samples per frame. + + } xcorr2xcorr_obj; + + xcorr2xcorr_obj * xcorr2xcorr_construct_zero(const unsigned int frameSize); + + void xcorr2xcorr_destroy(xcorr2xcorr_obj * obj); + + void xcorr2xcorr_process_max(xcorr2xcorr_obj * obj, const xcorrs_obj * xcorrs, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, xcorrs_obj * xcorrsMax); + + void xcorr2xcorr_process_reset(xcorr2xcorr_obj * obj, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, const unsigned int iPoint, xcorrs_obj * xcorrs); + +#endif \ No newline at end of file diff --git a/src/utils/cmatrix.c b/src/utils/cmatrix.c new file mode 100644 index 0000000..30baaa9 --- /dev/null +++ b/src/utils/cmatrix.c @@ -0,0 +1,214 @@ + + #include "cmatrix.h" + + cmatrix_obj * cmatrix_construct_zero(const unsigned int nRows, const unsigned int nCols) { + + cmatrix_obj * obj; + + obj = (cmatrix_obj *) malloc(sizeof(cmatrix_obj)); + + obj->nRows = nRows; + obj->nCols = nCols; + + obj->real = (float *) malloc(sizeof(float) * nRows * nCols); + obj->imag = (float *) malloc(sizeof(float) * nRows * nCols); + + memset(obj->real, 0x00, sizeof(float) * nRows * nCols); + memset(obj->imag, 0x00, sizeof(float) * nRows * nCols); + + return obj; + + } + + cmatrix_obj * cmatrix_construct_matrix(const cmatrix_obj * cmatrix) { + + cmatrix_obj * obj; + + obj = (cmatrix_obj *) malloc(sizeof(cmatrix_obj)); + + obj->nRows = cmatrix->nRows; + obj->nCols = cmatrix->nCols; + + obj->real = (float *) malloc(sizeof(float) * obj->nRows * obj->nCols); + obj->imag = (float *) malloc(sizeof(float) * obj->nRows * obj->nCols); + + memcpy(obj->real, cmatrix->real, sizeof(float) * cmatrix->nRows * cmatrix->nCols); + memcpy(obj->imag, cmatrix->imag, sizeof(float) * cmatrix->nRows * cmatrix->nCols); + + return obj; + + } + + void cmatrix_copy_zero(cmatrix_obj * obj) { + + memset(obj->real, 0x00, sizeof(float) * obj->nRows * obj->nCols); + memset(obj->imag, 0x00, sizeof(float) * obj->nRows * obj->nCols); + + } + + void cmatrix_copy_cmatrix(cmatrix_obj * obj, const cmatrix_obj * cmatrix) { + + memcpy(obj->real, cmatrix->real, sizeof(float) * cmatrix->nRows * cmatrix->nCols); + memcpy(obj->imag, cmatrix->imag, sizeof(float) * cmatrix->nRows * cmatrix->nCols); + + } + + void cmatrix_destroy(cmatrix_obj * obj) { + + free((void *) obj->real); + free((void *) obj->imag); + free((void *) obj); + + } + + void cmatrix_transpose(cmatrix_obj * obj, const cmatrix_obj * src) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->real[iRow * obj->nRows + iCol] = src->real[iCol * obj->nRows + iRow]; + obj->imag[iRow * obj->nRows + iCol] = src->imag[iCol * obj->nRows + iRow]; + + } + + } + + } + + void cmatrix_hermitian(cmatrix_obj * obj, const cmatrix_obj * src) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->real[iRow * obj->nRows + iCol] = src->real[iCol * obj->nRows + iRow]; + obj->imag[iRow * obj->nRows + iCol] = -1.0f * src->imag[iCol * obj->nRows + iRow]; + + } + + } + + } + + void cmatrix_add(cmatrix_obj * obj, const cmatrix_obj * src1, const cmatrix_obj * src2) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->real[iRow * obj->nCols + iCol] = src1->real[iRow * obj->nCols + iCol] + src2->real[iRow * obj->nCols + iCol]; + + } + + } + + } + + void cmatrix_sub(cmatrix_obj * obj, const cmatrix_obj * src1, const cmatrix_obj * src2) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->real[iRow * obj->nCols + iCol] = src1->real[iRow * obj->nCols + iCol] - src2->real[iRow * obj->nCols + iCol]; + + } + + } + + } + + void cmatrix_mul(cmatrix_obj * obj, const cmatrix_obj * src1, const cmatrix_obj * src2) { + + unsigned int iRow; + unsigned int iCol; + unsigned int iElement; + + float real1, imag1; + float real2, imag2; + float real12, imag12; + + for (iRow = 0; iRow < src1->nRows; iRow++) { + + for (iCol = 0; iCol < src2->nCols; iCol++) { + + obj->real[iRow*obj->nCols+iCol] = 0.0f; + obj->imag[iRow*obj->nCols+iCol] = 0.0f; + + for (iElement = 0; iElement < src1->nCols; iElement++) { + + real1 = src1->real[iRow*src1->nCols+iElement]; + imag1 = src1->imag[iRow*src1->nCols+iElement]; + real2 = src2->real[iElement*src2->nCols+iCol]; + imag2 = src2->imag[iElement*src2->nCols+iCol]; + + real12 = real1 * real2 - imag1 * imag2; + imag12 = real1 * imag2 + imag1 * real2; + + obj->real[iRow*obj->nCols+iCol] += real12; + obj->imag[iRow*obj->nCols+iCol] += imag12; + + } + + } + + } + + } + + void cmatrix_scale(cmatrix_obj * obj, const cmatrix_obj * src, const float scale) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < src->nRows; iRow++) { + + for (iCol = 0; iCol < src->nCols; iCol++) { + + obj->real[iRow * obj->nCols + iCol] = scale * src->real[iRow * obj->nCols + iCol]; + obj->imag[iRow * obj->nCols + iCol] = scale * src->imag[iRow * obj->nCols + iCol]; + + } + + } + + } + + void cmatrix_zero(cmatrix_obj * obj) { + + memset(obj->real, 0x00, sizeof(float) * obj->nRows * obj->nCols); + memset(obj->imag, 0x00, sizeof(float) * obj->nRows * obj->nCols); + + } + + void cmatrix_printf(const cmatrix_obj * obj) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + printf("(%+1.5f + %+1.5fj) ",obj->real[iRow*obj->nCols+iCol],obj->imag[iRow*obj->nCols+iCol]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/utils/cmatrix.h b/src/utils/cmatrix.h new file mode 100644 index 0000000..2536257 --- /dev/null +++ b/src/utils/cmatrix.h @@ -0,0 +1,44 @@ +#ifndef __ODAS_UTILS_CMATRIX +#define __ODAS_UTILS_CMATRIX + + #include + #include + #include + #include + + typedef struct cmatrix_obj { + + float * real; + float * imag; + unsigned int nRows; + unsigned int nCols; + + } cmatrix_obj; + + cmatrix_obj * cmatrix_construct_zero(const unsigned int nRows, const unsigned int nCols); + + cmatrix_obj * cmatrix_construct_matrix(const cmatrix_obj * cmatrix); + + void cmatrix_copy_zero(cmatrix_obj * obj); + + void cmatrix_copy_cmatrix(cmatrix_obj * obj, const cmatrix_obj * cmatrix); + + void cmatrix_destroy(cmatrix_obj * obj); + + void cmatrix_transpose(cmatrix_obj * obj, const cmatrix_obj * src); + + void cmatrix_hermitian(cmatrix_obj * obj, const cmatrix_obj * src); + + void cmatrix_add(cmatrix_obj * obj, const cmatrix_obj * src1, const cmatrix_obj * src2); + + void cmatrix_sub(cmatrix_obj * obj, const cmatrix_obj * src1, const cmatrix_obj * src2); + + void cmatrix_mul(cmatrix_obj * obj, const cmatrix_obj * src1, const cmatrix_obj * src2); + + void cmatrix_scale(cmatrix_obj * obj, const cmatrix_obj * src, const float scale); + + void cmatrix_zero(cmatrix_obj * obj); + + void cmatrix_printf(const cmatrix_obj * obj); + +#endif \ No newline at end of file diff --git a/src/utils/fft.c b/src/utils/fft.c new file mode 100644 index 0000000..32d1e89 --- /dev/null +++ b/src/utils/fft.c @@ -0,0 +1,77 @@ + + #include "fft.h" + + fft_obj * fft_construct(const unsigned int frameSize) { + + fft_obj * obj; + + obj = (fft_obj *) malloc(sizeof(fft_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = frameSize/2+1; + obj->realArray = (float *) fftwf_malloc(sizeof(float) * obj->frameSize); + obj->complexArray = (fftwf_complex *) fftwf_malloc(sizeof(fftwf_complex) * obj->halfFrameSize); + + obj->R2C = fftwf_plan_dft_r2c_1d( obj->frameSize, obj->realArray, obj->complexArray, FFTW_ESTIMATE ); + obj->C2R = fftwf_plan_dft_c2r_1d( obj->frameSize, obj->complexArray, obj->realArray, FFTW_ESTIMATE ); + + return obj; + + } + + void fft_destroy(fft_obj * obj) { + + fftwf_destroy_plan( obj->R2C ); + fftwf_destroy_plan( obj->C2R ); + + fftwf_free(obj->realArray); + fftwf_free(obj->complexArray); + + fftwf_cleanup(); + + free((void *) obj); + + } + + void fft_r2c(fft_obj * obj, const float * in, float * out) { + + unsigned int iSample; + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + obj->realArray[iSample] = in[iSample]; + + } + + fftwf_execute( obj->R2C ); + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + out[iSample*2+0] = obj->complexArray[iSample][0]; + out[iSample*2+1] = obj->complexArray[iSample][1]; + + } + + + } + + void fft_c2r(fft_obj * obj, const float * in, float * out) { + + unsigned int iSample; + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + obj->complexArray[iSample][0] = in[iSample*2+0]; + obj->complexArray[iSample][1] = in[iSample*2+1]; + + } + + fftwf_execute( obj->C2R ); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + out[iSample] = obj->realArray[iSample] / ((float) obj->frameSize); + + } + + } \ No newline at end of file diff --git a/src/utils/fft.h b/src/utils/fft.h new file mode 100644 index 0000000..4246abf --- /dev/null +++ b/src/utils/fft.h @@ -0,0 +1,66 @@ +#ifndef __ODAS_UTILS_FFT +#define __ODAS_UTILS_FFT + + /** + * \file fft.h + * \author François Grondin + * \version 2.0 + * \date 2017-01-25 + * \copyright + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + #include + #include + + //! FFT object. + typedef struct fft_obj { + + unsigned int frameSize; ///< Frame size (in samples). + unsigned int halfFrameSize; ///< Half frame size (frame size divided by 2 plus 1). + fftwf_plan R2C; ///< FFTW plan for FFT from real to complex. + fftwf_plan C2R; ///< FFTW plan for FFT from complex to real. + float * realArray; ///< Array that holds all real values. + fftwf_complex * complexArray; ///< Array that holds all complex values. + + } fft_obj; + + /** Constructor. Initialize all fields to perform FFT. + \param size FFT size (in samples). + \return Pointer to the instantiated object. + */ + fft_obj * fft_construct(const unsigned int size); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void fft_destroy(fft_obj * obj); + + /** Perform Fast Fourier Transform (real vector as input, complex vector as output). + \param obj Object used. + \param in Pointer to the real array used for input. + \param out Pointer to the complex array used for output. + */ + void fft_r2c(fft_obj * obj, const float * in, float * out); + + /** Perform Inverse Fast Fourier Transform (complex vector as input, real vector as output). + \param obj Object used. + \param in Pointer to the complex array used for input. + \param out Pointer to the real array used for output. + */ + void fft_c2r(fft_obj * obj, const float * in, float * out); + +#endif \ No newline at end of file diff --git a/src/utils/fifo.c b/src/utils/fifo.c new file mode 100644 index 0000000..2fe8247 --- /dev/null +++ b/src/utils/fifo.c @@ -0,0 +1,92 @@ + + #include "fifo.h" + + fifo_obj * fifo_construct_zero(const unsigned int nMaxElements) { + + fifo_obj * obj; + + obj = (fifo_obj *) malloc(sizeof(fifo_obj)); + + obj->array = (void **) malloc(sizeof(void *) * nMaxElements); + memset(obj->array, 0x00, sizeof(void *) * nMaxElements); + + obj->nElements = 0; + obj->nMaxElements = nMaxElements; + + pthread_mutex_init(&(obj->use), NULL); + sem_init(&(obj->pop), 0, 0); + sem_init(&(obj->push), 0, nMaxElements); + + return obj; + + } + + void fifo_destroy(fifo_obj * obj) { + + sem_destroy(&(obj->pop)); + sem_destroy(&(obj->push)); + pthread_mutex_destroy(&(obj->use)); + free((void *) obj->array); + free((void *) obj); + + } + + void fifo_push(fifo_obj * obj, void * element) { + + sem_wait(&(obj->push)); + + pthread_mutex_lock(&(obj->use)); + + obj->array[obj->nElements] = element; + obj->nElements++; + + pthread_mutex_unlock(&(obj->use)); + + sem_post(&(obj->pop)); + + } + + void * fifo_pop(fifo_obj * obj) { + + void * rtnPtr; + + sem_wait(&(obj->pop)); + + pthread_mutex_lock(&(obj->use)); + + rtnPtr = obj->array[0]; + memmove(&(obj->array[0]), &(obj->array[1]), (obj->nElements-1) * sizeof(void *)); + obj->nElements--; + memset(&(obj->array[obj->nElements]), 0x00, (obj->nMaxElements-obj->nElements) * sizeof(void *)); + + pthread_mutex_unlock(&(obj->use)); + + sem_post(&(obj->push)); + + return rtnPtr; + + } + + int fifo_nElements(fifo_obj * obj) { + + int nElements; + + pthread_mutex_lock(&(obj->use)); + nElements = obj->nElements; + pthread_mutex_unlock(&(obj->use)); + + return nElements; + + } + + void fifo_printf(const fifo_obj * obj) { + + unsigned int iElement; + + for (iElement = 0; iElement < obj->nMaxElements; iElement++) { + + printf("(%03u): %p\n",iElement,obj->array[iElement]); + + } + + } \ No newline at end of file diff --git a/src/utils/fifo.h b/src/utils/fifo.h new file mode 100644 index 0000000..8e3e05c --- /dev/null +++ b/src/utils/fifo.h @@ -0,0 +1,34 @@ +#ifndef __ODAS_UTILS_FIFO +#define __ODAS_UTILS_FIFO + + #include + #include + #include + #include + #include + + typedef struct fifo_obj { + + void ** array; + unsigned int nElements; + unsigned int nMaxElements; + + pthread_mutex_t use; + sem_t push; + sem_t pop; + + } fifo_obj; + + fifo_obj * fifo_construct_zero(const unsigned int nMaxElements); + + void fifo_destroy(fifo_obj * obj); + + void fifo_push(fifo_obj * obj, void * element); + + void * fifo_pop(fifo_obj * obj); + + int fifo_nElements(fifo_obj * obj); + + void fifo_printf(const fifo_obj * obj); + +#endif \ No newline at end of file diff --git a/src/utils/gaussian.c b/src/utils/gaussian.c new file mode 100644 index 0000000..7440ee2 --- /dev/null +++ b/src/utils/gaussian.c @@ -0,0 +1,558 @@ + + #include "gaussian.h" + + gaussian_1d_obj * gaussian_1d_construct_zero(void) { + + gaussian_1d_obj * obj; + + obj = (gaussian_1d_obj *) malloc(sizeof(gaussian_1d_obj)); + + obj->weight = 1.0f; + obj->mu_x = 0.0f; + obj->sigma_x = 1.0f; + obj->scaleFactor = (obj->weight / (obj->sigma_x * powf(2*M_PI,(1.0f/2.0f)))); + + return obj; + + } + + gaussian_2d_obj * gaussian_2d_construct_zero(void) { + + gaussian_2d_obj * obj; + + obj = (gaussian_2d_obj *) malloc(sizeof(gaussian_2d_obj)); + + obj->weight = 1.0f; + obj->mu_x = 0.0f; + obj->mu_y = 0.0f; + obj->sigma_x = 1.0f; + obj->sigma_y = 1.0f; + obj->scaleFactor = (obj->weight / (obj->sigma_x*obj->sigma_y * powf(2*M_PI,(2.0f/2.0f)))); + + return obj; + + } + + gaussian_3d_obj * gaussian_3d_construct_zero(void) { + + gaussian_3d_obj * obj; + + obj = (gaussian_3d_obj *) malloc(sizeof(gaussian_3d_obj)); + + obj->weight = 1.0f; + obj->mu_x = 0.0f; + obj->mu_y = 0.0f; + obj->mu_z = 0.0f; + obj->sigma_x = 1.0f; + obj->sigma_y = 1.0f; + obj->sigma_z = 1.0f; + obj->scaleFactor = (obj->weight / (obj->sigma_x*obj->sigma_y*obj->sigma_z * powf(2*M_PI,(3.0f/2.0f)))); + + return obj; + + } + + gaussian_1d_obj * gaussian_1d_construct_weightmusigma(const float weight, const float mu_x, const float sigma_x) { + + gaussian_1d_obj * obj; + + obj = (gaussian_1d_obj *) malloc(sizeof(gaussian_1d_obj)); + + obj->weight = weight; + obj->mu_x = mu_x; + obj->sigma_x = sigma_x; + obj->scaleFactor = (obj->weight / (obj->sigma_x * powf(2*M_PI,(1.0f/2.0f)))); + + return obj; + + } + + gaussian_2d_obj * gaussian_2d_construct_weigthmusigma(const float weight, const float mu_x, const float mu_y, const float sigma_x, const float sigma_y) { + + gaussian_2d_obj * obj; + + obj = (gaussian_2d_obj *) malloc(sizeof(gaussian_2d_obj)); + + obj->weight = weight; + obj->mu_x = mu_x; + obj->mu_y = mu_y; + obj->sigma_x = sigma_x; + obj->sigma_y = sigma_y; + obj->scaleFactor = (obj->weight / (obj->sigma_x*obj->sigma_y * powf(2*M_PI,(2.0f/2.0f)))); + + return obj; + + } + + gaussian_3d_obj * gaussian_3d_construct_weightmusigma(const float weight, const float mu_x, const float mu_y, const float mu_z, const float sigma_x, const float sigma_y, const float sigma_z) { + + gaussian_3d_obj * obj; + + obj = (gaussian_3d_obj *) malloc(sizeof(gaussian_3d_obj)); + + obj->weight = weight; + obj->mu_x = mu_x; + obj->mu_y = mu_y; + obj->mu_z = mu_z; + obj->sigma_x = sigma_x; + obj->sigma_y = sigma_y; + obj->sigma_z = sigma_z; + obj->scaleFactor = (obj->weight / (obj->sigma_x*obj->sigma_y*obj->sigma_z * powf(2*M_PI,(3.0f/2.0f)))); + + return obj; + + } + + gaussian_1d_obj * gaussian_1d_construct_gaussian(const gaussian_1d_obj * gaussian) { + + gaussian_1d_obj * obj; + + obj = (gaussian_1d_obj *) malloc(sizeof(gaussian_1d_obj)); + + obj->weight = gaussian->weight; + obj->mu_x = gaussian->mu_x; + obj->sigma_x = gaussian->sigma_x; + obj->scaleFactor = (obj->weight / (obj->sigma_x * powf(2*M_PI,(1.0f/2.0f)))); + + return obj; + + } + + gaussian_2d_obj * gaussian_2d_construct_gaussian(const gaussian_2d_obj * gaussian) { + + gaussian_2d_obj * obj; + + obj = (gaussian_2d_obj *) malloc(sizeof(gaussian_2d_obj)); + + obj->weight = gaussian->weight; + obj->mu_x = gaussian->mu_x; + obj->mu_y = gaussian->mu_y; + obj->sigma_x = gaussian->sigma_x; + obj->sigma_y = gaussian->sigma_y; + obj->scaleFactor = (obj->weight / (obj->sigma_x*obj->sigma_y * powf(2*M_PI,(2.0f/2.0f)))); + + return obj; + + } + + gaussian_3d_obj * gaussian_3d_construct_gaussian(const gaussian_3d_obj * gaussian) { + + gaussian_3d_obj * obj; + + obj = (gaussian_3d_obj *) malloc(sizeof(gaussian_3d_obj)); + + obj->weight = gaussian->weight; + obj->mu_x = gaussian->mu_x; + obj->mu_y = gaussian->mu_y; + obj->mu_z = gaussian->mu_z; + obj->sigma_x = gaussian->sigma_x; + obj->sigma_y = gaussian->sigma_y; + obj->sigma_z = gaussian->sigma_z; + obj->scaleFactor = (obj->weight / (obj->sigma_x*obj->sigma_y*obj->sigma_z * powf(2*M_PI,(3.0f/2.0f)))); + + return obj; + + } + + void gaussian_1d_destroy(gaussian_1d_obj * obj) { + + free((void *) obj); + + } + + void gaussian_2d_destroy(gaussian_2d_obj * obj) { + + free((void *) obj); + + } + + void gaussian_3d_destroy(gaussian_3d_obj * obj) { + + free((void *) obj); + + } + + float gaussian_1d_eval(const gaussian_1d_obj * obj, const float x) { + + float value; + float diff_x; + float diff2_x; + float sigma_x; + float sigma2_x; + float expr; + + diff_x = x - obj->mu_x; + diff2_x = diff_x * diff_x; + + sigma_x = obj->sigma_x; + sigma2_x = sigma_x * sigma_x; + + expr = -0.5f * (diff2_x/sigma2_x); + + value = obj->scaleFactor * expf(expr); + + return value; + + } + + float gaussian_2d_eval(const gaussian_2d_obj * obj, const float x, const float y) { + + float value; + float diff_x, diff_y; + float diff2_x, diff2_y; + float sigma_x, sigma_y; + float sigma2_x, sigma2_y; + float expr; + + diff_x = x - obj->mu_x; + diff_y = y - obj->mu_y; + diff2_x = diff_x * diff_x; + diff2_y = diff_y * diff_y; + sigma_x = obj->sigma_x; + sigma_y = obj->sigma_y; + sigma2_x = sigma_x * sigma_x; + sigma2_y = sigma_y * sigma_y; + + expr = -0.5f * ((diff2_x/sigma2_x)+(diff2_y/sigma2_y)); + + value = obj->scaleFactor * expf(expr); + + return value; + + } + + float gaussian_3d_eval(const gaussian_3d_obj * obj, const float x, const float y, const float z) { + + float value; + float diff_x, diff_y, diff_z; + float diff2_x, diff2_y, diff2_z; + float sigma_x, sigma_y, sigma_z; + float sigma2_x, sigma2_y, sigma2_z; + float expr; + + diff_x = x - obj->mu_x; + diff_y = y - obj->mu_y; + diff_z = z - obj->mu_z; + diff2_x = diff_x * diff_x; + diff2_y = diff_y * diff_y; + diff2_z = diff_z * diff_z; + sigma_x = obj->sigma_x; + sigma_y = obj->sigma_y; + sigma_z = obj->sigma_z; + sigma2_x = sigma_x * sigma_x; + sigma2_y = sigma_y * sigma_y; + sigma2_z = sigma_z * sigma_z; + + expr = -0.5f * ((diff2_x/sigma2_x)+(diff2_y/sigma2_y)+(diff2_z/sigma2_z)); + + value = obj->scaleFactor * expf(expr); + + return value; + + } + + void gaussian_1d_printf(const gaussian_1d_obj * obj) { + + printf("weight = %+1.3f, mu = %+1.3f, sigma = %+1.3f\n",obj->weight, obj->mu_x,obj->sigma_x); + + } + + void gaussian_2d_printf(const gaussian_2d_obj * obj) { + + printf("weight = %+1.3f, mu = (%+1.3f,%+1.3f), sigma = (%+1.3f,%+1.3f)\n",obj->weight, obj->mu_x,obj->mu_y,obj->sigma_x,obj->sigma_y); + + } + + void gaussian_3d_printf(const gaussian_3d_obj * obj) { + + printf("weight = %+1.3f, mu = (%+1.3f,%+1.3f,%+1.3f), sigma = (%+1.3f,%+1.3f,%+1.3f)\n",obj->weight, obj->mu_x,obj->mu_y,obj->mu_z,obj->sigma_x,obj->sigma_y,obj->sigma_z); + + } + + gaussians_1d_obj * gaussians_1d_construct_null(const unsigned int nSignals) { + + gaussians_1d_obj * obj; + unsigned int iSignal; + + obj = (gaussians_1d_obj *) malloc(sizeof(gaussians_1d_obj)); + + obj->nSignals = nSignals; + obj->array = (gaussian_1d_obj **) malloc(sizeof(gaussian_1d_obj *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = NULL; + } + + return obj; + + } + + gaussians_2d_obj * gaussians_2d_construct_null(const unsigned int nSignals) { + + gaussians_2d_obj * obj; + unsigned int iSignal; + + obj = (gaussians_2d_obj *) malloc(sizeof(gaussians_2d_obj)); + + obj->nSignals = nSignals; + obj->array = (gaussian_2d_obj **) malloc(sizeof(gaussian_2d_obj *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = NULL; + } + + return obj; + + } + + gaussians_3d_obj * gaussians_3d_construct_null(const unsigned int nSignals) { + + gaussians_3d_obj * obj; + unsigned int iSignal; + + obj = (gaussians_3d_obj *) malloc(sizeof(gaussians_3d_obj)); + + obj->nSignals = nSignals; + obj->array = (gaussian_3d_obj **) malloc(sizeof(gaussian_3d_obj *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = NULL; + } + + return obj; + + } + + gaussians_1d_obj * gaussians_1d_construct_gaussians(const gaussians_1d_obj * gaussians) { + + gaussians_1d_obj * obj; + unsigned int iSignal; + + obj = (gaussians_1d_obj *) malloc(sizeof(gaussians_1d_obj)); + + obj->nSignals = gaussians->nSignals; + obj->array = (gaussian_1d_obj **) malloc(sizeof(gaussian_1d_obj *) * gaussians->nSignals); + + for (iSignal = 0; iSignal < gaussians->nSignals; iSignal++) { + obj->array[iSignal] = gaussian_1d_construct_gaussian(gaussians->array[iSignal]); + } + + return obj; + + } + + gaussians_2d_obj * gaussians_2d_construct_gaussians(const gaussians_2d_obj * gaussians) { + + gaussians_2d_obj * obj; + unsigned int iSignal; + + obj = (gaussians_2d_obj *) malloc(sizeof(gaussians_2d_obj)); + + obj->nSignals = gaussians->nSignals; + obj->array = (gaussian_2d_obj **) malloc(sizeof(gaussian_2d_obj *) * gaussians->nSignals); + + for (iSignal = 0; iSignal < gaussians->nSignals; iSignal++) { + obj->array[iSignal] = gaussian_2d_construct_gaussian(gaussians->array[iSignal]); + } + + return obj; + + } + + gaussians_3d_obj * gaussians_3d_construct_gaussians(const gaussians_3d_obj * gaussians) { + + gaussians_3d_obj * obj; + unsigned int iSignal; + + obj = (gaussians_3d_obj *) malloc(sizeof(gaussians_3d_obj)); + + obj->nSignals = gaussians->nSignals; + obj->array = (gaussian_3d_obj **) malloc(sizeof(gaussian_3d_obj *) * gaussians->nSignals); + + for (iSignal = 0; iSignal < gaussians->nSignals; iSignal++) { + obj->array[iSignal] = gaussian_3d_construct_gaussian(gaussians->array[iSignal]); + } + + return obj; + + } + + void gaussians_1d_destroy(gaussians_1d_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + if (obj->array[iSignal] != NULL) { + gaussian_1d_destroy(obj->array[iSignal]); + } + + } + + free((void *) obj->array); + + free((void *) obj); + + } + + void gaussians_2d_destroy(gaussians_2d_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + if (obj->array[iSignal] != NULL) { + gaussian_2d_destroy(obj->array[iSignal]); + } + + } + + free((void *) obj->array); + + free((void *) obj); + + } + + void gaussians_3d_destroy(gaussians_3d_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + if (obj->array[iSignal] != NULL) { + gaussian_3d_destroy(obj->array[iSignal]); + } + + } + + free((void *) obj->array); + + free((void *) obj); + + } + + float gaussians_1d_eval(const gaussians_1d_obj * obj, const float x) { + + unsigned int iSignal; + float value; + + value = 0.0f; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + value += gaussian_1d_eval(obj->array[iSignal], x); + + } + + return value; + + } + + float gaussians_2d_eval(const gaussians_2d_obj * obj, const float x, const float y) { + + unsigned int iSignal; + float value; + + value = 0.0f; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + value += gaussian_2d_eval(obj->array[iSignal], x, y); + + } + + return value; + + } + + float gaussians_3d_eval(const gaussians_3d_obj * obj, const float x, const float y, const float z) { + + unsigned int iSignal; + float value; + + value = 0.0f; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + value += gaussian_3d_eval(obj->array[iSignal], x, y, z); + + } + + return value; + + } + + void gaussians_1d_printf(const gaussians_1d_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%03u): ",iSignal); + + if (obj->array[iSignal] != NULL) { + + printf("weight = %+1.3f, mu = %+1.3f, sigma = %+1.3f",obj->array[iSignal]->weight, obj->array[iSignal]->mu_x,obj->array[iSignal]->sigma_x); + + } + else { + + printf("(null)"); + + } + + printf("\n"); + + } + + } + + void gaussians_2d_printf(const gaussians_2d_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%03u): ",iSignal); + + if (obj->array[iSignal] != NULL) { + + printf("weight = %+1.3f, mu = (%+1.3f,%+1.3f), sigma = (%+1.3f,%+1.3f)",obj->array[iSignal]->weight, obj->array[iSignal]->mu_x,obj->array[iSignal]->mu_y,obj->array[iSignal]->sigma_x,obj->array[iSignal]->sigma_y); + + } + else { + + printf("(null)"); + + } + + printf("\n"); + + } + + } + + void gaussians_3d_printf(const gaussians_3d_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + printf("(%03u): ",iSignal); + + if (obj->array[iSignal] != NULL) { + + printf("weight = %+1.3f, mu = (%+1.3f,%+1.3f,%+1.3f), sigma = (%+1.3f,%+1.3f,%+1.3f)",obj->array[iSignal]->weight, obj->array[iSignal]->mu_x,obj->array[iSignal]->mu_y,obj->array[iSignal]->mu_z,obj->array[iSignal]->sigma_x,obj->array[iSignal]->sigma_y,obj->array[iSignal]->sigma_z); + + } + else { + + printf("(null)"); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/utils/gaussian.h b/src/utils/gaussian.h new file mode 100644 index 0000000..39e9625 --- /dev/null +++ b/src/utils/gaussian.h @@ -0,0 +1,275 @@ +#ifndef __ODAS_UTILS_GAUSSIAN +#define __ODAS_UTILS_GAUSSIAN + + #include + #include + #include + + //! 1-D gaussian + typedef struct gaussian_1d_obj { + + float weight; ///< Weight of the gaussian. + float mu_x; ///< Mean of the gaussian. + float sigma_x; ///< Standard deviation of the gaussian. + float scaleFactor; ///< Precomputed scale factor for the exponential function. + + } gaussian_1d_obj; + + //! 2-D gaussian + typedef struct gaussian_2d_obj { + + float weight; ///< Weight of the gaussian. + float mu_x; ///< X-component of the mean of the gaussian. + float mu_y; ///< Y-component of the mean of the gaussian. + float sigma_x; ///< X-component of the standard deviation of the gaussian. + float sigma_y; ///< Y-component of the standard deviation of the gaussian. + float scaleFactor; ///< Precomputed scale factor for the exponential function. + + } gaussian_2d_obj; + + //! 3-D gaussian + typedef struct gaussian_3d_obj { + + float weight; ///< Weight of the gaussian. + float mu_x; ///< X-component of the mean of the gaussian. + float mu_y; ///< Y-component of the mean of the gaussian. + float mu_z; ///< Z-component of the mean of the gaussian. + float sigma_x; ///< X-component of the standard deviation of the gaussian. + float sigma_y; ///< Y-component of the standard deviation of the gaussian. + float sigma_z; ///< Z-component of the standard deviation of the gaussian. + float scaleFactor; ///< Precomputed scale factor for the exponential function. + + } gaussian_3d_obj; + + //! 1-D gaussian mixture model + typedef struct gaussians_1d_obj { + + unsigned int nSignals; ///< Number of gaussians. + gaussian_1d_obj ** array; ///< List of gaussians. + + } gaussians_1d_obj; + + //! 2-D gaussian mixture model + typedef struct gaussians_2d_obj { + + unsigned int nSignals; ///< Number of gaussians. + gaussian_2d_obj ** array; ///< List of gaussians. + + } gaussians_2d_obj; + + //! 3-D gaussian mixture model + typedef struct gaussians_3d_obj { + + unsigned int nSignals; ///< Number of gaussians. + gaussian_3d_obj ** array; ///< List of gaussians. + + } gaussians_3d_obj; + + /** Constructor. Initialize all fields to zero (weight to 1, mean to 0, standard deviation to 1). + \return Pointer to the instantiated object. + */ + gaussian_1d_obj * gaussian_1d_construct_zero(void); + + /** Constructor. Initialize all fields to zero (weight to 1, means to 0, standard deviations to 1). + \return Pointer to the instantiated object. + */ + gaussian_2d_obj * gaussian_2d_construct_zero(void); + + /** Constructor. Initialize all fields to zero (weight to 1, means to 0, standard deviations to 1). + \return Pointer to the instantiated object. + */ + gaussian_3d_obj * gaussian_3d_construct_zero(void); + + /** Constructor. Initialize all fields to weight, mu and sigma. + \param weight Weight value. + \param mu_x Mean value. + \param sigma_x Standard deviation value. + \return Pointer to the instantiated object. + */ + gaussian_1d_obj * gaussian_1d_construct_weightmusigma(const float weight, const float mu_x, const float sigma_x); + + /** Constructor. Initialize all fields to weight, mus and sigmas. + \param weight Weight value. + \param mu_x X-coordinate of the mean. + \param mu_y Y-coordinate of the mean. + \param sigma_x X-coordinate of the standard deviation. + \param sigma_y Y-coordinate of the standard deviation. + \return Pointer to the instantiated object. + */ + gaussian_2d_obj * gaussian_2d_construct_weightmusigma(const float weight, const float mu_x, const float mu_y, const float sigma_x, const float sigma_y); + + /** Constructor. Initialize all fields to weight, mus and sigmas. + \param weight Weight value. + \param mu_x X-coordinate of the mean. + \param mu_y Y-coordinate of the mean. + \param mu_z Z-coordinate of the mean. + \param sigma_x X-coordinate of the standard deviation. + \param sigma_y Y-coordinate of the standard deviation. + \param sigma_z Z-coordinate of the standard deviation. + \return Pointer to the instantiated object. + */ + gaussian_3d_obj * gaussian_3d_construct_weightmusigma(const float weight, const float mu_x, const float mu_y, const float mu_z, const float sigma_x, const float sigma_y, const float sigma_z); + + /** Constructor. Clone the object. + \param gaussian Object to cloned. + \return Pointer to the instantiated object. + */ + gaussian_1d_obj * gaussian_1d_construct_gaussian(const gaussian_1d_obj * gaussian); + + /** Constructor. Clone the object. + \param gaussian Object to cloned. + \return Pointer to the instantiated object. + */ + gaussian_2d_obj * gaussian_2d_construct_gaussian(const gaussian_2d_obj * gaussian); + + /** Constructor. Clone the object. + \param gaussian Object to cloned. + \return Pointer to the instantiated object. + */ + gaussian_3d_obj * gaussian_3d_construct_gaussian(const gaussian_3d_obj * gaussian); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void gaussian_1d_destroy(gaussian_1d_obj * obj); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void gaussian_2d_destroy(gaussian_2d_obj * obj); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void gaussian_3d_destroy(gaussian_3d_obj * obj); + + /** Evaluate the gaussian at x. + \param obj Object to be used. + \param x Value of x. + \return Value of the gaussian. + */ + float gaussian_1d_eval(const gaussian_1d_obj * obj, const float x); + + /** Evaluate the gaussian at x and y. + \param obj Object to be used. + \param x Value of x. + \param y Value of y. + \return Value of the gaussian. + */ + float gaussian_2d_eval(const gaussian_2d_obj * obj, const float x, const float y); + + /** Evaluate the gaussian at x, y and z. + \param obj Object to be used. + \param x Value of x. + \param y Value of y. + \param z Value of z. + \return Value of the gaussian. + */ + float gaussian_3d_eval(const gaussian_3d_obj * obj, const float x, const float y, const float z); + + /** Print the content of the gaussian. + \param obj Object to be used. + */ + void gaussian_1d_printf(const gaussian_1d_obj * obj); + + /** Print the content of the gaussian. + \param obj Object to be used. + */ + void gaussian_2d_printf(const gaussian_2d_obj * obj); + + /** Print the content of the gaussian. + \param obj Object to be used. + */ + void gaussian_3d_printf(const gaussian_3d_obj * obj); + + /** Constructor. Fill the array of objects with null pointers. + \param nSignals Number of gaussians. + \return Pointer to the instantiated object. + */ + gaussians_1d_obj * gaussians_1d_construct_null(const unsigned int nSignals); + + /** Constructor. Fill the array of objects with null pointers. + \param nSignals Number of gaussians. + \return Pointer to the instantiated object. + */ + gaussians_2d_obj * gaussians_2d_construct_null(const unsigned int nSignals); + + /** Constructor. Fill the array of objects with null pointers. + \param nSignals Number of gaussians. + \return Pointer to the instantiated object. + */ + gaussians_3d_obj * gaussians_3d_construct_null(const unsigned int nSignals); + + /** Constructor. Clone the gaussians. + \param gaussians Object to be cloned. + \return Pointer to the instantiated object. + */ + gaussians_1d_obj * gaussians_1d_construct_gaussians(const gaussians_1d_obj * gaussians); + + /** Constructor. Clone the gaussians. + \param gaussians Object to be cloned. + \return Pointer to the instantiated object. + */ + gaussians_2d_obj * gaussians_2d_construct_gaussians(const gaussians_2d_obj * gaussians); + + /** Constructor. Clone the gaussians. + \param gaussians Object to be cloned. + \return Pointer to the instantiated object. + */ + gaussians_3d_obj * gaussians_3d_construct_gaussians(const gaussians_3d_obj * gaussians); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void gaussians_1d_destroy(gaussians_1d_obj * obj); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void gaussians_2d_destroy(gaussians_2d_obj * obj); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void gaussians_3d_destroy(gaussians_3d_obj * obj); + + /** Evaluate the gaussian mixture model (GMM) at x. + \param obj Object to be used. + \param x Value of x. + \return Value of the GMM. + */ + float gaussians_1d_eval(const gaussians_1d_obj * obj, const float x); + + /** Evaluate the gaussian mixture model (GMM) at x and y. + \param obj Object to be used. + \param x Value of x. + \param y Value of y. + \return Value of the GMM. + */ + float gaussians_2d_eval(const gaussians_2d_obj * obj, const float x, const float y); + + /** Evaluate the gaussian mixture model (GMM) at x, y and z. + \param obj Object to be used. + \param x Value of x. + \param y Value of y. + \param z Value of z. + \return Value of the GMM. + */ + float gaussians_3d_eval(const gaussians_3d_obj * obj, const float x, const float y, const float z); + + /** Print the content of the gaussian mixture model (GMM). + \param obj Object to be used. + */ + void gaussians_1d_printf(const gaussians_1d_obj * obj); + + /** Print the content of the gaussian mixture model (GMM). + \param obj Object to be used. + */ + void gaussians_2d_printf(const gaussians_2d_obj * obj); + + /** Print the content of the gaussian mixture model (GMM). + \param obj Object to be used. + */ + void gaussians_3d_printf(const gaussians_3d_obj * obj); + +#endif \ No newline at end of file diff --git a/src/utils/gaussjordan.c b/src/utils/gaussjordan.c new file mode 100644 index 0000000..141676e --- /dev/null +++ b/src/utils/gaussjordan.c @@ -0,0 +1,169 @@ + + #include "gaussjordan.h" + + gaussjordan_obj * gaussjordan_construct_zero(const unsigned int nRowsCols, const float epsilon) { + + gaussjordan_obj * obj; + + obj = (gaussjordan_obj *) malloc(sizeof(gaussjordan_obj)); + + obj->nRowsCols = nRowsCols; + obj->epsilon = epsilon; + + obj->array = (float *) malloc(sizeof(float) * nRowsCols * nRowsCols); + memset(obj->array, 0x00, sizeof(float) * nRowsCols * nRowsCols); + + return obj; + + } + + void gaussjordan_destroy(gaussjordan_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void gaussjordan_process(gaussjordan_obj * obj, const float * src, float * dest) { + + unsigned int nRows; + unsigned int nCols; + + signed int iRow; + signed int iRowUnder; + signed int iRowOther; + signed int iCol; + + float epsilon; + char nonZero; + char singular; + + float element1; + float element2; + float gain; + + epsilon = 1E-20f; + + nRows = obj->nRowsCols; + nCols = obj->nRowsCols; + + // Copy source + + memcpy(obj->array, src, sizeof(float) * nRows * nCols); + + // Create identity matrix + + memset(dest, 0x00, sizeof(float) * nRows * nCols); + + for (iRow = 0; iRow < nRows; iRow++) { + + dest[iRow * nRows + iRow] = 1.0f; + + } + + // Invert + + singular = 0x00; + + for (iRow = 0; iRow < nRows; iRow++) { + + // Check if the leading number is zero + + nonZero = 0x00; + + for (iRowUnder = iRow; iRowUnder < nRows; iRowUnder++) { + + if (fabs(obj->array[iRowUnder * nRows + iRow]) > epsilon) { + + nonZero = 0x01; + break; + + } + + } + + // If all following terms are zero, then cannot invert matrix + + if (nonZero == 0x00) { + + singular = 0x01; + break; + + } + + // If the leading number is zero, then swap rows in both matrices + + if (iRow != iRowUnder) { + + // Swap memory + + for (iCol = 0; iCol < nCols; iCol++) { + + element1 = obj->array[iRow * nRows + iCol]; + element2 = obj->array[iRowUnder * nRows + iCol]; + + obj->array[iRow * nRows + iCol] = element2; + obj->array[iRowUnder * nRows + iCol] = element1; + + element1 = dest[iRow * nRows + iCol]; + element2 = dest[iRowUnder * nRows + iCol]; + + dest[iRow * nRows + iCol] = element2; + dest[iRowUnder * nRows + iCol] = element1; + + } + + } + + // Normalize to generate a leading 1 + + gain = 1.0f / obj->array[iRow * nRows + iRow]; + + for (iCol = iRow; iCol < nCols; iCol++) { + + obj->array[iRow * nRows + iCol] *= gain; + + } + + for (iCol = 0; iCol < nCols; iCol++) { + + dest[iRow * nRows + iCol] *= gain; + + } + + // Subtract from all rows + + for (iRowOther = 0; iRowOther < nRows; iRowOther++) { + + if (iRowOther != iRow) { + + gain = obj->array[iRowOther * nRows + iRow]; + + for (iCol = 0; iCol < nCols; iCol++) { + + obj->array[iRowOther * nRows + iCol] -= (obj->array[iRow * nRows + iCol] * gain); + dest[iRowOther * nRows + iCol] -= (dest[iRow * nRows + iCol] * gain); + + } + + } + + } + + } + + if (singular != 0x00) { + + for (iRow = 0; iRow < nRows; iRow++) { + + for (iCol = 0; iCol < nCols; iCol++) { + + dest[iRow * nRows + iCol] = +INFINITY; + + } + + } + + } + + } \ No newline at end of file diff --git a/src/utils/gaussjordan.h b/src/utils/gaussjordan.h new file mode 100644 index 0000000..47f1c08 --- /dev/null +++ b/src/utils/gaussjordan.h @@ -0,0 +1,22 @@ +#ifndef __ODAS_UTILS_GAUSSJORDAN +#define __ODAS_UTILS_GAUSSJORDAN + + #include + #include + #include + + typedef struct gaussjordan_obj { + + unsigned int nRowsCols; + float * array; + float epsilon; + + } gaussjordan_obj; + + gaussjordan_obj * gaussjordan_construct_zero(const unsigned int nRowsCols, const float epsilon); + + void gaussjordan_destroy(gaussjordan_obj * obj); + + void gaussjordan_process(gaussjordan_obj * obj, const float * src, float * dest); + +#endif \ No newline at end of file diff --git a/src/utils/inverse.c b/src/utils/inverse.c new file mode 100644 index 0000000..35c8e25 --- /dev/null +++ b/src/utils/inverse.c @@ -0,0 +1,98 @@ + + #include "inverse.h" + + inverse_real_obj * inverse_real_construct_zero(const unsigned int nRowsCols, const float epsilon) { + + inverse_real_obj * obj; + + obj = (inverse_real_obj *) malloc(sizeof(inverse_real_obj)); + + obj->nRowsCols = nRowsCols; + obj->gaussjordan = gaussjordan_construct_zero(nRowsCols, epsilon); + + return obj; + + } + + void inverse_real_destroy(inverse_real_obj * obj) { + + gaussjordan_destroy(obj->gaussjordan); + free((void *) obj); + + } + + void inverse_real_process(inverse_real_obj * obj, const matrix_obj * src, matrix_obj * dest) { + + gaussjordan_process(obj->gaussjordan, src->array, dest->array); + + } + + inverse_complex_obj * inverse_complex_construct_zero(const unsigned int nRowsCols, const float epsilon) { + + inverse_complex_obj * obj; + + obj = (inverse_complex_obj *) malloc(sizeof(inverse_complex_obj)); + + obj->nRowsCols = nRowsCols; + obj->gaussjordan = gaussjordan_construct_zero(nRowsCols, epsilon); + + obj->A = matrix_construct_zero(nRowsCols,nRowsCols); + obj->B = matrix_construct_zero(nRowsCols,nRowsCols); + obj->Ainv = matrix_construct_zero(nRowsCols,nRowsCols); + obj->Binv = matrix_construct_zero(nRowsCols,nRowsCols); + obj->BAinv = matrix_construct_zero(nRowsCols,nRowsCols); + obj->ABinv = matrix_construct_zero(nRowsCols,nRowsCols); + obj->BAinvB = matrix_construct_zero(nRowsCols,nRowsCols); + obj->ABinvA = matrix_construct_zero(nRowsCols,nRowsCols); + obj->ApBAinvB = matrix_construct_zero(nRowsCols,nRowsCols); + obj->BpABinvA = matrix_construct_zero(nRowsCols,nRowsCols); + obj->ApBAinvB_inv = matrix_construct_zero(nRowsCols,nRowsCols); + obj->BpABinvA_inv = matrix_construct_zero(nRowsCols,nRowsCols); + obj->mBpABinvA_inv = matrix_construct_zero(nRowsCols,nRowsCols); + + return obj; + + } + + void inverse_complex_destroy(inverse_complex_obj * obj) { + + matrix_destroy(obj->A); + matrix_destroy(obj->B); + matrix_destroy(obj->Ainv); + matrix_destroy(obj->Binv); + matrix_destroy(obj->BAinv); + matrix_destroy(obj->ABinv); + matrix_destroy(obj->BAinvB); + matrix_destroy(obj->ABinvA); + matrix_destroy(obj->ApBAinvB); + matrix_destroy(obj->BpABinvA); + matrix_destroy(obj->ApBAinvB_inv); + matrix_destroy(obj->BpABinvA_inv); + matrix_destroy(obj->mBpABinvA_inv); + + } + + void inverse_complex_process(inverse_complex_obj * obj, const cmatrix_obj * src, cmatrix_obj * dest) { + + memcpy(obj->A->array, src->real, sizeof(float) * obj->nRowsCols * obj->nRowsCols); + memcpy(obj->B->array, src->imag, sizeof(float) * obj->nRowsCols * obj->nRowsCols); + + gaussjordan_process(obj->gaussjordan, obj->A->array, obj->Ainv->array); + gaussjordan_process(obj->gaussjordan, obj->B->array, obj->Binv->array); + + matrix_mul(obj->BAinv, obj->B, obj->Ainv); + matrix_mul(obj->ABinv, obj->A, obj->Binv); + matrix_mul(obj->BAinvB, obj->BAinv, obj->B); + matrix_mul(obj->ABinvA, obj->ABinv, obj->A); + matrix_add(obj->ApBAinvB, obj->A, obj->BAinvB); + matrix_add(obj->BpABinvA, obj->B, obj->ABinvA); + + gaussjordan_process(obj->gaussjordan, obj->ApBAinvB->array, obj->ApBAinvB_inv->array); + gaussjordan_process(obj->gaussjordan, obj->BpABinvA->array, obj->BpABinvA_inv->array); + + matrix_scale(obj->mBpABinvA_inv, obj->BpABinvA_inv, -1.0f); + + memcpy(dest->real, obj->ApBAinvB_inv->array, sizeof(float) * obj->nRowsCols * obj->nRowsCols); + memcpy(dest->imag, obj->mBpABinvA_inv->array, sizeof(float) * obj->nRowsCols * obj->nRowsCols); + + } \ No newline at end of file diff --git a/src/utils/inverse.h b/src/utils/inverse.h new file mode 100644 index 0000000..b6a256d --- /dev/null +++ b/src/utils/inverse.h @@ -0,0 +1,56 @@ +#ifndef __ODAS_UTILS_INVERSE +#define __ODAS_UTILS_INVERSE + + #include "gaussjordan.h" + #include "matrix.h" + #include "cmatrix.h" + + typedef struct inverse_real_obj { + + unsigned int nRowsCols; + + gaussjordan_obj * gaussjordan; + + } inverse_real_obj; + + typedef struct inverse_complex_obj { + + unsigned int nRowsCols; + + gaussjordan_obj * gaussjordan; + + matrix_obj * A; + matrix_obj * B; + + matrix_obj * Ainv; + matrix_obj * Binv; + + matrix_obj * BAinv; + matrix_obj * ABinv; + + matrix_obj * BAinvB; + matrix_obj * ABinvA; + + matrix_obj * ApBAinvB; + matrix_obj * BpABinvA; + + matrix_obj * ApBAinvB_inv; + matrix_obj * BpABinvA_inv; + + matrix_obj * mBpABinvA_inv; + + } inverse_complex_obj; + + inverse_real_obj * inverse_real_construct_zero(const unsigned int nRowsCols, const float epsilon); + + void inverse_real_destroy(inverse_real_obj * obj); + + void inverse_real_process(inverse_real_obj * obj, const matrix_obj * src, matrix_obj * dest); + + inverse_complex_obj * inverse_complex_construct_zero(const unsigned int nRowsCols, const float epsilon); + + void inverse_complex_destroy(inverse_complex_obj * obj); + + void inverse_complex_process(inverse_complex_obj * obj, const cmatrix_obj * src, cmatrix_obj * dest); + +#endif \ No newline at end of file diff --git a/src/utils/matrix.c b/src/utils/matrix.c new file mode 100644 index 0000000..b3a02ea --- /dev/null +++ b/src/utils/matrix.c @@ -0,0 +1,262 @@ + + #include "matrix.h" + + matrix_obj * matrix_construct_zero(const unsigned int nRows, const unsigned int nCols) { + + matrix_obj * obj; + unsigned int iRow; + unsigned int iCol; + + obj = (matrix_obj *) malloc(sizeof(matrix_obj)); + + obj->nRows = nRows; + obj->nCols = nCols; + obj->array = (float *) malloc(sizeof(float) * nRows * nCols); + + memset(obj->array, 0x00, sizeof(float) * nRows * nCols); + + return obj; + + } + + matrix_obj * matrix_construct_matrix(const matrix_obj * matrix) { + + matrix_obj * obj; + + unsigned int iRow; + unsigned int iCol; + + obj = (matrix_obj *) malloc(sizeof(matrix_obj)); + + obj->nRows = matrix->nRows; + obj->nCols = matrix->nCols; + obj->array = (float *) malloc(sizeof(float) * matrix->nRows * matrix->nCols); + + memcpy(obj->array, matrix->array, sizeof(float) * matrix->nRows * matrix->nCols); + + return obj; + + } + + void matrix_copy_zero(matrix_obj * obj) { + + unsigned int iRow; + unsigned int iCol; + + memset(obj->array, 0x00, sizeof(float) * obj->nRows * obj->nCols); + + } + + void matrix_copy_matrix(matrix_obj * obj, const matrix_obj * matrix) { + + unsigned int iRow; + unsigned int iCol; + + memcpy(obj->array, matrix->array, sizeof(float) * matrix->nRows * matrix->nCols); + + } + + void matrix_destroy(matrix_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + void matrix_transpose(matrix_obj * obj, const matrix_obj * src) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->array[iRow*obj->nCols+iCol] = src->array[iCol*src->nCols+iRow]; + + } + + } + + } + + void matrix_add(matrix_obj * obj, const matrix_obj * src1, const matrix_obj * src2) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->array[iRow*obj->nCols+iCol] = src1->array[iRow*src1->nCols+iCol] + src2->array[iRow*src2->nCols+iCol]; + + } + + } + + } + + void matrix_sub(matrix_obj * obj, const matrix_obj * src1, const matrix_obj * src2) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + obj->array[iRow*obj->nCols+iCol] = src1->array[iRow*src1->nCols+iCol] - src2->array[iRow*src2->nCols+iCol]; + + } + + } + + } + + void matrix_mul(matrix_obj * obj, const matrix_obj * src1, const matrix_obj * src2) { + + unsigned int iRow; + unsigned int iCol; + unsigned int iElement; + + for (iRow = 0; iRow < src1->nRows; iRow++) { + + for (iCol = 0; iCol < src2->nCols; iCol++) { + + obj->array[iRow*obj->nCols+iCol] = 0.0f; + + for (iElement = 0; iElement < src1->nCols; iElement++) { + + obj->array[iRow*obj->nCols+iCol] += (src1->array[iRow*src1->nCols+iElement] * src2->array[iElement*src2->nCols+iCol]); + + } + + } + + } + + } + + void matrix_inv(matrix_obj * obj, const matrix_obj * src) { + + float a00, a01, a02, a10, a11, a12, a20, a21, a22; + float det; + + if ((src->nRows == 2) && (src->nCols == 2)) { + + a00 = src->array[0*src->nRows+0]; + a01 = src->array[0*src->nRows+1]; + a10 = src->array[1*src->nRows+0]; + a11 = src->array[1*src->nRows+1]; + + det = a00*a11 - a01*a10; + + obj->array[0*obj->nRows+0] = +a11 / det; + obj->array[0*obj->nRows+1] = -a01 / det; + obj->array[1*obj->nRows+0] = -a10 / det; + obj->array[1*obj->nRows+1] = +a00 / det; + + } + + if ((src->nRows == 3) && (src->nCols == 3)) { + + a00 = src->array[0*src->nRows+0]; + a01 = src->array[0*src->nRows+1]; + a02 = src->array[0*src->nRows+2]; + a10 = src->array[1*src->nRows+0]; + a11 = src->array[1*src->nRows+1]; + a12 = src->array[1*src->nRows+2]; + a20 = src->array[2*src->nRows+0]; + a21 = src->array[2*src->nRows+1]; + a22 = src->array[2*src->nRows+2]; + + det = a00*a11*a22 - a00*a12*a21 - a01*a10*a22 + a01*a12*a20 + a02*a10*a21 - a02*a11*a20; + + obj->array[0*obj->nRows+0] = +(a11*a22 - a12*a21) / det; + obj->array[0*obj->nRows+1] = -(a01*a22 - a02*a21) / det; + obj->array[0*obj->nRows+2] = +(a01*a12 - a02*a11) / det; + obj->array[1*obj->nRows+0] = -(a10*a22 - a12*a20) / det; + obj->array[1*obj->nRows+1] = +(a00*a22 - a02*a20) / det; + obj->array[1*obj->nRows+2] = -(a00*a12 - a02*a10) / det; + obj->array[2*obj->nRows+0] = +(a10*a21 - a11*a20) / det; + obj->array[2*obj->nRows+1] = -(a00*a21 - a01*a20) / det; + obj->array[2*obj->nRows+2] = +(a00*a11 - a01*a10) / det; + + } + + } + + float matrix_det(const matrix_obj * obj) { + + float a00, a01, a02, a10, a11, a12, a20, a21, a22; + float det; + + det = 0.0f; + + if ((obj->nRows == 3) && (obj->nCols == 3)) { + + a00 = obj->array[0*obj->nRows+0]; + a01 = obj->array[0*obj->nRows+1]; + a10 = obj->array[1*obj->nRows+0]; + a11 = obj->array[1*obj->nRows+1]; + + det = a00*a11 - a01*a10; + + } + + if ((obj->nRows == 3) && (obj->nCols == 3)) { + + a00 = obj->array[0*obj->nRows+0]; + a01 = obj->array[0*obj->nRows+1]; + a02 = obj->array[0*obj->nRows+2]; + a10 = obj->array[1*obj->nRows+0]; + a11 = obj->array[1*obj->nRows+1]; + a12 = obj->array[1*obj->nRows+2]; + a20 = obj->array[2*obj->nRows+0]; + a21 = obj->array[2*obj->nRows+1]; + a22 = obj->array[2*obj->nRows+2]; + + det = a00*a11*a22 - a00*a12*a21 - a01*a10*a22 + a01*a12*a20 + a02*a10*a21 - a02*a11*a20; + + } + + return det; + + } + + void matrix_scale(matrix_obj * obj, const matrix_obj * src, const float scale) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < src->nRows; iRow++) { + + for (iCol = 0; iCol < src->nCols; iCol++) { + + obj->array[iRow*obj->nCols+iCol] = scale * src->array[iRow*src->nCols+iCol]; + + } + + } + + } + + void matrix_printf(const matrix_obj * obj) { + + unsigned int iRow; + unsigned int iCol; + + for (iRow = 0; iRow < obj->nRows; iRow++) { + + for (iCol = 0; iCol < obj->nCols; iCol++) { + + printf("%+1.5f ",obj->array[iRow*obj->nCols+iCol]); + + } + + printf("\n"); + + } + + } \ No newline at end of file diff --git a/src/utils/matrix.h b/src/utils/matrix.h new file mode 100644 index 0000000..5b4f682 --- /dev/null +++ b/src/utils/matrix.h @@ -0,0 +1,98 @@ +#ifndef __ODAS_UTILS_MATRIX +#define __ODAS_UTILS_MATRIX + + #include + #include + #include + #include + + //! Matrix + typedef struct matrix_obj { + + float * array; ///< Array of elements in the matrix. + unsigned int nRows; ///< Number of rows. + unsigned int nCols; ///< Number of columns. + + } matrix_obj; + + /** Constructor. Initialize all elements to zero in a matrix nRows x nCols. + \param nRows Number of rows. + \param nCols Number of columns. + \return Pointer to the instantiated object. + */ + matrix_obj * matrix_construct_zero(const unsigned int nRows, const unsigned int nCols); + + /** Constructor. Clone the object. + \param matrix Object to be cloned. + \return Pointer to the instantiated object. + */ + matrix_obj * matrix_construct_matrix(const matrix_obj * matrix); + + /** Set elements to 0. + \param obj Object to be used. + */ + void matrix_copy_zero(matrix_obj * obj); + + /** Set fields to the field values of the model object. No memory allocated. + \param matrix Object to be copied. + \param obj Object to be modified. + */ + void matrix_copy_matrix(matrix_obj * obj, const matrix_obj * matrix); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void matrix_destroy(matrix_obj * obj); + + /** Compute the matrix transpose. + \param src Matrix to be transpose. + \param obj Transposed matrix. + */ + void matrix_transpose(matrix_obj * obj, const matrix_obj * src); + + /** Add two matrices. + \param src1 First matrix to be added. + \param src2 Second matrix to be added. + \param obj Result of the addition. + */ + void matrix_add(matrix_obj * obj, const matrix_obj * src1, const matrix_obj * src2); + + /** Subtract two matrices. + \param src1 Matrix to be subtracted from. + \param src2 Matrix to subtract. + \param obj Result of the subtraction. + */ + void matrix_sub(matrix_obj * obj, const matrix_obj * src1, const matrix_obj * src2); + + /** Multiply two matrices. + \param src1 First matrix to be multiplied. + \param src2 Second matrix to be multiplied. + \param obj Result of the multiplication. + */ + void matrix_mul(matrix_obj * obj, const matrix_obj * src1, const matrix_obj * src2); + + /** Inverse a matrix. + \param src Matrix to be inverted. + \param obj Inverted matrix. + */ + void matrix_inv(matrix_obj * obj, const matrix_obj * src); + + /** Compute the determinant. + \param obj Matrix which determinant is computed. + \return Determinant value. + */ + float matrix_det(const matrix_obj * obj); + + /** Multiply a matrix by a scalar. + \param src Matrix to be scaled. + \param scale Scaling factor. + \param obj Scaled matrix. + */ + void matrix_scale(matrix_obj * obj, const matrix_obj * src, const float scale); + + /** Print the content of the matrix. + \param obj Object to be used. + */ + void matrix_printf(const matrix_obj * obj); + +#endif \ No newline at end of file diff --git a/src/utils/pcm.c b/src/utils/pcm.c new file mode 100644 index 0000000..b3a98b8 --- /dev/null +++ b/src/utils/pcm.c @@ -0,0 +1,138 @@ + #include "pcm.h" + + float pcm_signedXXbits2normalized(const char * bytes, const unsigned int nBytes) { + + int sample32; + float sampleFloat; + + switch(nBytes) { + + case 1: + + sample32 = 0; + sample32 += ((((signed char) bytes[3]) << 0) & 0xFFFFFFFF); + + sampleFloat = (float) sample32; + + sampleFloat /= 128.0f; + + break; + + case 2: + + sample32 = 0; + sample32 += ((((signed char) bytes[2]) << 0) & 0x000000FF); + sample32 += ((((signed char) bytes[3]) << 8) & 0xFFFFFF00); + + sampleFloat = (float) sample32; + + sampleFloat /= 32768.0f; + + break; + + case 3: + + sample32 = 0; + sample32 += ((((signed char) bytes[1]) << 0) & 0x000000FF); + sample32 += ((((signed char) bytes[2]) << 8) & 0x0000FF00); + sample32 += ((((signed char) bytes[3]) << 16) & 0xFFFF0000); + + sampleFloat = (float) sample32; + + sampleFloat /= 8388608.0f; + + break; + + case 4: + + sample32 = 0; + sample32 += ((((signed char) bytes[0]) << 0) & 0x000000FF); + sample32 += ((((signed char) bytes[1]) << 8) & 0x0000FF00); + sample32 += ((((signed char) bytes[2]) << 16) & 0x00FF0000); + sample32 += ((((signed char) bytes[3]) << 24) & 0xFF000000); + + sampleFloat = (float) sample32; + + sampleFloat /= 2147483648.0f; + + break; + + } + + return sampleFloat; + + } + + void pcm_signedXXbits2json(const char * bytes, const unsigned int nBytes, char * json) { + + unsigned int iByte; + char high; + char low; + + char hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + + for (iByte = 0; iByte < nBytes; iByte++) { + + high = (bytes[iByte] >> 4) & 0x0F; + low = (bytes[iByte]) & 0x0F; + + json[iByte*2+0] = hex[high]; + json[iByte*2+1] = hex[low]; + + } + + } + + void pcm_normalized2signedXXbits(const float sample, const unsigned int nBytes, char * bytes) { + + int sample32; + + switch(nBytes) { + + case 1: + + sample32 = (signed int) (roundf(sample * 128.0f)); + + bytes[0] = 0x00; + bytes[1] = 0x00; + bytes[2] = 0x00; + bytes[3] = (signed char) ((sample32 & 0x000000FF) >> 0); + + break; + + case 2: + + sample32 = (signed int) (roundf(sample * 32768.0f)); + + bytes[0] = 0x00; + bytes[1] = 0x00; + bytes[2] = (signed char) ((sample32 & 0x000000FF) >> 0); + bytes[3] = (signed char) ((sample32 & 0x0000FF00) >> 8); + + break; + + case 3: + + sample32 = (signed int) (roundf(sample * 8388608.0f)); + + bytes[0] = 0x00; + bytes[1] = (signed char) ((sample32 & 0x000000FF) >> 0); + bytes[2] = (signed char) ((sample32 & 0x0000FF00) >> 8); + bytes[3] = (signed char) ((sample32 & 0x00FF0000) >> 16); + + break; + + case 4: + + sample32 = (signed int) (roundf(sample * 2147483648.0f)); + + bytes[0] = (signed char) ((sample32 & 0x000000FF) >> 0); + bytes[1] = (signed char) ((sample32 & 0x0000FF00) >> 8); + bytes[2] = (signed char) ((sample32 & 0x00FF0000) >> 16); + bytes[3] = (signed char) ((sample32 & 0xFF000000) >> 24); + + break; + + } + + } diff --git a/src/utils/pcm.h b/src/utils/pcm.h new file mode 100644 index 0000000..270125b --- /dev/null +++ b/src/utils/pcm.h @@ -0,0 +1,13 @@ +#ifndef __ODAS_UTILS_PCM +#define __ODAS_UTILS_PCM + + #include + #include + + float pcm_signedXXbits2normalized(const char * bytes, const unsigned int nBytes); + + void pcm_signedXXbits2json(const char * bytes, const unsigned int nBytes, char * json); + + void pcm_normalized2signedXXbits(const float sample, const unsigned int nBytes, char * bytes); + +#endif \ No newline at end of file diff --git a/src/utils/random.c b/src/utils/random.c new file mode 100644 index 0000000..846d724 --- /dev/null +++ b/src/utils/random.c @@ -0,0 +1,186 @@ + + #include "random.h" + + random_obj * random_construct_zero(const unsigned int N) { + + random_obj * obj; + unsigned int n; + time_t t; + + obj = (random_obj *) malloc(sizeof(random_obj)); + + obj->N = N; + obj->pdf = (float *) malloc(sizeof(float) * N); + obj->cdf = (float *) malloc(sizeof(float) * (N+1)); + + for (n = 0; n < N; n++) { + obj->pdf[n] = 0.0f; + obj->cdf[n] = 0.0f; + } + + obj->I = (unsigned int) floorf(logf(N)/logf(2.0f)) + 1; + + srand((unsigned) time(&t)); + + return obj; + + } + + void random_destroy(random_obj * obj) { + + free((void *) obj->pdf); + free((void *) obj->cdf); + free((void *) obj); + + } + + void random_pdf(random_obj * obj, const float * pdf) { + + unsigned int n; + float cdfTotal; + + cdfTotal = 0.0f; + + for (n = 0; n < obj->N; n++) { + + obj->pdf[n] = pdf[n]; + obj->cdf[n] = cdfTotal; + cdfTotal += pdf[n]; + + } + + obj->cdf[obj->N] = cdfTotal; + + } + + void random_generate(const random_obj * obj, const unsigned int nSamples, unsigned int * indexes) { + + unsigned int iSample; + float rndNumber; + + unsigned int indexLow; + unsigned int indexHigh; + unsigned int indexMiddle; + unsigned int i; + + for (iSample = 0; iSample < nSamples; iSample++) { + + rndNumber = (float) ((double)rand() / (double)RAND_MAX); + + indexLow = 0; + indexHigh = obj->N; + + for (i = 0; i < obj->I; i++) { + + indexMiddle = (indexLow + indexHigh) / 2; + + if (obj->cdf[indexMiddle] <= rndNumber) { + + indexLow = indexMiddle; + + } + else { + + indexHigh = indexMiddle; + + } + + } + + indexes[iSample] = indexLow; + + } + + } + + normal_obj * normal_construct_zero(const double epsilon) { + + normal_obj * obj; + time_t t; + + obj = (normal_obj *) malloc(sizeof(normal_obj)); + + obj->epsilon = epsilon; + + srand((unsigned) time(&t)); + + return obj; + + } + + void normal_destroy(normal_obj * obj) { + + free((void *) obj); + + } + + void normal_generate(const normal_obj * obj, const unsigned int nSamples, float * values) { + + unsigned int iSample; + double u1, u2; + double z0, z1; + + for (iSample = 0; iSample < nSamples; iSample+=2) { + + do { + + u1 = ((double)rand() / (double)RAND_MAX); + u2 = ((double)rand() / (double)RAND_MAX); + + } while (u1 <= obj->epsilon); + + z0 = sqrt(-2.0 * log(u1)) * cos(2.0*M_PI*u2); + values[iSample] = (float) z0; + + if ((iSample+1) < nSamples) { + z1 = sqrt(-2.0 * log(u1)) * sin(2.0*M_PI*u2); + values[iSample+1] = (float) z1; + } + + } + + } + + normaloff_obj * normaloff_construct_rnd(const double epsilon, const unsigned int N) { + + normaloff_obj * obj; + normal_obj * normal; + unsigned int n; + time_t t; + + obj = (normaloff_obj *) malloc(sizeof(normaloff_obj)); + + obj->N = N; + + obj->values = (float *) malloc(sizeof(float) * N); + + normal = normal_construct_zero(epsilon); + normal_generate(normal, N, obj->values); + normal_destroy(normal); + + srand((unsigned) time(&t)); + + return obj; + + } + + void normaloff_destroy(normaloff_obj * obj) { + + free((void *) obj->values); + free((void *) obj); + + } + + void normaloff_generate(const normaloff_obj * obj, const unsigned int nSamples, float * values) { + + unsigned int iSample; + unsigned int index; + + for (iSample = 0; iSample < nSamples; iSample++) { + + index = rand() % (obj->N); + values[iSample] = obj->values[index]; + + } + + } diff --git a/src/utils/random.h b/src/utils/random.h new file mode 100644 index 0000000..254d029 --- /dev/null +++ b/src/utils/random.h @@ -0,0 +1,96 @@ +#ifndef __ODAS_UTILS_RANDOM +#define __ODAS_UTILS_RANDOM + + #include + #include + #include + #include + + //! Random number generator + typedef struct random_obj { + + unsigned int N; ///< Number of elements in the space + unsigned int I; ///< Number of iterations to perform a binary search + float * pdf; ///< Probability density function (probability mass function) + float * cdf; ///< Cumulative density function + + } random_obj; + + //! Standard normal number generator + typedef struct normal_obj { + + double epsilon; ///< Small value to perform the Box-Muller transform. + + } normal_obj; + + //! Standard normal number generator offline + typedef struct normaloff_obj { + + unsigned int N; ///< Number of samples. + float * values; ///< Normally distributed samples. + + } normaloff_obj; + + /** Constructor. Initialize all elements to zero. + \param N Number of elements in the space. + \return Pointer to the instantiated object. + */ + random_obj * random_construct_zero(const unsigned int N); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void random_destroy(random_obj * obj); + + /** Set the PDF. + \param pdf Array that contains the PDF values. + \param obj Object to be modified. + */ + void random_pdf(random_obj * obj, const float * pdf); + + /** Pick element randomly according to the PDF, and return the index. + \param nSamples Number of elements to pick. + \param indexes Array that contains the returned indexes. + \param obj Object to be used. + */ + void random_generate(const random_obj * obj, const unsigned int nSamples, unsigned int * indexes); + + /** Constructor. + \param epsilon Small value to perform the Box-Muller transform. + \return Pointer of the instantiated object. + */ + normal_obj * normal_construct_zero(const double epsilon); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void normal_destroy(normal_obj * obj); + + /** Generate a random number according to a standard normal distribution. + \param nSamples Number of random numbers to generate. + \param values Array that contains the generated random numbers. + \param obj Object to be used. + */ + void normal_generate(const normal_obj * obj, const unsigned int nSamples, float * values); + + /** Constructor. + \param epsilon Small value to perform the Box-Muller transform. + \param N Number of random numbers generated offline and stored. + \return Pointer of the instantiated object. + */ + normaloff_obj * normaloff_construct_rnd(const double epsilon, const unsigned int N); + + /** Destructor. Free memory. + \param obj Object to be destroyed. + */ + void normaloff_destroy(normaloff_obj * obj); + + /** Generate a random number according to a standard normal distribution. + \param nSamples Number of random numbers to generate. + \param values Array that contains the generated random numbers. + \param obj Object to be used. + */ + void normaloff_generate(const normaloff_obj * obj, const unsigned int nSamples, float * values); + + +#endif \ No newline at end of file diff --git a/src/utils/transcendental.c b/src/utils/transcendental.c new file mode 100644 index 0000000..760ab22 --- /dev/null +++ b/src/utils/transcendental.c @@ -0,0 +1,78 @@ + + #include "transcendental.h" + + transcendental_obj * transcendental_construct_zero(const float minValue, const float maxValue, const unsigned int nElements) { + + transcendental_obj * obj; + unsigned int iElement; + float v; + float g; + float intPart; + float fracPart; + + const float table[21] = {0.75008f,0.93640f,1.11688f,1.28852f,1.45013f,1.60184f,1.74422f, + 1.87812f,2.00448f,2.12417f,2.23799f,2.34656f,2.45053f,2.55031f, + 2.64646f,2.73921f,2.82895f,2.91602f,3.00049f,3.08265f,3.16270f}; + + obj = (transcendental_obj *) malloc(sizeof(transcendental_obj)); + + obj->minValue = minValue; + obj->maxValue = maxValue; + obj->interval = (maxValue-minValue) / ((float) (nElements-1)); + + obj->array = (float *) malloc(sizeof(float) * nElements); + memset(obj->array, 0x00, sizeof(float) * nElements); + + obj->nElements = nElements; + + v = 0.0f; + + for (iElement = 0; iElement < nElements; iElement++) { + + if (v <= 9.5f) { + + intPart = floorf(2.0f * v); + fracPart = 2.0f * v - intPart; + + g = ((1-fracPart) * table[((unsigned int) intPart)] + fracPart * table[((unsigned int) intPart) + 1]) / sqrtf(v + 0.0001f); + + } + else { + + g = 1.0f; + + } + + obj->array[iElement] = g; + + v += obj->interval; + + } + + return obj; + + } + + void transcendental_destroy(transcendental_obj * obj) { + + free((void *) obj->array); + free((void *) obj); + + } + + float transcendental_process(const transcendental_obj * obj, const float value) { + + signed int iElement; + + iElement = ((signed int) floorf(value / obj->interval)) + 1; + + if (iElement < 0) { + iElement = 0; + } + if (iElement > (obj->nElements - 1)) { + iElement = obj->nElements - 1; + } + + return obj->array[iElement]; + + } \ No newline at end of file diff --git a/src/utils/transcendental.h b/src/utils/transcendental.h new file mode 100644 index 0000000..b87f491 --- /dev/null +++ b/src/utils/transcendental.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_UTILS_TRANSCENDENTAL +#define __ODAS_UTILS_TRANSCENDENTAL + + #include + #include + #include + #include + + typedef struct transcendental_obj { + + float maxValue; + float minValue; + float interval; + + float * array; + unsigned int nElements; + + } transcendental_obj; + + transcendental_obj * transcendental_construct_zero(const float minValue, const float maxValue, const unsigned int nElements); + + void transcendental_destroy(transcendental_obj * obj); + + float transcendental_process(const transcendental_obj * obj, const float value); + +#endif \ No newline at end of file -- 2.34.1