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); } }
private void SetupVoice(AudioFormat format) { WaveFormat wFmt = new WaveFormat(format.SampleRate, format.BitsPerSample, format.Channels); SourceVoice = _engine.Device.CreateSourceVoice(wFmt); if (_submixer != null) { var vsDesc = new VoiceSendDescriptor(); vsDesc.OutputVoice = _submixer.SubMixerVoice; SourceVoice.SetOutputVoices(new VoiceSendDescriptor[] { vsDesc }); } SourceVoice.SetVolume(_volume); }
public XAudio2Player(IXAudio2SourceVoice source) { _source = source; }