Exemple #1
0
        public void BeginFadeOut(double fadeDurationInMilliseconds)
        {
            object obj = this.lockObject;

            lock (obj)
            {
                this.fadeSamplePosition = 0;
                this.fadeSampleCount    = (int)(fadeDurationInMilliseconds * (double)this.source.WaveFormat.SampleRate / 1000.0);
                this.fadeState          = FadeInOutSampleProvider.FadeState.FadingOut;
            }
        }
Exemple #2
0
        private void FadeIn(float[] buffer, int offset, int sourceSamplesRead)
        {
            int i = 0;

            while (i < sourceSamplesRead)
            {
                float num = (float)this.fadeSamplePosition / (float)this.fadeSampleCount;
                for (int j = 0; j < this.source.WaveFormat.Channels; j++)
                {
                    buffer[offset + i++] *= num;
                }
                this.fadeSamplePosition++;
                if (this.fadeSamplePosition > this.fadeSampleCount)
                {
                    this.fadeState = FadeInOutSampleProvider.FadeState.FullVolume;
                    return;
                }
            }
        }
Exemple #3
0
        private void FadeOut(float[] buffer, int offset, int sourceSamplesRead)
        {
            int i = 0;

            while (i < sourceSamplesRead)
            {
                float num = 1f - (float)this.fadeSamplePosition / (float)this.fadeSampleCount;
                for (int j = 0; j < this.source.WaveFormat.Channels; j++)
                {
                    buffer[offset + i++] *= num;
                }
                this.fadeSamplePosition++;
                if (this.fadeSamplePosition > this.fadeSampleCount)
                {
                    this.fadeState = FadeInOutSampleProvider.FadeState.Silence;
                    FadeInOutSampleProvider.ClearBuffer(buffer, i + offset, sourceSamplesRead - i);
                    return;
                }
            }
        }
Exemple #4
0
 public FadeInOutSampleProvider(ISampleProvider source, bool initiallySilent = false)
 {
     this.source    = source;
     this.fadeState = (initiallySilent ? FadeInOutSampleProvider.FadeState.Silence : FadeInOutSampleProvider.FadeState.FullVolume);
 }