#include #include #include #include "Fl_Osc_Widget.H" //consider merging with Fl_Oscilloscope class Fl_OscilSpectrum : public Fl_Box, Fl_Osc_Widget { public: Fl_OscilSpectrum(int x,int y, int w, int h, const char *label=0) :Fl_Box(x,y,w,h,label), nsamples(0), spc(NULL) {} ~Fl_OscilSpectrum(void) { delete[] spc; osc->removeLink(loc, (Fl_Osc_Widget*) this); } void init(bool base_spectrum_p) { Fl_Osc_Pane *og = fetch_osc_pane(this); assert(og); loc = og->base + (base_spectrum_p ? "base-spectrum": "spectrum"); osc = og->osc; assert(osc); osc->createLink(loc, (Fl_Osc_Widget*) this); update(); } void update(void) { osc->requestValue(loc); } virtual void OSC_value(unsigned N, void *data) override { assert(!(N%4)); const size_t new_samples = N / 4; //resize buffer if needed if(new_samples != nsamples) { delete [] spc; spc = new float[new_samples]; nsamples = new_samples; } memcpy(spc, data, N); //normalize float max=0; for (unsigned i=0; i(int)nsamples) n=nsamples; fl_rectf(ox,oy,lx,ly,0,0,0); //draw if(this->active_r()) fl_color(0,0,255); else fl_color(this->parent()->color()); fl_line_style(FL_DOT); for(int i=1; iactive_r()) fl_color(0,255,0); else fl_color(this->parent()->color()); fl_line_style(0); if(!spc) return; //draws the spectrum for(int i=0; idB2rap(-maxdb)) x=rap2dB(x)/maxdb+1; else x=0; int val=(int) ((ly-2)*x); if (val>0) fl_line(ox+tmp,oy+ly-2-val,ox+tmp,oy+ly-2); } } private: size_t nsamples; float *spc; };