Skip to content

Commit

Permalink
lipsync lpc
Browse files Browse the repository at this point in the history
  • Loading branch information
huailiang committed May 24, 2020
1 parent 2ff5ca2 commit 2cbf79c
Show file tree
Hide file tree
Showing 17 changed files with 431 additions and 73 deletions.
46 changes: 32 additions & 14 deletions Assets/LipSync/Editor/LpcEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void LpcShow()

private void OnEnable()
{
if(model==null)
if (model == null)
{
model = new LpcModel();
}
Expand All @@ -34,27 +34,37 @@ private void OnGUI()
GUILayout.BeginVertical();

GUILayout.Space(10);
audioClip = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", audioClip, typeof(AudioClip), false);
audioClip = (AudioClip) EditorGUILayout.ObjectField("Audio Clip", audioClip, typeof(AudioClip), false);

if (GUILayout.Button("Analy"))
{
Normalize();
var split = MakeFrame();
Formant(split);
}
GUILayout.BeginHorizontal();
if (GUILayout.Button("root"))
{
float[] poly = new float[] { -8, 12, -6, 1};
float[] poly = new float[] {-8, 12, -6, 1};
var ret = model.FindRoots(poly);
foreach (var it in ret)
{
Debug.Log(it);
}
}
if (GUILayout.Button("c-root"))
{
double[] poly = new Double[] {-8, 12, -6, 1};
var roots = model.FindCRoots(poly);
for (int i = 0; i < roots.Length; i++)
{
Debug.Log("i: " + roots[i]);
}
}
if (GUILayout.Button("correlate"))
{
var a = new float[] { 3, 1, 2, 4, 3, 5, 6, 5, 6, 2 };
var v = new float[] { 3, 1, 4, 2 };
var a = new float[] {3, 1, 2, 4, 3, 5, 6, 5, 6, 2};
var v = new float[] {3, 1, 4, 2};
var t = model.Correlate(a, v);
string str = "";
for (int i = 0; i < t.Length; i++)
Expand All @@ -65,21 +75,23 @@ private void OnGUI()
}
if (GUILayout.Button("toeplitz"))
{
float[] c = new float[] { 3, 4, 2, -6, 7, 3, 1, -3 };
ToeplitzMtrix toeplitzMtrix;
toeplitzMtrix = new ToeplitzMtrix(c);
float[] c = new float[]
{
3, 4, 2, -2.6f, 1.7f, 4.3f, 121, 321, 1.3f, 1, -3, 3, 4, 11, 9, -4, 7, 12, 0.3f, -7.0f
};
ToeplitzMtrix toeplitzMtrix = new ToeplitzMtrix(c);
Debug.Log(toeplitzMtrix);
var t = toeplitzMtrix.Inverse();
int n = (int)Math.Sqrt((double)t.Length);
int n = (int) Math.Sqrt((double) t.Length);
string msg = "size: " + n;
for (int i = 0; i < n; i++)
{
msg += "\n";
for (int j = 0; j < n; j++)
msg += t[i, j].ToString("f3") + "\t";
for (int j = 0; j < n; j++) msg += t[i, j].ToString("f3") + "\t";
}
Debug.Log(msg);
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
if (!string.IsNullOrEmpty(info))
{
Expand Down Expand Up @@ -144,6 +156,7 @@ private void Formant(List<float[]> splitting)
int i = 0;
float a = 0.67f;
info = String.Empty;
List<double[]> ret = new List<double[]>();
while (i < splitting.Count())
{
float[] FL = PreEmphasis(splitting[i], a);
Expand All @@ -152,9 +165,14 @@ private void Formant(List<float[]> splitting)
{
FL[i] = FL[i] * w[i];
}
var coefficients = model.EstimateLpcCoefficients(FL, 2 + fs / 1000);
var formants = model.FindFormants(coefficients, fs);
AppendInfo(i, formants);
var coefficients = model.Estimate(FL, 2 + fs / 1000);
var rts = model.FindCRoots(coefficients);
rts = rts.Where(x => x.imag >= 0).ToArray();
var frqs = rts.Select(x => x.arg * (fs / (2 * Mathf.PI))).ToList();
frqs.Sort();
double[] fmts = {frqs[1], frqs[2], frqs[3]};
Debug.Log(frqs[1] + " " + frqs[2] + " " + frqs[3]);
ret.Add(fmts);
i++;
}
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/LipSync/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Assets/LipSync/Plugins/ZSolver.bundle.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/LipSync/Plugins/ZSolver.bundle/Contents.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Assets/LipSync/Plugins/ZSolver.bundle/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>18G3020</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>ZSolver</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string></string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string></string>
<key>CSResourcesFileMapped</key>
<true/>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>11C504</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>19B90</string>
<key>DTSDKName</key>
<string>macosx10.15</string>
<key>DTXcode</key>
<string>1131</string>
<key>DTXcodeBuild</key>
<string>11C504</string>
<key>LSMinimumSystemVersion</key>
<string>10.14</string>
<key>NSHumanReadableCopyright</key>
<string></string>
</dict>
</plist>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/LipSync/Plugins/ZSolver.bundle/Contents/MacOS.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict/>
<key>files2</key>
<dict/>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2cbf79c

Please sign in to comment.