Esempio n. 1
0
        public static EffectDefinition CreateAudioEnvelope(double volumePercent, double fadeInDuration,
                                                           double fadeOutDuration, double duration)
        {
            if ((volumePercent < 0) || (volumePercent > 1))
            {
                throw new SplicerException("Volume percentage must be between 0 and 1");
            }

            if ((fadeInDuration + fadeOutDuration) > duration)
            {
                throw new SplicerException(
                    "Sum of the fade-in and fade-out durations must not exceed the total duration");
            }

            string volumeValue = volumePercent.ToString(CultureInfo.InvariantCulture);

            var definition = new EffectDefinition(AudioMixerEffect);

            var volumeParameter = new Parameter();
            volumeParameter.Name = "Vol";

            if (fadeInDuration > 0)
            {
                volumeParameter.Value = "0";
                volumeParameter.Intervals.Add(new Interval(fadeInDuration, volumeValue));
            }
            else
            {
                volumeParameter.Value = volumeValue;
            }

            if (fadeOutDuration > 0)
            {
                volumeParameter.Intervals.Add(new Interval(duration - (fadeInDuration + fadeOutDuration), volumeValue));
                volumeParameter.Intervals.Add(new Interval(duration, "0"));
            }
            else
            {
                volumeParameter.Intervals.Add(new Interval(duration, volumeValue));
            }

            definition.Parameters.Add(volumeParameter);

            return definition;
        }
        public void JumpVolume()
        {
            // and audible demonstration of the difference between interpolating
            // parameter values for an effect, and jumping directly to them.

            string outputFile = "JumpVolume.wma";

            using (ITimeline timeline = new DefaultTimeline())
            {
                IGroup group = timeline.AddAudioGroup();
                ITrack track = group.AddTrack();
                IClip clip = track.AddClip("testinput.mp3", GroupMediaType.Audio, InsertPosition.Relative, 0, 0, 10);

                var effectDefinition = new EffectDefinition(StandardEffects.AudioMixerEffect);

                var volumeParameter = new Parameter("Vol", 0.0, 2, 1.0);
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 2.5, "0.2"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 3.5, "0.8"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 4.5, "0.2"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Jump, 5, "1.0"));
                volumeParameter.Intervals.Add(new Interval(IntervalMode.Interpolate, clip.Duration, "0.0"));

                effectDefinition.Parameters.Add(volumeParameter);

                clip.AddEffect(0, clip.Duration, effectDefinition);

                using (
                    var renderer =
                        new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.MediumQualityAudio))
                {
                    renderer.Render();
                }
            }
        }