Esempio n. 1
0
        public OrderSound(string message, float Depth, float Frequency, float Feedback, float WetDryMix, float ReverbTime, float HighFrequencyRTRatio)
        {
            Thread theRT = new Thread(delegate()
            {
                {
                    m_AudioStream = new MemoryStream();
                    using (SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer())
                    {
                        speechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
                        speechSynthesizer.Rate = Rate;
                        speechSynthesizer.SetOutputToWaveStream(m_AudioStream);
                        speechSynthesizer.SpeakCompleted += new EventHandler <SpeakCompletedEventArgs>(WriteCompleate);
                        speechSynthesizer.SpeakAsync(message);
                        state = SOUNDSTATE.FORMING;
                        manualReset.WaitOne();
                        state = SOUNDSTATE.READY;
                        m_AudioStream.Seek(0, SeekOrigin.Begin);
                        flanger = new FlangerEffect(GetSoundSource(m_AudioStream))
                        {
                            Depth     = Depth,
                            Frequency = Frequency,
                            Feedback  = Feedback,
                            WetDryMix = WetDryMix
                        };
                        rev = new DmoWavesReverbEffect(flanger.ToStereo())
                        {
                            ReverbTime           = ReverbTime,
                            HighFrequencyRTRatio = HighFrequencyRTRatio
                        };
                        rev.WriteToWaveStream(m_AudioStream2);
                        soundOut = GetSoundOut();
                        soundOut.Initialize(GetSoundSource(m_AudioStream2));
                        soundOut.Volume   = 1;
                        soundOut.Stopped += DonePlaying;
                        soundOut.Play();

                        state = SOUNDSTATE.PLAYING;
                        manualReset.WaitOne();
                    }
                }
            })
            {
                IsBackground = true
            };

            theRT.Start();
        }
Esempio n. 2
0
        private void applyEffectButton_Click(object sender, EventArgs e)
        {
            AudioEffect effect;

            var fs = _signal.SamplingRate;

            var winSize = int.Parse(winSizeTextBox.Text);
            var hopSize = int.Parse(hopSizeTextBox.Text);
            var tsm     = (TsmAlgorithm)tsmComboBox.SelectedIndex;

            var shift = float.Parse(pitchShiftTextBox.Text);

            if (tremoloRadioButton.Checked)
            {
                var freq  = float.Parse(tremoloFrequencyTextBox.Text);
                var index = float.Parse(tremoloIndexTextBox.Text);
                effect = new TremoloEffect(fs, freq, index);
            }
            else if (overdriveRadioButton.Checked)
            {
                var gain = float.Parse(distortionGainTextBox.Text);
                effect = new OverdriveEffect(gain);
            }
            else if (distortionRadioButton.Checked)
            {
                var gain = float.Parse(distortionGainTextBox.Text);
                effect = new DistortionEffect(gain);
            }
            else if (tubeDistortionRadioButton.Checked)
            {
                var gain = float.Parse(distortionGainTextBox.Text);
                var mix  = float.Parse(wetTextBox.Text);
                var dist = float.Parse(distTextBox.Text);
                var q    = float.Parse(qTextBox.Text);
                effect = new TubeDistortionEffect(gain, mix, q, dist);
            }
            else if (echoRadioButton.Checked)
            {
                var delay = float.Parse(echoDelayTextBox.Text);
                var decay = float.Parse(echoDecayTextBox.Text);
                effect = new EchoEffect(fs, delay, decay);
            }
            else if (delayRadioButton.Checked)
            {
                var delay = float.Parse(echoDelayTextBox.Text);
                var decay = float.Parse(echoDecayTextBox.Text);
                effect = new DelayEffect(fs, delay, decay);
            }
            else if (wahwahRadioButton.Checked)
            {
                var lfoFrequency = float.Parse(lfoFreqTextBox.Text);
                var minFrequency = float.Parse(minFreqTextBox.Text);
                var maxFrequency = float.Parse(maxFreqTextBox.Text);
                var q            = float.Parse(lfoQTextBox.Text);
                //effect = new WahwahEffect(fs, lfoFrequency, minFrequency, maxFrequency, q);
                effect = new AutowahEffect(fs, minFrequency, maxFrequency, q);
            }
            else if (flangerRadioButton.Checked)
            {
                var lfoFrequency = float.Parse(lfoFreqTextBox.Text);
                var maxDelay     = float.Parse(maxDelayTextBox.Text);
                effect = new FlangerEffect(fs, maxDelay, lfoFrequency);
            }
            else if (pitchShiftRadioButton.Checked)
            {
                effect = pitchShiftCheckBox.Checked ? new PitchShiftEffect(shift, winSize, hopSize, tsm) : null;
                //effect = pitchShiftCheckBox.Checked ? new WhisperEffect(hopSize, winSize) : null;
                //effect = new MorphEffect(hopSize, winSize);
            }
            else
            {
                var lfoFrequency = float.Parse(lfoFreqTextBox.Text);
                var minFrequency = float.Parse(minFreqTextBox.Text);
                var maxFrequency = float.Parse(maxFreqTextBox.Text);
                var q            = float.Parse(lfoQTextBox.Text);

                var lfo = new SawtoothBuilder()
                          .SetParameter("freq", lfoFrequency)
                          .SetParameter("min", minFrequency)
                          .SetParameter("max", maxFrequency)
                          .SampledAt(_signal.SamplingRate);

                effect = new PhaserEffect(fs, lfo, q);
            }

            if (effect != null)
            {
                effect.Wet = float.Parse(wetTextBox.Text);
                effect.Dry = float.Parse(dryTextBox.Text);

                _filteredSignal = effect.ApplyTo(_signal, FilteringMethod.Auto);

                //DiscreteSignal morph;
                //using (var stream = new FileStream(@"D:\Docs\Research\DATABASE\Dictor1\wav\gtr16khz.wav", FileMode.Open))
                //{
                //    var waveFile = new WaveFile(stream);
                //    morph = waveFile[Channels.Average];
                //}

                //_filteredSignal = ((MorphEffect)effect).ApplyTo(_signal, morph);
            }
            else
            {
                _filteredSignal = Operation.TimeStretch(_signal, shift, tsm);
                //Operation.TimeStretch(_signal, shift, winSize, hopSize, tsm);
            }

            signalAfterFilteringPanel.Signal           = _filteredSignal;
            spectrogramAfterFilteringPanel.Spectrogram = _stft.Spectrogram(_filteredSignal.Samples);
        }
Esempio n. 3
0
        private void updateSoundEffects(bool newEffects)
        {
            if (_conf.SoundEffects.Count == 0)
            {
                _conf.SoundEffects[AudioEffects.ParamEq] = 1;
            }

            int  i         = 0;
            bool wasPlayed = _sound.Status.Looping || _sound.Status.Playing;
            bool looped    = _sound.Status.Looping;

            if (newEffects)
            {
                EffectDescription[] effs = new EffectDescription[_conf.SoundEffects.Count];
                foreach (AudioEffects eff in _conf.SoundEffects.Keys)
                {
                    switch (eff)
                    {
                    case AudioEffects.Chorus: effs[i].GuidEffectClass = DSoundHelper.StandardChorusGuid; break;

                    case AudioEffects.Compressor: effs[i].GuidEffectClass = DSoundHelper.StandardCompressorGuid; break;

                    case AudioEffects.Distortion: effs[i].GuidEffectClass = DSoundHelper.StandardDistortionGuid; break;

                    case AudioEffects.Echo: effs[i].GuidEffectClass = DSoundHelper.StandardEchoGuid; break;

                    case AudioEffects.Flanger: effs[i].GuidEffectClass = DSoundHelper.StandardFlangerGuid; break;

                    case AudioEffects.Gargle: effs[i].GuidEffectClass = DSoundHelper.StandardGargleGuid; break;

                    case AudioEffects.I3DLevel2Reverb: effs[i].GuidEffectClass = DSoundHelper.StandardInteractive3DLevel2ReverbGuid; break;

                    case AudioEffects.ParamEq: effs[i].GuidEffectClass = DSoundHelper.StandardParamEqGuid; break;

                    case AudioEffects.WavesReverb: effs[i].GuidEffectClass = DSoundHelper.StandardWavesReverbGuid; break;

                    default: break;
                    }
                    i += 1;
                }
                _sound.Stop();
                _sound.SetEffects(effs);
            }
            i = 0;
            foreach (AudioEffects eff in _conf.SoundEffects.Keys)
            {
                float val = (float)_conf.SoundEffects[eff];
                switch (eff)
                {
                case AudioEffects.Chorus:
                    val += 40;
                    ChorusEffect  chorus        = (ChorusEffect)_sound.GetEffects(i);
                    EffectsChorus chorus_params = chorus.AllParameters;
                    chorus_params.Delay     = 10 + val / (float)10; // 15.0f;
                    chorus_params.Depth     = ChorusEffect.DepthMax - 80 + val;
                    chorus_params.Phase     = ChorusEffect.PhaseNegative180;
                    chorus_params.Waveform  = ChorusEffect.WaveTriangle;
                    chorus_params.WetDryMix = val + val / 5 - 20;    // 50.0f;
                    chorus.AllParameters    = chorus_params;
                    break;

                case AudioEffects.Compressor:
                    //CompressorEffect com = (CompressorEffect)_sound.GetEffects(i);
                    //EffectsCompressor ecom = com.AllParameters;
                    // ecom.Threshold = ((CompressorEffect.ThresholdMax - CompressorEffect.ThresholdMin) / 100) * val;

                    //  com.AllParameters = ecom;
                    break;

                case AudioEffects.Distortion:
                    val += 10;
                    DistortionEffect  dis        = (DistortionEffect)_sound.GetEffects(i);
                    EffectsDistortion dis_params = dis.AllParameters;
                    dis_params.Gain                  = -35 + val;
                    dis_params.Edge                  = val - 5;
                    dis_params.PostEqBandwidth       = (float)(val % 99) * 20 + 2000;
                    dis_params.PostEqCenterFrequency = (float)(val % 99) * 20 + 2000;
                    // dis_params.PreLowpassCutoff = (float)(_conf.SoundEffects[eff] + 1) ;
                    dis.AllParameters = dis_params;
                    break;

                case AudioEffects.Gargle:
                    GargleEffect  gar  = (GargleEffect)_sound.GetEffects(i);
                    EffectsGargle egar = (EffectsGargle)gar.AllParameters;
                    egar.RateHz       = (int)val * 25;
                    gar.AllParameters = egar;

                    break;

                case AudioEffects.Echo:
                    /*Interactive3DLevel2ReverbEffect env1 = (Interactive3DLevel2ReverbEffect)_sound.GetEffects(i);
                     * EffectsInteractive3DLevel2Reverb enviroEffects1 = env1.AllParameters;
                     * enviroEffects1.Reflections = 10 * _conf.SoundEffects[eff];
                     * enviroEffects1.Reverb = 2 * _conf.SoundEffects[eff];
                     * enviroEffects1.Diffusion = 0.1f * _conf.SoundEffects[eff];
                     * env1.AllParameters = enviroEffects1;
                     * break;*/
                    EchoEffect  echo        = (EchoEffect)_sound.GetEffects(i);
                    EffectsEcho echo_params = echo.AllParameters;
                    echo_params.LeftDelay  = (_conf.SoundEffects[eff] + 1) * 5; // 250.0f;
                    echo_params.RightDelay = (_conf.SoundEffects[eff] + 1) * 5; // 250.0f;
//echo_params.RightDelay = 1.0f * _conf.SoundEffects[eff];
                    echo_params.Feedback  = val;                                //20;//1  + _conf.SoundEffects[eff] ;// 85.0f;
                    echo_params.PanDelay  = 1;
                    echo_params.WetDryMix = (_conf.SoundEffects[eff]) + 1;
                    echo.AllParameters    = echo_params;
                    break;

                case AudioEffects.Flanger:
                    FlangerEffect  flan  = (FlangerEffect)_sound.GetEffects(i);
                    EffectsFlanger eflan = flan.AllParameters;
                    val += 40;
                    //eflan.Delay = FlangerEffect.DelayMax + 80 - val;
                    eflan.Depth        = FlangerEffect.DepthMax - 80 + val;
                    eflan.Phase        = FlangerEffect.Phase90;
                    eflan.Waveform     = FlangerEffect.WaveTriangle;
                    eflan.WetDryMix    = FlangerEffect.WetDryMixMax - val / 5; // +val / 5 - 20;// 50.0f;
                    flan.AllParameters = eflan;
                    break;

                case AudioEffects.I3DLevel2Reverb:
                    Interactive3DLevel2ReverbEffect  env           = (Interactive3DLevel2ReverbEffect)_sound.GetEffects(i);
                    EffectsInteractive3DLevel2Reverb enviroEffects = env.AllParameters;
                    enviroEffects.DecayHfRatio = 2.0f;
                    enviroEffects.DecayTime    = 20.0f;
                    enviroEffects.Density      = 1.0f;
                    enviroEffects.Diffusion    = 2.0f;
                    enviroEffects.Reflections  = (int)(val / 10);
                    enviroEffects.Reverb       = 2;
                    env.AllParameters          = enviroEffects;
                    break;

                case AudioEffects.ParamEq: break;

                case AudioEffects.WavesReverb:
                    val += 85;
                    WavesReverbEffect  wrev  = (WavesReverbEffect)_sound.GetEffects(i);
                    EffectsWavesReverb ewrev = wrev.AllParameters;
                    //ewrev.ReverbMix = (float)_conf.SoundEffects[eff] / (float)100;
                    ewrev.ReverbTime = val * 20;
                    //ewrev.HighFrequencyRtRatio = (float)val / (float)100;
                    ewrev.ReverbMix = -95.5f + (float)val;    // (val >= 96) ? 0 : val - 96;
                    //MessageBox.Show(String.Format("{0} / {1}, {2} / {3}", WavesReverbEffect.ReverbMixMin, WavesReverbEffect.ReverbTimeMax, WavesReverbEffect.ReverbTimeMin, WavesReverbEffect.ReverbTimeMax));

                    //MessageBox.Show(string.Format("{0} - {1} - {2}", WavesReverbEffect.ReverbTimeMin,WavesReverbEffect.ReverbMixMin, WavesReverbEffect.HighFrequencyRtRatioMin), "");
                    wrev.AllParameters = ewrev;
                    break;

                default: break;
                }
                i += 1;
            }
            if (newEffects && wasPlayed)
            {
                _sound.Play(0, looped ? BufferPlayFlags.Looping : BufferPlayFlags.Default);
            }
        }