示例#1
0
        /// <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]));
            }
        }
示例#2
0
        /// <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();
                }
            }
        }
示例#3
0
        /// <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));
        }
示例#4
0
 /// <summary>
 /// Creates a new source voice
 /// </summary>
 /// <param name="format">Voice format</param>
 /// <param name="voiceFlags">Voice flags</param>
 /// <returns>Returns the new voice</returns>
 internal SourceVoice CreateVoice(WaveFormat format, VoiceFlags voiceFlags)
 {
     return(new SourceVoice(
                this.device,
                format,
                voiceFlags,
                XAudio2.MaximumFrequencyRatio));
 }
示例#5
0
 /// <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
     );
示例#6
0
        /// <summary>
        ///     Creates and configures a submix voice.
        /// </summary>
        /// <param name="inputChannels">
        ///     Number of channels in the input audio data of the submix voice. The
        ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
        /// </param>
        /// <param name="inputSampleRate">
        ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
        ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
        ///     <see cref="MaximumSampleRate" />.
        /// </param>
        /// <param name="flags">
        ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
        ///     <see cref="VoiceFlags.UseFilter" />.
        /// </param>
        /// <param name="processingStage">
        ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
        ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value
        ///     are
        ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
        ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
        /// </param>
        /// <param name="sendList">
        ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
        ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
        ///     submix voice. This parameter is optional and can be null.
        /// </param>
        /// <returns>On success, returns a pointer to the new <see cref="XAudio2SubmixVoice" /> object.</returns>
        public IntPtr CreateSubmixVoicePtr(int inputChannels, int inputSampleRate, VoiceFlags flags,
                                           int processingStage, VoiceSends?sendList, EffectChain?effectChain)
        {
            IntPtr ptr;
            int    result = CreateSubmixVoiceNative(out ptr, inputChannels, inputSampleRate, flags, processingStage,
                                                    sendList,
                                                    effectChain);

            XAudio2Exception.Try(result, N, "CreateSubmixVoiceNative");
            return(ptr);
        }
示例#7
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);
        }
    }
示例#8
0
        /// <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);
                }
            }
        }
示例#9
0
        /// <summary>
        ///     Creates and configures a submix voice.
        /// </summary>
        /// <param name="pSubmixVoice">On success, returns a pointer to the new <see cref="XAudio2SubmixVoice" /> object.</param>
        /// <param name="inputChannels">
        ///     Number of channels in the input audio data of the submix voice. The
        ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
        /// </param>
        /// <param name="inputSampleRate">
        ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
        ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
        ///     <see cref="MaximumSampleRate" />.
        /// </param>
        /// <param name="flags">
        ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
        ///     <see cref="VoiceFlags.UseFilter" />.
        /// </param>
        /// <param name="processingStage">
        ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
        ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value are
        ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
        ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
        /// </param>
        /// <param name="sendList">
        ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
        ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
        ///     submix voice. This parameter is optional and can be null.
        /// </param>
        /// <returns>HRESULT</returns>
        public override unsafe int CreateSubmixVoiceNative(out IntPtr pSubmixVoice, int inputChannels,
                                                           int inputSampleRate, VoiceFlags flags,
                                                           int processingStage, VoiceSends?sendList, EffectChain?effectChain)
        {
            VoiceSends  value0 = sendList.HasValue ? sendList.Value : new VoiceSends();
            EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain();

            fixed(void *ptr = &pSubmixVoice)
            {
                return(InteropCalls.CallI(UnsafeBasePtr,
                                          ptr,
                                          inputChannels,
                                          inputSampleRate,
                                          flags,
                                          processingStage,
                                          sendList.HasValue ? &value0 : (void *)IntPtr.Zero,
                                          effectChain.HasValue ? &value1 : (void *)IntPtr.Zero,
                                          ((void **)(*(void **)UnsafeBasePtr))[9]));
            }
        }
示例#10
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);
            }
        }
示例#11
0
 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();
 }
示例#12
0
 public static unsafe int CallI(void* basePtr, void* filterParameters, int sourceChannels, int parametersByteSize,
     VoiceFlags maxFrequencyRatio, int processingStage, void* p3, void* p4, void* p5)
 {
     throw new NotImplementedException();
 }
示例#13
0
 /// <summary>
 ///     Creates and configures a source voice.
 /// </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>
 /// <returns>If successful, returns a new <see cref="XAudio2SourceVoice" /> object.</returns>
 public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags)
 {
     const float defaultFreqRatio = 4.0f;
     return CreateSourceVoice(sourceFormat, flags, defaultFreqRatio, null, null, null);
 }
示例#14
0
        /// <summary>
        ///     Creates and configures a submix voice.
        /// </summary>
        /// <param name="inputChannels">
        ///     Number of channels in the input audio data of the submix voice. The
        ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
        /// </param>
        /// <param name="inputSampleRate">
        ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
        ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
        ///     <see cref="MaximumSampleRate" />.
        /// </param>
        /// <param name="flags">
        ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
        ///     <see cref="VoiceFlags.UseFilter" />.
        /// </param>
        /// <returns>On success, returns a new <see cref="XAudio2SubmixVoice" /> object.</returns>
        public XAudio2SubmixVoice CreateSubmixVoice(int inputChannels, int inputSampleRate, VoiceFlags flags)
        {
            IntPtr ptr = CreateSubmixVoicePtr(inputChannels, inputSampleRate, flags, 0, null, null);

            return(new XAudio2SubmixVoice(ptr, _version));
        }
示例#15
0
        /// <summary>
        ///     Creates and configures a submix voice.
        /// </summary>
        /// <param name="inputChannels">
        ///     Number of channels in the input audio data of the submix voice. The
        ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
        /// </param>
        /// <param name="inputSampleRate">
        ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
        ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
        ///     <see cref="MaximumSampleRate" />.
        /// </param>
        /// <param name="flags">
        ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
        ///     <see cref="VoiceFlags.UseFilter" />.
        /// </param>
        /// <param name="processingStage">
        ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
        ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value
        ///     are
        ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
        ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
        /// </param>
        /// <param name="sendList">
        ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
        ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
        ///     submix voice. This parameter is optional and can be null.
        /// </param>
        /// <returns>On success, returns a new <see cref="XAudio2SubmixVoice" /> object.</returns>
        public XAudio2SubmixVoice CreateSubmixVoice(int inputChannels, int inputSampleRate, VoiceFlags flags,
                                                    int processingStage, VoiceSends?sendList, EffectChain?effectChain)
        {
            IntPtr ptr = CreateSubmixVoicePtr(inputChannels, inputSampleRate, flags, processingStage, sendList,
                                              effectChain);

            return(new XAudio2SubmixVoice(ptr, _version));
        }
示例#16
0
 /// <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
     );
示例#17
0
 /// <summary>
 ///     Creates and configures a submix voice.
 /// </summary>
 /// <param name="pSubmixVoice">On success, returns a pointer to the new <see cref="XAudio2SubmixVoice" /> object.</param>
 /// <param name="inputChannels">
 ///     Number of channels in the input audio data of the submix voice. The
 ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
 /// </param>
 /// <param name="inputSampleRate">
 ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
 ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
 ///     <see cref="MaximumSampleRate" />.
 /// </param>
 /// <param name="flags">
 ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
 ///     <see cref="VoiceFlags.UseFilter" />.
 /// </param>
 /// <param name="processingStage">
 ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
 ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value
 ///     are
 ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
 ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
 /// </param>
 /// <param name="sendList">
 ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
 ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
 ///     submix voice. This parameter is optional and can be null.
 /// </param>
 /// <returns>HRESULT</returns>
 public abstract int CreateSubmixVoiceNative(out IntPtr pSubmixVoice, int inputChannels,
                                             int inputSampleRate, VoiceFlags flags,
                                             int processingStage, VoiceSends?sendList, EffectChain?effectChain);
示例#18
0
 /// <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);
 }
示例#19
0
 /// <summary>
 ///     Creates and configures a submix voice.
 /// </summary>
 /// <param name="pSubmixVoice">On success, returns a pointer to the new <see cref="XAudio2SubmixVoice" /> object.</param>
 /// <param name="inputChannels">
 ///     Number of channels in the input audio data of the submix voice. The
 ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
 /// </param>
 /// <param name="inputSampleRate">
 ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
 ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
 ///     <see cref="MaximumSampleRate" />.
 /// </param>
 /// <param name="flags">
 ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
 ///     <see cref="VoiceFlags.UseFilter" />.
 /// </param>
 /// <param name="processingStage">
 ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
 ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value are
 ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
 ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
 /// </param>
 /// <param name="sendList">
 ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
 ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
 ///     submix voice. This parameter is optional and can be null.
 /// </param>
 /// <returns>HRESULT</returns>
 public unsafe override int CreateSubmixVoiceNative(out IntPtr pSubmixVoice, int inputChannels,
     int inputSampleRate, VoiceFlags flags,
     int processingStage, VoiceSends? sendList, EffectChain? effectChain)
 {
     VoiceSends value0 = sendList.HasValue ? sendList.Value : new VoiceSends();
     EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain();
     fixed (void* ptr = &pSubmixVoice)
     {
         return InteropCalls.CallI(UnsafeBasePtr,
             ptr,
             inputChannels,
             inputSampleRate,
             flags,
             processingStage,
             sendList.HasValue ? &value0 : (void*) IntPtr.Zero,
             effectChain.HasValue ? &value1 : (void*) IntPtr.Zero,
             ((void**) (*(void**) UnsafeBasePtr))[9]);
     }
 }
示例#20
0
 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();
 }
示例#21
0
 /// <summary>
 ///     Creates and configures a submix voice.
 /// </summary>
 /// <param name="inputChannels">
 ///     Number of channels in the input audio data of the submix voice. The
 ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
 /// </param>
 /// <param name="inputSampleRate">
 ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
 ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
 ///     <see cref="MaximumSampleRate" />.
 /// </param>
 /// <param name="flags">
 ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
 ///     <see cref="VoiceFlags.UseFilter" />.
 /// </param>
 /// <param name="processingStage">
 ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
 ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value
 ///     are
 ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
 ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
 /// </param>
 /// <param name="sendList">
 ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
 ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
 ///     submix voice. This parameter is optional and can be null.
 /// </param>
 /// <returns>On success, returns a pointer to the new <see cref="XAudio2SubmixVoice" /> object.</returns>
 public IntPtr CreateSubmixVoicePtr(int inputChannels, int inputSampleRate, VoiceFlags flags,
     int processingStage, VoiceSends? sendList, EffectChain? effectChain)
 {
     IntPtr ptr;
     int result = CreateSubmixVoiceNative(out ptr, inputChannels, inputSampleRate, flags, processingStage,
         sendList,
         effectChain);
     XAudio2Exception.Try(result, N, "CreateSubmixVoiceNative");
     return ptr;
 }
示例#22
0
 /// <summary>
 ///     Creates and configures a submix voice.
 /// </summary>
 /// <param name="pSubmixVoice">On success, returns a pointer to the new <see cref="XAudio2SubmixVoice" /> object.</param>
 /// <param name="inputChannels">
 ///     Number of channels in the input audio data of the submix voice. The
 ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
 /// </param>
 /// <param name="inputSampleRate">
 ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
 ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
 ///     <see cref="MaximumSampleRate" />.
 /// </param>
 /// <param name="flags">
 ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
 ///     <see cref="VoiceFlags.UseFilter" />.
 /// </param>
 /// <param name="processingStage">
 ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
 ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value
 ///     are
 ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
 ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
 /// </param>
 /// <param name="sendList">
 ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
 ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
 ///     submix voice. This parameter is optional and can be null.
 /// </param>
 /// <returns>HRESULT</returns>
 public abstract int CreateSubmixVoiceNative(out IntPtr pSubmixVoice, int inputChannels,
     int inputSampleRate, VoiceFlags flags,
     int processingStage, VoiceSends? sendList, EffectChain? effectChain);
示例#23
0
 /// <summary>
 ///     Creates and configures a submix voice.
 /// </summary>
 /// <param name="inputChannels">
 ///     Number of channels in the input audio data of the submix voice. The
 ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
 /// </param>
 /// <param name="inputSampleRate">
 ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
 ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
 ///     <see cref="MaximumSampleRate" />.
 /// </param>
 /// <param name="flags">
 ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
 ///     <see cref="VoiceFlags.UseFilter" />.
 /// </param>
 /// <returns>On success, returns a new <see cref="XAudio2SubmixVoice" /> object.</returns>
 public XAudio2SubmixVoice CreateSubmixVoice(int inputChannels, int inputSampleRate, VoiceFlags flags)
 {
     IntPtr ptr = CreateSubmixVoicePtr(inputChannels, inputSampleRate, flags, 0, null, null);
     return new XAudio2SubmixVoice(ptr, _version);
 }
示例#24
0
 /// <summary>
 ///     Creates and configures a submix voice.
 /// </summary>
 /// <param name="inputChannels">
 ///     Number of channels in the input audio data of the submix voice. The
 ///     <paramref name="inputChannels" /> must be less than or equal to <see cref="MaxAudioChannels" />.
 /// </param>
 /// <param name="inputSampleRate">
 ///     Sample rate of the input audio data of submix voice. This rate must be a multiple of
 ///     <see cref="QuantumDenominator" />. InputSampleRate must be between <see cref="MinimumSampleRate" /> and
 ///     <see cref="MaximumSampleRate" />.
 /// </param>
 /// <param name="flags">
 ///     Flags that specify the behavior of the submix voice. It can be <see cref="VoiceFlags.None" /> or
 ///     <see cref="VoiceFlags.UseFilter" />.
 /// </param>
 /// <param name="processingStage">
 ///     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 <paramref name="processingStage" /> value and before all other voices that include a larger
 ///     <paramref name="processingStage" /> value. Voices that include the same <paramref name="processingStage" /> value
 ///     are
 ///     processed in any order. A submix voice cannot send to another submix voice with a lower or equal
 ///     <paramref name="processingStage" /> value. This prevents audio being lost due to a submix cycle.
 /// </param>
 /// <param name="sendList">
 ///     List of <see cref="VoiceSends" /> structures that describe the set of destination voices for the
 ///     submix voice. If <paramref name="sendList" /> is NULL, the send list will default 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
 ///     submix voice. This parameter is optional and can be null.
 /// </param>
 /// <returns>On success, returns a new <see cref="XAudio2SubmixVoice" /> object.</returns>
 public XAudio2SubmixVoice CreateSubmixVoice(int inputChannels, int inputSampleRate, VoiceFlags flags,
     int processingStage, VoiceSends? sendList, EffectChain? effectChain)
 {
     IntPtr ptr = CreateSubmixVoicePtr(inputChannels, inputSampleRate, flags, processingStage, sendList,
         effectChain);
     return new XAudio2SubmixVoice(ptr, _version);
 }
示例#25
0
        /// <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();
            }
        }
示例#26
0
        /// <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]);
            }
        }
示例#27
0
文件: XAudio2_7.cs 项目: opcon/cscore
        /// <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);
                }
            }
        }
示例#28
0
 internal static unsafe int CallI(void *_basePtr, void *ptr, VoiceFlags flags, float maxFrequencyRatio, void *p1,
                                  void *p2, void *p3, void *p4)
 {
     throw new NotImplementedException();
 }
示例#29
0
        /// <summary>
        ///     Creates and configures a source voice.
        /// </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>
        /// <returns>If successful, returns a new <see cref="XAudio2SourceVoice" /> object.</returns>
        public XAudio2SourceVoice CreateSourceVoice(WaveFormat sourceFormat, VoiceFlags flags)
        {
            const float defaultFreqRatio = 4.0f;

            return(CreateSourceVoice(sourceFormat, flags, defaultFreqRatio, null, null, null));
        }
示例#30
0
 public static unsafe int CallI(void *basePtr, void *filterParameters, int sourceChannels, int parametersByteSize,
                                VoiceFlags maxFrequencyRatio, int processingStage, void *p3, void *p4, void *p5)
 {
     throw new NotImplementedException();
 }
示例#31
0
 internal static unsafe int CallI(void* _basePtr, void* ptr, VoiceFlags flags, float maxFrequencyRatio, void* p1,
     void* p2, void* p3, void* p4)
 {
     throw new NotImplementedException();
 }