#include #include #include "Fl_EQGraph.H" #include "common.H" #include "../Effects/EffectMgr.h" #include "../DSP/FFTwrapper.h" #include "../globals.h" #include #define MAX_DB 30 Fl_EQGraph::Fl_EQGraph(int x,int y, int w, int h, const char *label) :Fl_Box(x,y,w,h,label), Fl_Osc_Widget(this), samplerate(48000), gain(0.5f) { memset(num, 0, sizeof(num)); memset(dem, 0, sizeof(dem)); num[0] = 1; dem[0] = 1; ext = "eq-coeffs"; osc->createLink("/samplerate", this); osc->requestValue("/samplerate"); oscRegister("eq-coeffs"); oscRegister("parameter0"); } Fl_EQGraph::~Fl_EQGraph(void) {} void Fl_EQGraph::OSC_raw(const char *msg) { if(strstr(msg, "samplerate") && !strcmp("f", rtosc_argument_string(msg))) { samplerate = rtosc_argument(msg, 0).f; } else if(strstr(msg, "parameter0") && !strcmp("i", rtosc_argument_string(msg))) { gain = powf(0.005f, (1.0f-rtosc_argument(msg, 0).i/127.0f)) * 10.0f; } else { memcpy(dem, rtosc_argument(msg, 0).b.data, sizeof(dem)); memcpy(num, rtosc_argument(msg, 1).b.data, sizeof(num)); redraw(); } } void Fl_EQGraph::update(void) { oscWrite("eq-coeffs"); } void Fl_EQGraph::draw_freq_line(float freq, int type) { fl_color(FL_GRAY); float freqx=getfreqpos(freq); switch(type){ case 0:if (active_r()) fl_color(FL_WHITE); else fl_color(205,205,205); fl_line_style(FL_SOLID); break; case 1:fl_line_style(FL_DOT);break; case 2:fl_line_style(FL_DASH);break; }; if ((freqx>0.0)&&(freqx<1.0)) fl_line(x()+(int) (freqx*w()),y(), x()+(int) (freqx*w()),y()+h()); } void Fl_EQGraph::draw(void) { int ox=x(),oy=y(),lx=w(),ly=h(),i; double iy,oiy; float freqx; if (active_r()) fl_color(fl_darker(FL_GRAY)); else fl_color(FL_GRAY); fl_rectf(ox,oy,lx,ly); //draw the lines fl_color(fl_lighter(FL_GRAY)); fl_line_style(FL_SOLID); fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2); freqx=getfreqpos(1000.0); if ((freqx>0.0)&&(freqx<1.0)) fl_line(ox+(int) (freqx*lx),oy, ox+(int) (freqx*lx),oy+ly); for (i=1;i<10;i++) { if(i==1) { draw_freq_line(i*100.0,0); draw_freq_line(i*1000.0,0); } else if (i==5) { draw_freq_line(i*10.0,2); draw_freq_line(i*100.0,2); draw_freq_line(i*1000.0,2); } else { draw_freq_line(i*10.0,1); draw_freq_line(i*100.0,1); draw_freq_line(i*1000.0,1); }; }; draw_freq_line(10000.0,0); draw_freq_line(20000.0,1); fl_line_style(FL_DOT); int GY=6;if (lysamplerate/2) break; iy=getresponse(ly,frq); if ((oiy>=0) && (oiy=0) && (iy num_res = 0; //std::complex dem_res = 0; for(int i = 0; i < MAX_EQ_BANDS*MAX_FILTER_STAGES; ++i) { if(num[3*i] == 0) break; std::complex num_res= 0; std::complex dem_res= 0; for(int j=0; j<3; ++j) { num_res += FFTpolar(num[3*i+j], j*angle); dem_res += FFTpolar(dem[3*i+j], j*angle); } mag *= abs(num_res/dem_res); } float dbresp=20*log(mag*gain)/log(10); //rescale return (int) ((dbresp/MAX_DB+1.0)*maxy/2.0); } float Fl_EQGraph::getfreqx(float x) const { if(x>1.0) x=1.0; return(20.0*pow((float)1000.0,x)); } float Fl_EQGraph::getfreqpos(float freq) const { if(freq<0.00001) freq=0.00001; return(log(freq/20.0)/log(1000.0)); }