/// <summary>
        /// Takes a specified amount of time from the source stream
        /// </summary>
        /// <param name="sampleProvider">Source sample provider</param>
        /// <param name="take">Duration to take</param>
        /// <returns>A sample provider that reads up to the specified amount of time</returns>
        public static ISampleProvider TakeWithFade(this ISampleProvider sampleProvider, TimeSpan take, TimeSpan fadeIn, TimeSpan fadeOut, TimeSpan skip)
        {
            var offset = new OffsetSampleProvider(sampleProvider)
            {
                SkipOver = skip, Take = take
            };

            if (fadeIn == TimeSpan.Zero && fadeOut == TimeSpan.Zero)
            {
                return(offset);
            }
            var fade = new TimedFadeInOutSampleProvider(offset, fadeIn != TimeSpan.Zero);

            if (fadeIn != TimeSpan.Zero)
            {
                fade.AddFadeIn(TimeSpan.Zero, fadeIn);
            }
            if (fadeOut != TimeSpan.Zero)
            {
                fade.AddFadeOut(take - fadeOut, fadeOut);
            }
            return(fade);
        }
Пример #2
0
        private static ISampleProvider GetProvider(ISampleProvider source, TimeSpan take, TimeSpan fadeIn, TimeSpan fadeOut, TimeSpan skip, float volume)
        {
            var offset = new OffsetSampleProvider(source)
            {
                SkipOver = skip, Take = take
            };
            var mono = offset.ToMono(volume, volume);

            if (fadeIn == TimeSpan.Zero && fadeOut == TimeSpan.Zero)
            {
                return(mono);
            }
            var fade = new TimedFadeInOutSampleProvider(mono, fadeIn != TimeSpan.Zero);

            if (fadeIn != TimeSpan.Zero)
            {
                fade.AddFadeIn(TimeSpan.Zero, fadeIn);
            }
            if (fadeOut != TimeSpan.Zero)
            {
                fade.AddFadeOut(take - fadeOut, fadeOut);
            }
            return(fade);
        }