예제 #1
0
        public VuMeter(AudioPlayer player, AudioRecorder recorder)
        {
            m_Player   = player;
            m_Recorder = recorder;
            m_EnableAudioLevelAlerts = false;

            m_Player.PcmDataBufferAvailable   += new AudioPlayer.PcmDataBufferAvailableHandler(OnPcmDataBufferAvailable_Player);
            m_Recorder.PcmDataBufferAvailable += new AudioRecorder.PcmDataBufferAvailableHandler(OnPcmDataBufferAvailable_Recorder);
            m_Player.StateChanged             += new AudioPlayer.StateChangedHandler(StateChanged);
            m_Recorder.StateChanged           += new AudioRecorder.StateChangedHandler(StateChanged);
        }
예제 #2
0
        public void OnPcmDataBufferAvailable_Recorder(object sender, AudioRecorder.PcmDataBufferAvailableEventArgs e)
        {
            AudioRecorder ob_AudioRecorder = sender as AudioRecorder;

            if (ob_AudioRecorder == null || ob_AudioRecorder != m_Recorder)
            {
                Debug.Fail("This should never happen !!!?");
                return;
            }
#if CLONE_PCM_BUFFER
            if (m_PcmDataBuffer == null || m_PcmDataBuffer.Length != e.PcmDataBuffer.Length)
            {
                Console.WriteLine("*** creating m_Recorder buffer");
                m_PcmDataBuffer = new byte[e.PcmDataBuffer.Length];
            }
            Array.Copy(e.PcmDataBuffer, m_PcmDataBuffer, e.PcmDataBuffer.Length);
#else
            m_PcmDataBuffer       = e.PcmDataBuffer;
            m_PcmDataBufferLength = e.PcmDataBufferLength;
#endif
            m_computingPeakDb = true;
            double[] peakDb = computePeakDb(m_Recorder.RecordingPCMFormat);
            m_computingPeakDb = false;

            PeakMeterUpdateHandler del = PeakMeterUpdated;

            if ((m_Recorder.CurrentState == AudioRecorder.State.Monitoring || m_Recorder.CurrentState == AudioRecorder.State.Recording) &&
                del != null)
            {
                m_PeakMeterUpdateEventArgs.PeakDb = peakDb;

                del(this, m_PeakMeterUpdateEventArgs);
            }
            //var del_ = PeakMeterUpdated;
            //if (del_ != null)
            //{
            //m_PeakMeterUpdateEventArgs.PeakDb = peakDb;
            //del_(this, m_PeakMeterUpdateEventArgs);
            //}

            int index = 0;
            for (int i = 0; i < peakDb.Length; i++)
            {
                double peak = peakDb[i];
                index++;
                if (peak < 0)
                {
                    continue;
                }

                PeakOverloadHandler delOverload = PeakMeterOverloaded;
                if ((m_Recorder.CurrentState == AudioRecorder.State.Monitoring || m_Recorder.CurrentState == AudioRecorder.State.Recording) &&
                    delOverload != null)
                {
                    m_PeakOverloadEventArgs.Channel = index;

                    delOverload(this, m_PeakOverloadEventArgs);
                }
                //var del = PeakMeterOverloaded;
                //if (del != null)
                //{
                //m_PeakOverloadEventArgs.Channel = index;
                //m_PeakOverloadEventArgs.Time = m_Recorder.CurrentDurationInLocalUnits;
                //del(this, m_PeakOverloadEventArgs);
                //}
            }
        }