Пример #1
0
        void OnVideoEnd(VideoPlayer player)
        {
            Debug.Log("On Video End");
            data.SaveToFile(SpectrumData.DataPath(player.clip));
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#endif
        }
        void Start()
        {
            osc = GetComponent <FaustPlugin_SimpleOsc>();

            var player = GetComponent <VideoPlayer>();

            data.LoadFile(SpectrumData.DataPath(player.clip));

            GetComponent <GLDrawer>().OnDraw += OnGLDraw;
        }
 void Update()
 {
     if (currentIndex < data.frames.Count)
     {
         var frame = data.frames[currentIndex];
         for (int i = 0; i < frame.Count; i++)
         {
             float freq = SpectrumData.IndexToFrequency(frame.index[i]);
             float gain = frame.level[i];
             SetParameter(i, freq, gain);
         }
         for (int i = frame.Count; i < SpectrumData.PEAKS; i++)
         {
             SetParameter(i, 50, 0);
         }
     }
     currentIndex++;
 }
        void OnGLDraw()
        {
            GL.Begin(GL.LINES);
            GL.Color(Color.red);

            if (currentIndex < data.frames.Count)
            {
                float width  = Screen.width;
                float height = Screen.height;
                float offset = 0;

                var frame = data.frames[currentIndex];
                for (int i = frame.Count - 1; i >= 0; i--)
                {
                    float freq = SpectrumData.IndexToFrequency(frame.index[i]);
                    float x    = Mathf.InverseLerp(0, 22050, freq) * width;
                    float y    = frame.level[i] * height * 10;
                    GL.Vertex3(x, offset, 0);
                    GL.Vertex3(x, offset + y, 0);
                }
            }

            GL.End();
        }