Пример #1
0
    void GetCurWave()
    {
        // clear the texture
        texture.SetPixels(blank, 0);

        // get samples from channel 0 (left)
        //audioSource.GetOutputData(samples, channel);
        //float[] spectrum = new float[256];

        StringBuilder str = new StringBuilder();

        samples = comm.GetSamples();

        for (int i = 0; i < 10; i++)
        {
            str.Append(samples[i] + "\n");
        }

        debugText.text = str.ToString();

        // draw the waveform
        for (int i = 1; i < samples.Length; i++)
        {
            texture.SetPixel((int)(width * i / size), (int)(height * (samples[i] + 1f) / 2f), waveformColor);
            //texture.SetPixel((int)(Mathf.Log(spectrum[i - 1]) + 10), (int)(Mathf.Log(spectrum[i]) + 10), waveformColor);
        } // upload to the graphics card

        texture.Apply();
    }
Пример #2
0
    void Update()
    {
        if (!is_running)
        {
            return;
        }

        //float[] spects = AudioListener.GetSpectrumData (1024, 0, FFTWindow.Rectangular);
        float[] spects;

        if (_update_timer <= 0)
        {
            spects        = comm.GetSamples();
            _update_timer = updateTime;
            //StringBuilder str = new StringBuilder();

            //for (int i = 0; i < 10; i++)
            //{
            //    str.Append(spects[i] + "\n");
            //}

            //debugText.text = str.ToString();

            for (int i = 0; i < cubes.Length; i++)
            {
                // Save the old size
                Vector3 previousScale = cubes[i].transform.localScale;

                // The new size
                if (stretchAxis == axisStrech.dx)
                {
                    previousScale.x = spects[i] * sizePower;
                }

                if (stretchAxis == axisStrech.dy)
                {
                    previousScale.y = spects[i] * sizePower;
                }

                if (stretchAxis == axisStrech.dz)
                {
                    previousScale.z = spects[i] * sizePower;
                }

                if (stretchAxis == axisStrech.dyAndDz)
                {
                    previousScale.y = spects[i] * sizePower;
                    previousScale.z = spects[i] * sizePower;
                }

                if (stretchAxis == axisStrech.all)
                {
                    previousScale.x = spects[i] * sizePower;
                    previousScale.y = spects[i] * sizePower;
                    previousScale.z = spects[i] * sizePower;
                }

                // Reset size
                cubes[i].transform.localScale = previousScale;

                //if (i == 0) {
                //	Debug.Log (spects [i]);
                //}

                // Colour change
                if (currentChannel == channelColour.red)
                {
                    barColor.r = currentRed + spects[i] * colorPower;
                }

                if (currentChannel == channelColour.green)
                {
                    barColor.g = currentGreen + spects[i] * colorPower;
                }

                if (currentChannel == channelColour.blue)
                {
                    barColor.b = currentBlue + spects[i] * colorPower;
                }

                if (currentChannel == channelColour.all)
                {
                    barColor.b = currentBlue + (spects[i] * colorPower);
                    barColor.g = currentGreen + (spects[i] * colorPower);
                    barColor.r = currentRed + (spects[i] * colorPower);
                }

                cubes[i].GetComponent <Image>().color = barColor;
            }
        }
        else
        {
            _update_timer -= Time.deltaTime;
        }
    }