Exemplo n.º 1
0
        public void Load()
        {
            isLoaded = IsFixed == isFixed && PlayRangeStart == playRangeStart && PlayRangeEnd == playRangeEnd;

            if (!isLoaded)
            {
                AudioClip clip = Resources.Load <AudioClip>(Path);

                if (clip == null)
                {
                    return;
                }

                float[] dataLeft;
                float[] dataRight;

                if (IsFixed)
                {
                    clip.GetUntangledData(out dataLeft, out dataRight, (int)(PlayRangeStart * clip.samples), (int)((PlayRangeEnd - PlayRangeStart) * clip.samples * clip.channels));
                }
                else
                {
                    clip.GetUntangledData(out dataLeft, out dataRight);
                }

                pureData.communicator.WriteArray("uaudioclip_left" + Name, dataLeft);
                pureData.communicator.WriteArray("uaudioclip_right" + Name, dataRight);

                Resources.UnloadAsset(clip);
                isLoaded       = true;
                isFixed        = IsFixed;
                playRangeStart = PlayRangeStart;
                playRangeEnd   = PlayRangeEnd;
            }
        }
Exemplo n.º 2
0
        void ShowWaveCurves()
        {
            if (curveLeft == null || curveRight == null)
            {
                float[] dataLeft;
                float[] dataRight;
                clip.GetUntangledData(out dataLeft, out dataRight);

                curveLeft  = curveLeft ?? GetCurveFromData(dataLeft, 10000);
                curveRight = curveRight ?? GetCurveFromData(dataRight, 10000);
            }

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField(string.Format("Start: {0} ({1}s) | End: {2} ({3}s)", info.playRangeStart.Round(0.001), (info.adjustedPlayRangeStart * clip.length).Round(0.001), info.playRangeEnd.Round(0.001), (info.adjustedPlayRangeEnd * clip.length).Round(0.001)));
            EditorGUILayout.Space();

            float labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 40;
            EditorGUILayout.PropertyField(infoProperty.FindPropertyRelative("isFixed"), "Fixed".ToGUIContent(), GUILayout.Width(60));
            EditorGUIUtility.labelWidth = labelWidth;

            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.MinMaxSlider(ref info.playRangeStart, ref info.playRangeEnd, 0, 1);
            info.playRangeStart = float.IsNaN(info.playRangeStart) ? 0 : Mathf.Clamp(info.playRangeStart, 0, info.playRangeEnd);
            info.playRangeEnd   = float.IsNaN(info.playRangeEnd) ? 1 : Mathf.Clamp(info.playRangeEnd, info.playRangeStart, 1);

            if (EditorGUI.EndChangeCheck())
            {
                info.playRangeStart = float.IsNaN(info.playRangeStart) ? 0 : Mathf.Clamp(info.playRangeStart, 0, info.playRangeEnd);
                info.playRangeEnd   = float.IsNaN(info.playRangeEnd) ? 1 : Mathf.Clamp(info.playRangeEnd, info.playRangeStart, 1);

                for (int i = 0; i < targets.Length; i++)
                {
                    PureDataSetup selectedSetup = targets[i] as PureDataSetup;

                    if (selectedSetup != null && selectedSetup != setup)
                    {
                        selectedSetup.Info.playRangeStart = float.IsNaN(selectedSetup.Info.playRangeStart) ? 0 : Mathf.Clamp(info.playRangeStart, 0, selectedSetup.Info.playRangeEnd);
                        selectedSetup.Info.playRangeEnd   = float.IsNaN(selectedSetup.Info.playRangeEnd) ? 1 : Mathf.Clamp(info.playRangeEnd, selectedSetup.Info.playRangeStart, 1);
                    }
                }
            }

            if (clip.channels > 1)
            {
                ShowWaveCurve(curveLeft, 24);
                ShowWaveCurve(curveRight, 24);
            }
            else
            {
                ShowWaveCurve(curveLeft, 48);
            }
        }
Exemplo n.º 3
0
        void InitializeTextures()
        {
            float[]   dataLeft;
            float[]   dataRight;
            AudioClip clip = clipProperty.GetValue <AudioClip>();

            if (clip == null)
            {
                textureLeft = GetWaveTexture(null, 1024, 256, 2);
            }
            else
            {
                clip.GetUntangledData(out dataLeft, out dataRight);

                textureLeft = GetWaveTexture(dataLeft, 1024, 256 / clip.channels, 2);

                if (clip.channels > 1)
                {
                    textureRight = GetWaveTexture(dataRight, 1024, 256 / clip.channels, 2);
                }
            }
        }
Exemplo n.º 4
0
 public static void GetUntangledData(this AudioClip audioClip, out float[] dataLeft, out float[] dataRight)
 {
     audioClip.GetUntangledData(out dataLeft, out dataRight, 0, audioClip.samples * audioClip.channels);
 }