zynaddsubfx

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

commit 936102ee5ed3e0d68894c476be904e8154cc775a
parent 5893d0652842c3cf050bd7103a4962f96853b460
Author: paulnasca <paulnasca>
Date:   Fri, 18 Jun 2004 16:54:04 +0000

*** empty log message ***

Diffstat:
Msrc/Misc/Config.C | 2++
Msrc/Misc/Config.h | 1+
Msrc/Synth/ADnote.C | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/Synth/ADnote.h | 7+++++--
Msrc/UI/ConfigUI.fl | 20++++++++++----------
5 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/src/Misc/Config.C b/src/Misc/Config.C @@ -57,6 +57,8 @@ Config::Config(){ cfg.GzipCompression=3; +// cfg.Interpolation=0; + winwavemax=1;winmidimax=1; //try to find out how many input midi devices are there #ifdef WINMIDIIN diff --git a/src/Misc/Config.h b/src/Misc/Config.h @@ -37,6 +37,7 @@ class Config{ int BankUIAutoClose; int DumpNotesToFile,DumpAppend; int GzipCompression; +// int Interpolation; char *DumpFile; char *bankRootDirList,*currentBankDir; } cfg; diff --git a/src/Synth/ADnote.C b/src/Synth/ADnote.C @@ -107,15 +107,17 @@ ADnote::ADnote(ADnoteParameters *pars,Controller *ctl_,REALTYPE freq,REALTYPE ve oscposhi[nvoice]=0;oscposlo[nvoice]=0.0; oscposhiFM[nvoice]=0;oscposloFM[nvoice]=0.0; - NoteVoicePar[nvoice].OscilSmp=new REALTYPE[OSCIL_SIZE+1];//the extra point contains the first point + NoteVoicePar[nvoice].OscilSmp=new REALTYPE[OSCIL_SIZE+OSCIL_SMP_EXTRA_SAMPLES];//the extra points contains the first point //Get the voice's oscil or external's voice oscil int vc=nvoice; if (pars->VoicePar[nvoice].Pextoscil!=-1) vc=pars->VoicePar[nvoice].Pextoscil; oscposhi[nvoice]=pars->VoicePar[vc].OscilSmp->get(NoteVoicePar[nvoice].OscilSmp,getvoicebasefreq(nvoice), pars->VoicePar[nvoice].Presonance); - //I store the first elment to the last position for speedups - NoteVoicePar[nvoice].OscilSmp[OSCIL_SIZE]=NoteVoicePar[nvoice].OscilSmp[0]; + + //I store the first elments to the last position for speedups + for (int i=0;i<OSCIL_SMP_EXTRA_SAMPLES;i++) NoteVoicePar[nvoice].OscilSmp[OSCIL_SIZE+i]=NoteVoicePar[nvoice].OscilSmp[i]; + oscposhi[nvoice]+=(int)((pars->VoicePar[nvoice].Poscilphase-64.0)/128.0*OSCIL_SIZE+OSCIL_SIZE*4); oscposhi[nvoice]%=OSCIL_SIZE; @@ -327,7 +329,7 @@ void ADnote::initparameters(){ /* Voice Modulation Parameters Init */ if ((NoteVoicePar[nvoice].FMEnabled!=NONE)&&(NoteVoicePar[nvoice].FMVoice<0)){ - NoteVoicePar[nvoice].FMSmp=new REALTYPE[OSCIL_SIZE+1]; + NoteVoicePar[nvoice].FMSmp=new REALTYPE[OSCIL_SIZE+OSCIL_SMP_EXTRA_SAMPLES]; //Perform Anti-aliasing only on MORPH or RING MODULATION REALTYPE tmp=1.0; @@ -342,7 +344,7 @@ void ADnote::initparameters(){ if (partparams->VoicePar[nvoice].PextFMoscil!=-1) vc=partparams->VoicePar[nvoice].PextFMoscil; oscposhiFM[nvoice]=(oscposhi[nvoice]+partparams->VoicePar[vc].FMSmp->get(NoteVoicePar[nvoice].FMSmp,tmp)) % OSCIL_SIZE; - NoteVoicePar[nvoice].FMSmp[OSCIL_SIZE]=NoteVoicePar[nvoice].FMSmp[0]; + for (int i=0;i<OSCIL_SMP_EXTRA_SAMPLES;i++) NoteVoicePar[nvoice].FMSmp[OSCIL_SIZE+i]=NoteVoicePar[nvoice].FMSmp[i]; oscposhiFM[nvoice]+=(int)((partparams->VoicePar[nvoice].PFMoscilphase-64.0)/128.0*OSCIL_SIZE+OSCIL_SIZE*4); oscposhiFM[nvoice]%=OSCIL_SIZE; }; @@ -550,16 +552,17 @@ inline void ADnote::fadein(REALTYPE *smps){ }; /* - * Computes the Oscillator (Without Modulation) + * Computes the Oscillator (Without Modulation) - LinearInterpolation */ -inline void ADnote::ComputeVoiceOscillator(int nvoice){ +inline void ADnote::ComputeVoiceOscillator_LinearInterpolation(int nvoice){ int i,poshi; REALTYPE poslo; poshi=oscposhi[nvoice]; poslo=oscposlo[nvoice]; + REALTYPE *smps=NoteVoicePar[nvoice].OscilSmp; for (i=0;i<SOUND_BUFFER_SIZE;i++){ - tmpwave[i]=NoteVoicePar[nvoice].OscilSmp[poshi]*(1.0-poslo)+NoteVoicePar[nvoice].OscilSmp[poshi+1]*poslo; + tmpwave[i]=smps[poshi]*(1.0-poslo)+smps[poshi+1]*poslo; poslo+=oscfreqlo[nvoice]; if (poslo>=1.0) { poslo-=1.0; @@ -572,13 +575,50 @@ inline void ADnote::ComputeVoiceOscillator(int nvoice){ oscposlo[nvoice]=poslo; }; + + +/* + * Computes the Oscillator (Without Modulation) - CubicInterpolation + * + The differences from the Linear are to little to deserve to be used. This is because I am using a large OSCIL_SIZE (>512) +inline void ADnote::ComputeVoiceOscillator_CubicInterpolation(int nvoice){ + int i,poshi; + REALTYPE poslo; + + poshi=oscposhi[nvoice]; + poslo=oscposlo[nvoice]; + REALTYPE *smps=NoteVoicePar[nvoice].OscilSmp; + REALTYPE xm1,x0,x1,x2,a,b,c; + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + xm1=smps[poshi]; + x0=smps[poshi+1]; + x1=smps[poshi+2]; + x2=smps[poshi+3]; + a=(3.0 * (x0-x1) - xm1 + x2) / 2.0; + b = 2.0*x1 + xm1 - (5.0*x0 + x2) / 2.0; + c = (x1 - xm1) / 2.0; + tmpwave[i]=(((a * poslo) + b) * poslo + c) * poslo + x0; + printf("a\n"); + //tmpwave[i]=smps[poshi]*(1.0-poslo)+smps[poshi+1]*poslo; + poslo+=oscfreqlo[nvoice]; + if (poslo>=1.0) { + poslo-=1.0; + poshi++; + }; + poshi+=oscfreqhi[nvoice]; + poshi&=OSCIL_SIZE-1; + }; + oscposhi[nvoice]=poshi; + oscposlo[nvoice]=poslo; +}; +*/ /* * Computes the Oscillator (Morphing) */ inline void ADnote::ComputeVoiceOscillatorMorph(int nvoice){ int i; REALTYPE amp; - ComputeVoiceOscillator(nvoice); + ComputeVoiceOscillator_LinearInterpolation(nvoice); if (FMnewamplitude[nvoice]>1.0) FMnewamplitude[nvoice]=1.0; if (FMoldamplitude[nvoice]>1.0) FMoldamplitude[nvoice]=1.0; @@ -619,7 +659,7 @@ inline void ADnote::ComputeVoiceOscillatorMorph(int nvoice){ inline void ADnote::ComputeVoiceOscillatorRingModulation(int nvoice){ int i; REALTYPE amp; - ComputeVoiceOscillator(nvoice); + ComputeVoiceOscillator_LinearInterpolation(nvoice); if (FMnewamplitude[nvoice]>1.0) FMnewamplitude[nvoice]=1.0; if (FMoldamplitude[nvoice]>1.0) FMoldamplitude[nvoice]=1.0; if (NoteVoicePar[nvoice].FMVoice>=0){ @@ -781,7 +821,9 @@ int ADnote::noteout(REALTYPE *outl,REALTYPE *outr){ case PHASE_MOD:ComputeVoiceOscillatorFrequencyModulation(nvoice,0);break; case FREQ_MOD:ComputeVoiceOscillatorFrequencyModulation(nvoice,1);break; //case PITCH_MOD:ComputeVoiceOscillatorPitchModulation(nvoice);break; - default:ComputeVoiceOscillator(nvoice); + default:ComputeVoiceOscillator_LinearInterpolation(nvoice); + //if (config.cfg.Interpolation) ComputeVoiceOscillator_CubicInterpolation(nvoice); + }; } else ComputeVoiceNoise(nvoice); // Voice Processing diff --git a/src/Synth/ADnote.h b/src/Synth/ADnote.h @@ -33,7 +33,9 @@ //Globals //FM amplitude tune -#define FM_AMP_MULTIPLIER 14.73 // ln(2500000) +#define FM_AMP_MULTIPLIER 14.71280603 + +#define OSCIL_SMP_EXTRA_SAMPLES 5 class ADnote{ //ADDitive note public: @@ -58,7 +60,8 @@ class ADnote{ //ADDitive note void KillNote(); inline REALTYPE getvoicebasefreq(int nvoice); inline REALTYPE getFMvoicebasefreq(int nvoice); - inline void ComputeVoiceOscillator(int nvoice); + inline void ComputeVoiceOscillator_LinearInterpolation(int nvoice); + inline void ComputeVoiceOscillator_CubicInterpolation(int nvoice); inline void ComputeVoiceOscillatorMorph(int nvoice); inline void ComputeVoiceOscillatorRingModulation(int nvoice); inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice,int FMmode);//FMmode=0 for phase modulation, 1 for Frequency modulation diff --git a/src/UI/ConfigUI.fl b/src/UI/ConfigUI.fl @@ -42,7 +42,7 @@ o->hide();} xywh {5 5 500 305} } { Fl_Group {} { - label {Main settings} selected + label {Main settings} xywh {5 25 500 285} } { Fl_Group {} { @@ -160,21 +160,27 @@ config.cfg.SoundBufferSize=strtoul(o->value(),&tmp,10);} xywh {15 225 240 20} labelfont 1 labelsize 12 align 128 } Fl_Group {} { - xywh {15 115 230 85} box ENGRAVED_BOX + xywh {15 110 230 85} box ENGRAVED_BOX } { Fl_File_Input {} { label {Dump File} callback {snprintf(config.cfg.DumpFile,config.maxstringsize,"%s",o->value());} - xywh {20 160 220 35} align 5 + xywh {20 155 220 35} align 5 code0 {o->insert(config.cfg.DumpFile);} } Fl_Check_Button {} { label {Dump notes} callback {config.cfg.DumpNotesToFile=(int) o->value(); dump.startnow();//this has effect only if this option was disabled} - xywh {20 120 100 20} down_box DOWN_BOX + xywh {20 115 100 20} down_box DOWN_BOX code0 {o->value(config.cfg.DumpNotesToFile);} } + Fl_Check_Button {} { + label Append + callback {config.cfg.DumpAppend=(int) o->value();} + xywh {160 115 80 20} down_box DOWN_BOX + code0 {o->value(config.cfg.DumpAppend);} + } } Fl_Group {} { xywh {255 45 245 260} box ENGRAVED_FRAME @@ -219,12 +225,6 @@ midiinputnamebox->label(config.winmididevices[config.cfg.WindowsMidiInId].name); } } } - Fl_Check_Button {} { - label Append - callback {config.cfg.DumpAppend=(int) o->value();} - xywh {160 120 80 20} down_box DOWN_BOX - code0 {o->value(config.cfg.DumpAppend);} - } Fl_Counter {} { label {XML compression level} callback {config.cfg.GzipCompression=(int) o->value();}