예제 #1
0
        /// <summary>
        /// 音频数据更新
        /// </summary>
        /// <param name="args"></param>
        private void AudioInput_DataGenerated(DataGeneratedEventArgs args)
        {
            double[][] samples = args.Samples;

            if (samples.Length == 0)
            {
                return;
            }

            //源波
            double[] souceWave = samples[0];

            List <double> sampledData = new List <double>();

            //采样后的信号
            double[] sampledWave = new double[souceWave.Count()];
            int      impact      = (int)(_samplingFrequency / Param.secSamplingFrequency);

            for (int i = 0; i < souceWave.Count(); i++)
            {
                if (i % impact == 0)
                {
                    sampledWave[i] = souceWave[i];
                    sampledData.Add(souceWave[i]);
                }
                else
                {
                    sampledWave[i] = 0.0;
                }
            }



            //为示波器输入数据
            if (m_WaveformMonitor != null)
            {
                double[][] waveData = new double[_seriesNames.Count()][];
                waveData[0] = souceWave;
                waveData[1] = sampledWave;
                m_WaveformMonitor.FeedData(waveData);
            }

            List <double> pcmCode = new List <double>();

            foreach (var item in sampledData)
            {
                int[] codes = PCMCaculator.PCM_Encode(item);
                foreach (var code in codes)
                {
                    pcmCode.Add(code);
                }
            }
            //为示波器输入数据
            if (m_CodeMonitor != null)
            {
                double[][] Data = new double[1][];
                Data[0] = pcmCode.ToArray();
                m_CodeMonitor.FeedData(Data);
            }
        }
예제 #2
0
        /// <summary>
        /// 音频数据更新
        /// </summary>
        /// <param name="args"></param>
        private void AudioInput_DataGenerated(DataGeneratedEventArgs args)
        {
            double[][] samples = args.Samples;

            if (samples.Length == 0)
            {
                return;
            }

            //源波
            double[] souceWave = samples[0];

            //生成载波
            double MaxAmplitude = 10000;

            double[] carryWave = WaveGenerator.Sine(samples[0].Count(),
                                                    (int)MaxAmplitude, _samplingFrequency, Param.moudulateFrequency);

            //生成调制波
            double[] modulatedWava = new double[souceWave.Count()];
            for (int i = 0; i < souceWave.Count(); i++)
            {
                double signal = souceWave[i] * carryWave[i];
                //每个信号除以载波幅度以约束其值范围
                signal          /= MaxAmplitude;
                modulatedWava[i] = signal;
            }

            //为示波器输入数据
            if (m_aWaveformMonitors != null)
            {
                double[][] waveData = new double[_seriesNames.Count()][];
                waveData[0] = souceWave;
                waveData[1] = carryWave;
                waveData[2] = modulatedWava;
                waveData[3] = samples[0];
                m_aWaveformMonitors.FeedData(waveData);
            }

            //Feed multi-channel data to FFT calculator. If it gives a calculated result, set multi-channel result in the selected FFT chart
            if (m_fftCalculator != null)
            {
                double[][][] yValues;
                double[][][] xValues;

                double[][] data = new double[2][];
                data[0] = souceWave;
                data[1] = modulatedWava;
                if (m_fftCalculator.FeedDataAndCalculate(data, out xValues, out yValues))
                {
                    int rowCount = xValues.Length;
                    m_aSpectrograms2D_source.SetData(yValues, 0, rowCount);
                    m_AreaSpectrum_souce.SetData(xValues[0][0], yValues[0][0]);
                    m_aSpectrograms2D_signal.SetData(yValues, 1, rowCount);
                    m_AreaSpectrum_signal.SetData(xValues[0][1], yValues[0][1]);
                }
            }

            //TODO
            //base.DataGenerated(samples[0].Length);
        }