/// <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); } }
private void HandleDataGenerated(object sender, DataGeneratedEventArgs e) { // Save the internal result. if (!this.c_OnlyComparisonDataCheckBox.Checked) { this.m_Bitmaps.Add(AlgorithmTraceImageGeneration.RenderTraceResult( sender as RuntimeLayer, e.Data, e.GSArrayWidth, e.GSArrayHeight, e.GSArrayDepth)); if (this.IsHandleCreated) { this.Invoke(new Action(() => { this.c_TraceProgress.Value += 1; this.Text = "Trace Algorithm (" + (this.c_TraceProgress.Maximum - this.c_TraceProgress.Value) + " operations remaining)"; })); } } // Save the normal result. int computations; this.m_DisableHandlers(); var data = (sender as RuntimeLayer) .GenerateData(e.GSAbsoluteX - e.GSMaxOffsetX, e.GSAbsoluteY - e.GSMaxOffsetY, e.GSAbsoluteZ - e.GSMaxOffsetZ, e.GSArrayWidth, e.GSArrayHeight, e.GSArrayDepth, out computations); this.m_Bitmaps.Add(AlgorithmTraceImageGeneration.RenderTraceResult( sender as RuntimeLayer, data, e.GSArrayWidth, e.GSArrayHeight, e.GSArrayDepth)); this.m_EnableHandlers(); if (this.IsHandleCreated) { this.Invoke(new Action(() => { this.c_TraceProgress.Value += 1; this.Text = "Trace Algorithm (" + (this.c_TraceProgress.Maximum - this.c_TraceProgress.Value) + " operations remaining)"; })); } }
/// <summary> /// 音频 /// </summary> /// <param name="args"></param> private void AudioInput_DataGenerated(DataGeneratedEventArgs args) { double[][] samples = args.Samples; if (samples.Length == 0) { return; } int channelIndex = 0; if (m_aWaveformMonitors != null) { foreach (WaveformMonitor wm in m_aWaveformMonitors) { wm.FeedData(new double[1][] { samples[channelIndex] }); channelIndex++; } } //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; if (m_fftCalculator.FeedDataAndCalculate(samples, out xValues, out yValues)) { int rowCount = xValues.Length; for (channelIndex = 0; channelIndex < _channelCount; channelIndex++) { if (m_aSpectrograms2D != null) { m_aSpectrograms2D[channelIndex].SetData(yValues, channelIndex, rowCount); } } } } //TODO //base.DataGenerated(samples[0].Length); }
static void HandleDataGenerated(object sender, DataGeneratedEventArgs e) { var name = (string)(sender as RuntimeLayer).Userdata; if (!m_SaveNames.ContainsKey(name)) { m_SaveNames[name] = 0; } m_SaveNames[name] += 1; // Save the internal result. var bitmap = AlgorithmTraceImageGeneration.RenderTraceResult( sender as RuntimeLayer, e.Data, e.GSArrayWidth, e.GSArrayHeight, e.GSArrayDepth); Console.WriteLine(name + ": " + m_SaveNames[name] + " (internal)"); bitmap.Save("layer_" + ++m_Count + ".png"); // Save the normal result. int computations; DisableHandler(); var data = (sender as RuntimeLayer) .GenerateData(e.GSAbsoluteX - e.GSMaxOffsetX, e.GSAbsoluteY - e.GSMaxOffsetY, e.GSAbsoluteZ - e.GSMaxOffsetZ, e.GSArrayWidth, e.GSArrayHeight, e.GSArrayDepth, out computations); var alt = AlgorithmTraceImageGeneration.RenderTraceResult( sender as RuntimeLayer, data, e.GSArrayWidth, e.GSArrayHeight, e.GSArrayDepth); Console.WriteLine(name + ": " + m_SaveNames[name] + " (normal)"); alt.Save("layer_" + ++m_Count + ".png"); EnableHandler(); }
/// <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); }