Example #1
0
        void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
        {
            bool wasMuted   = _isMuted;
            int  lastVolume = _volume;

            _isMuted = _audioDefaultDevice.Muted;
            if (_waveVolume && OSInfo.OSInfo.Win8OrLater())
            {
                _isMutedVolume = (int)GetValue(_componentType, MixerControlType.Mute) == 1;
            }
            _volume = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum);

            if (ControlChanged != null && (wasMuted != _isMuted || lastVolume != _volume))
            {
                ControlChanged(null, null);
                if (_waveVolume && OSInfo.OSInfo.Win8OrLater() && (_isMutedVolume != IsMuted))
                {
                    SetValue(_mixerControlDetailsMute, _isMuted);
                }
            }
        }
Example #2
0
    void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
    { 
      bool wasMuted = _isMuted;
      int lastVolume = _volume;
      _isMuted = _audioDefaultDevice.Muted;
      if (_waveVolume && OSInfo.OSInfo.Win8OrLater())
      {
        _isMutedVolume = (int) GetValue(_componentType, MixerControlType.Mute) == 1;
      }
      _volume = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum);

      if (ControlChanged != null && (wasMuted != _isMuted || lastVolume != _volume))
      {
        ControlChanged(null, null);
        if (_waveVolume && OSInfo.OSInfo.Win8OrLater() && (_isMutedVolume != IsMuted))
        {
          SetValue(_mixerControlDetailsMute, _isMuted);
        }
      }
    }
Example #3
0
    void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
    { 
      bool wasMuted = _isMuted;
      int lastVolume = _volume;
      _isMuted = _audioDefaultDevice.Muted;
      _volume = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum);

      if (ControlChanged != null && (wasMuted != _isMuted || lastVolume != _volume))
      {
        ControlChanged(null, null);
      }
    }
Example #4
0
 internal void FireNotification(AudioVolumeNotificationData NotificationData)
 {
   AudioEndpointVolumeNotificationDelegate del = OnVolumeNotification;
   if (del != null)
   {
     del(NotificationData);
   }
 }
Example #5
0
    public int OnNotify(IntPtr NotifyData)
    {
      //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the
      //number of audio channels available we cannot just call PtrToStructure 
      //to get all data, thats why it is split up into two steps, first the static
      //data is marshalled into the data structure, then with some IntPtr math the
      //remaining floats are read from memory.
      AUDIO_VOLUME_NOTIFICATION_DATA data = (AUDIO_VOLUME_NOTIFICATION_DATA)Marshal.PtrToStructure(NotifyData, typeof(AUDIO_VOLUME_NOTIFICATION_DATA));

      //Determine offset in structure of the first float
      IntPtr Offset = Marshal.OffsetOf(typeof(AUDIO_VOLUME_NOTIFICATION_DATA), "ChannelVolume");
      //Determine offset in memory of the first float
      IntPtr FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset);

      float[] voldata = new float[data.nChannels];

      //Read all floats from memory.
      for (int i = 0; i < data.nChannels; i++)
      {
        voldata[i] = (float)Marshal.PtrToStructure(FirstFloatPtr, typeof(float));
      }

      //Create combined structure and Fire Event in parent class.
      AudioVolumeNotificationData NotificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata);
      _Parent.FireNotification(NotificationData);
      return 0; //S_OK
    }
   void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
   {
     try
     {
       if ((data?.MasterVolume == null) || IsMixerLocked())
       {
         Log.Debug("Mixer: AudioEndpointVolume_OnVolumeNotification early return,, IsMixerLocked():{0}, data null:{1}", IsMixerLocked(), (data?.MasterVolume == null));
         return;
       }
         
       using (MixerLock(lockTimeout))
       { 
         bool wasMuted = _isMuted;
         int lastVolume = _volume;
         bool waveChange = false;
                 
         bool isMutedMaster = _audioDefaultDevice.Muted;
         int volumeMaster = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum);
         if (_useWave)
         {
           bool isMutedWave = (int)GetValue(_componentType, MixerControlType.Mute) == 1;
           int volumeWave = (int)GetValue(_componentType, MixerControlType.Volume);
           
           if ((isMutedWave != _isMutedWave) || (volumeWave != _volumeWave))
           {
             _isMutedWave = isMutedWave;
             _volumeWave = volumeWave;
             waveChange = true;
           }
         }
                   
         if (waveChange)
         {
           _isMuted = _isMutedWave;
           _volume = _volumeWave;
         }
         else
         {
           _isMuted = isMutedMaster;
           _volume = volumeMaster;
         }
 
         if (wasMuted != _isMuted || lastVolume != _volume)
         {
           Log.Debug("Mixer: AudioEndpointVolume change, new muted = {0}, new volume = {1}, old muted = {2}, old volume = {3}, waveChange = {4}", _isMuted, _volume, wasMuted, lastVolume, waveChange);
         }
   
         if (ControlChanged != null && (wasMuted != _isMuted || 
                                        lastVolume != _volume || 
                                        (_useWave && OSInfo.OSInfo.Win8OrLater() && (isMutedMaster != _isMuted)) ))
         {
           ControlChanged(null, null);
           if (_useWave && OSInfo.OSInfo.Win8OrLater() && (isMutedMaster != _isMuted))
           {
             SetValue(_mixerControlDetailsMute, isMutedMaster);
           }
         }
         
         if (VolumeHandler.Instance != null) VolumeHandler.Instance.mixer_UpdateVolume();
       }
     }
     catch (Exception ex)
     {
       Log.Error($"Mixer: error occured in AudioEndpointVolume_OnVolumeNotification(): {ex}");
     }
   }