zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 1d5a39ff8e877c8c33be86f1034b5e2e5b4f9d5f
parent 608f09ef47e310056052a28614a6ecf5c7c1906c
Author: paulnasca <paulnasca>
Date:   Sat, 14 Aug 2004 14:40:54 +0000

*** empty log message ***

Diffstat:
MChangeLog | 4+++-
Msrc/Params/PADnoteParameters.C | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/Params/PADnoteParameters.h | 8+++++++-
Msrc/UI/PADnoteUI.fl | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/main.C | 2+-
5 files changed, 165 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -680,5 +680,7 @@ - Corectata eroare care facea ca sa nu mearga MIDI - LANSAT PE INTERNET - VERSIUNEA (2.0.0pre2 VST) -------------------------------------------------------------------------------------------------- - +13 Aug 2004 - Inceput sa scriu modurile continous si discrete la PADnote +14 Aug 2004 - Terminat modul continous la PADnote + diff --git a/src/Params/PADnoteParameters.C b/src/Params/PADnoteParameters.C @@ -320,9 +320,9 @@ REALTYPE PADnoteParameters::getNhr(int n){ }; /* - * Generates the long spectrum (only amplitudes are generated; phases will be random) + * Generates the long spectrum for Bandwidth mode (only amplitudes are generated; phases will be random) */ -void PADnoteParameters::generatespectrum(REALTYPE *spectrum, int size,REALTYPE basefreq,REALTYPE *profile,int profilesize,REALTYPE bwadjust){ +void PADnoteParameters::generatespectrum_bandwidthMode(REALTYPE *spectrum, int size,REALTYPE basefreq,REALTYPE *profile,int profilesize,REALTYPE bwadjust){ for (int i=0;i<size;i++) spectrum[i]=0.0; REALTYPE harmonics[OSCIL_SIZE/2]; @@ -388,6 +388,59 @@ void PADnoteParameters::generatespectrum(REALTYPE *spectrum, int size,REALTYPE b }; /* + * Generates the long spectrum for non-Bandwidth modes (only amplitudes are generated; phases will be random) + */ +void PADnoteParameters::generatespectrum_otherModes(REALTYPE *spectrum, int size,REALTYPE basefreq,REALTYPE *profile,int profilesize,REALTYPE bwadjust){ + for (int i=0;i<size;i++) spectrum[i]=0.0; + + REALTYPE harmonics[OSCIL_SIZE/2]; + for (int i=0;i<OSCIL_SIZE/2;i++) harmonics[i]=0.0; + //get the harmonic structure from the oscillator (I am using the frequency amplitudes, only) + oscilgen->get(harmonics,basefreq,false); + + //normalize + REALTYPE max=0.0; + for (int i=0;i<OSCIL_SIZE/2;i++) if (harmonics[i]>max) max=harmonics[i]; + if (max<0.000001) max=1; + for (int i=0;i<OSCIL_SIZE/2;i++) harmonics[i]/=max; + + for (int nh=1;nh<OSCIL_SIZE/2;nh++){//for each harmonic + REALTYPE realfreq=getNhr(nh)*basefreq; + + ///sa fac aici interpolarea si sa am grija daca frecv descresc + + if (realfreq>SAMPLE_RATE*0.49999) break; + if (realfreq<20.0) break; +// if (harmonics[nh-1]<1e-4) continue; + + + REALTYPE amp=harmonics[nh-1]; + if (resonance->Penabled) amp*=resonance->getfreqresponse(realfreq); + int cfreq=(int) (realfreq/(SAMPLE_RATE*0.5)*size); + + spectrum[cfreq]=amp+1e-9; + }; + + if (Pmode!=1){ + int old=0; + for (int k=1;k<size;k++){ + if ( (spectrum[k]>1e-10) || (k==(size-1)) ){ + int delta=k-old; + REALTYPE val1=spectrum[old]; + REALTYPE val2=spectrum[k]; + REALTYPE idelta=1.0/delta; + for (int i=0;i<delta;i++){ + REALTYPE x=idelta*i; + spectrum[old+i]=val1*(1.0-x)+val2*x; + }; + old=k; + }; + }; + }; + +}; + +/* * Applies the parameters (i.e. computes all the samples, based on parameters); */ void PADnoteParameters::applyparameters(bool lockmutex){ @@ -420,17 +473,19 @@ void PADnoteParameters::applyparameters(bool lockmutex){ REALTYPE tmp=adj[nsample]-adj[samplemax-1]*0.5; REALTYPE basefreqadjust=pow(2.0,tmp); - generatespectrum(spectrum,spectrumsize,basefreq*basefreqadjust,profile,profilesize,bwadjust); + if (Pmode==0) generatespectrum_bandwidthMode(spectrum,spectrumsize,basefreq*basefreqadjust,profile,profilesize,bwadjust); + else generatespectrum_otherModes(spectrum,spectrumsize,basefreq*basefreqadjust,profile,profilesize,bwadjust); const int extra_samples=3;//the last samples contains the first samples (used for linear/cubic interpolation) newsample.smp=new REALTYPE[samplesize+extra_samples]; - for (int i=0;i<spectrumsize;i++){//makes the phases as random + newsample.smp[0]=0.0; + for (int i=1;i<spectrumsize;i++){//makes the phases as random REALTYPE phase=RND*6.29; newsample.smp[i]=spectrum[i]*cos(phase); - newsample.smp[samplesize-1-i]=spectrum[i]*sin(phase); + newsample.smp[samplesize-i]=spectrum[i]*sin(phase); }; - fft->freqs2smps(newsample.smp,newsample.smp);//that's all; here is the single ifft for the whole sample; no windows are used :-) + fft->freqs2smps(newsample.smp,newsample.smp);//that's all; here is the only ifft for the whole sample; no windows are used :-) //normalize(rms) @@ -464,12 +519,12 @@ void PADnoteParameters::applyparameters(bool lockmutex){ //delete the additional samples that might exists and are not useful for (int i=samplemax;i<PAD_MAX_SAMPLES;i++) deletesample(i); - }; void PADnoteParameters::add2XML(XMLwrapper *xml){ xml->addparbool("stereo",PStereo); + xml->addpar("mode",Pmode); xml->addpar("bandwidth",Pbandwidth); xml->addpar("bandwidth_scale",Pbwscale); @@ -565,6 +620,7 @@ void PADnoteParameters::add2XML(XMLwrapper *xml){ void PADnoteParameters::getfromXML(XMLwrapper *xml){ PStereo=xml->getparbool("stereo",PStereo); + Pmode=xml->getpar127("mode",0); Pbandwidth=xml->getpar("bandwidth",Pbandwidth,0,1000); Pbwscale=xml->getpar127("bandwidth_scale",Pbwscale); diff --git a/src/Params/PADnoteParameters.h b/src/Params/PADnoteParameters.h @@ -49,6 +49,10 @@ class PADnoteParameters{ //parameters + //the mode: 0 - bandwidth, 1 - discrete (bandwidth=0), 2 - continous + //the harmonic profile is used only on mode 0 + unsigned char Pmode; + //Harmonic profile (the frequency distribution of a single harmonic) struct { struct{//base function @@ -149,7 +153,8 @@ class PADnoteParameters{ }sample[PAD_MAX_SAMPLES],newsample; private: - void generatespectrum(REALTYPE *spectrum, int size,REALTYPE basefreq,REALTYPE *profile,int profilesize,REALTYPE bwadjust); + void generatespectrum_bandwidthMode(REALTYPE *spectrum, int size,REALTYPE basefreq,REALTYPE *profile,int profilesize,REALTYPE bwadjust); + void generatespectrum_otherModes(REALTYPE *spectrum, int size,REALTYPE basefreq,REALTYPE *profile,int profilesize,REALTYPE bwadjust); void deletesamples(); void deletesample(int n); @@ -158,4 +163,5 @@ class PADnoteParameters{ }; + #endif diff --git a/src/UI/PADnoteUI.fl b/src/UI/PADnoteUI.fl @@ -58,15 +58,18 @@ if (!visible()) return; REALTYPE smps[lx]; REALTYPE realbw=pars->getprofile(smps,lx); +bool active=active_r(); //draw the equivalent bandwidth -fl_color(220,220,220); +if (active) fl_color(220,220,220); + else fl_color(160,165,165); fl_line_style(0); int rbw=(int)(realbw*(lx-1.0)/2.0); for (int i=lx/2-rbw;i<(lx/2+rbw);i++) fl_line(ox+i,oy,ox+i,oy+ly-1); fl_line_style(0); -fl_color(200,200,200); +if (active) fl_color(200,200,200); + else fl_color(160,160,160); for (int i=1;i<10;i++){ int kx=(int)(lx/10.0*i); fl_line(ox+kx,oy,ox+kx,oy+ly-1); @@ -76,6 +79,7 @@ for (int i=1;i<5;i++){ fl_line(ox,oy+ly-ky,ox+lx,oy+ly-ky-1); }; + fl_color(120,120,120); fl_line_style(FL_DOT); fl_line(ox+lx/2,oy,ox+lx/2,oy+ly); @@ -85,17 +89,19 @@ fl_line_style(0); int old=0; for (int i=0;i<lx;i++){ int val=(int) ((ly-2)*smps[i]); - fl_color(180,210,240); + if (active) fl_color(180,210,240); + else fl_color(150,150,155); fl_line(ox+i,oy+ly-1,ox+i,oy+ly-1-val); - fl_color(0,0,100); + if (active) fl_color(0,0,100); + else fl_color(150,150,150); if (i>0) fl_line(ox+i-1,oy+ly-2-old,ox+i,oy+ly-2-val); old=val; }; - fl_line_style(FL_DASH); -fl_color(0,100,220); +if (active) fl_color(0,100,220); + else fl_color(150,160,170); fl_line(ox+lx/2-rbw,oy,ox+lx/2-rbw,oy+ly-1); fl_line(ox+lx/2+rbw,oy,ox+lx/2+rbw,oy+ly-1); @@ -152,21 +158,48 @@ for (int i=0;i<n;i++){ if (max<0.000001) max=1.0; max=max*1.05; +REALTYPE spectrum[lx]; +for (int i=0;i<lx;i++) spectrum[i]=0; - -fl_color(180,0,0); -fl_line_style(0); for (int i=1;i<n;i++){ REALTYPE nhr=pars->getNhr(i); int kx=(int)(lx/(REALTYPE)maxharmonic*nhr); if ((kx<0)||(kx>lx)) continue; - REALTYPE x=spc[i-1]/max; + spectrum[kx]=spc[i-1]/max+1e-9; + +}; + +fl_color(180,0,0); +fl_line_style(0); + +if (pars->Pmode==2){ + int old=0; + for (int i=1;i<lx;i++){ + if ((spectrum[i]>1e-10)||(i==(lx-1))){ + int delta=i-old; + REALTYPE val1=spectrum[old]; + REALTYPE val2=spectrum[i]; + + REALTYPE idelta=1.0/delta; + for (int j=0;j<delta;j++){ + REALTYPE x=idelta*j; + spectrum[old+j]=val1*(1.0-x)+val2*x; + }; + old=i; + }; + + }; +}; + +for (int i=0;i<lx;i++){ + REALTYPE x=spectrum[i]; if (x>dB2rap(-maxdb)) x=rap2dB(x)/maxdb+1; else continue; int yy=(int)(x*ly); - fl_line(ox+kx,oy+ly-1-yy,ox+kx,oy+ly-1); + fl_line(ox+i,oy+ly-1-yy,ox+i,oy+ly-1); + };} {} } decl {Master *master;} {} @@ -178,7 +211,7 @@ class PADnoteUI {} { Function {make_window()} {} { Fl_Window padnotewindow { label {PAD synth Parameters} - xywh {184 106 535 450} type Double visible + xywh {76 165 535 450} type Double hide } { Fl_Tabs {} { callback {if (o->value()!=harmonicstructuregroup) applybutton->hide(); @@ -186,11 +219,12 @@ class PADnoteUI {} { xywh {0 0 535 395} } { Fl_Group harmonicstructuregroup { - label {Harmonic Structure} selected + label {Harmonic Structure} xywh {0 20 535 375} box ENGRAVED_BOX } { - Fl_Group {} { + Fl_Group bwprofilegroup { xywh {5 30 90 260} box ENGRAVED_BOX + code0 {if (pars->Pmode!=0) o->deactivate();} } { Fl_Dial {} { label Width @@ -384,21 +418,23 @@ resui->resonancewindow->show(); resui->setcbwidget(cbwidget);} xywh {375 225 80 20} box THIN_UP_BOX } - Fl_Dial {} { + Fl_Dial bwdial { label BandWidth callback {bwcents->value(pars->setPbandwidth((int) o->value())); cbwidget->do_callback();} xywh {15 295 35 35} box ROUND_UP_BOX labelsize 11 maximum 1000 step 1 code0 {o->value(pars->Pbandwidth);} + code1 {if (pars->Pmode!=0) o->deactivate();} class WidgetPDial } Fl_Value_Output bwcents { label cents - xywh {55 305 55 15} labelsize 10 align 8 maximum 10000 step 0.1 + xywh {55 305 55 15} labelsize 10 align 6 maximum 10000 step 0.1 code0 {o->value(pars->setPbandwidth(pars->Pbandwidth));} + code1 {if (pars->Pmode!=0) o->deactivate();} } Fl_Group {} { - xywh {310 295 220 45} box ENGRAVED_BOX + xywh {315 295 215 45} box ENGRAVED_BOX } { Fl_Choice {} { label OvertonesPosition @@ -469,7 +505,7 @@ cbwidget->do_callback();} label {Bandwidth Scale} callback {pars->Pbwscale=(int) o->value(); cbwidget->do_callback();} - xywh {165 305 80 20} down_box BORDER_BOX labelsize 10 align 5 textsize 12 + xywh {120 305 80 20} down_box BORDER_BOX labelsize 10 align 5 textsize 12 code0 {o->value(pars->Pbwscale);} } { menuitem {} { @@ -655,14 +691,50 @@ cbwidget->do_callback();} } } Fl_Group hprofile { - xywh {100 45 430 85} box FLAT_BOX color 54 selection_color 218 labelcolor 63 + xywh {100 45 430 90} box FLAT_BOX color 54 selection_color 218 labelcolor 63 code0 {PADnoteHarmonicProfile *hpui=new PADnoteHarmonicProfile(o->x(),o->y(),o->w(),o->h(),"");} code1 {hpui->init(pars,master);} + code2 {if (pars->Pmode!=0) { o->deactivate(); o->color(48);};} } {} Fl_Box {} { label {Profile of One Harmonic (Frequency Distribution)} xywh {160 25 315 20} } + Fl_Choice {} { + label {Spectrum Mode} + callback {pars->Pmode=(int) o->value(); + +if (pars->Pmode==0){ + bwprofilegroup->activate(); + bwdial->activate(); + bwcents->activate(); + hprofile->activate(); + hprofile->color(54); +} else { + bwprofilegroup->deactivate(); + bwdial->deactivate(); + bwcents->deactivate(); + hprofile->deactivate(); + hprofile->color(48); +}; + +cbwidget->do_callback();} selected + xywh {220 305 90 20} down_box BORDER_BOX labelfont 1 labelsize 10 labelcolor 0 align 5 textsize 12 + code0 {o->value(pars->Pmode);} + } { + menuitem {} { + label Bandwidth + xywh {105 105 100 20} labelfont 1 labelsize 12 + } + menuitem {} { + label Discrete + xywh {125 125 100 20} labelfont 1 labelsize 12 labelcolor 0 + } + menuitem {} { + label Continous + xywh {115 115 100 20} labelfont 1 labelsize 12 labelcolor 0 + } + } } Fl_Group {} { label {Envelopes&LFOs} diff --git a/src/main.C b/src/main.C @@ -86,7 +86,7 @@ void set_realtime(){ sched_param sc; sc.sched_priority=50; - int err=sched_setscheduler(0,SCHED_FIFO,&sc); + sched_setscheduler(0,SCHED_FIFO,&sc); // if (err==0) printf("Real-time"); #endif };