public override void Stop() { this.status = AdsrStatus.Release; }
public override void Render(float[] leftChannel,float[] rightChannel) { ISoundRender soundRender = this.SoundInputs[0]; int channelSize = leftChannel.Length; float leftVolume = volume * (1.0f-pan) * velocity; float rightVolume = volume * pan * velocity; if (soundRender.Playing) soundRender.Render(leftChannel,rightChannel); else { int i; this.playing = false; for (i=0; i<channelSize; i++) leftChannel[i] = 0.0f; for (i=0; i<channelSize; i++) rightChannel[i] = 0.0f; return; } for (int i=0; i<channelSize; i++) { switch(status) { case AdsrStatus.PreDelay: preDelaySamplesElapsed++; if (preDelaySamplesElapsed >= preDelaySamples) { status = AdsrStatus.Attack; } break; case AdsrStatus.Attack: ADSRenvelope += attackLevel; if (ADSRenvelope >= 1.0f) { ADSRenvelope = 1.0f; status = AdsrStatus.Decay; } break; case AdsrStatus.Decay: ADSRenvelope -= decayLevel; if (ADSRenvelope <= sustainLevel) { ADSRenvelope = sustainLevel; status = AdsrStatus.Sustain; } break; case AdsrStatus.Sustain: ADSRenvelope = sustainLevel; break; case AdsrStatus.Release: ADSRenvelope -= releaseLevel; if (ADSRenvelope <= 0.0f) { ADSRenvelope = 0.0f; playing = false; } break; } leftChannel[i] = leftChannel[i] * leftVolume * ADSRenvelope; rightChannel[i] = rightChannel[i] * rightVolume * ADSRenvelope; } }