Unity中实现获取音频的频谱的可视化均衡器
来源:互联网 发布:大富豪3.5源码下载 编辑:程序博客网 时间:2024/06/06 08:34
直接贴代码了,拿来就能用。
参考位置也提供了,需要的人拿走。
分类: Unity3D
类别: 音频处理
------------------------------------------------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
//Reference document
//http://www.41post.com/4776/programming/unity-making-a-simple-audio-visualization
//
[RequireComponent (typeof(AudioSource))]
public class AudioSourceGetSpectrumData : MonoBehaviour {
public FFTWindow fftWindow = FFTWindow.Rectangular;
public int sampleSection = 256;
public float[] spectrum;
public float[] spectrumLogValues;
public float sampleInterval = 0.1f;
public int logLevel = 0;
public int dropSpeed = 1;
public int maxHeight = 50;
private float currentSampleTime = 0;
private float[] currDropSpeeds;
void Update( )
{
if(currentSampleTime < sampleInterval)
{
currentSampleTime += Time.deltaTime;
return;
}
else
currentSampleTime -= sampleInterval;
if(spectrum == null || spectrum.Length !=sampleSection)
spectrum = new float[sampleSection];
if(spectrumLogValues == null || spectrumLogValues.Length !=sampleSection)
spectrumLogValues = new float[sampleSection];
if(currDropSpeeds == null || currDropSpeeds.Length !=sampleSection)
currDropSpeeds = new float[sampleSection];
AudioListener.GetSpectrumData( spectrum, 0, fftWindow);
for( int i = 1; i < spectrum.Length-1; i++ )
{
float currentVal = 0;
if(logLevel == 0)
currentVal = spectrum[i];
if(logLevel < 0)
currentVal = Mathf.Clamp(spectrum[i]*(maxHeight+i*i), 0, maxHeight);
else
currentVal = -Mathf.Log(spectrum[i], logLevel);
if(spectrumLogValues[i] == 0 || currentVal - spectrumLogValues[i] >= Mathf.Abs(currDropSpeeds[i]))
{
currDropSpeeds[i] = 0;
spectrumLogValues[i] = currentVal;
}
else
{
spectrumLogValues[i] = Mathf.Clamp(spectrumLogValues[i]- currDropSpeeds[i], 0, maxHeight);
currDropSpeeds[i] += dropSpeed * Time.deltaTime;
}
}
}
void OnDrawGizmos()
{
for( int i = 1; i < spectrumLogValues.Length-1; i++)
Gizmos.DrawCube(new Vector3(i*1, 0.5f * spectrumLogValues[i], 0), new Vector3(1, spectrumLogValues[i], 1));
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
- Unity中实现获取音频的频谱的可视化均衡器
- [DirectSound] 基于DirectSound的音频均衡器实现
- Unity 音乐可视化(音乐频谱控制物体的运动)
- Unity将麦克风获取的音频实时的处理成可视化的音波
- js获取音频条 频谱的动画数据 每秒频谱数值
- android,音频频谱的绘制
- 简单的AS3 MP3音频频谱
- Unity实时获取麦克风音频,处理成可视化
- 通过html5的Audio API和canvas实现音频可视化
- android获取和展示音乐的频谱
- android获取和展示音乐的频谱
- android获取和展示音乐的频谱
- android获取和展示音乐的频谱
- gcov获取程序频谱信息的步骤
- unity学习日记:音频可视化
- 音频均衡器Equalizer算法研究与实现
- 音频均衡器Equalizer算法研究与实现
- Unity中关于可视化辅助类Gizmos的使用
- Silent Transactions Attacks正确解法
- Linux命令行下使用Axel多线程下载
- iOS 解决警告“ld: warning: directory not found for option”
- python——判断一段音频是否有声音
- smarty1
- Unity中实现获取音频的频谱的可视化均衡器
- Harris 角点
- SQL安装
- 【小知识】解决mysql的卡死问题
- 高精度除法并计算除余数(综合高精减法和加法)
- Linux下 php环境安装、配置composer,使用composer安装laravel、zan等框架
- Java小白的奋斗之旅:文件搜索器
- Mysql 时间格式默认空串 '0000-00-00 00:00:00' select抛出异常的解决方法
- User-Agent-Switcher和fiddler