From 9e4a783709a6b79fc254a021fb7c1c8a159a2340 Mon Sep 17 00:00:00 2001 From: "dev@dev.com" Date: Sun, 29 May 2022 13:22:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=8E=A7?= =?UTF-8?q?=E5=88=B6FFT=E9=A2=91=E7=B9=81=E7=A8=8B=E5=BA=A6=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20frame=5Fspan=20=EF=BC=8C=E4=BB=A5=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=9C=A8=E9=AB=98=E9=87=87=E6=A0=B7=E7=8E=87=E4=B8=8B?= =?UTF-8?q?=EF=BC=8CFFT=E7=94=A8=E4=BA=8E=E9=A2=91=E8=B0=B1=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=9D=A5=E4=B8=8D=E5=8F=8A=E5=A4=84=E7=90=86=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决该问题终极手段是多线程,但多线程显著增加了复杂性,让代码用于教学不再合适。因此,通过简单的设置间隔来变相解决该问题。 --- .../transform_fft/function_info.cpp | 13 ++++-- modules/transforms/transform_fft/main.cpp | 40 +++++++++++-------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/modules/transforms/transform_fft/function_info.cpp b/modules/transforms/transform_fft/function_info.cpp index 9ca69c0..6c2172c 100644 --- a/modules/transforms/transform_fft/function_info.cpp +++ b/modules/transforms/transform_fft/function_info.cpp @@ -24,12 +24,19 @@ const char * g_info = "{\n\ \"tooltip\":\"0=Real,1=Complex\",\n\ \"default\":0\n\ },\n\ - \"mod:\":{\n\ + \"frame_span\":{\n\ + \"type\":\"int\",\n\ + \"tooltip\":\"Frame Span (count) between each fft calc. Slower CPU need larger spans.\",\n\ + \"range\":\">=1\",\n\ + \"default\":16\n\ + },\n\ + \"mod\":{\n\ \"type\":\"int\",\n\ - \"tooltip\":\"0=frame,1=continous\",\n\ + \"tooltip\":\"WorkingMod\",\n\ + \"range\":\"0=Frame,1=Continous\",\n\ \"default\":0\n\ },\n\ - \"fftsize\":{\n\ + \"fftsize\":{\n\ \"type\":\"int\",\n\ \"tooltip\":\"fft size\",\n\ \"default\":1024\n\ diff --git a/modules/transforms/transform_fft/main.cpp b/modules/transforms/transform_fft/main.cpp index 6e8d1c1..1675cdf 100644 --- a/modules/transforms/transform_fft/main.cpp +++ b/modules/transforms/transform_fft/main.cpp @@ -48,12 +48,12 @@ int main(int argc , char * argv[]) } else if (args.contains("function"/*,"tranform_fft"*/))//正常运行模式 { - unsigned int imod = args.toUInt("mod",0); - if (!imod) - ret = do_fftw(args); - else - ret = do_fftw_continous(args); - } + unsigned int imod = args.toUInt("mod",0); + if (!imod) + ret = do_fftw(args); + else + ret = do_fftw_continous(args); + } else { fprintf(stderr,"Error:Function does not exits."); @@ -72,14 +72,15 @@ int do_fftw(const cmdlineParser & args) unsigned int instance = args.toInt("instance",0); unsigned int isource = args.toInt("signal",0); unsigned int FFT = args.toInt("FFT",0); - unsigned int Spec = args.toInt("Spec",0); - unsigned int itmstamp_in = args.toUInt("tmstamp_in",0); + unsigned int Spec = args.toInt("Spec",0); + unsigned int itmstamp_in = args.toUInt("tmstamp_in",0); unsigned int itmstamp_out = args.toUInt("tmstamp_out",0); - unsigned int itypes = args.toUInt("input_type",0);//0=real,1=complex - //工作模式 - const int sptype = args.toInt("sptype",0); fprintf(stderr,"sptype is %d.",sptype); + unsigned int itypes = args.toUInt("input_type",0);//0=real,1=complex + const unsigned int frame_span = args.toInt("frame_span",1)>0?args.toInt("frame_span",1):1; + //工作模式 + const int sptype = args.toInt("sptype",0); fprintf(stderr,"sptype is %d.",sptype); - int channels = args.toInt("channels",1); + int channels = args.toInt("channels",1); if (channels<1) channels = 1; @@ -90,8 +91,7 @@ int do_fftw(const cmdlineParser & args) fprintf(stderr,"fftsize must >16."); return res; } - - fflush(stderr); + fflush(stderr); try{ //判断参数合法性 @@ -148,7 +148,10 @@ int do_fftw(const cmdlineParser & args) const unsigned long long llts = map_tmst_outside[header.path_id]; push_subject(itmstamp_out,header.path_id,sizeof(unsigned long long),(const unsigned char *)&llts); } - } + } + + if (map_tmst_inside[header.path_id]++%frame_span) + continue; const unsigned char * pdta = packagedta.data(); //Normalizer @@ -328,7 +331,6 @@ int do_fftw(const cmdlineParser & args) push_subject(FFT,header.path_id,fftsize*sizeof(double)/(itypes==0?2:1),(const unsigned char *)vec_fft_abs.data()); if (Spec>0) push_subject(Spec,header.path_id,fftsize*sizeof(double),(const unsigned char *)out); - ++map_tmst_inside[header.path_id]; } } @@ -359,6 +361,8 @@ int do_fftw_continous(const cmdlineParser & args) unsigned int FFT = args.toInt("FFT",0); unsigned int Spec = args.toInt("Spec",0); unsigned int itmstamp_in = args.toUInt("tmstamp_in",0); + const unsigned int frame_span = args.toInt("frame_span",1)>0?args.toInt("frame_span",1):1; + unsigned int itypes = args.toUInt("input_type",0);//0=real,1=complex //工作模式 const int sptype = args.toInt("sptype",0); fprintf(stderr,"sptype is %d.",sptype); @@ -394,6 +398,7 @@ int do_fftw_continous(const cmdlineParser & args) //Ring buf unordered_map > map_buf_inside; unordered_map map_buf_pos,map_buf_deal; + unordered_map cal_cnt; for (int i=0;i(2*RingSize); map_buf_pos[header.path_id] = 0; map_buf_deal[header.path_id] = 0; + cal_cnt[header.path_id] = 0; } + if (cal_cnt[header.path_id]++%frame_span) + continue; const unsigned char * pdta = packagedta.data(); //Normalizer -- GitLab