Skip to content

Commit

Permalink
lipsync
Browse files Browse the repository at this point in the history
  • Loading branch information
huailiang committed Apr 29, 2020
1 parent 449018c commit bff0c8e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
Binary file modified Assets/LipSync/Demo/Scenes/AudioScene.unity
Binary file not shown.
Binary file modified Assets/LipSync/Demo/Scenes/FmodScene.unity
Binary file not shown.
15 changes: 6 additions & 9 deletions Assets/LipSync/Scripts/Core/MathToolBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static float[] DiscreteCosineTransform(float[] data)
{
sumCos += data[k] * Mathf.Cos((Mathf.PI / data.Length) * m * (k + 0.5f));
}

result[m] = (sumCos > 0) ? sumCos : -sumCos;
}

Expand Down Expand Up @@ -122,13 +121,11 @@ public static void FindLocalLargestPeaks(float[] data, float[] peakValue, int[]

isIncreasing = false;
}

if (peakNum >= peakValue.Length)
{
break;
}
}
Debug.Log("len: " + peakValue.Length);
}

/// <summary>
Expand All @@ -142,7 +139,7 @@ public static float[] GenerateGaussianFilter(int size, float deviationSquare)
float[] result = new float[size];

float sum = 0.0f;
float mu = (float) (size - 1) / 2;
float mu = (float)(size - 1) / 2;
for (int i = 0; i < size; ++i)
{
float param = -((i - mu) * (i - mu)) / (2 * deviationSquare);
Expand Down Expand Up @@ -179,16 +176,16 @@ public static float[] GenerateWindow(int size, EWindowType windowType)
break;
case EWindowType.Hanning:
for (int i = 0; i < size; ++i)
result[i] = (float) (0.5f * (1.0 - Mathf.Cos((2 * Mathf.PI * i) / size)));
result[i] = (float)(0.5f * (1.0 - Mathf.Cos((2 * Mathf.PI * i) / size)));
break;
case EWindowType.BlackMan:
for (int i = 0; i < size; ++i)
result[i] = (float) (0.42f - 0.5 * Mathf.Cos((2 * Mathf.PI * i) / size)) +
(float) (0.08 * Mathf.Cos(4 * Mathf.PI * i) / size);
result[i] = (float)(0.42f - 0.5 * Mathf.Cos((2 * Mathf.PI * i) / size)) +
(float)(0.08 * Mathf.Cos(4 * Mathf.PI * i) / size);
break;
case EWindowType.BlackmanHarris:
for (int i = 0; i < size; ++i)
result[i] = (float) ((0.35875 - 0.48829 * Mathf.Cos((2 * Mathf.PI * i) / size)) +
result[i] = (float)((0.35875 - 0.48829 * Mathf.Cos((2 * Mathf.PI * i) / size)) +
(0.14128 * Mathf.Cos(4 * Mathf.PI * i) / size) -
(0.01168 * Mathf.Cos(6 * Mathf.PI * i / size)));
break;
Expand Down Expand Up @@ -229,4 +226,4 @@ public static float GetValueFromArray(float[] data, int index, EPaddleType paddl
}
}
}
}
}
2 changes: 1 addition & 1 deletion Assets/LipSync/Scripts/LipSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void UpdateForward()
}
}
visualization.Update(runtimeRecognizer.playingAudioSpectrum);
if (recognizeText) recognizeText.text = recognizeResult;
if (recognizeText) recognizeText.text = "RecognizeResult: " + recognizeResult;
}
}

Expand Down

0 comments on commit bff0c8e

Please sign in to comment.