Interpolation rate added to smooth discrete steps with small microphone arrays
authorFrancoisGrondin <francois.grondin2@usherbrooke.ca>
Thu, 21 Sep 2017 17:36:54 +0000 (13:36 -0400)
committerFrancoisGrondin <francois.grondin2@usherbrooke.ca>
Thu, 21 Sep 2017 17:36:54 +0000 (13:36 -0400)
12 files changed:
demo/parameters.c
src/init/delay.c
src/init/delay.h
src/init/scanning.c
src/init/scanning.h
src/module/mod_resample.c
src/module/mod_ssl.c
src/module/mod_ssl.h
src/module/mod_sspf.c
src/system/freq2freq.c
src/system/freq2freq.h
src/system/xcorr2aimg.c

index c38ff0fb97f95421b436995c203acd612bb15a32..eb115720dc6b3e42bc02c0f19f2530eeb3d9262d 100644 (file)
             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                                                  |
         // +----------------------------------------------------------+
index a83cb77db413eae1ed37401aae51e82b54573a5a..6dc3c6d884f088326478306b9710d95b0132153d 100644 (file)
@@ -1,7 +1,7 @@
 
     #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) {
+    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;
 
@@ -21,7 +21,7 @@
 
         for (iPair = 0; iPair < nPairs; iPair++) {
 
-            obj->min[iPair] = frameSize - 1;
+            obj->min[iPair] = frameSize * interpRate - 1;
             obj->max[iPair] = 0;
 
         }
@@ -39,9 +39,9 @@
                     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) / soundspeed->mu) * dist;
+                    tau = -1.0f * (((float) fS * interpRate) / soundspeed->mu) * dist;
 
-                    tdoa = (unsigned int) (roundf(tau)+(float) (frameSize/2));
+                    tdoa = (unsigned int) (roundf(tau)+(float) (interpRate * frameSize/2));
                     obj->array[iPoint*nPairs+iPair] = tdoa;
 
                     if (tdoa < obj->min[iPair]) {
@@ -63,7 +63,7 @@
 
     }
 
-    taus_obj * delay_taus(const points_obj * points, const mics_obj * mics, const soundspeed_obj * soundspeed, const unsigned int fS, const unsigned int frameSize) {
+    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;
 
@@ -90,8 +90,8 @@
 
         obj = taus_construct_zero(points->nPoints, nPairs);
 
-        mu_t = -1.0f * ((float) fS) / soundspeed->mu;
-        sigma2_t = ((float) fS) * soundspeed->sigma2 / (soundspeed->mu * soundspeed->mu);
+        mu_t = -1.0f * ((float) fS * interpRate) / soundspeed->mu;
+        sigma2_t = ((float) fS * interpRate) * soundspeed->sigma2 / (soundspeed->mu * soundspeed->mu);
 
         iPair = 0;
 
                     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) (frameSize/2);
+                    obj->mu[iPoint*nPairs+iPair] = mu_tau + (float) (interpRate*frameSize/2);
                     obj->sigma2[iPoint*nPairs+iPair] = sigma2_tau;
 
                 }
index 5b6c97aff81d4dd5f71c005d717a09295d013ff6..7aec099b8b25c0bc3359f98f6fa7c32c597de9f0 100644 (file)
     #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);
+    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);
+    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
 
index 428ea84b8c84434d19f43dc25b18c69ab1ae6653..4c0265a5234ac56cbe0eb49607a0e4bc2473dc6d 100644 (file)
@@ -1,7 +1,7 @@
 
     #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) {
+    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;
@@ -33,7 +33,8 @@
                                              mics, 
                                              soundspeed, 
                                              fS, 
-                                             frameSize);            
+                                             frameSize,
+                                             interpRate);            
 
             // Generate gains in space
             spatialgains = directivity_spatialgains(mics, 
@@ -65,7 +66,8 @@
                                   mics, 
                                   soundspeed, 
                                   fS, 
-                                  frameSize);
+                                  frameSize,
+                                  interpRate);
 
                 obj->deltas[iLevel] = hit_train(taus, 
                                                 obj->tdoas[iLevel], 
index 3176d6bae1b6d4490f79116fd2d723c6e1fcf0c7..728e4b933138461e70e9a9c4625cc71908534513 100644 (file)
@@ -20,6 +20,6 @@
     #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);
+    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
index bb8dcd7ccae8e0a374b35b0edebf202573995ae1..1063704fc1cce311e3e15d03824289ac340958b6 100644 (file)
@@ -41,7 +41,7 @@
                 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 = freq2freq_construct_zero(obj->halfFrameSize, obj-> lowPassCut, 0.0f, 0.0f, 0.0f, 0.0f);
+                obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, 0, obj->lowPassCut, 0.0f, 0.0f, 0.0f, 0.0f);
                 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);
@@ -62,7 +62,7 @@
                 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 = freq2freq_construct_zero(obj->halfFrameSize, obj-> lowPassCut, 0.0f, 0.0f, 0.0f, 0.0f);
+                obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, 0, obj-> lowPassCut, 0.0f, 0.0f, 0.0f, 0.0f);
                 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);
index 36582ed7656581bb6da571848c23abe6c63d46f9..7c0bd974f33e36a3035def96e378ecfb850a9b18 100644 (file)
@@ -1,5 +1,5 @@
     
-    #include "mod_ssl.h"    
+    #include "mod_ssl.h"       
 
     // +----------------------------------------------------------+
     // | Object - Constructor                                     |
@@ -21,6 +21,9 @@
         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->samplerate->mu, 
                                          mod_ssl_config->soundspeed, 
                                          mod_ssl_config->nMatches, 
-                                         2 * (msg_spectra_config->halfFrameSize - 1), 
+                                         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->gainMin,
+                                         mod_ssl_config->interpRate);      
 
-        obj->freq2freq = freq2freq_construct_zero(msg_spectra_config->halfFrameSize, 
+        obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, 
+                                                  obj->halfFrameSizeInterp,
                                                   0,
                                                   mod_ssl_config->epsilon,
                                                   0.0f,
                                                   0.0f,
-                                                  0.0f);
+                                                  0.0f);   
 
         obj->phasors = freqs_construct_zero(mod_ssl_config->mics->nChannels, 
                                             msg_spectra_config->halfFrameSize);
         obj->products = freqs_construct_zero(mod_ssl_config->mics->nPairs, 
                                              msg_spectra_config->halfFrameSize);
 
-        obj->freq2xcorr = freq2xcorr_construct_zero(2 * (msg_spectra_config->halfFrameSize - 1), 
-                                                    msg_spectra_config->halfFrameSize);
+        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,
-                                            2 * (msg_spectra_config->halfFrameSize - 1));
+                                            obj->frameSizeInterp);
 
         obj->xcorrsMax = xcorrs_construct_zero(mod_ssl_config->mics->nPairs,
-                                               2 * (msg_spectra_config->halfFrameSize - 1));
+                                               obj->frameSizeInterp);
 
         obj->aimgs = (aimg_obj **) malloc(sizeof(aimg_obj *) * msg_pots_config->nPots);
 
@@ -66,8 +74,8 @@
 
         }
 
-        obj->xcorr2xcorr = xcorr2xcorr_construct_zero(2 * (msg_spectra_config->halfFrameSize - 1));
-
+        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++) {
         freq2freq_destroy(obj->freq2freq);
         freqs_destroy(obj->phasors);
         freqs_destroy(obj->products);
+        freqs_destroy(obj->productsInterp);
         freq2xcorr_destroy(obj->freq2xcorr);
         xcorrs_destroy(obj->xcorrs);
         xcorrs_destroy(obj->xcorrsMax);
                                       obj->scans->pairs,
                                       obj->products);        
 
+            freq2freq_process_interpolate(obj->freq2freq,
+                                          obj->products,
+                                          obj->productsInterp);
+
             freq2xcorr_process(obj->freq2xcorr, 
-                               obj->products, 
+                               obj->productsInterp, 
                                obj->scans->pairs,
-                               obj->xcorrs);
+                               obj->xcorrs);           
 
             for (iPot = 0; iPot < obj->nPots; iPot++) {
                 
                 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;
+                obj->pots->array[iPot * 4 + 3] = maxValue * ((float) obj->interpRate);
 
             }
             
index b294bc56d150de4d6cfb4867fb4b3a244e002da8..20a1c51de0e72356460e8720484e05c6f97109fd 100644 (file)
         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;
         
@@ -61,6 +65,7 @@
         soundspeed_obj * soundspeed;
         spatialfilter_obj * spatialfilter;
 
+        unsigned int interpRate;
         float epsilon; 
         unsigned int nLevels;
         unsigned int * levels;
index 231ef3aa487f9fb1e8074fca295420c1ba6c5664..a4ea687e9a20cd0911c57fdc816eeb6af084f005 100644 (file)
@@ -17,7 +17,7 @@
 
         obj->freq2env = freq2env_construct_zero(obj->halfFrameSize, obj->nSeps);
         obj->envs = envs_construct_zero(obj->nSeps, obj->halfFrameSize);
-        obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, 0, obj->epsilon, obj->alpha, obj->beta, obj->Ginterf);
+        obj->freq2freq = freq2freq_construct_zero(obj->halfFrameSize, 0, 0, obj->epsilon, obj->alpha, obj->beta, obj->Ginterf);
 
         obj->in1 = (msg_spectra_obj *) NULL;
         obj->in2 = (msg_envs_obj *) NULL;
@@ -50,7 +50,7 @@
             }
 
             freq2env_process(obj->freq2env, obj->in1->freqs, obj->envs);
-            freq2freq_process_postfilter(obj->freq2freq,  obj->in3->tracks, obj->in1->freqs, obj->envs, obj->in2->envs, obj->out->freqs);
+            freq2freq_process_postfilter(obj->freq2freq, obj->in3->tracks, obj->in1->freqs, obj->envs, obj->in2->envs, obj->out->freqs);
 
             obj->out->timeStamp = obj->in1->timeStamp;
 
index ce9c16b5932fdbf8d9c2fa45774ecdca464c2772..ef89bd12388ea0f0c7c1b6921ded6d279c7e6261 100644 (file)
@@ -1,13 +1,14 @@
     
     #include "freq2freq.h"
 
-    freq2freq_obj * freq2freq_construct_zero(const unsigned int halfFrameSize, const unsigned int lowPassCut, const float epsilon, const float alpha, const float beta, const float Ginterf) {
+    freq2freq_obj * freq2freq_construct_zero(const unsigned int halfFrameSize, const unsigned int halfFrameSizeInterp, const unsigned int lowPassCut, const float epsilon, const float alpha, const float beta, const float Ginterf) {
 
         freq2freq_obj * obj;
 
         obj = (freq2freq_obj *) malloc(sizeof(freq2freq_obj));
 
         obj->halfFrameSize = halfFrameSize;
+        obj->halfFrameSizeInterp = halfFrameSizeInterp;
         obj->lowPassCut = lowPassCut;
         obj->epsilon = epsilon;
 
 
         }
 
+    }
+
+    void freq2freq_process_interpolate(freq2freq_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);
+
+        }
+
     }
\ No newline at end of file
index 2b6098c1a1024f9196f4cac8211531ba3d185cc7..ee759a5b6e2d804bf9c1588d28f7349dd94a7b68 100644 (file)
@@ -6,14 +6,13 @@
 
     #include "../signal/env.h"
     #include "../signal/freq.h"
-    #include "../signal/gain.h"
-    #include "../signal/mask.h"
     #include "../signal/pair.h"
     #include "../signal/track.h"
     
     typedef struct freq2freq_obj {
 
         unsigned int halfFrameSize;
+        unsigned int halfFrameSizeInterp;
         unsigned int lowPassCut;
         float epsilon;
         float alpha;
@@ -22,7 +21,7 @@
 
     } freq2freq_obj;
 
-    freq2freq_obj * freq2freq_construct_zero(const unsigned int halfFrameSize, const unsigned int lowPassCut, const float epsilon, const float alpha, const float beta, const float Ginterf);
+    freq2freq_obj * freq2freq_construct_zero(const unsigned int halfFrameSize, const unsigned int halfFrameSizeInterp, const unsigned int lowPassCut, const float epsilon, const float alpha, const float beta, const float Ginterf);
 
     void freq2freq_destroy(freq2freq_obj * obj);
 
@@ -34,4 +33,6 @@
 
     void freq2freq_process_postfilter(freq2freq_obj * obj, const tracks_obj * tracks, const freqs_obj * freqsSeps, const envs_obj * envsSeps, const envs_obj * envsDiffuse, freqs_obj * freqsPosts);
 
+    void freq2freq_process_interpolate(freq2freq_obj * obj, const freqs_obj * freqs, const freqs_obj * freqsInterp);
+
 #endif
\ No newline at end of file
index 892bd9c72a83f908c59deefbb39e0978730417d7..d1fd4cee32d4a9525eb4aeca0867c06d74236583 100644 (file)
 
             }
 
-            aimg->array[iPoint] /= ((float) spatialindexes->count[iPoint]);
+            aimg->array[iPoint] /= ((float) spatialindexes->count[iPoint]);     
 
         }
 
+        
+
     }
\ No newline at end of file