Beispiel #1
0
    public unsafe IXAudio2SubmixVoice CreateSubmixVoice(
        int inputChannels      = 2,
        int inputSampleRate    = 44100,
        SubmixVoiceFlags flags = SubmixVoiceFlags.None,
        int processingStage    = 0,
        EffectDescriptor[]?effectDescriptors = null)
    {
        if (effectDescriptors != null)
        {
            var effectChain             = new EffectChain();
            var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
            for (int i = 0; i < effectDescriptorNatives.Length; i++)
            {
                effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
            }

            effectChain.EffectCount = effectDescriptorNatives.Length;
            fixed(void *pEffectDescriptors = &effectDescriptorNatives[0])
            {
                effectChain.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;
                return(CreateSubmixVoice(inputChannels, inputSampleRate, (int)flags, processingStage, null, effectChain));
            }
        }
        else
        {
            return(CreateSubmixVoice(inputChannels, inputSampleRate, (int)flags, processingStage, null, null));
        }
    }
Beispiel #2
0
 /// <summary>
 /// Replaces the effect chain of the voice.
 /// </summary>
 /// <param name="effectDescriptors">
 /// An array of <see cref="EffectDescriptor"/> that describes the new effect chain to use.
 /// If null is passed, the current effect chain is removed. If array is non null, its length must be at least of 1.
 /// </param>
 public void SetEffectChain(params EffectDescriptor[] effectDescriptors)
 {
     unsafe
     {
         if (effectDescriptors != null)
         {
             var tempSendDescriptor      = new EffectChain();
             var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
             for (int i = 0; i < effectDescriptorNatives.Length; i++)
             {
                 effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
             }
             tempSendDescriptor.EffectCount = effectDescriptorNatives.Length;
             fixed(void *pEffectDescriptors = &effectDescriptorNatives[0])
             {
                 tempSendDescriptor.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;
                 SetEffectChain(tempSendDescriptor);
             }
         }
         else
         {
             SetEffectChain((EffectChain?)null);
         }
     }
 }
Beispiel #3
0
 public MainForm(ICollection <Effect> effects)
 {
     InitializeComponent();
     effectChain        = new EffectChain();
     audioPlaybackGraph = new AudioPlaybackGraph(effectChain);
     tabPageRecord.Controls.Add(new RecordingPage()
     {
         Dock = DockStyle.Fill
     });
     tabPageAbout.Controls.Add(new AboutPage()
     {
         Dock = DockStyle.Fill
     });
     connectionStatusPage = new ConnectionStatusPage()
     {
         Dock = DockStyle.Fill
     };
     effectsPage = new EffectsPage(effectChain, effects, audioPlaybackGraph)
     {
         Dock = DockStyle.Fill
     };
     tabPage1.Controls.Add(connectionStatusPage);
     tabPage2.Controls.Add(effectsPage);
     log           = connectionStatusPage.Log;
     audioPipeline = new AudioPipeline(effectChain);
 }
Beispiel #4
0
 public EffectStream(EffectChain effects, WaveStream sourceStream)
 {
     this.effects = effects;
     this.source = sourceStream;
     foreach (Effect effect in effects)
     {
         InitialiseEffect(effect);
     }
 }
 public EffectsPage(EffectChain effectsChain, ICollection <Effect> availableEffects, AudioPlaybackGraph audioPlaybackGraph)
 {
     this.effectsChain       = effectsChain;
     this.availableEffects   = availableEffects;
     this.audioPlaybackGraph = audioPlaybackGraph;
     InitializeComponent();
     playbackButtons = new List <ToolStripItem> {
         buttonPlay, buttonPause, buttonOpen, buttonStop, buttonRewind
     };
 }
Beispiel #6
0
        public Form1()
        {
            InitializeComponent();

            // register the event that is fired after the key press.
            hook.KeyPressed += new EventHandler <KeyPressedEventArgs>(hook_KeyPressed);
            hook.RegisterHotKey(NexusSpeech.ModifierKeys.Control, Keys.F1);
            hook.RegisterHotKey(NexusSpeech.ModifierKeys.Control, Keys.F2);

            effects           = new EffectChain();
            effects.Modified += (s, a) => playbackMixer?.UpdateEffectChain(effects.ToArray());
        }
Beispiel #7
0
 public void PlayNonStop()
 {
     var reader = new WaveFileReader(_sample);
         var loop = new LoopStream(reader);
         var effects = new EffectChain();
         var effectStream = new EffectStream(effects, loop);
         _pitch = new SuperPitch();
         effectStream.AddEffect(_pitch);
         _wave = new WaveOut();
         _wave.Init(effectStream);
         _wave.Play();
 }
 void UpdateEffect()
 {
     if (effectChainIndex < skill.effectChains.Count)
     {
         EffectChain effectChain = skill.effectChains[effectChainIndex];
         if (effectChain.delay <= pastTime)
         {
             effectChainIndex++;
             ShowEffectChain(effectChain, GeneratePositionByType(effectChain.positionType).position);
         }
     }
 }
Beispiel #9
0
    public unsafe IXAudio2SourceVoice CreateSourceVoice(
        WaveFormat sourceFormat,
        VoiceFlags flags                     = VoiceFlags.None,
        float maxFrequencyRatio              = 1.0f,
        bool enableCallbackEvents            = false,
        EffectDescriptor[]?effectDescriptors = null)
    {
        IntPtr waveformatPtr = WaveFormat.MarshalToPtr(sourceFormat);

        IXAudio2SourceVoice.VoiceCallbackImpl?callback = enableCallbackEvents ? new IXAudio2SourceVoice.VoiceCallbackImpl() : default;

        try
        {
            if (effectDescriptors != null)
            {
                var effectChain             = new EffectChain();
                var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
                for (int i = 0; i < effectDescriptorNatives.Length; i++)
                {
                    effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
                }

                effectChain.EffectCount = effectDescriptorNatives.Length;
                fixed(void *pEffectDescriptors = &effectDescriptorNatives[0])
                {
                    effectChain.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;
                    IXAudio2SourceVoice voice = CreateSourceVoice(waveformatPtr, flags, maxFrequencyRatio, callback, null, effectChain);

                    if (callback != null)
                    {
                        callback.Voice = voice;
                    }
                    voice._callback = callback;
                    return(voice);
                }
            }
            else
            {
                IXAudio2SourceVoice voice = CreateSourceVoice(waveformatPtr, flags, maxFrequencyRatio, callback, null, null);
                if (callback != null)
                {
                    callback.Voice = voice;
                }
                voice._callback = callback;
                return(voice);
            }
        }
        finally
        {
            Marshal.FreeHGlobal(waveformatPtr);
        }
    }
Beispiel #10
0
    public unsafe IXAudio2MasteringVoice CreateMasteringVoice(
        int inputChannels            = DefaultChannels,
        int inputSampleRate          = DefaultSampleRate,
        AudioStreamCategory category = AudioStreamCategory.GameEffects,
        string deviceId = "",
        EffectDescriptor[]?effectDescriptors = null)
    {
        if (effectDescriptors != null)
        {
            var effectChain             = new EffectChain();
            var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
            for (int i = 0; i < effectDescriptorNatives.Length; i++)
            {
                effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
            }

            effectChain.EffectCount = effectDescriptorNatives.Length;
            fixed(void *pEffectDescriptors = &effectDescriptorNatives[0])
            {
                effectChain.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;

                if (string.IsNullOrEmpty(deviceId))
                {
                    return(CreateMasteringVoice(inputChannels, inputSampleRate, 0, null, effectChain, category));
                }
                else
                {
                    return(CreateMasteringVoice(inputChannels, inputSampleRate, 0, deviceId, effectChain, category));
                }
            }
        }
        else
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                return(CreateMasteringVoice(inputChannels, inputSampleRate, 0, null, null, category));
            }
            else
            {
                return(CreateMasteringVoice(inputChannels, inputSampleRate, 0, deviceId, null, category));
            }
        }
    }
        public AudioPipeline(EffectChain effects)
        {
            // Audio pipeline:
            // get the audio from Skype
            this.bufferStream = new SkypeBufferProvider(16000);
            // convert to 32 bit floating point
            var bufferStream32 = new Pcm16BitToSampleProvider(bufferStream);
            // pass through the effects
            var effectStream = new EffectStream(bufferStream32);

            // now mix in any sound effects
            mixer = new MixingSampleProvider(effectStream.WaveFormat);
            mixer.AddMixerInput(effectStream);

            // and convert back to 16 bit ready to be given back to skype
            outputProvider = new SampleToWaveProvider16(mixer);

            effects.Modified += (s, a) => effectStream.UpdateEffectChain(effects.ToArray());
        }
Beispiel #12
0
        public SkypeConnector(ILog log, EffectChain effects)
        {
            this.log = log;
            InitSockets();

            skype = new Skype();
            ISkype iSkype = (ISkype)skype;

            if (!iSkype.Client.IsRunning)
            {
                log.Error("Skype is not running");
            }

            _ISkypeEvents_Event events = (_ISkypeEvents_Event)skype;

            events.AttachmentStatus += OnSkypeAttachmentStatus;
            skype.CallStatus += OnSkypeCallStatus;
            skype.Error += OnSkypeError;
            skype.Attach(Protocol, false);

            bufferStream = new SkypeBufferStream(44100);
            OutputStream = new EffectStream(effects, bufferStream);
        }
Beispiel #13
0
        public unsafe IXAudio2SourceVoice CreateSourceVoice(
            WaveFormat sourceFormat,
            VoiceFlags flags                     = VoiceFlags.None,
            float maxFrequencyRatio              = 1.0f,
            IXAudio2VoiceCallback callback       = null,
            EffectDescriptor[] effectDescriptors = null)
        {
            var waveformatPtr = WaveFormat.MarshalToPtr(sourceFormat);

            try
            {
                if (effectDescriptors != null)
                {
                    var effectChain             = new EffectChain();
                    var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
                    for (int i = 0; i < effectDescriptorNatives.Length; i++)
                    {
                        effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
                    }

                    effectChain.EffectCount = effectDescriptorNatives.Length;
                    fixed(void *pEffectDescriptors = &effectDescriptorNatives[0])
                    {
                        effectChain.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;
                        return(CreateSourceVoice(waveformatPtr, flags, maxFrequencyRatio, callback, null, effectChain));
                    }
                }
                else
                {
                    return(CreateSourceVoice(waveformatPtr, flags, maxFrequencyRatio, callback, null, null));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(waveformatPtr);
            }
        }
Beispiel #14
0
        public SkypeConnector(ILog log, EffectChain effects)
        {
            this.log = log;
            InitSockets();


            skype = new Skype();
            ISkype iSkype = (ISkype)skype;

            if (!iSkype.Client.IsRunning)
            {
                log.Error("Skype is not running");
            }

            _ISkypeEvents_Event events = (_ISkypeEvents_Event)skype;

            events.AttachmentStatus += OnSkypeAttachmentStatus;
            skype.CallStatus        += OnSkypeCallStatus;
            skype.Error             += OnSkypeError;
            skype.Attach(Protocol, false);

            bufferStream = new SkypeBufferStream(44100);
            OutputStream = new EffectStream(effects, bufferStream);
        }
Beispiel #15
0
 public MainFormAudioGraph(ILog log)
 {
     this.log = log;
     effects = new EffectChain();
 }
Beispiel #16
0
 private void CreateSourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio, IntPtr callback, EffectDescriptor[] effectDescriptors)
 {
     var waveformatPtr = WaveFormat.MarshalToPtr(sourceFormat);
     try
     {
         if (effectDescriptors != null)
         {
             unsafe
             {
                 var tempSendDescriptor = new EffectChain();
                 var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
                 for (int i = 0; i < effectDescriptorNatives.Length; i++)
                     effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
                 tempSendDescriptor.EffectCount = effectDescriptorNatives.Length;
                 fixed (void* pEffectDescriptors = &effectDescriptorNatives[0])
                 {
                     tempSendDescriptor.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;
                     device.CreateSourceVoice_(this, waveformatPtr, flags, maxFrequencyRatio, callback, null, tempSendDescriptor);
                 }
             }
         }
         else
         {
             device.CreateSourceVoice_(this, waveformatPtr, flags, maxFrequencyRatio, callback, null, null);
         }
     }
     finally
     {
         Marshal.FreeHGlobal(waveformatPtr);
     }
 }
Beispiel #17
0
        private EffectChain CreateEffectChain(Sample sample)
        {
            EffectChain effectChain = new EffectChain();
            List<Effect> listEffect = new List<Effect>();

            List<List<Effect>> listListEffect;

            if (dicEffect.ContainsKey(sample.Name))
            {
                listListEffect = dicEffect[sample.Name];
            }
            else
            {
                listListEffect = new List<List<Effect>>();
                dicEffect.Add(sample.Name, listListEffect);
            }

            listListEffect.Add(listEffect);

            //AddEffect(effectChain, listEffect, typeof(Volume));
            //AddEffect(effectChain, listEffect, typeof(Chorus));
            //AddEffect(effectChain, listEffect, typeof(JSNet.Delay));
            //AddEffect(effectChain, listEffect, typeof(Flanger));
            //AddEffect(effectChain, listEffect, typeof(Tremolo));
            AddEffect(effectChain, listEffect, typeof(SuperPitch));

            return effectChain;
        }
Beispiel #18
0
        private Effect AddEffect(EffectChain effectChain, List<Effect> listEffect, Type typeOfEffect)
        {
            Effect effect = (Effect)Activator.CreateInstance(typeOfEffect);
            effectChain.Add(effect);
            listEffect.Add(effect);
            effect.SampleRate = 44100f;
            effect.Enabled = false;

            foreach (Slider slider in effect.Sliders)
            {
                slider.Value = slider.Default;
            }

            effect.Slider();

            return effect;
        }
Beispiel #19
0
 public Channel(SampleBuffer outputBuffer)
 {
     this.buffer      = new SampleBuffer(4);
     this.effectChain = new EffectChain(outputBuffer);
     this.gain        = 1f;
 }
Beispiel #20
0
 public AudioPlaybackGraph(EffectChain effectChain)
 {
     this.effectChain      = effectChain;
     effectChain.Modified += EffectChainOnModified;
 }
 public NightcoreGenerator(GeneratorOptions options)
 {
     this.options     = options;
     this.effectChain = new EffectChain();
 }
 public MainFormAudioGraph(ILog log)
 {
     this.log = log;
     effects  = new EffectChain();
 }
Beispiel #23
0
        /// <summary>	
        /// Creates and configures a submix voice with an effect chain.	
        /// </summary>	
        /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param>
        /// <param name="inputChannels">[in]  Number of channels in the input audio data of the submix voice. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. </param>
        /// <param name="inputSampleRate">[in]  Sample rate of the input audio data of submix voice. This rate must be a multiple of  XAUDIO2_QUANTUM_DENOMINATOR.  InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. </param>
        /// <param name="flags">[in]  Flags that specify the behavior of the submix voice. Can be 0 or the following: ValueDescriptionXAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.? </param>
        /// <param name="processingStage">[in]  An arbitrary number that specifies when this voice is processed with respect to other submix  voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other  voices that include a smaller ProcessingStage value, and before all other voices  that include a larger ProcessingStage value. Voices that include the same  ProcessingStage value are processed in any order. A submix voice cannot send to  another submix voice with a lower or equal ProcessingStage value; this prevents  audio being lost due to a submix cycle. </param>
        /// <param name="effectDescriptors">[in, optional] Pointer to a list of XAUDIO2_EFFECT_CHAIN structures that describe an effect chain to use in the submix voice.</param>
        /// <returns>No documentation.</returns>
        /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 ProcessingStage,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged>
        public SubmixVoice(XAudio2 device, int inputChannels, int inputSampleRate, SubmixVoiceFlags flags, int processingStage, EffectDescriptor[] effectDescriptors)
            : base(IntPtr.Zero)
        {

            if (effectDescriptors != null)
            {
                unsafe
                {
                    var tempSendDescriptor = new EffectChain();
                    var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length];
                    for (int i = 0; i < effectDescriptorNatives.Length; i++)
                        effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]);
                    tempSendDescriptor.EffectCount = effectDescriptorNatives.Length;
                    fixed (void* pEffectDescriptors = &effectDescriptorNatives[0])
                    {
                        tempSendDescriptor.EffectDescriptorPointer = (IntPtr)pEffectDescriptors;
                        device.CreateSubmixVoice(this, inputChannels, inputSampleRate, unchecked((int)flags), processingStage, null, tempSendDescriptor);
                    }
                }
            }
            else
            {
                device.CreateSubmixVoice(this, inputChannels, inputSampleRate, unchecked((int)flags), processingStage, null, null);
            }
        }
Beispiel #24
0
        internal unsafe void CreateMasteringVoice27(MasteringVoice masteringVoiceOut, int inputChannels, int inputSampleRate, int flags, int deviceIndex, EffectChain? effectChainRef)
        {
	        IntPtr zero = IntPtr.Zero;
	        EffectChain value;
	        if (effectChainRef.HasValue)
	        {
		        value = effectChainRef.Value;
	        }
	        Result result = LocalInterop.Calliint(this._nativePointer, (void*)&zero, inputChannels, inputSampleRate, flags, deviceIndex, effectChainRef.HasValue ? ((void*)(&value)) : ((void*)IntPtr.Zero), *(*(void***)this._nativePointer + 10));
	        masteringVoiceOut.NativePointer = zero;
	        result.CheckError();
        }