protected IWaveSource CutWaveSource(IWaveSource source) { // ReSharper disable CompareOfFloatsByEqualityOperator if (StartTime == 0 && EndTime == 0) { return(source); } var startTime = TimeSpan.FromMilliseconds(StartTime); var endTime = TimeSpan.FromMilliseconds(EndTime); return(source.AppendSource(x => new CutSource(x, startTime, endTime - startTime))); }
protected IWaveSource CutWaveSource(IWaveSource source) { try { // ReSharper disable CompareOfFloatsByEqualityOperator if (StartTime == 0 && EndTime == 0) { return(source); } var startTime = TimeSpan.FromMilliseconds(StartTime); var endTime = TimeSpan.FromMilliseconds(EndTime); return(source.AppendSource(x => new CutSource(x, startTime, endTime - startTime))); } catch (Exception ex) { CommonHelper.AddLog(ex.ToString()); return(source); } }
private IWaveSource addEffectsToSource(IWaveSource source, int chorusLevel, int reverbLevel, int echoDelay, int distortionLevel, bool radio) { // Effects level is increased by damage if distortion is enabled int effectsLevel = fxLevel(distortionLevel); // Add various effects... Logging.Debug("Effects level is " + effectsLevel + ", chorus level is " + chorusLevel + ", reverb level is " + reverbLevel + ", echo delay is " + echoDelay); // We need to extend the duration of the wave source if we have any effects going on if (chorusLevel != 0 || reverbLevel != 0 || echoDelay != 0) { // Add a base of 500ms plus 10ms per effect level over 50 Logging.Debug("Extending duration by " + 500 + Math.Max(0, (effectsLevel - 50) * 10) + "ms"); source = source.AppendSource(x => new ExtendedDurationWaveSource(x, 500 + Math.Max(0, (effectsLevel - 50) * 10))); } // We always have chorus if (chorusLevel != 0) { source = source.AppendSource(x => new DmoChorusEffect(x) { Depth = chorusLevel, WetDryMix = Math.Min(100, (int)(180 * (effectsLevel) / ((decimal)100))), Delay = 16, Frequency = (effectsLevel / 10), Feedback = 25 }); } // We only have reverb and echo if we're not transmitting or receiving if (!radio) { if (reverbLevel != 0) { source = source.AppendSource(x => new DmoWavesReverbEffect(x) { ReverbTime = (int)(1 + 999 * (effectsLevel) / ((decimal)100)), ReverbMix = Math.Max(-96, -96 + (96 * reverbLevel / 100)) }); } if (echoDelay != 0) { source = source.AppendSource(x => new DmoEchoEffect(x) { LeftDelay = echoDelay, RightDelay = echoDelay, WetDryMix = Math.Max(5, (int)(10 * (effectsLevel) / ((decimal)100))), Feedback = 0 }); } } // Apply a high pass filter for a radio effect else { var sampleSource = source.ToSampleSource().AppendSource(x => new BiQuadFilterSource(x)); sampleSource.Filter = new HighpassFilter(source.WaveFormat.SampleRate, 1015); source = sampleSource.ToWaveSource(); } // Adjust gain if (effectsLevel != 0 && chorusLevel != 0) { int radioGain = radio ? 7 : 0; source = source.AppendSource(x => new DmoCompressorEffect(x) { Gain = effectsLevel / 15 + radioGain }); } return(source); }
static private void ApplyEffects(ref IWaveSource src, SoundEffectSettings ap) // ap may be null { if (ap != null && ap.Any) { int extend = 0; if (ap.echoenabled) { extend = ap.echodelay * 2; } if (ap.chorusenabled) { extend = Math.Max(extend, 50); } if (ap.reverbenabled) { extend = Math.Max(extend, 50); } if (extend > 0) { //System.Diagnostics.Debug.WriteLine("Extend by " + extend + " ms due to effects"); src = src.AppendSource(x => new ExtendWaveSource(x, extend)); } if (ap.chorusenabled) { src = src.AppendSource(x => new DmoChorusEffect(x) { WetDryMix = ap.chorusmix, Feedback = ap.chorusfeedback, Delay = ap.chorusdelay, Depth = ap.chorusdepth }); } if (ap.reverbenabled) { src = src.AppendSource(x => new DmoWavesReverbEffect(x) { InGain = 0, ReverbMix = ap.reverbmix, ReverbTime = ((float)ap.reverbtime) / 1000.0F, HighFrequencyRTRatio = ((float)ap.reverbhfratio) / 1000.0F }); } if (ap.distortionenabled) { src = src.AppendSource(x => new DmoDistortionEffect(x) { Gain = ap.distortiongain, Edge = ap.distortionedge, PostEQCenterFrequency = ap.distortioncentrefreq, PostEQBandwidth = ap.distortionfreqwidth }); } if (ap.gargleenabled) { src = src.AppendSource(x => new DmoGargleEffect(x) { RateHz = ap.garglefreq }); } if (ap.echoenabled) { src = src.AppendSource(x => new DmoEchoEffect(x) { WetDryMix = ap.echomix, Feedback = ap.echofeedback, LeftDelay = ap.echodelay, RightDelay = ap.echodelay }); } if (ap.pitchshiftenabled) { ISampleSource srs = src.ToSampleSource(); srs = srs.AppendSource(x => new PitchShifter(x) { PitchShiftFactor = ((float)ap.pitchshift) / 100.0F }); src = srs.ToWaveSource(); } } }
private void addEffectsToSource(ref IWaveSource source, int chorusLevel, int reverbLevel, int echoDelay, int distortionLevel) { // Add various effects... Logging.Debug("Effects level is " + configuration.EffectsLevel + ", chorus level is " + chorusLevel + ", reverb level is " + reverbLevel + ", echo delay is " + echoDelay); // We need to extend the duration of the wave source if we have any effects going on if (chorusLevel != 0 || reverbLevel != 0 || echoDelay != 0) { // Add a base of 500ms plus 10ms per effect level over 50 Logging.Debug("Extending duration by " + 500 + Math.Max(0, (configuration.EffectsLevel - 50) * 10) + "ms"); source = source.AppendSource(x => new ExtendedDurationWaveSource(x, 500 + Math.Max(0, (configuration.EffectsLevel - 50) * 10))); } // We always have chorus if (chorusLevel != 0) { Logging.Debug("Adding chorus"); source = source.AppendSource(x => new DmoChorusEffect(x) { Depth = chorusLevel, WetDryMix = Math.Min(100, (int)(180 * ((decimal)configuration.EffectsLevel) / ((decimal)100))), Delay = 16, Frequency = (configuration.EffectsLevel / 10), Feedback = 25 }); } // We only have reverb and echo if we're not transmitting or receiving //if (!radio) //{ if (reverbLevel != 0) { Logging.Debug("Adding reverb"); // We tone down the reverb level with the distortion level, as the combination is nasty source = source.AppendSource(x => new DmoWavesReverbEffect(x) { ReverbTime = (int)(1 + 999 * ((decimal)configuration.EffectsLevel) / ((decimal)100)), ReverbMix = Math.Max(-96, -96 + (96 * reverbLevel / 100) - distortionLevel) }); } if (echoDelay != 0) { Logging.Debug("Adding echo"); // We tone down the echo level with the distortion level, as the combination is nasty source = source.AppendSource(x => new DmoEchoEffect(x) { LeftDelay = echoDelay, RightDelay = echoDelay, WetDryMix = Math.Max(5, (int)(10 * ((decimal)configuration.EffectsLevel) / ((decimal)100)) - distortionLevel), Feedback = Math.Max(0, 10 - distortionLevel / 2) }); } //} if (configuration.EffectsLevel > 0 && distortionLevel > 0) { Logging.Debug("Adding distortion"); source = source.AppendSource(x => new DmoDistortionEffect(x) { Edge = distortionLevel, Gain = -distortionLevel / 2, PostEQBandwidth = 4000, PostEQCenterFrequency = 4000 }); } //if (radio) //{ // source = source.AppendSource(x => new DmoDistortionEffect(x) { Edge = 7, Gain = -distortionLevel / 2, PostEQBandwidth = 2000, PostEQCenterFrequency = 6000 }); // source = source.AppendSource(x => new DmoCompressorEffect(x) { Attack = 1, Ratio = 3, Threshold = -10 }); //} }
private IWaveSource addEffectsToSource(IWaveSource source, int chorusLevel, int reverbLevel, int echoDelay, int distortionLevel, bool radio) { // Effects level is increased by damage if distortion is enabled int effectsLevel = fxLevel(distortionLevel); // Add various effects... Logging.Debug("Effects level is " + effectsLevel + ", chorus level is " + chorusLevel + ", reverb level is " + reverbLevel + ", echo delay is " + echoDelay); // We need to extend the duration of the wave source if we have any effects going on if (chorusLevel != 0 || reverbLevel != 0 || echoDelay != 0) { // Add a base of 500ms plus 10ms per effect level over 50 int extMs = 500 + Math.Max(0, (effectsLevel - 50) * 10); Logging.Debug("Extending duration by " + extMs + "ms"); source = source.AppendSource(x => new ExtendedDurationWaveSource(x, extMs)); } // We always apply chorus effects. if (chorusLevel != 0) { // The "wetDryMix" mix is the percent of added chorus, with 0 indicating no added chorus. const int delay = 16; const int feedback = 25; float wetDryMix = Math.Min(100, (int)(180 * effectsLevel / (decimal)100)); float frequency = (effectsLevel / 10); source = source.AppendSource(x => new DmoChorusEffect(x) { Depth = chorusLevel, WetDryMix = wetDryMix, Delay = delay, Frequency = frequency, Feedback = feedback }); } // Apply a high pass filter for a radio effect if (radio) { var sampleSource = source.ToSampleSource().AppendSource(x => new BiQuadFilterSource(x)); sampleSource.Filter = new HighpassFilter(source.WaveFormat.SampleRate, 1015); source = sampleSource.ToWaveSource(); } // We only have reverb and echo if we're not transmitting or receiving else { if (reverbLevel != 0 && effectsLevel != 0) { float reverbTime = (int)(1 + (999 * effectsLevel / (decimal)100)); float reverbMix = Math.Max(-96, -96 + (96 * reverbLevel / 100)); source = source.AppendSource(x => new DmoWavesReverbEffect(x) { ReverbTime = reverbTime, ReverbMix = reverbMix }); } if (echoDelay != 0 && effectsLevel != 0) { // The "wetDryMix" mix is the percent of added echo, with 0 indicating no added echo. const int feedback = 0; float wetDryMix = Math.Max(5, (int)(10 * effectsLevel / (decimal)100)); source = source.AppendSource(x => new DmoEchoEffect(x) { LeftDelay = echoDelay, RightDelay = echoDelay, WetDryMix = wetDryMix, Feedback = feedback }); } } // Adjust gain const int standardGain = 10; int radioGain = radio ? 7 : 0; source = source.AppendSource(x => new DmoCompressorEffect(x) { Gain = (effectsLevel / 15) + radioGain + standardGain }); return(source); }
public async Task <bool> OpenTrack(IPlaySource track, bool openCrossfading, long position) { IsLoading = true; if (!openCrossfading) { StopPlayback(); } if (_crossfadeService.IsFading) { _crossfadeService.Cancel(); } if (_soundSource != null && !openCrossfading) { _soundSource.Dispose(); } if (openCrossfading && _soundSource != null) { _soundOut.Stopped -= SoundOut_Stopped; _loopStream.StreamFinished -= LoopStream_StreamFinished; _simpleNotificationSource.BlockRead -= SimpleNotificationSource_BlockRead; _crossfadeService.CrossfadeOut(_soundOut, CrossfadeDuration).Forget(); _soundOut = null; } var tempSource = await GetSoundSource(track, position); if (tempSource == null) { return(false); } _soundSource = tempSource; if (_soundSource.WaveFormat.SampleRate < 44100) //Correct sample rate { _soundSource = _soundSource.ChangeSampleRate(44100); } _soundSource = _soundSource .AppendSource(x => new LoopStream(x), out _loopStream) .AppendSource(x => Equalizer.Create10BandEqualizer(x.ToSampleSource()), out _equalizer) .AppendSource(x => new SimpleNotificationSource(x) { Interval = 100 }, out _simpleNotificationSource) .ToWaveSource(); _loopStream.EnableLoop = IsLooping; _loopStream.StreamFinished += LoopStream_StreamFinished; _simpleNotificationSource.BlockRead += SimpleNotificationSource_BlockRead; for (var i = 0; i < EqualizerBands.Count; i++) { SetEqualizerBandValue(EqualizerBands.Bands[i].Value, i); } if (_soundOut == null) { _soundOut = _soundOutProvider.GetSoundOut(); _soundOut.Stopped += SoundOut_Stopped; } _soundOut.Initialize(_soundSource); _soundOut.Volume = Volume; IsLoading = false; OnTrackLengthChanged(); _playTimeStopwatch.Reset(); if (openCrossfading) { await TogglePlayPause(); _fadingService.FadeIn(_soundOut, Volume).Forget(); } CurrentStateChanged(); OnPositionChanged(); return(true); }