Skip to content

Commit

Permalink
code-optimus
Browse files Browse the repository at this point in the history
  • Loading branch information
huailiang committed May 1, 2020
1 parent 7e5a56d commit 8dc392e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Assets/FMODBuild*
Assets/Plugins*
Assets/StreamingAssets*
fmod_editor.log
**/cn*

# Autogenerated VS/MD solution and project files
*.unityproj
Expand Down
2 changes: 1 addition & 1 deletion Assets/LipSync/Editor/LipSyncOfflineRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public string[] RecognizeAllByAudioClip(AudioClip audioClip)
{
MathToolBox.Convolute(currentAudioSpectrum, gaussianFilter, MathToolBox.EPaddleType.Repeat, smoothedAudioSpectrum);
MathToolBox.FindLocalLargestPeaks(smoothedAudioSpectrum, peakValues, peakPositions);
frequencyUnit = audioClip.frequency / 2 / windowSize;
frequencyUnit = audioClip.frequency / windowSize;
for (int l = 0; l < formantArray.Length; ++l)
{
formantArray[l] = peakPositions[l] * frequencyUnit;
Expand Down
4 changes: 2 additions & 2 deletions Assets/LipSync/Scripts/Core/LipSyncRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class LipSyncRecognizer
protected const int FORMANT_COUNT = 1;

protected string[] vowelsByFormantJP = { "i", "u", "e", "o", "a" };
protected float[] vowelFormantFloorJP = { 0.0f, 250.0f, 300.0f, 450.0f, 600.0f };
protected float[] vowelFormantFloorJP = { 0.0f, 500.0f, 600.0f, 900.0f, 1200.0f };
protected string[] vowelsByFormantCN = { "i", "v", "u", "e", "o", "a" };
protected float[] vowelFormantFloorCN = { 0.0f, 100.0f, 250.0f, 300.0f, 450.0f, 600.0f };
protected float[] vowelFormantFloorCN = { 0.0f, 200.0f, 500.0f, 600.0f, 900.0f, 1200.0f };

protected string[] currentVowels;
protected float[] currentVowelFormantCeilValues;
Expand Down
2 changes: 1 addition & 1 deletion Assets/LipSync/Scripts/Core/LipSyncRuntimeRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void Recognize(ref string result, int sampleRate)
{
MathToolBox.Convolute(playingAudioSpectrum, gaussianFilter, MathToolBox.EPaddleType.Repeat, smoothedAudioSpectrum);
MathToolBox.FindLocalLargestPeaks(smoothedAudioSpectrum, peakValues, peakPositions);
frequencyUnit = sampleRate / 2 / windowSize;
frequencyUnit = sampleRate / windowSize;
for (int i = 0; i < formantArray.Length; ++i)
{
formantArray[i] = peakPositions[i] * frequencyUnit;
Expand Down
8 changes: 6 additions & 2 deletions Assets/LipSync/Scripts/Core/MathToolBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ public static void Convolute(float[] data, float[] filter, EPaddleType paddleTyp
/// <param name="data">Source data.</param>
/// <param name="peakValue">Array to store peak values.</param>
/// <param name="peakPosition">Array to store peak values' positions.</param>
public static void FindLocalLargestPeaks(float[] data, float[] peakValue, int[] peakPosition)
public static void FindLocalLargestPeaks(float[] data, float[] peakValue, int[] peakPosition)
{
int peakNum = 0;
float lastPeak = 0.0f;
int lastPeakPosition = 0;
bool isIncreasing = false;
bool isPeakIncreasing = false;

string str = "";
for (int i = 0; i < data.Length - 1; ++i)
{
if (data[i] < data[i + 1])
Expand All @@ -96,8 +97,9 @@ public static void FindLocalLargestPeaks(float[] data, float[] peakValue, int[]
}
else
{
if (isIncreasing)
if (isIncreasing)
{
str += (i * 86) + "-";
if (lastPeak < data[i]) // Peak found. 找到峰值, 一般fft窗口有两三个峰值
{
isPeakIncreasing = true;
Expand All @@ -121,11 +123,13 @@ public static void FindLocalLargestPeaks(float[] data, float[] peakValue, int[]

isIncreasing = false;
}

if (peakNum >= peakValue.Length)
{
break;
}
}
Debug.Log(str + " " + peakNum + " " + peakPosition[0] * 86);
}

/// <summary>
Expand Down

0 comments on commit 8dc392e

Please sign in to comment.