Exemplo n.º 1
0
        public void Stop()
        {
            if (AudioMeter == null)
            {
                Logger.Log("Attempted to Stop an already stopped AudioMeterEvent");
                return;
            }
            AudioMeter      audioMeter;
            KeepaliveTimers keepaliveTimers;

            lock (Mutex)
            {
                audioMeter = AudioMeter;
                AudioMeter = null;

                Logger.Log("Stopped audio meter monitoring");
                if (CurrentKeepaliveTimers != null)
                {
                    EventQueue.EnqueueEvent(() => { StoppedSounding(this, System.EventArgs.Empty); });
                }

                keepaliveTimers        = CurrentKeepaliveTimers;
                CurrentKeepaliveTimers = null;
            }
            audioMeter.Dispose();
            if (keepaliveTimers != null)
            {
                keepaliveTimers.Dispose();
            }
        }
Exemplo n.º 2
0
        void AudioMeter_SoundDetected(object sender, AudioMeter.SoundDetectedEventArgs eventArgs)
        {
            bool initial;
            var  keepaliveTimers = new KeepaliveTimers(KeepaliveInterval, KeepaliveDuration);

            lock (Mutex)
            {
                if (sender != AudioMeter)
                {
                    return;                        // Don't race against Stop()
                }
                initial = CurrentKeepaliveTimers == null;
                if (!initial)
                {
                    keepaliveTimers = CurrentKeepaliveTimers;
                }
                else
                {
                    Logger.Log("Sounding (initial, " + eventArgs.PeakLevel + ")");
                    EventQueue.EnqueueEvent(() => { Sounding(this, System.EventArgs.Empty); });
                    CurrentKeepaliveTimers = keepaliveTimers;
                }
            }

            if (!initial)
            {
                keepaliveTimers.ResetDuration();
                return;
            }
            keepaliveTimers.IntervalElapsed += KeepaliveTimers_IntervalElapsed;
            keepaliveTimers.DurationElapsed += KeepaliveTimers_DurationElapsed;
            keepaliveTimers.Start();
        }
Exemplo n.º 3
0
        void KeepaliveTimers_DurationElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            KeepaliveTimers keepaliveTimers;

            lock (Mutex)
            {
                if (sender != CurrentKeepaliveTimers)
                {
                    return;
                }
                keepaliveTimers        = CurrentKeepaliveTimers;
                CurrentKeepaliveTimers = null;

                Logger.Log("Expiry");
                EventQueue.EnqueueEvent(() => { StoppedSounding(this, System.EventArgs.Empty); });
            }
            keepaliveTimers.Dispose();
        }