/// <summary>
        /// Creates a new Audio endpoint volume
        /// </summary>
        /// <param name="realEndpointVolume">IAudioEndpointVolume COM interface</param>
        internal AudioEndpointVolume(IAudioEndpointVolume realEndpointVolume)
        {
            uint hardwareSupp;

            audioEndPointVolume = realEndpointVolume;
            channels = new AudioEndpointVolumeChannels(audioEndPointVolume);
            stepInformation = new AudioEndpointVolumeStepInformation(audioEndPointVolume);
            Marshal.ThrowExceptionForHR(audioEndPointVolume.QueryHardwareSupport(out hardwareSupp));
            hardwareSupport = (EEndpointHardwareSupport)hardwareSupp;
            volumeRange = new AudioEndpointVolumeVolumeRange(audioEndPointVolume);
            callBack = new AudioEndpointVolumeCallback(this);
            Marshal.ThrowExceptionForHR(audioEndPointVolume.RegisterControlChangeNotify(callBack));
        }
Exemple #2
0
 public AudioEngine(
     // todo create audio module factory
     IContainerProvider container,
     ILogger logger,
     IModuleService moduleService,
     IModuleConnectionService moduleConnectionService,
     IApiClient apiClient)
 {
     _container               = container;
     _logger                  = logger;
     _moduleService           = moduleService;
     _moduleConnectionService = moduleConnectionService;
     _apiClient               = apiClient;
     _modules                 = new List <IAudioModule>();
     _deviceEnumerator        = new MMDeviceEnumerator();
     _endpointVolumeCallback  = new AudioEndpointVolumeCallback();
 }
Exemple #3
0
        private void GetMMD()
        {
            M.D(1000, "GetMMD");
            L.MMD = CSCore.CoreAudioAPI.MMDeviceEnumerator.TryGetDefaultAudioEndpoint(CSCore.CoreAudioAPI.DataFlow.Render, CSCore.CoreAudioAPI.Role.Multimedia);
            if (L.MMD == null)
            {
                M.D(1001, M.Kind.ER, "MMD=null"); return;
            }

            AEV  = AudioEndpointVolume.FromDevice(L.MMD);
            AEVC = new AudioEndpointVolumeCallback();
            AEVC.NotifyRecived += AEV_NotifyRecived;
            AEV.RegisterControlChangeNotify(AEVC);
            L.MSD = new MasterData(AEV.IsMuted, AEV.MasterVolumeLevelScalar);

            AMI = AudioMeterInformation.FromDevice(L.MMD);
            //M.D(1008);
            //TryGetSs();
            M.D(1009);
        }
Exemple #4
0
        private void GetMMD()
        {
            DW(1000);
            L.MMD = CSCore.CoreAudioAPI.MMDeviceEnumerator.TryGetDefaultAudioEndpoint(CSCore.CoreAudioAPI.DataFlow.Render, CSCore.CoreAudioAPI.Role.Multimedia);
            if (L.MMD == null)
            {
                return;
            }

            AEV = AudioEndpointVolume.FromDevice(L.MMD);
            var aevc = new AudioEndpointVolumeCallback();

            aevc.NotifyRecived += Mepv_NotifyRecived;
            AEV.RegisterControlChangeNotify(aevc);
            L.MD = new MasterData(AEV.IsMuted, AEV.MasterVolumeLevelScalar);

            AMI = AudioMeterInformation.FromDevice(L.MMD);

            TryGetSs();
        }
        private void SetPlaybackDevice()
        {
            _playbackDevice = _enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
            if (_playbackDevice == null)
            {
                _logger.Warning("No audio device found with Console role");
                return;
            }
            _audioEndpointVolume = AudioEndpointVolume.FromDevice(_playbackDevice);

            AudioEndpointVolumeCallback audioEndpointVolumeCallback = new AudioEndpointVolumeCallback();

            audioEndpointVolumeCallback.NotifyRecived += (s, e) =>
            {
                UpdateVolumeDataModel();
            };
            _audioEndpointVolume.RegisterControlChangeNotify(audioEndpointVolumeCallback);
            DataModel.DefaultDeviceName = _playbackDevice.FriendlyName;
            _logger.Information(string.Format("Playback device {0} registered to to fill Playback volume data model", _playbackDevice.FriendlyName));
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aDefaultDeviceChangedHandler"></param>
        /// <param name="aVolumeChangedHandler"></param>
        public void Open(EventHandler <DefaultDeviceChangedEventArgs> aDefaultDeviceChangedHandler,
                         EventHandler <AudioEndpointVolumeCallbackEventArgs> aVolumeChangedHandler)
        {
            //Create device and register default device change notification
            iMultiMediaDeviceEnumerator   = new MMDeviceEnumerator();
            iMultiMediaNotificationClient = new MMNotificationClient(iMultiMediaDeviceEnumerator);
            iMultiMediaNotificationClient.DefaultDeviceChanged += iDefaultDeviceChangedHandler = aDefaultDeviceChangedHandler;
            iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            //Register to get volume modifications
            iAudioEndpointVolume         = AudioEndpointVolume.FromDevice(iMultiMediaDevice);
            iAudioEndpointVolumeCallback = new AudioEndpointVolumeCallback();
            iAudioEndpointVolumeCallback.NotifyRecived += iVolumeChangedHandler = aVolumeChangedHandler;
            iAudioEndpointVolume.RegisterControlChangeNotify(iAudioEndpointVolumeCallback);

            if (iVisualizerCount > 0)
            {
                // We probably got restarted, make sure visualization is running if needed
                StartAudioVisualization();
            }
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        public void Close()
        {
            StopAudioVisualization();

            // Client up our MM objects in reverse order
            if (iAudioEndpointVolumeCallback != null && iAudioEndpointVolume != null)
            {
                iAudioEndpointVolume.UnregisterControlChangeNotify(iAudioEndpointVolumeCallback);
            }

            if (iAudioEndpointVolumeCallback != null)
            {
                iAudioEndpointVolumeCallback.NotifyRecived -= iVolumeChangedHandler;
                iAudioEndpointVolumeCallback = null;
            }

            if (iAudioEndpointVolume != null)
            {
                iAudioEndpointVolume.Dispose();
                iAudioEndpointVolume = null;
            }

            if (iMultiMediaDevice != null)
            {
                iMultiMediaDevice.Dispose();
                iMultiMediaDevice = null;
            }

            if (iMultiMediaNotificationClient != null)
            {
                iMultiMediaNotificationClient.DefaultDeviceChanged -= iDefaultDeviceChangedHandler;
                iMultiMediaNotificationClient.Dispose();
                iMultiMediaNotificationClient = null;
            }

            if (iMultiMediaDeviceEnumerator != null)
            {
                iMultiMediaDeviceEnumerator.Dispose();
                iMultiMediaDeviceEnumerator = null;
            }
        }
        public void CanCreateAudioEndpointVolumeNotification()
        {
            using (var device = Utils.GetDefaultRenderDevice())
                using (var endpointVolume = AudioEndpointVolume.FromDevice(device))
                {
                    AudioEndpointVolumeCallback callback = new AudioEndpointVolumeCallback();
                    callback.NotifyRecived += (s, e) =>
                    {
                        Debug.WriteLine("Notification1");
                        //Debug.Assert(e.Channels == endpointVolume.ChannelCount);
                    };
                    endpointVolume.RegisterControlChangeNotify(callback);

                    var vol = endpointVolume.GetChannelVolumeLevelScalar(0);
                    endpointVolume.SetChannelVolumeLevelScalar(0, 1f, Guid.Empty);
                    endpointVolume.SetChannelVolumeLevelScalar(0, vol, Guid.Empty);

                    endpointVolume.UnregisterControlChangeNotify(callback);
                    System.Threading.Thread.Sleep(1000);
                }
        }
Exemple #9
0
        /// <summary>
        /// Disposes an instance of the <see cref="AudioCapture"/> class.
        /// </summary>
        public void Dispose()
        {
            this.StopCapture();

            if (this.volume != null)
            {
                if (this.volumeCallback != null)
                {
                    // Unregister the callback before releasing.
                    this.volume.UnregisterControlChangeNotify(this.volumeCallback);
                    this.volumeCallback = null;
                }

                Marshal.ReleaseComObject(this.volume);
                this.volume = null;
            }

            if (this.audioDevice != null)
            {
                Marshal.ReleaseComObject(this.audioDevice);
                this.audioDevice = null;
            }
        }
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     if (callBack != null)
     {
         Marshal.ThrowExceptionForHR(audioEndPointVolume.UnregisterControlChangeNotify(callBack));
         callBack = null;
     }
     GC.SuppressFinalize(this);
 }