private IEnumerator SolverCoroutine() { while (gameObject.activeInHierarchy) { if (SoundSource == null) yield return new WaitForSeconds(1 / SolverFrequency); float total = 0; sample = new float[SampleSize]; SoundSource.GetSpectrumData(sample, 0, FFTWindow.BlackmanHarris); for (int i = 0; i < SampleSize; i++) { total += sample[i]; } vol = total / SampleSize; vol *= AudioSensitivity; if (lastEmotion != CurrentEmotion) { if (emotionCoroutine != null) { StopCoroutine(emotionCoroutine); emotionCoroutine = null; } emotionCoroutine = StartCoroutine(BlendEmotionsCoroutine(currentEmotionOnly, GetPoseFor(CurrentEmotion))); Debug.Log("Starting a new blending from " + lastEmotion + " to " + CurrentEmotion); lastEmotion = CurrentEmotion; } AnalyseAudio(); yield return new WaitForSeconds(1 / SolverFrequency); lastType = currentType; } }
private void AnalyseAudio() { if (vol < WhisperingThreshold) { // Silence currentType = AudioFaceType.SILENCE; if (lastType != currentType) { if (CurrentPose != SilencePose && TargetLipSyncPose != SilencePose) { if (blendCoroutine != null) { StopCoroutine(blendCoroutine); } blendCoroutine = StartCoroutine(BlendLipSyncCoroutine(currentLipsyncOnly, SilencePose)); } } } else if (vol < MurmuringThreshold) { // Whispering currentType = AudioFaceType.WHISPERING; if (lastType != currentType) { if (CurrentPose != WhisperingPose && TargetLipSyncPose != WhisperingPose) { if (blendCoroutine != null) { StopCoroutine(blendCoroutine); } blendCoroutine = StartCoroutine(BlendLipSyncCoroutine(currentLipsyncOnly, WhisperingPose)); } } } else if (vol < NormalThreshold) { // Murmuring currentType = AudioFaceType.MURMURING; if (lastType != currentType) { if (CurrentPose != MurmuringPose && TargetLipSyncPose != MurmuringPose) { if (blendCoroutine != null) { StopCoroutine(blendCoroutine); } blendCoroutine = StartCoroutine(BlendLipSyncCoroutine(currentLipsyncOnly, MurmuringPose)); } } } else if (vol < ShoutingThreshold) { // Normal currentType = AudioFaceType.NORMAL; if (lastType != currentType) { if (CurrentPose != NormalPose && TargetLipSyncPose != NormalPose) { if (blendCoroutine != null) { StopCoroutine(blendCoroutine); } blendCoroutine = StartCoroutine(BlendLipSyncCoroutine(currentLipsyncOnly, NormalPose)); } } } else { // Shouting currentType = AudioFaceType.SHOUTING; if (lastType != currentType) { if (CurrentPose != NormalPose && TargetLipSyncPose != NormalPose) { if (blendCoroutine != null) { StopCoroutine(blendCoroutine); } blendCoroutine = StartCoroutine(BlendLipSyncCoroutine(currentLipsyncOnly, ShoutingPose)); } } } }
private void DrawLipSyncPoseSettings() { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.indentLevel++; foldOutLipSync = EditorGUILayout.Foldout(foldOutLipSync, new GUIContent("LipSync settings")); EditorGUI.indentLevel++; if (foldOutLipSync) { bool notNone = false; // SILENCE if (EditorGUILayout.Foldout(currentLipSyncDisplay == AudioFaceType.SILENCE, new GUIContent("Silence pose", "The facial pose to give to your character whenever they don't talk."))) { EditorGUI.indentLevel++; poseDisplayer.Draw(lipSync.SilencePose, lipSync); currentLipSyncDisplay = AudioFaceType.SILENCE; notNone = true; EditorGUI.indentLevel--; } // WHISPERING EditorGUILayout.BeginHorizontal(); lipSync.WhisperingThreshold = EditorGUILayout.Slider(new GUIContent("Whispering threshold"), lipSync.WhisperingThreshold, 0, 0.1f); if (GUILayout.Button(new GUIContent("=", "Reset"), GUILayout.Width(20))) { Undo.RecordObject(lipSync, "Reset _wsptshld"); lipSync.WhisperingThreshold = 1 / 500f; } EditorGUILayout.EndHorizontal(); if (EditorGUILayout.Foldout(currentLipSyncDisplay == AudioFaceType.WHISPERING, new GUIContent("Whispering pose", "The facial pose to give to your character whenever they are whispering."))) { EditorGUI.indentLevel++; poseDisplayer.Draw(lipSync.WhisperingPose, lipSync); currentLipSyncDisplay = AudioFaceType.WHISPERING; notNone = true; EditorGUI.indentLevel--; } // MURMURING EditorGUILayout.BeginHorizontal(); lipSync.MurmuringThreshold = EditorGUILayout.Slider(new GUIContent("Murmuring threshold"), lipSync.MurmuringThreshold, 0, 0.3f); if (GUILayout.Button(new GUIContent("=", "Reset"), GUILayout.Width(20))) { Undo.RecordObject(lipSync, "Reset _mrmthsld"); lipSync.MurmuringThreshold = 1 / 400f; } EditorGUILayout.EndHorizontal(); if (EditorGUILayout.Foldout(currentLipSyncDisplay == AudioFaceType.MURMURING, new GUIContent("Murmuring pose", "The facial pose to give to your character whenever they are murmuring (louder than whispering)."))) { EditorGUI.indentLevel++; poseDisplayer.Draw(lipSync.MurmuringPose, lipSync); currentLipSyncDisplay = AudioFaceType.MURMURING; notNone = true; EditorGUI.indentLevel--; } // NORMAL EditorGUILayout.BeginHorizontal(); lipSync.NormalThreshold = EditorGUILayout.Slider(new GUIContent("Normal threshold"), lipSync.NormalThreshold, 0, 0.8f); if (GUILayout.Button(new GUIContent("=", "Reset"), GUILayout.Width(20))) { Undo.RecordObject(lipSync, "Reset _nrmthsld"); lipSync.NormalThreshold = 0.004f; } EditorGUILayout.EndHorizontal(); if (EditorGUILayout.Foldout(currentLipSyncDisplay == AudioFaceType.NORMAL, new GUIContent("Normal pose", "The facial pose to give to your character whenever they he talks at a normal level."))) { EditorGUI.indentLevel++; poseDisplayer.Draw(lipSync.NormalPose, lipSync); currentLipSyncDisplay = AudioFaceType.NORMAL; notNone = true; EditorGUI.indentLevel--; } // SHOUTING EditorGUILayout.BeginHorizontal(); lipSync.ShoutingThreshold = EditorGUILayout.Slider(new GUIContent("Shouting threshold"), lipSync.ShoutingThreshold, 0, 1f); if (GUILayout.Button(new GUIContent("=", "Reset"), GUILayout.Width(20))) { Undo.RecordObject(lipSync, "Reset _shtthsld"); lipSync.ShoutingThreshold = 3 / 500f; } EditorGUILayout.EndHorizontal(); if (EditorGUILayout.Foldout(currentLipSyncDisplay == AudioFaceType.SHOUTING, new GUIContent("Shouting pose", "The facial pose to give to your character whenever they are bending your ears!"))) { EditorGUI.indentLevel++; poseDisplayer.Draw(lipSync.ShoutingPose, lipSync); currentLipSyncDisplay = AudioFaceType.SHOUTING; notNone = true; EditorGUI.indentLevel--; } if (!notNone) { currentLipSyncDisplay = AudioFaceType.NONE; ClearModel(); } } EditorGUI.indentLevel -= 2; EditorGUILayout.EndVertical(); }