Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix limiting FMmodfreqlo #264

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Params/EnvelopeParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void EnvelopeParams::add2XML(XMLwrapper& xml)
}

float EnvelopeParams::env_dB2rap(float db) {
return (powf(10.0f, db / 20.0f) - 0.01)/.99f;
return std::max(powf(10.0f, db / 20.0f) - 0.01,0.0)/.99f;
}

float EnvelopeParams::env_rap2dB(float rap) {
Expand Down
4 changes: 2 additions & 2 deletions src/Synth/ADnote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice,
float *tw = tmpwave_unison[k];
float fmold = vce.FMoldsmp[k];
for(int i = 0; i < synth.buffersize; ++i) {
fmold = fmodf(fmold + tw[i] * normalize, synth.oscilsize);
fmold = fmold + (tw[i] * normalize);
tw[i] = fmold;
}
vce.FMoldsmp[k] = fmold;
Expand Down Expand Up @@ -1557,7 +1557,7 @@ inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice,
int FMmodfreqhi = 0;
F2I(tw[i], FMmodfreqhi);
float FMmodfreqlo = tw[i]-FMmodfreqhi;//fmod(tw[i] /*+ 0.0000000001f*/, 1.0f);
if(FMmodfreqhi < 0)
if(FMmodfreqlo < 0)
FMmodfreqlo++;

//carrier
Expand Down
27 changes: 14 additions & 13 deletions src/Synth/Envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ Envelope::Envelope(EnvelopeParams &pars, float basefreq, float bufferdt,
envdt[i] = bufferdt / dtstretched;
else
envdt[i] = 2.0f; //any value larger than 1

switch(mode) {
case 2:
case ADSR_dB:
envval[i] = (1.0f - pars.Penvval[i] / 127.0f) * -40;
break;
case 3:
case ASR_freqlfo:
envval[i] =
(powf(2, 6.0f
* fabsf(pars.Penvval[i]
- 64.0f) / 64.0f) - 1.0f) * 100.0f;
if(pars.Penvval[i] < 64)
envval[i] = -envval[i];
break;
case 4:
case ADSR_filter:
envval[i] = (pars.Penvval[i] - 64.0f) / 64.0f * 6.0f; //6 octaves (filtru)
break;
case 5:
case ASR_bw:
envval[i] = (pars.Penvval[i] - 64.0f) / 64.0f * 10;
break;
case ADSR_lin:
default:
envval[i] = pars.Penvval[i] / 127.0f;
}
Expand Down Expand Up @@ -109,27 +109,29 @@ void Envelope::watch(float time, float value)
float factor2;
pos[0] = time;
switch(mode) {
case 2:
case ADSR_dB:
pos[1] = 1 - value / -40.f;
watchOut(pos, 2);
break;
case 3:
case ASR_freqlfo:
factor1 = log(value/100. + 1.) / (6. * log(2));
factor2 = log(1. - value/100.) / (6. * log(2));
pos[1] = ((0.5 * factor1) >= 0) ? (0.5 * factor1 + 0.5) : (0.5 - factor2 * 0.5);
watchOut(pos, 2);
break;
case 4:
case ADSR_filter:
pos[1] = (value + 6.) / 12.f;
watchOut(pos, 2);
break;
case 5:
case ASR_bw:
pos[1] = (value + 10.) / 20.f;
watchOut(pos, 2);
break;
case ADSR_lin:
default:
pos[1] = value;
watchOut(pos, 2);
break;
}
}

Expand Down Expand Up @@ -243,10 +245,9 @@ float Envelope::envout_dB()
out = v2;
}

if(out > 0.001f)
envoutval = EnvelopeParams::env_rap2dB(out);
else
envoutval = MIN_ENVELOPE_DB;

envoutval = EnvelopeParams::env_rap2dB(out);

out = envoutval;
} else
out = envout(false);
Expand Down
1 change: 0 additions & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ typedef std::complex<fftwf_real> fft_t;
* Envelope Limits
*/
#define MAX_ENVELOPE_POINTS 40
#define MIN_ENVELOPE_DB -400

/*
* The threshold for the amplitude interpolation used if the amplitude
Expand Down