Exemplo n.º 1
0
        private void OnAmplitudeChanged()
        {
            numAmplitude.Value = _amplitude;
            if (_form != null)
            {
                _form.Amplitude = _amplitude;
            }

            if (!_fireEvent)
            {
                return;
            }

            if (AmplitudeChanged != null)
            {
                AmplitudeChanged.Invoke(this, null);
            }
        }
Exemplo n.º 2
0
        private void DataArrived(object sender, WaveInEventArgs e)
        {
            double sum = 0;

            double[] _waveLeft = new double[e.Buffer.Length / 4];

            // Split out channels from sample
            for (int i = 0; i < e.Buffer.Length; i += 4)
            {
                double sample = (double)BitConverter.ToInt16(e.Buffer, i) / 32768.0;
                sum += (sample * sample);
            }

            double rms = Math.Sqrt(sum / (_waveLeft.Length / 2));
            double res = 20 * Math.Log10(rms);

            AmplitudeChanged?.Invoke(null, new AmplitudeChangedEventArgs(res));
            InvokeEventsIfReq(res);
        }