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); }
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"); } } }