public void EnvToSecs(bool sustainIsGain) { // EG times need to be converted from timecents to seconds. // Pin very short EG segments. Timecents don't get to zero, and our EG is // happier with zero values. Delay = (Delay < -11950.0f ? 0.0f : SynthHelper.Timecents2Secs(Delay)); Attack = (Attack < -11950.0f ? 0.0f : SynthHelper.Timecents2Secs(Attack)); Release = (Release < -11950.0f ? 0.0f : SynthHelper.Timecents2Secs(Release)); // If we have dynamic hold or decay times depending on key number we need // to keep the values in timecents so we can calculate it during startNote if (KeynumToHold == 0) { Hold = (Hold < -11950.0f ? 0.0f : SynthHelper.Timecents2Secs(Hold)); } if (KeynumToDecay == 0) { Decay = (Decay < -11950.0f ? 0.0f : SynthHelper.Timecents2Secs(Decay)); } if (Sustain < 0.0f) { Sustain = 0.0f; } else if (sustainIsGain) { Sustain = SynthHelper.DecibelsToGain(-Sustain / 10.0f); } else { Sustain = 1.0f - (Sustain / 1000.0f); } }
public void CalcPitchRatio(float pitchShift, float outSampleRate) { var note = PlayingKey + Region.Transpose + Region.Tune / 100.0; var adjustedPitch = Region.PitchKeyCenter + (note - Region.PitchKeyCenter) * (Region.PitchKeyTrack / 100.0); if (pitchShift != 0) { adjustedPitch += pitchShift; } PitchInputTimecents = adjustedPitch * 100.0; PitchOutputFactor = Region.SampleRate / (SynthHelper.Timecents2Secs(Region.PitchKeyCenter * 100.0) * outSampleRate); }
public void Setup( Envelope newParameters, int midiNoteNumber, int midiVelocity, bool isAmpEnv, float outSampleRate) { Parameters = new Envelope(newParameters); if (Parameters.KeynumToHold > 0) { Parameters.Hold += Parameters.KeynumToHold * (60.0f - midiNoteNumber); Parameters.Hold = Parameters.Hold < -10000.0f ? 0.0f : SynthHelper.Timecents2Secs(Parameters.Hold); } if (Parameters.KeynumToDecay > 0) { Parameters.Decay += Parameters.KeynumToDecay * (60.0f - midiNoteNumber); Parameters.Decay = Parameters.Decay < -10000.0f ? 0.0f : SynthHelper.Timecents2Secs(Parameters.Decay); } MidiVelocity = (short)midiVelocity; IsAmpEnv = isAmpEnv; NextSegment(VoiceEnvelopeSegment.None, outSampleRate); }