Skip to content

Commit

Permalink
add smoothness preference of mfcc texture on timeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Jul 31, 2024
1 parent 68807ff commit e1e22b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Assets/uLipSync/Editor/Preference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ internal class EditorPrefsStr
{
public const string DisplayWaveformOnTimeline = "uLipSync-Timeline-DisplayWaveform";
public const string MaxWidthOfWaveformTextureOnTimeline = "uLipSync-Timeline-MaxWidthOfWaveformTexture";
public const string TextureSmoothOnTimeline = "uLipSync-Timeline-TextureSmooth";
}

internal class EditorPrefsDefault
{
public const int MinWidthOfWaveformTextureOnTimeline = 32;
public const int MaxWidthOfWaveformTextureOnTimeline = 2048;
public const float TextureSmoothOnTimeline = 0.85f;
}

public static class Preference
Expand All @@ -31,6 +33,12 @@ public static int maxWidthOfWaveformTextureOnTimeline
get => EditorPrefs.GetInt(EditorPrefsStr.MaxWidthOfWaveformTextureOnTimeline, EditorPrefsDefault.MaxWidthOfWaveformTextureOnTimeline);
set => EditorPrefs.SetInt(EditorPrefsStr.MaxWidthOfWaveformTextureOnTimeline, value);
}

public static float textureSmoothOnTimeline
{
get => EditorPrefs.GetFloat(EditorPrefsStr.TextureSmoothOnTimeline, EditorPrefsDefault.TextureSmoothOnTimeline);
set => EditorPrefs.SetFloat(EditorPrefsStr.TextureSmoothOnTimeline, value);
}
}

public class PreferenceProvider : SettingsProvider
Expand Down Expand Up @@ -72,6 +80,15 @@ public override void OnGUI(string searchContext)
}
}

{
float current = Preference.textureSmoothOnTimeline;
float result = EditorGUILayout.FloatField("Texture Smoothness On Timeline", current);
if (Math.Abs(current - result) > 0f)
{
Preference.textureSmoothOnTimeline = Math.Clamp(result, 0f, 1f);
}
}

--EditorGUI.indentLevel;

EditorGUIUtility.labelWidth = defaultLabelWidth;
Expand Down
3 changes: 2 additions & 1 deletion Assets/uLipSync/Editor/Timeline/uLipSyncClipEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ Texture2D CreateCachedTexture(uLipSyncClip clip, int width, int height)
width,
Preference.minWidthOfWaveformTextureOnTimeline,
Preference.maxWidthOfWaveformTextureOnTimeline);
var tex = TextureCreator.CreateBakedDataWaveTexture(data, width, height);
var smooth = Preference.textureSmoothOnTimeline;
var tex = TextureCreator.CreateBakedDataWaveTexture(data, width, height, smooth);
var cache = new TextureCache { texture = tex };
_textures.Add(clip, cache);

Expand Down
7 changes: 4 additions & 3 deletions Assets/uLipSync/Runtime/Core/TextureCreator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using Unity.Burst;
using Unity.Collections;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void Execute()
targetColor += phonemeColors[colorIndex] * phonemeRatios[ratioIndex];
}

currentColor += (targetColor - currentColor) * smooth;
currentColor += (targetColor - currentColor) * (1f - smooth);

for (int y = 0; y < height; ++y)
{
Expand All @@ -71,7 +72,7 @@ public void Execute()
}
}

public static Texture2D CreateBakedDataWaveTexture(BakedData data, int width, int height)
public static Texture2D CreateBakedDataWaveTexture(BakedData data, int width, int height, float smooth = 0.85f)
{
var tex = new Texture2D(width, height);

Expand Down Expand Up @@ -104,7 +105,7 @@ public static Texture2D CreateBakedDataWaveTexture(BakedData data, int width, in
width = width,
height = height,
phonemeCount = phonemeCount,
smooth = 0.15f,
smooth = Mathf.Clamp(smooth, 0f, 1f),
};
job.Schedule().Complete();

Expand Down

0 comments on commit e1e22b2

Please sign in to comment.