コード例 #1
0
// catch the peak overload event triggered by VuMeter
        public void CatchPeakOverloadEvent(VuMeter ob_VuMeter, PeakOverload ob_PeakOverload)
        {
            if (ob_PeakOverload.Channel == 1)
            {
                txtOverloadLeft.Text = ob_VuMeter.m_MeanValueLeft.ToString();
            }

            if (ob_PeakOverload.Channel == 2)
            {
                txtOverloadRight.Text = ob_VuMeter.m_MeanValueRight.ToString();
            }

            BeepEnabled = true;
        }
コード例 #2
0
        void AnimationComputation()
        {
            //Thread.Sleep (25) ;
// finds the origin i.e upper left corner of graph display rectangle
            //origin is computed from centre position of graph
            int OriginX = m_GraphPositionX - Convert.ToInt32((m_ScaleFactor * 60));
            int OriginY = m_GraphPositionY - Convert.ToInt32(125 * m_ScaleFactor);

            // create an local array and fill the amplitude value of both channels from function
            int [] AmpArray = new int [2];
            Array.Copy(AmplitudeValue(), AmpArray, 2);

// feed the amplitude in sampple array for computing mean value

            SampleArrayLeft [m_SampleArrayPosition]  = AmpArray [0];
            SampleArrayRight [m_SampleArrayPosition] = AmpArray [1];


            m_SampleArrayPosition++;
            if (m_SampleArrayPosition >= m_SampleCount)
            {
                m_SampleArrayPosition = 0;
            }

            // Find Mean Values of Left and Right Channels
            m_MeanValueLeft = m_MeanValueRight = 0;
            for (int i = 0; i < m_SampleCount; i++)
            {
                m_MeanValueLeft  = m_MeanValueLeft + SampleArrayLeft [i];
                m_MeanValueRight = m_MeanValueRight + SampleArrayRight [i];
            }
            m_MeanValueLeft  = m_MeanValueLeft / m_SampleCount;
            m_MeanValueRight = m_MeanValueRight / m_SampleCount;

// update peak values if it is greater than previous value
            if (m_PeakValueLeft < m_MeanValueLeft)
            {
                arPeakOverloadValue[0] = m_PeakValueLeft = m_MeanValueLeft;
            }

            if (m_PeakValueRight < m_MeanValueRight)
            {
                arPeakOverloadValue[1] = m_PeakValueRight = m_MeanValueRight;
            }


            // Check for Peak Overload  and fire event if overloaded
            if (m_MeanValueLeft > m_UpperThreshold)
            {
                arPeakOverloadFlag [0] = true;

                PeakOverload ob_PeakOverload = new PeakOverload(1, ob_AudioPlayer.GetCurrentBytePosition(), ob_AudioPlayer.GetCurrentTimePosition());

                ob_PeakOverload.PeakOverloadEvent += new DPeakOverloadEvent(ob_VuMeterForm.CatchPeakOverloadEvent);

                ob_PeakOverload.NotifyPeakOverload(this, ob_PeakOverload);
            }
            else
            {
                arPeakOverloadFlag [0] = false;
            }

            if (m_MeanValueRight > m_UpperThreshold)
            {
                m_bOverload            = true;
                arPeakOverloadFlag [1] = true;
                PeakOverload ob_PeakOverload = new PeakOverload(2, ob_AudioPlayer.GetCurrentBytePosition(), ob_AudioPlayer.GetCurrentTimePosition());

                ob_PeakOverload.PeakOverloadEvent += new DPeakOverloadEvent(ob_VuMeterForm.CatchPeakOverloadEvent);

                ob_PeakOverload.NotifyPeakOverload(this, ob_PeakOverload);
            }
            else
            {
                arPeakOverloadFlag [1] = false;
            }

// compute the cordinates of graph and animation
            DisplayGraph();


            int ThresholdFactor = 12500 / (m_UpperThreshold - m_LowerThreshold);
            int DisplayAmpLeft  = (m_MeanValueLeft * ThresholdFactor) / 100;
            int DisplayAmpRight = (m_MeanValueRight * ThresholdFactor) / 100;
            int Offset          = 65 - ((m_LowerThreshold * ThresholdFactor) / 100);

            DisplayAmpLeft  = DisplayAmpLeft + Offset;
            DisplayAmpRight = DisplayAmpRight + Offset;

            Graph.EraserLeft  = OriginY + Convert.ToInt32(m_ScaleFactor * (254 - DisplayAmpLeft));
            Graph.EraserRight = OriginY + Convert.ToInt32(m_ScaleFactor * (254 - DisplayAmpRight));

//Thread.Sleep (25) ;
// Update ccurrent graph cordinates to VuMeter display
            ob_UpdateForms.NotifyUpdateForms(this, ob_UpdateForms);
        }