Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
        public static void DrawMixer(InAudioNode node)
        {
            var serialized = new SerializedObject(node);

            serialized.Update();
            if (!node.IsRoot)
            {
                bool overrideParent = EditorGUILayout.Toggle("Override Parent Mixer Group", node.OverrideParentMixerGroup);
                if (overrideParent != node.OverrideParentMixerGroup)
                {
                    InUndoHelper.RecordObjectFull(new Object[] { node._nodeData, node }, "Override parent mixer group");
                    node.OverrideParentMixerGroup = overrideParent;
                }
                if (!node.OverrideParentMixerGroup)
                {
                    GUI.enabled = false;
                }
            }

            EditorGUILayout.BeginHorizontal();

            if (node.IsRoot)
            {
                EditorGUILayout.PropertyField(serialized.FindProperty("MixerGroup"), new GUIContent("Mixer Group"));
            }
            else if (node.OverrideParentMixerGroup)
            {
                EditorGUILayout.PropertyField(serialized.FindProperty("MixerGroup"), new GUIContent("Mixer Group"));
            }
            else
            {
                EditorGUILayout.PropertyField(new SerializedObject(node.GetParentMixerGroup()).FindProperty("MixerGroup"), new GUIContent("Parent Mixer Group"));
            }

            GUI.enabled = node.GetMixerGroup() != null;
            if (GUILayout.Button("Find", GUILayout.Width(40)))
            {
                SearchHelper.SearchFor(node.MixerGroup);
            }
            EditorGUILayout.EndHorizontal();
            serialized.ApplyModifiedProperties();
            GUI.enabled = true;
        }
Ejemplo n.º 3
0
    public static void DrawMixer(InAudioNode node)
    {
        var serialized = new SerializedObject(node);
        serialized.Update();
        if (!node.IsRoot)
        {
            bool overrideParent = EditorGUILayout.Toggle("Override Parent Mixer Group", node.OverrideParentMixerGroup);
            if (overrideParent != node.OverrideParentMixerGroup)
            {
                InUndoHelper.RecordObjectFull(new Object[] {node._nodeData, node}, "Override parent mixer group");
                node.OverrideParentMixerGroup = overrideParent;
            }
            if (!node.OverrideParentMixerGroup)
                GUI.enabled = false;
        }
        
        EditorGUILayout.BeginHorizontal();

        if (node.IsRoot)
        {
            EditorGUILayout.PropertyField(serialized.FindProperty("MixerGroup"), new GUIContent("Mixer Group"));
        }
        else if (node.OverrideParentMixerGroup)
        {
            EditorGUILayout.PropertyField(serialized.FindProperty("MixerGroup"), new GUIContent("Mixer Group"));
        }
        else
        {
            EditorGUILayout.PropertyField(new SerializedObject(node.GetParentMixerGroup()).FindProperty("MixerGroup"), new GUIContent("Parent Mixer Group"));
        }

        GUI.enabled = node.GetMixerGroup() != null;
        if (GUILayout.Button("Find", GUILayout.Width(40)))
        {
            SearchHelper.SearchFor(node.MixerGroup);
        }
        EditorGUILayout.EndHorizontal();
        serialized.ApplyModifiedProperties();
            GUI.enabled = true;
    }
Ejemplo n.º 4
0
    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);
        }
        else
        {
            Debug.LogWarning("InAudio: Audio clip missing on audio node \"" + currentNode.Name + "\", id=" + currentNode._ID);
        }
        return length;
    }
Ejemplo n.º 5
0
    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");
        }
    }
Ejemplo n.º 6
0
        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");
                }
            }
        }