zoukankan      html  css  js  c++  java
  • UWP

      xmal:

    <Grid MinHeight="600">
        <canvas:CanvasAnimatedControl x:Name="drawWaveformCanvas" Draw="DrawWaveformCanvas_Draw" ClearColor="LightGray"/>
    </Grid>
    

      xmal.cs:

    unsafe private void ProcessFrameOutput(AudioFrame frame)
    {
    	using (AudioBuffer buffer = frame.LockBuffer(AudioBufferAccessMode.Write))
    	using (IMemoryBufferReference reference = buffer.CreateReference())
    	{
    		byte* dataInBytes;
    		uint capacityInBytes;
    
    		((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacityInBytes);
    
    		float* dataInFloat = (float*)dataInBytes;
    		int dataInFloatLength = (int)buffer.Length / sizeof(float);
    		for (int i = 0; i < dataInFloatLength; i++)
    		{
    			try
    			{
    				waveformFloatData.Add(dataInFloat[i] * 200.0f + 300);
    			}
    			catch
    			{
    
    			}
    		}
    	}
    }
    
    private void DrawWaveformCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
    {
    	float xAxis = 0.0f;
    	for (int i = 0; i < waveformFloatData.Count; i++)
    	{
    		if (i == 0) continue;
    		Vector2 point1 = new Vector2(xAxis, waveformFloatData[i - 1]);
    		Vector2 point2 = new Vector2(xAxis, waveformFloatData[i]);
    		args.DrawingSession.DrawLine(point1, point2, Colors.Red, 1f);
    		xAxis += 0.3f;
    	}
    	waveformFloatData.Clear();
    }
    

      截图:

  • 相关阅读:
    Vue项目端口号占用
    理解vuex -- vue的状态管理模式
    2018-7-10杂记
    JS 数组操作总结
    JS 字符串操作总结
    【javascript练习题】函数
    【javascript练习题】this指针和作用域
    canal实时同步mysql binlog到rabbitmq
    Hexo+GitHub+Netlify一站式搭建属于自己的博客网站
    Git学习原版手稿
  • 原文地址:https://www.cnblogs.com/darkchii/p/12549703.html
Copyright © 2011-2022 走看看