Skip to content

Commit

Permalink
spectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
huailiang committed Apr 30, 2020
1 parent bff0c8e commit 7e5a56d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Assets/LipSync/Scripts/AudioVisualization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


/*
* 均衡器可视化
* https://baike.baidu.com/item/均衡器/3136238
* 在线声谱分析
* https://bideyuanli.com/pp
*/
Expand All @@ -15,7 +17,7 @@ public class AudioVisualization
float[] bandBuffer = new float[band_cnt];
float[] bufferDecrease = new float[band_cnt];
float[] freqBandHighest = new float[band_cnt];
public static float[] AudioBandBuffer = new float[band_cnt];
float[] AudioBandBuffer = new float[band_cnt];

Renderer[] renders = new Renderer[band_cnt];
Material[] mat = new Material[band_cnt];
Expand Down Expand Up @@ -95,13 +97,13 @@ void VisulizeBand()
{
for (int i = 0; i < band_cnt; i++)
{
float v = Mathf.Max(0, AudioVisualization.AudioBandBuffer[i]);
float v = Mathf.Max(0, AudioBandBuffer[i]);
float y = v * 8 + 0.1f;
if (!float.IsNaN(y))
{
Vector3 scale = renders[i].transform.localScale;
renders[i].transform.localScale = new Vector3(scale.x, y, scale.z);
Color color = new Color(v, v, v);
Color color = new Color(0, 0, v);
mat[i].SetColor("_EmissionColor", color);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/LipSync/Scripts/Core/MathToolBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public static void FindLocalLargestPeaks(float[] data, float[] peakValue, int[]
}
else
{
if (isIncreasing)
if (isIncreasing)
{
if (lastPeak < data[i]) // Peak found. 找到峰值
if (lastPeak < data[i]) // Peak found. 找到峰值, 一般fft窗口有两三个峰值
{
isPeakIncreasing = true;
}
Expand Down

0 comments on commit 7e5a56d

Please sign in to comment.