Example #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="XAudio2_8" /> class.
        /// </summary>
        /// <param name="processor">
        ///     Specifies which CPU to use. Use <see cref="XAudio2Processor.Xaudio28DefaultProcessor" /> as
        ///     default value.
        /// </param>
        public unsafe XAudio2_8(XAudio2Processor processor)
        {
            IntPtr ptr    = IntPtr.Zero;
            var    pptr   = new IntPtr(&ptr);
            int    result = NativeMethods.XAudio2Create(pptr, 0, processor);

            XAudio2Exception.Try(result, "Interop", "XAudio2Create");

            Version = XAudio2Version.XAudio2_8;
            BasePtr = ptr;
        }
Example #2
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);
        }
Example #3
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");
                }
            }
        }
Example #4
0
 /// <summary>
 ///     Sets XAudio2 parameters and prepares XAudio2 for use.
 /// </summary>
 /// <param name="flags">Flags that specify the behavior of the XAudio2 object. This value must be 0.</param>
 /// <param name="processor">
 ///     Specifies which CPU to use. Use <see cref="XAudio2Processor.XAudio27DefaultProcessor" /> as default value.
 /// </param>
 public void Initialize(int flags, XAudio2Processor processor)
 {
     XAudio2Exception.Try(InitializeNative(flags, processor), N, "Initialize");
 }
Example #5
0
 /// <summary>
 ///     Atomically applies a set of operations that are tagged with a given identifier.
 /// </summary>
 /// <param name="operationSet">
 ///     Identifier of the set of operations to be applied. To commit all pending operations, pass
 ///     <see cref="CommitAll" />.
 /// </param>
 public void CommitChanges(int operationSet)
 {
     XAudio2Exception.Try(CommitChangesNative(operationSet), N, "CommitChanges");
 }
Example #6
0
 /// <summary>
 ///     Starts the audio processing thread.
 /// </summary>
 public void StartEngine()
 {
     XAudio2Exception.Try(StartEngineNative(), N, "StartEngine");
 }
Example #7
0
 /// <summary>
 ///     Adds an <see cref="IXAudio2EngineCallback" /> from the <see cref="XAudio2" /> engine callback list.
 /// </summary>
 /// <param name="callback">
 ///     <see cref="IXAudio2EngineCallback" /> object to add to the <see cref="XAudio2" /> engine
 ///     callback list.
 /// </param>
 public void RegisterForCallbacks(IXAudio2EngineCallback callback)
 {
     XAudio2Exception.Try(RegisterForCallbacksNative(callback), N, "RegisterForCallbacks");
 }
 /// <summary>
 ///     Starts consumption and processing of audio by the voice. Delivers the result to any connected submix or mastering
 ///     voices, or to the output device.
 /// </summary>
 /// <param name="flags">Flags that control how the voice is started. Must be 0.</param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more details see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 public void Start(int flags, int operationSet)
 {
     XAudio2Exception.Try(StartNative(flags, operationSet), N, "Start");
 }
 /// <summary>
 ///     Reconfigures the voice to consume source data at a different sample rate than the rate specified when the voice was
 ///     created.
 /// </summary>
 /// <param name="newSourceSampleRate">
 ///     The new sample rate the voice should process submitted data at. Valid sample rates
 ///     are 1kHz to 200kHz.
 /// </param>
 public void SetSourceSampleRate(int newSourceSampleRate)
 {
     XAudio2Exception.Try(SetSourceSampleRateNative(newSourceSampleRate), N, "SetSourceSampleRate");
 }
 /// <summary>
 ///     Sets the frequency adjustment ratio of the voice.
 /// </summary>
 /// <param name="ratio">
 ///     Frequency adjustment ratio. This value must be between <see cref="XAudio2.MinFrequencyRatio" /> and
 ///     the MaxFrequencyRatio parameter specified when the voice was created
 ///     <see
 ///         cref="XAudio2.CreateSourceVoice(CSCore.WaveFormat,CSCore.XAudio2.VoiceFlags,float,CSCore.XAudio2.IXAudio2VoiceCallback,System.Nullable{CSCore.XAudio2.VoiceSends},System.Nullable{CSCore.XAudio2.EffectChain})" />
 ///     .
 /// </param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more details see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 public void SetFrequencyRatio(float ratio, int operationSet)
 {
     XAudio2Exception.Try(SetFrequencyRatioNative(ratio, operationSet), N, "SetFrequencyRatio");
 }
 /// <summary>
 ///     Stops looping the voice when it reaches the end of the current loop region.
 /// </summary>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more details see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 public void ExitLoop(int operationSet)
 {
     XAudio2Exception.Try(ExitLoopNative(operationSet), N, "ExitLoop");
 }
 /// <summary>
 ///     Notifies an XAudio2 voice that no more buffers are coming after the last one that is currently in its queue.
 /// </summary>
 public void Discontinuity()
 {
     XAudio2Exception.Try(DiscontinuityNative(), N, "Discontinuity");
 }
 /// <summary>
 ///     Removes all pending audio buffers from the voice queue. If the voice is started, the buffer that is currently
 ///     playing is not removed from the queue.
 /// </summary>
 /// <remarks>
 ///     See
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2sourcevoice.ixaudio2sourcevoice.flushsourcebuffers(v=vs.85).aspx.
 /// </remarks>
 public void FlushSourceBuffers()
 {
     XAudio2Exception.Try(FlushSourceBuffersNative(), N, "FlushSourceBuffers");
 }
 /// <summary>
 ///     Adds a new audio buffer to the voice queue.
 /// </summary>
 /// <param name="buffer"><see cref="XAudio2Buffer" /> structure to queue.</param>
 /// <remarks>
 ///     See
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2sourcevoice.ixaudio2sourcevoice.submitsourcebuffer(v=vs.85).aspx.
 /// </remarks>
 public unsafe void SubmitSourceBuffer(XAudio2Buffer buffer)
 {
     XAudio2Exception.Try(SubmitSourceBufferNative(new IntPtr(&buffer), IntPtr.Zero), N, "SubmitSourceBuffer");
 }
 /// <summary>
 ///     Stops consumption of audio by the current voice.
 /// </summary>
 /// <param name="flags">
 ///     Flags that control how the voice is stopped. Can be <see cref="SourceVoiceStopFlags.None" /> or
 ///     <see cref="SourceVoiceStopFlags.PlayTails" />.
 /// </param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more details see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 public void Stop(SourceVoiceStopFlags flags, int operationSet)
 {
     XAudio2Exception.Try(StopNative(flags, operationSet), N, "Stop");
 }