Beispiel #1
0
        private void CreateSourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio, VoiceCallback 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);
            }
        }