/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The /// sample rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" /> /// . /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first /// mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</returns> public IntPtr CreateSourceVoicePtr(WaveFormat sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends?sendList, EffectChain?effectChain) { GCHandle hWaveFormat = GCHandle.Alloc(sourceFormat, GCHandleType.Pinned); //todo: do we really need to use GCHandle? try { IntPtr ptr; int result = CreateSourceVoiceNative( out ptr, hWaveFormat.AddrOfPinnedObject(), flags, maxFrequencyRatio, voiceCallback, sendList, effectChain); XAudio2Exception.Try(result, N, "CreateSourceVoice"); return(ptr); } finally { if (hWaveFormat.IsAllocated) { hWaveFormat.Free(); } } }
public IXAudio2VoiceCallbackWrapper(IXAudio2VoiceCallback callback) { if (callback == null) { return; } _callback = callback; // Store callbacks to prevent them from being garbage collected _startCallback = (_, bytesRequired) => _callback.OnVoiceProcessingPassStart(bytesRequired); _endCallback = _ => _callback.OnVoiceProcessingPassEnd(); _streamEndCallback = _ => _callback.OnStreamEnd(); _bufferStartCallback = (_, context) => _callback.OnBufferStart(context); _bufferEndCallback = (_, context) => _callback.OnBufferEnd(context); _loopEndCallback = (_, context) => _callback.OnLoopEnd(context); _voiceErrorCallback = (_, context, error) => _callback.OnVoiceError(context, error); // Allocate memory for the C++ interface _nativePointer = Marshal.AllocHGlobal(IntPtr.Size * 8); // 7 methods + vtbl // Write pointer to vtbl Marshal.WriteIntPtr(_nativePointer, IntPtr.Add(_nativePointer, IntPtr.Size)); // Write the functions to the vtable WriteFunctionPointer(1, _startCallback); WriteFunctionPointer(2, _endCallback); WriteFunctionPointer(3, _streamEndCallback); WriteFunctionPointer(4, _bufferStartCallback); WriteFunctionPointer(5, _bufferEndCallback); WriteFunctionPointer(6, _loopEndCallback); WriteFunctionPointer(7, _voiceErrorCallback); }
private static void OnVoiceProcessingPassEndImpl(IntPtr thisObject) { IXAudio2VoiceCallbackShadow shadow = ToShadow <IXAudio2VoiceCallbackShadow>(thisObject); IXAudio2VoiceCallback callback = (IXAudio2VoiceCallback)shadow.Callback; callback.OnVoiceProcessingPassEnd(); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="pSourceVoice">If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</param> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The sample /// rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" />. /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>HRESULT</returns> public override unsafe int CreateSourceVoiceNative( out IntPtr pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends?sendList, //out EffectChain?effectChain ) { VoiceSends value0 = sendList.HasValue ? sendList.Value : new VoiceSends(); EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain(); IntPtr p = IntPtr.Zero; if (voiceCallback != null) { p = Marshal.GetComInterfaceForObject(voiceCallback, typeof(IXAudio2VoiceCallback)); p = Utils.Utils.GetComInterfaceForObjectWithAdjustedVtable(p, 7, 3); } fixed(void *ptr = &pSourceVoice) { return(InteropCalls.CallI(UnsafeBasePtr, ptr, sourceFormat, flags, maxFrequencyRatio, p.ToPointer(), sendList.HasValue ? &value0 : (void *)IntPtr.Zero, effectChain.HasValue ? &value1 : (void *)IntPtr.Zero, ((void **)(*(void **)UnsafeBasePtr))[8])); } }
private static void OnVoiceProcessingPassStartImpl(IntPtr thisObject, int bytes) { IXAudio2VoiceCallbackShadow shadow = ToShadow <IXAudio2VoiceCallbackShadow>(thisObject); IXAudio2VoiceCallback callback = (IXAudio2VoiceCallback)shadow.Callback; callback.OnVoiceProcessingPassStart(bytes); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The /// sample rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" /> /// . /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first /// mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>If successful, returns a new <see cref="XAudio2SourceVoice" /> object.</returns> public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends?sendList, EffectChain?effectChain) { IntPtr ptr = CreateSourceVoicePtr(sourceFormat, flags, maxFrequencyRatio, voiceCallback, sendList, effectChain); return(new XAudio2SourceVoice(ptr, _version)); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="pSourceVoice">If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</param> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The sample /// rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" />. /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first /// mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>HRESULT</returns> public abstract int CreateSourceVoiceNative( out IntPtr pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends?sendList, //out EffectChain?effectChain );
public SourceVoice(ComPtr <IXAudio2> xAudio2, WAVEFORMATEX format) { _callback = IXAudio2VoiceCallback.Create(this); fixed(IXAudio2SourceVoice **ppVoice = &_voice) { Common.CheckAndThrow(xAudio2.Get()->CreateSourceVoice(ppVoice, &format, pCallback: _callback), nameof(IXAudio2.CreateSourceVoice)); } _voice->SetVolume(0.1f); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="pSourceVoice">If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</param> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The sample /// rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" />. /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>HRESULT</returns> public override unsafe int CreateSourceVoiceNative( out IntPtr pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends?sendList, //out EffectChain?effectChain ) { VoiceSends value0 = sendList.HasValue ? sendList.Value : new VoiceSends(); EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain(); IntPtr p = IntPtr.Zero; if (voiceCallback != null) { p = Marshal.GetComInterfaceForObject(voiceCallback, typeof(IXAudio2VoiceCallback)); p = Utils.CSCoreUtils.GetComInterfaceForObjectWithAdjustedVtable(p, 7, 3); } try { fixed(void *ptr = &pSourceVoice) { return(InteropCalls.CallI(UnsafeBasePtr, ptr, sourceFormat, flags, maxFrequencyRatio, p.ToPointer(), sendList.HasValue ? &value0 : (void *)IntPtr.Zero, effectChain.HasValue ? &value1 : (void *)IntPtr.Zero, ((void **)(*(void **)UnsafeBasePtr))[5])); } } finally { if (p != IntPtr.Zero) { //while patching the IUnknown-members out of the vtable, we've made a backup of the release pointer, //which gets called here -> the Marshal.Release method would call any function on index 2 of the vtable //we've patched there Utils.CSCoreUtils.Release(p); //Marshal.Release(p); } } }
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); } }
internal static unsafe int CallI(void *_basePtr, void *ptr, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, void *p1, void *p2, void *p3) { throw new NotImplementedException(); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="pSourceVoice">If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</param> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The sample /// rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" />. /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>HRESULT</returns> public unsafe override int CreateSourceVoiceNative( out IntPtr pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends? sendList, //out EffectChain? effectChain ) { VoiceSends value0 = sendList.HasValue ? sendList.Value : new VoiceSends(); EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain(); IntPtr p = IntPtr.Zero; if (voiceCallback != null) { p = Marshal.GetComInterfaceForObject(voiceCallback, typeof (IXAudio2VoiceCallback)); p = Utils.Utils.GetComInterfaceForObjectWithAdjustedVtable(p, 7, 3); } fixed (void* ptr = &pSourceVoice) { return InteropCalls.CallI(UnsafeBasePtr, ptr, sourceFormat, flags, maxFrequencyRatio, p.ToPointer(), sendList.HasValue ? &value0 : (void*) IntPtr.Zero, effectChain.HasValue ? &value1 : (void*) IntPtr.Zero, ((void**) (*(void**) UnsafeBasePtr))[8]); } }
/// <summary> /// Return a pointer to the unmanaged version of this callback. /// </summary> /// <param name="callback">The callback.</param> /// <returns>A pointer to a shadow c++ callback</returns> public static IntPtr ToIntPtr(IXAudio2VoiceCallback callback) { return(ToCallbackPtr <IXAudio2VoiceCallback>(callback)); }
internal static unsafe int CallI(void* _basePtr, void* ptr, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, void* p1, void* p2, void* p3) { throw new NotImplementedException(); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The /// sample rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" /> /// . /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first /// mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</returns> public IntPtr CreateSourceVoicePtr(WaveFormat sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends? sendList, EffectChain? effectChain) { GCHandle hWaveFormat = GCHandle.Alloc(sourceFormat, GCHandleType.Pinned); //todo: do we really need to use GCHandle? try { IntPtr ptr; int result = CreateSourceVoiceNative( out ptr, hWaveFormat.AddrOfPinnedObject(), flags, maxFrequencyRatio, voiceCallback, sendList, effectChain); XAudio2Exception.Try(result, N, "CreateSourceVoice"); return ptr; } finally { if (hWaveFormat.IsAllocated) hWaveFormat.Free(); } }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="pSourceVoice">If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</param> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The sample /// rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" />. /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first /// mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>HRESULT</returns> public abstract int CreateSourceVoiceNative( out IntPtr pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends? sendList, //out EffectChain? effectChain );
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The /// sample rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" /> /// . /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first /// mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>If successful, returns a new <see cref="XAudio2SourceVoice" /> object.</returns> public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends? sendList, EffectChain? effectChain) { IntPtr ptr = CreateSourceVoicePtr(sourceFormat, flags, maxFrequencyRatio, voiceCallback, sendList, effectChain); return new XAudio2SourceVoice(ptr, _version); }
/// <summary> /// Creates and configures a source voice. For more information see /// http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2.ixaudio2.createsourcevoice(v=vs.85).aspx. /// </summary> /// <param name="pSourceVoice">If successful, returns a pointer to the new <see cref="XAudio2SourceVoice" /> object.</param> /// <param name="sourceFormat"> /// Pointer to a <see cref="WaveFormat" />. The following formats are supported: /// <ul> /// <li>8-bit (unsigned) integer PCM</li><li>16-bit integer PCM (optimal format for XAudio2)</li> /// <li>20-bit integer PCM (either in 24 or 32 bit containers)</li> /// <li>24-bit integer PCM (either in 24 or 32 bit containers)</li><li>32-bit integer PCM</li> /// <li>32-bit float PCM (preferred format after 16-bit integer)</li> /// </ul> /// The number of channels in a source voice must be less than or equal to <see cref="MaxAudioChannels" />. The sample /// rate of a source voice must be between <see cref="MinimumSampleRate" /> and <see cref="MaximumSampleRate" />. /// </param> /// <param name="flags"> /// <see cref="VoiceFlags" /> that specify the behavior of the source voice. A flag can be /// <see cref="VoiceFlags.None" /> or a combination of one or more of the following. /// Possible values are <see cref="VoiceFlags.NoPitch" />, <see cref="VoiceFlags.NoSampleRateConversition" /> and /// <see cref="VoiceFlags.UseFilter" />. <see cref="VoiceFlags.Music" /> is not supported on Windows. /// </param> /// <param name="maxFrequencyRatio"> /// Highest allowable frequency ratio that can be set on this voice. The value for this /// argument must be between <see cref="MinFrequencyRatio" /> and <see cref="MaxFrequencyRatio" />. /// </param> /// <param name="voiceCallback"> /// Client-provided callback interface, <see cref="IXAudio2VoiceCallback" />. This parameter is /// optional and can be null. /// </param> /// <param name="sendList"> /// List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the /// source voice. If <paramref name="sendList" /> is NULL, the send list defaults to a single output to the first mastering /// voice created. /// </param> /// <param name="effectChain"> /// List of <see cref="EffectChain" /> structures that describe an effect chain to use in the /// source voice. This parameter is optional and can be null. /// </param> /// <returns>HRESULT</returns> public unsafe override int CreateSourceVoiceNative( out IntPtr pSourceVoice, IntPtr sourceFormat, VoiceFlags flags, float maxFrequencyRatio, IXAudio2VoiceCallback voiceCallback, VoiceSends? sendList, //out EffectChain? effectChain ) { VoiceSends value0 = sendList.HasValue ? sendList.Value : new VoiceSends(); EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain(); IntPtr p = IntPtr.Zero; if (voiceCallback != null) { p = Marshal.GetComInterfaceForObject(voiceCallback, typeof (IXAudio2VoiceCallback)); p = Utils.Utils.GetComInterfaceForObjectWithAdjustedVtable(p, 7, 3); } try { fixed (void* ptr = &pSourceVoice) { return InteropCalls.CallI(UnsafeBasePtr, ptr, sourceFormat, flags, maxFrequencyRatio, p.ToPointer(), sendList.HasValue ? &value0 : (void*) IntPtr.Zero, effectChain.HasValue ? &value1 : (void*) IntPtr.Zero, ((void**) (*(void**) UnsafeBasePtr))[8]); } } finally { if (p != IntPtr.Zero) { //while patching the IUnknown-members out of the vtable, we've made a backup of the release pointer, //which gets called here -> the Marshal.Release method would call any function on index 2 of the vtable //we've patched there Utils.Utils.Release(p); //Marshal.Release(p); } } }