读取音频文件的谱线
2016-01-13 12:02
302 查看
源码
using UnityEngine; using System.Collections; using System.Collections.Generic; public class LightController : MonoBehaviour { public AudioSource shenYuan; public Renderer light1, light2, light3, light4; public float dumpX=0.3f, dumpY=0.3f, dumpZ=0.3f; // 采样宽度 public int sampWidth = 8; public float scaleAmount = 4; private float[] specTrum; private float startDetal; private List<Vector3> hights=new List<Vector3>(); // Use this for initialization void Start () { } // Update is called once per frame float jiange=0f; void Update () { specTrum = audio.GetSpectrumData(sampWidth, 0, FFTWindow.BlackmanHarris); float totalValue = 0; int i = 0; while (i < sampWidth){ totalValue = totalValue + specTrum[i]; i++; } dumpZ = totalValue*scaleAmount; Debug.Log(dumpZ); startDetal+=Time.deltaTime; if(startDetal>0.1f){ startDetal-=0.1f; jiange+=0.05f; hights.Add(new Vector3(jiange,dumpZ,0f)); } // light1.material.SetFloat ("_DampZ", dumpZ);33we // light1.material.SetFloat ("_DampX", dumpX); //light1.material.SetFloat ("_DampY", dumpY); // light2.material.SetFloat ("_DampZ", dumpZ); // light2.material.SetFloat ("_DampX", dumpX); //light2.material.SetFloat ("_DampY", dumpY); // light3.material.SetFloat ("_DampZ", dumpZ); // light3.material.SetFloat ("_DampX", dumpX); //light3.material.SetFloat ("_DampY", dumpY); // light4.material.SetFloat ("_DampZ", dumpZ); // light4.material.SetFloat ("_DampX", dumpX); //light4.material.SetFloat ("_DampY", dumpY); } private void OnDrawGizmos(){ for(int i=0;i<hights.Count;i++){ Gizmos.DrawLine(hights[i],new Vector3(hights[i].x,-hights[i].y,0f)); } } }
相关文章推荐
- 解决修改计算机名后tfs连接不上的错误
- 修改表触发器对应的序列号 (当增加或修改数据时需要用)
- 《从零开始学Swift》学习笔记(Day 59)——代码排版
- Fragment-学习笔记(一)
- 室内定位技术研发简介
- MySQL不支持中文、将编码修改为utf-8,仍不支持中文问题解决方案
- php表示 当天0点 和 24点的 时间戳
- 在使用Notepad++ WinSCP SFTP遇到的连接失败问题分析
- C#冒泡排序
- dbca静默建库
- ECS Linux下解压rar格式的压缩文件
- python基础入门学习笔记(Python环境搭建)
- spring自定义标签及获取注释里面的值
- VSTO:无法安装此应用程序,因为已安装具有相同标识的应用程序
- UITableView的分割线去除左侧15像素从最左边开始绘制
- table中thead保持不动,tbody滚动(2)
- installshield中杀死某一个进程
- PHP自动加载类
- 走进nginx事件驱动模型
- Android编程之控件状态配置文件实例