Esempio n. 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.CSCoreUtils.GetComInterfaceForObjectWithAdjustedVtable(p, 7, 3);
            }

            try
            {
                fixed(void *ptr = &pSourceVoice)
                {
                    return(LocalInterop.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);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Designates a new set of submix or mastering voices to receive the output of the voice.
        /// </summary>
        /// <param name="voiceSendDescriptors">
        ///     Array of <see cref="VoiceSendDescriptor" />s. if <paramref name="voiceSendDescriptors" /> is null, the voice will send
        ///     its output to the current mastering voice.
        ///     All voices in the <paramref name="voiceSendDescriptors" /> must have the same input sample rate.
        /// </param>
        public unsafe void SetOutputVoices(VoiceSendDescriptor[] voiceSendDescriptors)
        {
            if (voiceSendDescriptors == null)
            {
                XAudio2Exception.Try(SetOutputVoicesNative(null), InterfaceName, "SetOutputVoices");
            }
            else
            {
                fixed(void *ptr = &voiceSendDescriptors[0])
                {
                    var p = new VoiceSends
                    {
                        SendCount = voiceSendDescriptors.Length,
                        SendsPtr  = new IntPtr(ptr)
                    };

                    XAudio2Exception.Try(SetOutputVoicesNative(p), InterfaceName, "SetOutputVoices");
                }
            }
        }
Esempio n. 3
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(LocalInterop.Calli(UnsafeBasePtr,
                                          ptr,
                                          inputChannels,
                                          inputSampleRate,
                                          flags,
                                          processingStage,
                                          sendList.HasValue ? &value0 : (void *)IntPtr.Zero,
                                          effectChain.HasValue ? &value1 : (void *)IntPtr.Zero,
                                          ((void **)(*(void **)UnsafeBasePtr))[6]));
            }
        }