コード例 #1
0
 /// <summary>
 ///     Returns the number of available audio output devices.
 /// </summary>
 /// <param name="deviceCount">Number of available audio output devices.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetDeviceCountNative(out int deviceCount)
 {
     fixed(void *p = &deviceCount)
     {
         return(LocalInterop.Calli(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[3]));
     }
 }
コード例 #2
0
ファイル: XAudio2_8.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Removes an <see cref="IXAudio2EngineCallback" /> from the <see cref="XAudio2" /> engine callback list.
        /// </summary>
        /// <param name="callback">
        ///     <see cref="IXAudio2EngineCallback" /> object to remove from the <see cref="XAudio2" /> engine
        ///     callback list. If the given interface is present more than once in the list, only the first instance in the list
        ///     will be removed.
        /// </param>
        public override unsafe void UnregisterForCallbacks(IXAudio2EngineCallback callback)
        {
            IntPtr ptr = IntPtr.Zero;

            if (callback != null)
            {
                ptr = Marshal.GetComInterfaceForObject(callback, typeof(IXAudio2EngineCallback));
                ptr = Utils.CSCoreUtils.GetComInterfaceForObjectWithAdjustedVtable(ptr, 3, 3);
            }
            try
            {
                LocalInterop.Calli(UnsafeBasePtr, (void *)ptr, ((void **)(*(void **)UnsafeBasePtr))[4]);
            }
            finally
            {
                if (ptr != 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(ptr);
                    //Marshal.Release(ptr);
                }
            }
        }
コード例 #3
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Gets the current overall volume level of the voice.
 /// </summary>
 /// <param name="volume">
 ///     Returns the current overall volume level of the voice. See Remarks for more information on volume
 ///     levels.
 /// </param>
 /// <returns>HRESULT</returns>
 /// <remarks>
 ///     The master volume level is applied at different times depending on the type of voice.
 ///     For submix and mastering voices the volume level is applied just before the voice's built in filter and effect
 ///     chain is applied.
 ///     For source voices the master volume level is applied after the voice's filter and effect
 ///     chain is applied. Volume levels are expressed as floating-point amplitude multipliers
 ///     between -2^24 and 2^24, with a maximum
 ///     gain of 144.5 dB. A volume level of 1.0 means there is no attenuation or gain and 0 means silence.
 ///     Negative levels can be used to invert the audio's phase.
 /// </remarks>
 public unsafe int GetVolumeNative(out float volume)
 {
     fixed(void *p = &volume)
     {
         return(LocalInterop.Calli(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[13]));
     }
 }
コード例 #4
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Sets the volume levels for the voice, per channel. This method is valid only for source and submix voices, because
 ///     mastering voices do not specify volume per channel.
 /// </summary>
 /// <param name="channelCount">Number of channels in the voice.</param>
 /// <param name="volumes">
 ///     Array containing the new volumes of each channel in the voice. The array must have
 ///     <paramref name="channelCount" /> elements. See Remarks for more information on volume levels.
 /// </param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more information see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 /// <returns>HRESULT</returns>
 /// <remarks>
 ///     The master volume level is applied at different times depending on the type of voice.
 ///     For submix and mastering voices the volume level is applied just before the voice's built in filter and effect
 ///     chain is applied.
 ///     For source voices the master volume level is applied after the voice's filter and effect
 ///     chain is applied. Volume levels are expressed as floating-point amplitude multipliers
 ///     between -2^24 and 2^24, with a maximum
 ///     gain of 144.5 dB. A volume level of 1.0 means there is no attenuation or gain and 0 means silence.
 ///     Negative levels can be used to invert the audio's phase.
 /// </remarks>
 public unsafe int SetChannelVolumesNative(int channelCount, float[] volumes, int operationSet)
 {
     fixed(void *p = &volumes[0])
     {
         return(LocalInterop.Calli(UnsafeBasePtr, channelCount, p, operationSet, ((void **)(*(void **)UnsafeBasePtr))[14]));
     }
 }
コード例 #5
0
        /// <summary>
        ///     Creates and configures a mastering voice.
        /// </summary>
        /// <param name="pMasteringVoice">If successful, returns a pointer to the new <see cref="XAudio2MasteringVoice" /> object.</param>
        /// <param name="inputChannels">
        ///     Number of channels the mastering voice expects in its input audio. <paramref name="inputChannels" /> must be less than
        ///     or equal to <see cref="MaxAudioChannels" />.
        ///     You can set InputChannels to <see cref="DefaultChannels" />, which causes XAudio2 to try to detect the system
        ///     speaker configuration setup.
        /// </param>
        /// <param name="inputSampleRate">
        ///     Sample rate of the input audio data of the mastering voice. This rate must be a multiple of
        ///     <see cref="QuantumDenominator" />. <paramref name="inputSampleRate" /> must be between <see cref="MinimumSampleRate" />
        ///     and <see cref="MaximumSampleRate" />.
        ///     You can set InputSampleRate to <see cref="DefaultSampleRate" />, with the default being determined by the current
        ///     platform.
        /// </param>
        /// <param name="flags">Flags that specify the behavior of the mastering voice. Must be 0.</param>
        /// <param name="deviceId">
        ///     Identifier of the device to receive the output audio. Specifying the default value of 0 (zero)
        ///     causes XAudio2 to select the global default audio device.
        /// </param>
        /// <param name="effectChain">
        ///     <see cref="EffectChain" /> structure that describes an effect chain to use in the mastering
        ///     voice, or NULL to use no effects.
        /// </param>
        /// <param name="streamCategory"><b>Not valid for XAudio 2.7.</b></param>
        /// <returns>HRESULT</returns>
        public override unsafe int CreateMasteringVoiceNative(out IntPtr pMasteringVoice, int inputChannels,
                                                              int inputSampleRate, int flags,
                                                              object deviceId, EffectChain?effectChain, AudioStreamCategory streamCategory)
        {
            if (!(deviceId is int))
            {
                throw new ArgumentException("DeviceId has to be an integer.", "deviceId");
            }
            var device = (int)deviceId;

            EffectChain value1 = effectChain.HasValue ? effectChain.Value : new EffectChain();

            fixed(void *ptr = &pMasteringVoice)
            {
                return(LocalInterop.Calli(
                           UnsafeBasePtr,
                           ptr,
                           inputChannels,
                           inputSampleRate,
                           flags,
                           device,
                           effectChain.HasValue ? &value1 : (void *)IntPtr.Zero,
                           //streamCategory,
                           ((void **)(*(void **)UnsafeBasePtr))[10]));
            }
        }
コード例 #6
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Returns the volume levels for the voice, per channel.
 ///     These settings are applied after the effect chain is applied.
 ///     This method is valid only for source and submix voices, because mastering voices do not specify volume per channel.
 /// </summary>
 /// <param name="channelCount">Confirms the channel count of the voice.</param>
 /// <param name="volumes">
 ///     Returns the current volume level of each channel in the voice. The array must have at least
 ///     <paramref name="channelCount" /> elements.
 ///     See remarks for more information on volume levels.
 /// </param>
 /// <returns>HRESULT</returns>
 /// <remarks>
 ///     The master volume level is applied at different times depending on the type of voice.
 ///     For submix and mastering voices the volume level is applied just before the voice's built in filter and effect
 ///     chain is applied.
 ///     For source voices the master volume level is applied after the voice's filter and effect
 ///     chain is applied. Volume levels are expressed as floating-point amplitude multipliers
 ///     between -2^24 and 2^24, with a maximum
 ///     gain of 144.5 dB. A volume level of 1.0 means there is no attenuation or gain and 0 means silence.
 ///     Negative levels can be used to invert the audio's phase.
 /// </remarks>
 public unsafe int GetChannelVolumesNative(int channelCount, float[] volumes)
 {
     fixed(void *p = &volumes[0])
     {
         return(LocalInterop.Calli(UnsafeBasePtr, channelCount, p, ((void **)(*(void **)UnsafeBasePtr))[15]));
     }
 }
コード例 #7
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Returns the running state of the effect at a specified position in the effect chain of the voice.
 /// </summary>
 /// <param name="effectIndex">Zero-based index of an effect in the effect chain of the voice.</param>
 /// <param name="enabled">Returns true if the effect is enabled. If the effect is disabled, returns false.</param>
 public unsafe void GetEffectStateNative(int effectIndex, out NativeBool enabled)
 {
     fixed(void *p = &enabled)
     {
         LocalInterop.Calli1(UnsafeBasePtr, effectIndex, p, ((void **)(*(void **)UnsafeBasePtr))[5]);
     }
 }
コード例 #8
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Gets the voice's filter parameters.
 /// </summary>
 /// <param name="filterParameters">
 ///     <see cref="AudioSharp.XAudio2.FilterParameters" /> structure containing the filter
 ///     information.
 /// </param>
 /// <returns>HRESULT</returns>
 public unsafe int GetFilterParametersNative(out FilterParameters filterParameters)
 {
     filterParameters = default(FilterParameters);
     fixed(void *p = &filterParameters)
     {
         return(LocalInterop.Calli(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[9]));
     }
 }
コード例 #9
0
 /// <summary>
 ///     Returns current resource usage details, such as available memory or CPU usage.
 /// </summary>
 /// <param name="performanceData">
 ///     On success, pointer to an <see cref="AudioSharp.XAudio2.PerformanceData" /> structure that is
 ///     returned.
 /// </param>
 /// <returns>HRESULT</returns>
 public override unsafe void GetPerformanceDataNative(out PerformanceData performanceData)
 {
     performanceData = default(PerformanceData); //initialize performanceData to fix compiler error
     fixed(void *p = &performanceData)
     {
         LocalInterop.Calli5(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[14]);
     }
 }
コード例 #10
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Sets the filter parameters on one of this voice's sends.
        /// </summary>
        /// <param name="destinationVoice">The destination voice of the send whose filter parameters will be set.</param>
        /// <param name="filterParameters">
        ///     <see cref="AudioSharp.XAudio2.FilterParameters" /> structure containing the filter
        ///     information.
        /// </param>
        /// <param name="operationSet">
        ///     Identifies this call as part of a deferred batch. For more information see
        ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
        /// </param>
        /// <returns>HRESULT</returns>
        public unsafe int SetOutputFilterParametersNative(XAudio2Voice destinationVoice,
                                                          FilterParameters filterParameters,
                                                          int operationSet)
        {
            IntPtr pVoice = destinationVoice == null ? IntPtr.Zero : destinationVoice.BasePtr;

            return(LocalInterop.Calli(UnsafeBasePtr, (void *)pVoice, &filterParameters, operationSet,
                                      ((void **)(*(void **)UnsafeBasePtr))[10]));
        }
コード例 #11
0
        /// <summary>
        ///     <b>XAudio2.8 only:</b> Returns the channel mask for this voice.
        /// </summary>
        /// <param name="channelMask">
        ///     Returns the channel mask for this voice. This corresponds to the
        ///     <see cref="WaveFormatExtensible.ChannelMask" /> member of the <see cref="WaveFormatExtensible" /> class.
        /// </param>
        /// <returns>HRESULT</returns>
        public unsafe int GetChannelMaskNative(out ChannelMask channelMask)
        {
            if (Version != XAudio2Version.XAudio2_8)
                throw new InvalidOperationException("The Channelmask of a mastering voice is only available using XAudio2.8.");

            fixed(void *p = &channelMask)
            {
                return(LocalInterop.Calli(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[19]));
            }
        }
コード例 #12
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Gets the volume level of each channel of the final output for the voice. These channels are mapped to the input
        ///     channels of a specified destination voice.
        /// </summary>
        /// <param name="destinationVoice">The destination <see cref="XAudio2Voice" /> to retrieve the output matrix for.</param>
        /// <param name="sourceChannels">
        ///     Confirms the output channel count of the voice. This is the number of channels that are
        ///     produced by the last effect in the chain.
        /// </param>
        /// <param name="destinationChannels">Confirms the input channel count of the destination voice.</param>
        /// <param name="levelMatrix">
        ///     Array of [SourceChannels ?DestinationChannels] volume levels sent to the destination voice.
        ///     The level sent from source channel S to destination channel D is specified in the form levelMatrix[SourceChannels ?        ///     D + S].
        ///     For more details see
        ///     http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2voice.ixaudio2voice.getoutputmatrix(v=vs.85).aspx.
        /// </param>
        /// <returns>HRESULT</returns>
        public unsafe int GetOutputMatrixNative(XAudio2Voice destinationVoice, int sourceChannels,
                                                int destinationChannels, float[] levelMatrix)
        {
            IntPtr pVoice = destinationVoice == null ? IntPtr.Zero : destinationVoice.BasePtr;

            fixed(void *p = &levelMatrix[0])
            {
                return(LocalInterop.Calli(UnsafeBasePtr, (void *)pVoice, sourceChannels, destinationChannels, p,
                                          ((void **)(*(void **)UnsafeBasePtr))[17]));
            }
        }
コード例 #13
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Designates a new set of submix or mastering voices to receive the output of the voice.
        /// </summary>
        /// <param name="voiceSends">
        ///     VoiceSends structure which contains Output voices. If <paramref name="voiceSends" /> is null, the voice will send
        ///     its output to the current mastering voice. All of the voices in a send list must have the same input sample rate.
        /// </param>
        /// <returns>HRESULT</returns>
        public unsafe int SetOutputVoicesNative(VoiceSends?voiceSends)
        {
            VoiceSends value;

            if (voiceSends.HasValue)
            {
                value = voiceSends.Value;
            }

            return(LocalInterop.Calli(UnsafeBasePtr, voiceSends.HasValue ? &value : (void *)IntPtr.Zero,
                                      ((void **)(*(void **)UnsafeBasePtr))[1]));
        }
コード例 #14
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Returns the filter parameters from one of this voice's sends.
        /// </summary>
        /// <param name="destinationVoice">The destination voice of the send whose filter parameters will be read.</param>
        /// <param name="filterParameters">
        ///     <see cref="AudioSharp.XAudio2.FilterParameters" /> structure containing the filter
        ///     information.
        /// </param>
        /// <returns>HRESULT</returns>
        public unsafe int GetOutputFilterParametersNative(XAudio2Voice destinationVoice,
                                                          out FilterParameters filterParameters)
        {
            filterParameters = default(FilterParameters);

            IntPtr pVoice = destinationVoice == null ? IntPtr.Zero : destinationVoice.BasePtr;

            fixed(void *p = &filterParameters)
            {
                return(LocalInterop.Calli(UnsafeBasePtr, (void *)pVoice, p, ((void **)(*(void **)UnsafeBasePtr))[11]));
            }
        }
コード例 #15
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Replaces the effect chain of the voice.
        /// </summary>
        /// <param name="effectChain">
        ///     Describes the new effect chain to use.
        ///     If null is passed, the current effect chain is removed.
        /// </param>
        /// <returns>HRESULT</returns>
        public unsafe int SetEffectChainNative(EffectChain?effectChain)
        {
            var ptr = (void *)IntPtr.Zero;

            //check whether null is passed -> if null is passed, the chain will be removed
            if (effectChain.HasValue)
            {
                EffectChain value = effectChain.Value;
                ptr = &value;
            }

            return(LocalInterop.Calli(UnsafeBasePtr, ptr, ((void **)(*(void **)UnsafeBasePtr))[2]));
        }
コード例 #16
0
ファイル: XAudio2_8.cs プロジェクト: superowner/AudioSharp
        /// <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);
                }
            }
        }
コード例 #17
0
        /// <summary>
        ///     Returns the voice's current cursor position data.
        /// </summary>
        /// <param name="flags">
        ///     <b>XAudio2.8 only:</b> Flags controlling which voice state data should be returned.
        ///     Valid values are <see cref="GetVoiceStateFlags.Default" /> or <see cref="GetVoiceStateFlags.NoSamplesPlayed" />.
        ///     The default value is <see cref="GetVoiceStateFlags.Default" />. If you specify
        ///     <see cref="GetVoiceStateFlags.NoSamplesPlayed" />, GetState
        ///     returns only the buffer state, not the sampler state.
        ///     GetState takes roughly one-third as much time to complete when you specify
        ///     <see cref="GetVoiceStateFlags.NoSamplesPlayed" />.
        /// </param>
        /// <returns><see cref="VoiceState" /> structure containing the state of the voice.</returns>
        /// <remarks>If the <see cref="XAudio2Voice.Version"/> is not <see cref="XAudio2Version.XAudio2_8"/> the <paramref name="flags"/> parameter will be ignored.</remarks>
        public unsafe VoiceState GetState(GetVoiceStateFlags flags)
        {
            if (Version == XAudio2Version.XAudio2_7)
            {
                VoiceState voiceState = default(VoiceState);
                LocalInterop.Calli1(UnsafeBasePtr, &voiceState, ((void **)(*(void **)UnsafeBasePtr))[25]);
                return(voiceState);
            }
            if (Version == XAudio2Version.XAudio2_8)
            {
                VoiceState voiceState = default(VoiceState);
                LocalInterop.Calli1(UnsafeBasePtr, &voiceState, flags, ((void **)(*(void **)UnsafeBasePtr))[25]);
                return(voiceState);
            }

            throw new Exception("Invalid XAudio2 Version.");
        }
コード例 #18
0
        /// <summary>
        ///     Returns information about an audio output device.
        /// </summary>
        /// <param name="deviceIndex">
        ///     Index of the device to be queried. This value must be less than the count returned by
        ///     <see cref="GetDeviceCount" />.
        /// </param>
        /// <param name="deviceDetails"><see cref="DeviceDetails" /> structure.</param>
        /// <returns>HRESULT</returns>
        public unsafe int GetDeviceDetailsNative(int deviceIndex, out DeviceDetails deviceDetails)
        {
            var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DeviceDetails)));

            try
            {
                deviceDetails = default(DeviceDetails);
                int result = LocalInterop.Calli(UnsafeBasePtr, deviceIndex, ptr.ToPointer(),
                                                ((void **)(*(void **)UnsafeBasePtr))[4]);

                deviceDetails = (DeviceDetails)Marshal.PtrToStructure(ptr, typeof(DeviceDetails));
                return(result);
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
コード例 #19
0
ファイル: XAudio2_8.cs プロジェクト: superowner/AudioSharp
        /// <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]));
            }
        }
コード例 #20
0
ファイル: XAudio2_8.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Creates and configures a mastering voice.
        /// </summary>
        /// <param name="pMasteringVoice">If successful, returns a pointer to the new <see cref="XAudio2MasteringVoice" /> object.</param>
        /// <param name="inputChannels">
        ///     Number of channels the mastering voice expects in its input audio. <paramref name="inputChannels" /> must be less than
        ///     or equal to <see cref="MaxAudioChannels" />.
        ///     You can set InputChannels to <see cref="DefaultChannels" />, which causes XAudio2 to try to detect the system
        ///     speaker configuration setup.
        /// </param>
        /// <param name="inputSampleRate">
        ///     Sample rate of the input audio data of the mastering voice. This rate must be a multiple of
        ///     <see cref="QuantumDenominator" />. <paramref name="inputSampleRate" /> must be between <see cref="MinimumSampleRate" />
        ///     and <see cref="MaximumSampleRate" />.
        ///     You can set InputSampleRate to <see cref="DefaultSampleRate" />, with the default being determined by the current
        ///     platform.
        /// </param>
        /// <param name="flags">Flags that specify the behavior of the mastering voice. Must be 0.</param>
        /// <param name="deviceId">
        ///     Identifier of the device to receive the output audio. Specifying the default value of NULL
        ///     causes XAudio2 to select the global default audio device.
        /// </param>
        /// <param name="effectChain">
        ///     <see cref="EffectChain" /> structure that describes an effect chain to use in the mastering
        ///     voice, or NULL to use no effects.
        /// </param>
        /// <param name="streamCategory">The audio stream category to use for this mastering voice.</param>
        /// <returns>HRESULT</returns>
        public override unsafe int CreateMasteringVoiceNative(out IntPtr pMasteringVoice, int inputChannels,
                                                              int inputSampleRate, int flags,
                                                              object deviceId, EffectChain?effectChain, AudioStreamCategory streamCategory)
        {
            if (deviceId != null && !(deviceId is string))
            {
                throw new ArgumentException("DeviceId has to be a string.", "deviceId");
            }

            var    device    = deviceId as string;
            IntPtr pdeviceId = IntPtr.Zero;

            try
            {
                EffectChain value1 = effectChain ?? new EffectChain();
                if (device != null)
                {
                    pdeviceId = Marshal.StringToHGlobalUni(device);

                    fixed(void *ptr = &pMasteringVoice)
                    {
                        return(LocalInterop.Calli(
                                   UnsafeBasePtr,
                                   ptr,
                                   inputChannels,
                                   inputSampleRate,
                                   flags,
                                   (void *)pdeviceId,
                                   effectChain.HasValue ? &value1 : (void *)IntPtr.Zero,
                                   streamCategory,
                                   ((void **)(*(void **)UnsafeBasePtr))[7]));
                    }
            }
            finally
            {
                if (pdeviceId != IntPtr.Zero)
                    Marshal.FreeHGlobal(pdeviceId); }
            }
コード例 #21
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
        /// <summary>
        ///     Returns information about the creation flags, input channels, and sample rate of a voice.
        /// </summary>
        /// <param name="voiceDetails"><see cref="AudioSharp.XAudio2.VoiceDetails" /> object containing information about the voice.</param>
        /// <returns>HRESULT</returns>
        public unsafe int GetVoiceDetailsNative(out VoiceDetails voiceDetails)
        {
            voiceDetails = default(VoiceDetails);
            int result;

            if (_version == XAudio2Version.XAudio2_7)
            {
                var t = new VoiceDetails.VoiceDetails27();
                result       = LocalInterop.Calli(UnsafeBasePtr, &t, ((void **)(*(void **)UnsafeBasePtr))[0]);
                voiceDetails = VoiceDetails.FromNativeVoiceDetailsObject(t);
            }
            else if (_version == XAudio2Version.XAudio2_8)
            {
                var t = new VoiceDetails.VoiceDetails28();
                result       = LocalInterop.Calli(UnsafeBasePtr, &t, ((void **)(*(void **)UnsafeBasePtr))[0]);
                voiceDetails = VoiceDetails.FromNativeVoiceDetailsObject(t);
            }
            else
            {
                throw new Exception("Invalid XAudio2 version.");
            }

            return(result);
        }
コード例 #22
0
 /// <summary>
 ///     Stops the audio processing thread.
 /// </summary>
 public override unsafe void StopEngine()
 {
     LocalInterop.Calli7(UnsafeBasePtr, ((void **)(*(void **)UnsafeBasePtr))[12]);
 }
コード例 #23
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>
 /// <returns>HRESULT</returns>
 public override unsafe int CommitChangesNative(int operationSet)
 {
     return(LocalInterop.Calli(UnsafeBasePtr, operationSet, ((void **)(*(void **)UnsafeBasePtr))[13]));
 }
コード例 #24
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Sets the overall volume level for the voice.
 /// </summary>
 /// <param name="volume">Overall volume level to use. See Remarks for more information on volume levels.</param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more information see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 /// <returns>HRESULT</returns>
 /// <remarks>
 ///     The master volume level is applied at different times depending on the type of voice.
 ///     For submix and mastering voices the volume level is applied just before the voice's built in filter and effect
 ///     chain is applied.
 ///     For source voices the master volume level is applied after the voice's filter and effect
 ///     chain is applied. Volume levels are expressed as floating-point amplitude multipliers
 ///     between -2^24 and 2^24, with a maximum
 ///     gain of 144.5 dB. A volume level of 1.0 means there is no attenuation or gain and 0 means silence.
 ///     Negative levels can be used to invert the audio's phase.
 /// </remarks>
 public unsafe int SetVolumeNative(float volume, int operationSet)
 {
     return(LocalInterop.Calli(UnsafeBasePtr, volume, operationSet, ((void **)(*(void **)UnsafeBasePtr))[12]));
 }
コード例 #25
0
 /// <summary>
 ///     Changes <b>global</b> debug logging options for XAudio2.
 /// </summary>
 /// <param name="debugConfiguration"><see cref="DebugConfiguration" /> structure that contains the new debug configuration.</param>
 /// <param name="reserved">Reserved parameter. Must me NULL.</param>
 /// <returns>HRESULT</returns>
 public override unsafe void SetDebugConfigurationNative(DebugConfiguration debugConfiguration, IntPtr reserved)
 {
     LocalInterop.Calli4(UnsafeBasePtr, &debugConfiguration, reserved.ToPointer(), ((void **)(*(void **)UnsafeBasePtr))[15]);
 }
コード例 #26
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Sets the voice's filter parameters.
 /// </summary>
 /// <param name="filterParameters">
 ///     <see cref="AudioSharp.XAudio2.FilterParameters" /> structure containing the filter
 ///     information.
 /// </param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more information see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 /// <returns>HRESULT</returns>
 public unsafe int SetFilterParametersNative(FilterParameters filterParameters, int operationSet)
 {
     return(LocalInterop.Calli(UnsafeBasePtr, &filterParameters, operationSet, ((void **)(*(void **)UnsafeBasePtr))[8]));
 }
コード例 #27
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Returns the current effect-specific parameters of a given effect in the voice's effect chain.
 /// </summary>
 /// <param name="effectIndex">Zero-based index of an effect within the voice's effect chain.</param>
 /// <param name="effectParameters">Returns the current values of the effect-specific parameters.</param>
 /// <param name="parametersByteSize">Size of the <paramref name="effectParameters" /> array in bytes.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetEffectParametersNative(int effectIndex, IntPtr effectParameters, int parametersByteSize)
 {
     return(LocalInterop.Calli(UnsafeBasePtr, effectIndex, effectParameters.ToPointer(), parametersByteSize,
                               ((void **)(*(void **)UnsafeBasePtr))[7]));
 }
コード例 #28
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Sets parameters for a given effect in the voice's effect chain.
 /// </summary>
 /// <param name="effectIndex">Zero-based index of an effect within the voice's effect chain.</param>
 /// <param name="effectParameters"> New values of the effect-specific parameters. </param>
 /// <param name="parametersByteSize">Size of the <paramref name="effectParameters" /> array in bytes.</param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more information see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 /// <returns>HRESULT</returns>
 public unsafe int SetEffectParametersNative(int effectIndex, IntPtr effectParameters, int parametersByteSize,
                                             int operationSet)
 {
     return(LocalInterop.Calli(UnsafeBasePtr, effectIndex, effectParameters, parametersByteSize, operationSet,
                               ((void **)(*(void **)UnsafeBasePtr))[6]));
 }
コード例 #29
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Destroys the voice. If necessary, stops the voice and removes it from the XAudio2 graph.
 /// </summary>
 public unsafe void DestroyVoice()
 {
     LocalInterop.Calli2(UnsafeBasePtr, ((void **)(*(void **)UnsafeBasePtr))[18]);
 }
コード例 #30
0
ファイル: XAudio2Voice.cs プロジェクト: superowner/AudioSharp
 /// <summary>
 ///     Disables the effect at a given position in the effect chain of the voice.
 /// </summary>
 /// <param name="effectIndex">Zero-based index of an effect in the effect chain of the voice.</param>
 /// <param name="operationSet">
 ///     Identifies this call as part of a deferred batch. For more information see
 ///     http://msdn.microsoft.com/en-us/library/windows/desktop/ee415807(v=vs.85).aspx.
 /// </param>
 /// <returns>HRESULT</returns>
 public unsafe int DisableEffectNative(int effectIndex, int operationSet)
 {
     return(LocalInterop.Calli(UnsafeBasePtr, effectIndex, operationSet, ((void **)(*(void **)UnsafeBasePtr))[4]));
 }