/// <summary>
 /// The GetSimpleAudioVolume method retrieves a simple audio volume control.
 /// </summary>
 /// <param name="crossProcessSession">Specifies whether the request is for a cross-process session. Set to TRUE if the session is cross-process. Set to FALSE if the session is not cross-process.</param>
 /// <param name="audioSessionGuid">If the GUID does not identify a session that has been previously opened, the call opens a new but empty session. If the value is Guid.Empty, the method assigns the stream to the default session.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetSimpleAudioVolumeNative(Guid audioSessionGuid, NativeBool crossProcessSession, out SimpleAudioVolume audioVolume)
 {
     audioVolume = null;
     IntPtr ptr = IntPtr.Zero;
     int result = InteropCalls.CallI(_basePtr, &audioSessionGuid, crossProcessSession, &ptr, ((void**)(*(void**)_basePtr))[4]);
     if (ptr != IntPtr.Zero)
         audioVolume = new SimpleAudioVolume(ptr);
     return result;
 }
Beispiel #2
0
        /// <summary>
        /// The GetSimpleAudioVolume method retrieves a simple audio volume control.
        /// </summary>
        /// <param name="crossProcessSession">Specifies whether the request is for a cross-process session. Set to TRUE if the session is cross-process. Set to FALSE if the session is not cross-process.</param>
        /// <param name="audioSessionGuid">If the GUID does not identify a session that has been previously opened, the call opens a new but empty session. If the value is Guid.Empty, the method assigns the stream to the default session.</param>
        /// <returns>HRESULT</returns>
        public unsafe int GetSimpleAudioVolumeNative(Guid audioSessionGuid, NativeBool crossProcessSession, out SimpleAudioVolume audioVolume)
        {
            audioVolume = null;
            IntPtr ptr    = IntPtr.Zero;
            int    result = InteropCalls.CallI(_basePtr, &audioSessionGuid, crossProcessSession, &ptr, ((void **)(*(void **)_basePtr))[4]);

            if (ptr != IntPtr.Zero)
            {
                audioVolume = new SimpleAudioVolume(ptr);
            }
            return(result);
        }
Beispiel #3
0
        private void InitializeInternal()
        {
            _audioClient = AudioClient.FromMMDevice(Device);
            _outputFormat = SetupWaveFormat(_source.WaveFormat, _audioClient);

            long latency = _latency * 10000;

            if (!_eventSync)
            {
                _audioClient.Initialize(_shareMode, AudioClientStreamFlags.None, latency, 0, _outputFormat, Guid.Empty);
            }
            else //event sync
            {
                if (_shareMode == AudioClientShareMode.Exclusive) //exclusive
                {
                    _audioClient.Initialize(_shareMode, AudioClientStreamFlags.StreamFlags_EventCallback, latency, latency, _outputFormat, Guid.Empty);
                }
                else //shared
                {
                    _audioClient.Initialize(_shareMode, AudioClientStreamFlags.StreamFlags_EventCallback, 0, 0, _outputFormat, Guid.Empty);
                    _latency = (int)(_audioClient.StreamLatency / 10000);
                }

                _eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
                _audioClient.SetEventHandle(_eventWaitHandle.SafeWaitHandle.DangerousGetHandle());
            }

            _renderClient = AudioRenderClient.FromAudioClient(_audioClient);
            _simpleAudioVolume = SimpleAudioVolume.FromAudioClient(_audioClient);
            _simpleAudioVolume.MasterVolume = 1f;
        }
Beispiel #4
0
        private void CleanupResources()
        {
            if (_createdResampler && _source is DmoResampler)
            {
                ((DmoResampler)_source).DisposeResamplerOnly();
                _source = null;
            }

            if (_renderClient != null)
            {
                _renderClient.Dispose();
                _renderClient = null;
            }
            if (_audioClient != null)
            {
                try
                {
                    _audioClient.Reset();
                }
                catch (CoreAudioAPIException ex)
                {
                    if (ex.ErrorCode != unchecked((int)0x88890001)) //AUDCLNT_E_NOT_INITIALIZED
                    {
                        throw;
                    }
                }
                _audioClient.Dispose();
                _audioClient = null;
            }
            if (_simpleAudioVolume != null)
            {
                _simpleAudioVolume.Dispose();
                _simpleAudioVolume = null;
            }
            if (_eventWaitHandle != null)
            {
                _eventWaitHandle.Close();
                _eventWaitHandle = null;
            }

            _isInitialized = false;
        }