提交 ec680069 编写于 作者: D dev@dev.com

增加一个控制FFT频繁程度的参数 frame_span ,以解决在高采样率下,FFT用于频谱显示来不及处理的问题。

解决该问题终极手段是多线程,但多线程显著增加了复杂性,让代码用于教学不再合适。因此,通过简单的设置间隔来变相解决该问题。
上级 fb7f265a
......@@ -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\
......
......@@ -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<unsigned int, std::vector<double> > map_buf_inside;
unordered_map<unsigned int, long long > map_buf_pos,map_buf_deal;
unordered_map<unsigned int, long long > cal_cnt;
for (int i=0;i<fftsize;++i)
vec_fft_abs.push_back(0);
......@@ -427,7 +432,10 @@ int do_fftw_continous(const cmdlineParser & args)
map_buf_inside[header.path_id]=std::vector<double>(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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册