Esempio n. 1
0
 private static void UpdateAudioSources()
 {
     foreach (KeyValuePair <int, AudioSessionInformation> audioSession in Program.audioSessions)
     {
         AudioSessionInformation sessionInformation = audioSession.Value;
         float  num1        = Program.globalVolumeTarget / 100f;
         float  num2        = Program.globalAllowance / 100f;
         float  num3        = Program.globalMaxShift / 100f;
         string processName = sessionInformation.processName;
         if (Program.programSettingData.ContainsKey(processName))
         {
             ProgramSettings programSettings = Program.programSettingData[processName];
             num1 = programSettings.target / 100f;
             num2 = programSettings.allowance / 100f;
             num3 = programSettings.shift / 100f;
         }
         if (sessionInformation.audioMeter.BasePtr == IntPtr.Zero)
         {
             Program.audioSessions.Remove(sessionInformation.process);
             sessionInformation.Dispose();
             Program.FormListDirty();
         }
         else
         {
             float  val2_1       = num1 / sessionInformation.audioMeter.GetPeakValue();
             double masterVolume = (double)sessionInformation.volumeObject.MasterVolume;
             double peakValue    = (double)sessionInformation.audioMeter.PeakValue;
             float  num4         = Program.audioLastVol[sessionInformation.process];
             if ((double)sessionInformation.audioMeter.PeakValue >= (double)num1 * (double)sessionInformation.volumeObject.MasterVolume && (double)Math.Abs(val2_1 - num4) > (double)num2)
             {
                 float val2_2 = Math.Min(num4 + num3, Math.Max(num4 - num3, val2_1));
                 Program.audioLastVol[sessionInformation.process] = val2_2;
                 sessionInformation.volumeObject.MasterVolume     = Math.Min(1f, Math.Max(0.0f, val2_2));
             }
         }
     }
 }
Esempio n. 2
0
 private static void FindAudioSources()
 {
     using (AudioSessionManager2 audioSessionManager2 = Program.GetDefaultAudioSessionManager2(DataFlow.Render))
     {
         using (AudioSessionEnumerator sessionEnumerator = audioSessionManager2.GetSessionEnumerator())
         {
             foreach (AudioSessionControl audioSessionControl in sessionEnumerator)
             {
                 AudioSessionControl2 session = audioSessionControl.QueryInterface <AudioSessionControl2>();
                 if (!Program.audioSessions.ContainsKey(session.ProcessID))
                 {
                     AudioSessionInformation sessionInformation1 = new AudioSessionInformation(session);
                     Program.audioSessions.Add(session.ProcessID, sessionInformation1);
                     Program.audioLastVol.Add(session.ProcessID, sessionInformation1.volumeObject.MasterVolume * sessionInformation1.audioMeter.PeakValue);
                     Program.FormListDirty();
                     sessionInformation1.session.Process.Exited += (EventHandler)((sender, e) =>
                     {
                         Process process = sender as Process;
                         Program.audioSessions.TryGetValue(process.Id, out AudioSessionInformation sessionInformation);
                         sessionInformation.Dispose();
                         Program.audioSessions.Remove(process.Id);
                         Program.audioLastVol.Remove(process.Id);
                         Program.FormListDirty();
                     });
                 }
                 else
                 {
                     session.Dispose();
                 }
                 audioSessionControl.Dispose();
             }
             sessionEnumerator.Dispose();
         }
         audioSessionManager2.Dispose();
     }
 }