private void PlayNode(InAudioNode current, DSPTime endTime, float offset, InAudioData audioData) { float nodeVolume; double playTime = endTime.CurrentEndTime; if (endTime.Player != null && endTime.Player.clip != null) { int samples = endTime.Player.timeSamples; if (samples > 0 && samples < endTime.Player.clip.samples) { //Debug.Log("nonnull " + Time.time); double timeLeft = endTime.Player.clip.ExactLength() - samples / (double)endTime.Player.clip.frequency; double dspTime = AudioSettings.dspTime; playTime = dspTime + timeLeft; } } float length = PlayScheduled(ParentFolder, current, audioData, playTime, offset, out nodeVolume); Current.OriginalVolume = nodeVolume; endTime.CurrentEndTime += length; endTime.Player = Current.AudioSource; }
private float PlayScheduled(InAudioNode startNode, InAudioNode currentNode, InAudioData audioData, double playAtDSPTime, float offset, out float nodeVolume) { float length = 0; nodeVolume = 1; if (audioData._clip != null) { var clip = audioData._clip; length = clip.ExactLength(); length -= offset; float lengthOffset = offset * clip.frequency; var source = Current.AudioSource; source.clip = clip; nodeVolume = RuntimeHelper.CalcVolume(startNode, currentNode); Current.OriginalVolume = nodeVolume; SetVolume(Current, audioParameters.Volume); source.spatialBlend = RuntimeHelper.CalcBlend(startNode, currentNode); source.pitch = RuntimeHelper.CalcPitch(startNode, currentNode) * audioParameters.Pitch; source.rolloffMode = RuntimeHelper.CalcAttentutation(startNode, currentNode, source); if (audioParameters.SetMixer) { source.outputAudioMixerGroup = audioParameters.AudioMixer; } else { source.outputAudioMixerGroup = currentNode.GetMixerGroup(); } length = RuntimeHelper.LengthFromPitch(length, source.pitch); Current.EndTime = playAtDSPTime + length; Current.StartTime = playAtDSPTime; Current.UsedNode = currentNode; source.panStereo += audioParameters.StereoPan; source.spread = _spread; source.spatialBlend *= audioParameters.SpatialBlend; source.timeSamples = (int)(lengthOffset); source.PlayScheduled(playAtDSPTime); // SK: Koreographer integration var visor = Current.GetComponent <SonicBloom.Koreo.Players.AudioSourceVisor>(); if (!visor) { visor = Current.gameObject.AddComponent <SonicBloom.Koreo.Players.AudioSourceVisor>(); } visor.ScheduledPlayTime = playAtDSPTime; visor.ResyncTimings(0); } else { Debug.LogWarning("InAudio: Audio clip missing on audio node \"" + currentNode.Name + "\", id=" + currentNode._ID); } return(length); }
public static void Draw(InAudioNode node) { node.ScrollPosition = GUILayout.BeginScrollView(node.ScrollPosition); InUndoHelper.GUIUndo(node, "Name Change", ref node.Name, () => EditorGUILayout.TextField("Name", node.Name)); Rect area = GUILayoutUtility.GetLastRect(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); InAudioData audioData = node._nodeData as InAudioData; EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); var clip = (AudioClip)EditorGUILayout.ObjectField(audioData.AudioClip, typeof(AudioClip), false); Rect buttonArea = area; if (Application.isPlaying) { buttonArea.x += buttonArea.width - 100; buttonArea.width = 70; GUI.enabled = false; EditorGUI.LabelField(buttonArea, "Is Loaded"); buttonArea.x += 70; buttonArea.width = 10; EditorGUI.Toggle(buttonArea, audioData.IsLoaded); GUI.enabled = true; } AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>(); AudioPreview(node, source, audioData); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); if (clip != audioData.AudioClip) //Assign new clip { InUndoHelper.RecordObjectFull(audioData, "Changed " + node.Name + " Clip"); audioData.AudioClip = clip; EditorUtility.SetDirty(node._nodeData.gameObject); } EditorGUILayout.EndHorizontal(); if (clip != null) { DrawImportSettings(clip); } NodeTypeDataDrawer.Draw(node); GUILayout.EndScrollView(); }
private float PlayScheduled(InAudioNode startNode, InAudioNode currentNode, InAudioData audioData, double playAtDSPTime, float offset, out float nodeVolume) { float length = 0; nodeVolume = 1; if (audioData.Clip != null) { var clip = audioData.Clip; length = clip.ExactLength(); length -= offset; float lengthOffset = offset * clip.frequency; var source = Current.AudioSource; source.clip = clip; nodeVolume = RuntimeHelper.ApplyVolume(startNode, currentNode); SetVolume(Current, attachedToBus.FinalVolume); source.pitch = RuntimeHelper.ApplyPitch(startNode, currentNode); RuntimeHelper.ApplyAttentuation(startNode, currentNode, source); length = RuntimeHelper.LengthFromPitch(length, source.pitch); Current.EndTime = playAtDSPTime + length; Current.StartTime = playAtDSPTime; Current.UsedNode = currentNode; source.pan = pan2D; source.spread = spread; source.panLevel = pan; source.timeSamples = (int)(lengthOffset); source.PlayScheduled(playAtDSPTime); } return(length); }
private void PlayNode(InAudioNode current, DSPTime endTime, float offset, InAudioData audioData) { float nodeVolume; double playTime = endTime.CurrentEndTime; double timeLeft = 0; if (endTime.Player != null && endTime.Player.clip != null) { int samples = endTime.Player.timeSamples; if (samples > 0 && samples < endTime.Player.clip.samples) { timeLeft = TimeLeftOfClip(endTime, samples) / endTime.Player.pitch; double dspTime = AudioSettings.dspTime; playTime = dspTime + timeLeft; } } float length = PlayScheduled(ParentBeforeFolder, current, audioData, playTime, offset, out nodeVolume); endTime.CurrentEndTime += length; endTime.Player = Current.AudioSource; }
public static void Draw(InAudioNode node) { UndoHelper.GUIUndo(node, "Name Change", ref node.Name, () => EditorGUILayout.TextField("Name", node.Name)); Rect area = GUILayoutUtility.GetLastRect(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); InAudioData audioData = node.NodeData as InAudioData; EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(""); area = GUILayoutUtility.GetLastRect(); Rect objectArea = area; if (Application.isPlaying) { objectArea.width -= 100; } var clip = (AudioClip)EditorGUI.ObjectField(objectArea, audioData.EditorClip, typeof(AudioClip), false); Rect buttonArea = area; if (Application.isPlaying) { buttonArea.x += buttonArea.width - 100; buttonArea.width = 70; GUI.enabled = false; EditorGUI.LabelField(buttonArea, "Is Loaded"); buttonArea.x += 70; buttonArea.width = 10; EditorGUI.Toggle(buttonArea, audioData.RuntimeClip != null); GUI.enabled = true; } if (GUILayout.Button("Preview", GUILayout.Width(60))) { AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>(); var root = TreeWalker.FindParentBeforeFolder(node); source.volume = RuntimeHelper.ApplyVolume(root, node); source.pitch = RuntimeHelper.ApplyPitch(root, node); source.clip = audioData.EditorClip; source.Play(); } if (GUILayout.Button("Raw", GUILayout.Width(45))) { AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>(); source.clip = audioData.EditorClip; source.volume = 1.0f; source.pitch = 1.0f; source.Play(); } if (GUILayout.Button("Stop", GUILayout.Width(45))) { AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>(); source.Stop(); source.clip = null; } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); if (audioData.RuntimeClip != null && Application.isPlaying) { audioData.RuntimeClip = clip; } if (clip != audioData.EditorClip) //Assign new clip { UndoHelper.RecordObjectFull(new Object[] { audioData, node.GetBank().LazyBankFetch }, "Changed " + node.Name + " Clip"); audioData.EditorClip = clip; audioData.RuntimeClip = clip; AudioBankWorker.SwapClipInBank(node, clip); EditorUtility.SetDirty(node.GetBank().LazyBankFetch.gameObject); EditorUtility.SetDirty(node.NodeData.gameObject); } EditorGUILayout.EndHorizontal(); NodeTypeDataDrawer.Draw(node); }
private static void AudioPreview(InAudioNode node, AudioSource source, InAudioData audioData) { if (source != null && !source.isPlaying) { source.clip = null; source.outputAudioMixerGroup = null; } if (GUILayout.Button("Preview", GUILayout.Width(60))) { //AudioSource source = InAudioInstanceFinder.Instance.GetComponent<AudioSource>(); var root = TreeWalker.FindParentBeforeFolder(node); if (source != null) { source.SetLoudness(RuntimeHelper.CalcVolume(root, node)); source.pitch = RuntimeHelper.CalcPitch(root, node); source.clip = audioData._clip; source.outputAudioMixerGroup = node.GetMixerGroup(); source.Play(); } else Debug.LogError( "InAudio: Could not find preview audio source in the InAudio Manager.\nTry to restore the manager from the prefab"); } if (GUILayout.Button("Raw", GUILayout.Width(45))) { //AudioSource source = InAudioInstanceFinder.Instance.GetComponent<AudioSource>(); if (source != null) { source.clip = audioData._clip; source.volume = 1.0f; source.outputAudioMixerGroup = null; source.pitch = 1.0f; source.Play(); } else Debug.LogError( "InAudio: Could not find preview audio source in the InAudio Manager.\nTry to restore the manager from the prefab"); } if (GUILayout.Button("Stop", GUILayout.Width(45))) { //AudioSource source = InAudioInstanceFinder.Instance.GetComponent<AudioSource>(); if (source != null) { source.Stop(); source.clip = null; source.outputAudioMixerGroup = null; } else Debug.LogError( "InAudio: Could not find preview audio source in the InAudio Manager.\nTry to restore the manager from the prefab"); } }
private static void AudioPreview(InAudioNode node, AudioSource source, InAudioData audioData) { if (source != null && !source.isPlaying) { source.clip = null; source.outputAudioMixerGroup = null; } if (GUILayout.Button("Preview", GUILayout.Width(60))) { //AudioSource source = InAudioInstanceFinder.Instance.GetComponent<AudioSource>(); var root = TreeWalker.FindParentBeforeFolder(node); if (source != null) { source.SetLoudness(RuntimeHelper.CalcVolume(root, node)); source.pitch = RuntimeHelper.CalcPitch(root, node); source.clip = audioData.AudioClip; source.outputAudioMixerGroup = node.GetMixerGroup(); source.Play(); } else { Debug.LogError( "InAudio: Could not find preview audio source in the InAudio Manager.\nTry to restore the manager from the prefab"); } } if (GUILayout.Button("Raw", GUILayout.Width(45))) { //AudioSource source = InAudioInstanceFinder.Instance.GetComponent<AudioSource>(); if (source != null) { source.clip = audioData.AudioClip; source.volume = 1.0f; source.outputAudioMixerGroup = null; source.pitch = 1.0f; source.Play(); } else { Debug.LogError( "InAudio: Could not find preview audio source in the InAudio Manager.\nTry to restore the manager from the prefab"); } } if (GUILayout.Button("Stop", GUILayout.Width(45))) { //AudioSource source = InAudioInstanceFinder.Instance.GetComponent<AudioSource>(); if (source != null) { source.Stop(); source.clip = null; source.outputAudioMixerGroup = null; } else { Debug.LogError( "InAudio: Could not find preview audio source in the InAudio Manager.\nTry to restore the manager from the prefab"); } } }