void Update()
    {
        AudioListener.GetOutputData(waveData_, 1);
        var volume = waveData_.Select(x => x * x).Sum() / waveData_.Length;

        transform.localScale = Vector3.one * (volume + 1.0f);
    }
    // Update is called once per frame
    void Update()
    {
        if (++freq % 4 != 0)
        {
            return;
        }
        freq = 0;
        //float [] spectrum = new float[128];
        //AudioListener.GetOutputData(spectrum,1);
        float[] spectrum = AudioListener.GetOutputData(32, 0);
        for (int i = 0; i < objsNum; ++i)
        {
            Vector3 preScale = cubes[i].transform.localScale;
            preScale.y = Mathf.Abs(spectrum[i] * scale) + height;
            cubes[i].transform.localScale = preScale;
            Vector3 prePostion = cubes[i].transform.position;
            prePostion.y = preScale.y / 2;
            cubes[i].transform.position = prePostion;

            int red = (int)preScale.y;
            if (red > 255)
            {
                red = 255;
            }
            int        g      = Random.Range(0, 255);
            int        b      = Random.Range(0, 255);
            GameObject d      = cubes[i];
            var        render = d.GetComponent <Renderer>();
            render.material.color = new Color(red, g, b);
        }
    }
        /// <summary>
        ///
        /// </summary>
        public override void UpdateObservation()
        {
            var samples = new float[256];

            AudioListener.GetOutputData(samples, 0);
            this.ObservationArray = samples;
        }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        if (!ready)
        {
            return;
        }

        // pull fresh spectrum data each frame
        AudioListener.GetSpectrumData(spectrumL, 0, FFTWindow.BlackmanHarris);
        AudioListener.GetSpectrumData(spectrumR, 1, FFTWindow.BlackmanHarris);
        AudioListener.GetOutputData(outputL, 0);
        AudioListener.GetOutputData(outputR, 1);
        //spectrum = new float[numSamples];
        //AudioListener.GetOutputData(spectrum, 0);

        // clear previous values
        vocalSamples = 0f;
        samples      = 0f;

        if (fullSpectrumMode)
        {
            FullSpectrumUpdate();
        }
        else
        {
            FreqSpecificUpdate();
        }

        SphereUpdate();

        if (Input.GetKeyDown(KeyCode.U))
        {
            showGUI = !showGUI;
        }
    }
Beispiel #5
0
    //=======================================================================

    /// <summary>
    /// 오디오의 Output 값을 감지해 비주얼라이저를 통해 표시하는 함수
    /// </summary>
    public void DetectOutputSound()
    {
        // 0번 채널과 1번 채널의 OutputData를 담음
        AudioListener.GetOutputData(outputData0, 0);
        AudioListener.GetOutputData(outputData1, 1);

        // 결과를 담을 float 변수
        float result = 0f;

        // 모든 OutputData를 더해 result 변수에 저장
        for (int i = 0; i < outputData0.Length; i++)
        {
            result += Mathf.Abs(outputData0[i]);
        }
        for (int i = 0; i < outputData1.Length; i++)
        {
            result += Mathf.Abs(outputData1[i]);
        }

        //uText.text = result.ToString();
        //Debug.Log(result);

        outputAmount = result;
        // result의 값을 비주얼라이저에 표시
        if (outputCube != null)
        {
            outputCube.transform.localScale    = new Vector3(result / 100f, 1f, 1f);
            outputCube.transform.localPosition = new Vector3(-44f + (result / 200f), outputCube.transform.localPosition.y, outputCube.transform.localPosition.z);
        }
    }
Beispiel #6
0
    void AnalyzeSound()
    {
        // TODO: Analyze Stereo as well
        AudioListener.GetOutputData(samplesL, 0); // fill array with samples
        AudioListener.GetOutputData(samplesR, 1); // fill array with samples
        AudioListener.GetSpectrumData(spectrumL, 0, FFTWindow.BlackmanHarris);
        AudioListener.GetSpectrumData(spectrumR, 1, FFTWindow.BlackmanHarris);

        if (sampledTime > Time.deltaTime)
        {
            sampledBeginningIndex = SAMPLE_SIZE - (int)(Time.deltaTime * sampleRate);
        }

        // Overall channels db
        AnalyzeDB();

        // Calculate Pitch
        AnalyzePitch();

        // Update frequency bands:
        AnalyzeFrequencyBands();

        // Wave form:
        AnalyzeWaveForm();
    }
    // Update is called once per frame
    void Update()
    {
        // Unity's FFT function
        AudioListener.GetSpectrumData(spec, 0, FFTWindow.BlackmanHarris);
        for (int i = 0; i < spec.Length; i++)
        {
            Debug.DrawLine(new Vector3(i, 0, 0), new Vector3(i, spec[i] * 18000), Color.black);
        }

        // My FFT based on the output samples.
        AudioListener.GetOutputData(tmp, 0);
        // copy the output data into the complex array
        for (int i = 0; i < tmp.Length; i++)
        {
            spec2[i] = new  Complex(tmp[i], 0);
        }
        // calculate the FFT
        FFT.CalculateFFT(spec2, false);

        for (int i = 0; i < spec2.Length / 2; i++) // plot only the first half
        {
            // multiply the magnitude of each value by 2
            Debug.DrawLine(new Vector3(i, 0, 40), new Vector3(i, (float)spec2[i].magnitude * 36000, 40), Color.white);
            if (spec2 [i].magnitude * 18000 > 300)
            {
                Debug.Log(i);
            }
        }
    }
    void Update()
    {
        float[] samples0 = new float[1024];
        float[] samples1 = new float[1024];
        AudioListener.GetOutputData(samples0, 0);
        AudioListener.GetOutputData(samples1, 1);
        float max = 0;

        foreach (float s in samples0)
        {
            if (s > max)
            {
                max = s;
            }
        }
        foreach (float s in samples1)
        {
            if (s > max)
            {
                max = s;
            }
        }
        if (max > 1)
        {
            Debug.Log(max);
        }
    }
Beispiel #9
0
 // Update is called once per frame
 void Update()
 {
     AudioListener.GetOutputData(waveData, 1);
     volume /= 2.0f;
     volume += waveData.Select(x => x * x).Sum() / waveData.Length * 0.5f;
     this.transform.localPosition = childTransform.localPosition + new Vector3(0.0f, volume * 10f, 0.0f);
 }
Beispiel #10
0
    void PlaceNewObject()
    {
        //get the output data from the listener
        AudioListener.GetOutputData(volData, 0);

        //get the root mean square of the output data (this is the square root of the average of the samples)
        float curVol = RMS(volData);

        //amplify the volume, and maintain our range of minX and maxX
        float xPos = Mathf.Clamp(curVol * ctrlXPos, minX, maxX);

        Debug.Log(xPos);

        if (xPos > 0)
        {
            //instantiate our new visual object, adjusting x, y and z position as we go
            GameObject newVisual = Instantiate(visualPrefab, new Vector3((xPos > maxX ? maxX : xPos) * playerQuad.x, 0, 0), Quaternion.identity);
            newVisual.GetComponent <Note>().yMultiplier = playerQuad.z;
        }
        if (audSorGO.GetComponent <AudioSource>().isPlaying)
        {
            audioWasPlaying = true;
        }
        if (!audSorGO.GetComponent <AudioSource>().isPlaying&& audioWasPlaying)
        {
            StartCoroutine(EndMusic(1.5f));
        }
    }
Beispiel #11
0
    // Update is called once per frame
    void Update()
    {
        AudioListener.GetOutputData(visualiserValues, 0);

        float   yScale;
        Vector3 tempScale = new Vector3(0, 0, 0);

        for (int i = 0; i < visualiserHolder.childCount; i++)
        {
            yScale = 0;

            for (int j = 0; j < samplesPerInstance; j++)
            {
                yScale += visualiserValues[i * samplesPerInstance + j];
            }

            Transform visualiserTransform = visualiserHolder.GetChild(i);

            tempScale.x = visualiserTransform.localScale.x;
            tempScale.y = yScale;
            tempScale.z = visualiserTransform.localScale.z;

            visualiserTransform.localScale = tempScale;
        }
    }
Beispiel #12
0
    void Update()
    {
        float[] spectrum   = new float[256];
        float[] outputData = new float[1024];
        AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Hanning);
        AudioListener.GetOutputData(outputData, 0);
        for (int i = 1; i < spectrum.Length - 1; i++)
        {
            Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);
            Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i, Mathf.Log(spectrum[i]) + 10, 2), Color.cyan);
            Debug.DrawLine(new Vector3(Mathf.Log(i - 1), spectrum[i - 1] - 10, 1), new Vector3(Mathf.Log(i), spectrum[i] - 10, 1), Color.green);
            Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(spectrum[i - 1]), 3), new Vector3(Mathf.Log(i), Mathf.Log(spectrum[i]), 3), Color.blue);
        }

        float avg = 0;

        foreach (float f in outputData)
        {
            avg += Mathf.Abs(f);
        }
        avg /= outputData.Length;


        float newScale = 1.0f + (avg * 5);
        float oldScale = transform.localScale.y;
        float scale    = Mathf.Lerp(oldScale, newScale, Time.deltaTime * 10);

        transform.localScale = new Vector3(scale, scale, scale);
        GetComponent <Renderer>().material.color = Color.HSVToRGB(scale / 2, 1, 1);
    }
Beispiel #13
0
    void FixedUpdate()
    {
        spectrum = new float[256];

        float smoothTime = 0.9f;
        float yVelocity  = 0.1f;

        AudioListener.GetOutputData(spectrum, 0);//spectrum, 0, FFTWindow.Rectangular);

        //foreach (float f in spectrum)
        //Debug.Log(f);

        for (int i = 1; i < spectrum.Length - 1; i++)
        {
            Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);
            Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i, Mathf.Log(spectrum[i]) + 10, 2), Color.cyan);
            Debug.DrawLine(new Vector3(Mathf.Log(i - 1), spectrum[i - 1] - 10, 1), new Vector3(Mathf.Log(i), spectrum[i] - 10, 1), Color.green);
            Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(spectrum[i - 1]), 3), new Vector3(Mathf.Log(i), Mathf.Log(spectrum[i]), 3), Color.blue);


            float newScale = Mathf.SmoothDamp(AmpLow.transform.localScale.y, getMidValue(spectrum, 0, 50), ref yVelocity, smoothTime);
            AmpLow.transform.localScale = new Vector3(0.5f, newScale, 0.5f);

            AmpLowMid.transform.localScale  = new Vector3(0.5f, getMidValue(spectrum, 50, 50), 0.5f);
            AmpMid.transform.localScale     = new Vector3(0.5f, getMidValue(spectrum, 100, 50), 0.5f);
            AmpHighMid.transform.localScale = new Vector3(0.5f, getMidValue(spectrum, 150, 50), 0.5f);
            AmpHigh.transform.localScale    = new Vector3(0.5f, getMidValue(spectrum, 200, 50), 0.5f);
        }
    }
Beispiel #14
0
    // Update is called once per frame
    void Update()
    {
        float[] spectrum = new float [1024];
        AudioListener.GetOutputData(spectrum, 0);

        float c1 = spectrum[2] + spectrum[3] + spectrum[4];
        float c2 = spectrum[11] + spectrum[12] + spectrum[13];
        float c3 = spectrum[21] + spectrum[22] + spectrum[23];
        float c4 = spectrum[44] + spectrum[45] + spectrum[46] + spectrum[47] + spectrum[48] + spectrum[49];

        switch (num)
        {
        case 0:
            transform.localScale = scale + new Vector3(0, Mathf.Max(c1, 3f), 0);
            break;

        case 1:
            transform.localScale = scale + new Vector3(0, Mathf.Max(c2, 0.5f), 0);
            break;

        case 2:
            transform.localScale = scale + new Vector3(0, Mathf.Max(c3, 0.5f), 0);
            break;

        case 3:
            transform.localScale = scale + new Vector3(0, Mathf.Max(c4, 0.5f), 0);
            break;

        default:
            transform.localScale = scale + new Vector3(0, Mathf.Max(c4, 0.5f), 0);
            break;
        }

        Debug.Log(c1);
    }
Beispiel #15
0
        void Update()
        {
            if (m_audioListener != null)
            {
                AudioListener.GetOutputData(m_spectrum, 0);

                float sum = 0;

                for (int i = 0; i < m_spectrum.Length; i++)
                {
                    sum += m_spectrum[i] * m_spectrum[i]; // sum squared samples
                }

                float rmsValue = Mathf.Sqrt(sum / m_spectrum.Length); // rms = square root of average

                m_maxDB = 20 * Mathf.Log10(rmsValue / m_refValue);    // calculate dB

                if (m_maxDB < -80)
                {
                    m_maxDB = -80;                // clamp it to -80dB min
                }
                AudioListener.GetSpectrumData(m_spectrum, 0, m_FFTWindow);
            }
            else if (m_audioListener == null &&
                     m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ALWAYS)
            {
                FindAudioListener();
            }
        }
Beispiel #16
0
    // Update is called once per frame
    void Update()
    {
        AudioListener.GetOutputData(volumeSamples, 0);                  //Gathering audio data. Both left and right channel are gathered.
        AudioListener.GetOutputData(volumeSamples1, 1);

        for (int i = 0; i < volumeSamples[0]; i++)
        {
            volumeSamples[i] = (volumeSamples[i] + volumeSamples1[i]) / 2;                      //General output data is taken as the average between the two channels.
        }

        volumenumber = 0f;
        for (int j = 0; j < numSamples; j++)
        {
            volumenumber += volumeSamples[j] * volumeSamples[j];           //sum squared samples are taken of the audio data. This will result in a volume number that is higher the higher the volume is of the data.
        }
        //However, as we hear audio logarithmically, a direct numerical representation of audio volume is not accurate to how we hear it.
        //Instead, it should be mapped to decibel, which is done with this calculation:

        volumenumber = Mathf.Sqrt(volumenumber / numSamples);       //square root of average
        volumenumber = 20 * Mathf.Log10(volumenumber / volumeRef);  //convert to dB
        if (volumenumber < -160)
        {
            volumenumber = -160;                                           //Minimized, so volume can't be infinitely small.
        }
        gle.audioVolume = volumenumber + volumeScale;                      //Audiovolume is sent to the GlitchEffectArray and lineVolume scripts. Scale is added because the dB value is quite low.
        lineVol.AddNewVolume(volumenumber + volumeScale);
    }
Beispiel #17
0
    void Update()
    {
        float[] info = new float[detail];

        AudioListener.GetOutputData(info, 0);

        float packagedData = 0f;

        for (var x = 0; x < info.Length; x++)
        {
            packagedData += System.Math.Abs(info [x]);
        }

        float offset = Mathf.Clamp(packagedData * amplitude, 0, maxOffset);

        lines [_currentLine].SetActive(false);

        if (!reverseY)
        {
            transform.localPosition = new Vector3(transform.localPosition.x, _startPosition + offset, transform.localPosition.z);

            lines [_currentLine].transform.position = new Vector3(transform.position.x, transform.position.y - 5f, transform.position.z);
        }
        else
        {
            transform.localPosition = new Vector3(transform.localPosition.x, _startPosition - offset, transform.localPosition.z);

            lines [_currentLine].transform.position = new Vector3(transform.position.x, transform.position.y + 5f, transform.position.z);
        }

        lines [_currentLine].SetActive(true);

        _currentLine = (_currentLine + 1) % maxLinesSpawned;
    }
Beispiel #18
0
    void Update()
    {
        AudioListener.GetOutputData(wavedata, 1);
        var volume = wavedata.Select(x => x * x).Sum() / wavedata.Max();

        volume = volume / wavedata.Length;
        transform.localScale = (Vector3.one * 500.0f * volume + new Vector3(200f, 0, 200f));
    }
Beispiel #19
0
  void Update() {
    if (m_Active) {
      // Get audio data from Unity (Hint: replace this with your own!)
      AudioListener.GetOutputData(m_WaveformFloats, 0);

      // Send audio data to be processed into the shaders
      VisualizerManager.m_Instance.ProcessAudio(m_WaveformFloats, AudioSettings.outputSampleRate);
    }
  }
 void Update()
 {
     if (Time.frameCount % 10 == 0)
     {
         float[] samples = new float[512];
         AudioListener.GetOutputData(samples, 0);
         material.SetFloatArray("SoundBuffer", samples);
     }
 }
Beispiel #21
0
    static int GetOutputData(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        float[] objs0 = LuaScriptMgr.GetArrayNumber <float>(L, 1);
        int     arg1  = (int)LuaScriptMgr.GetNumber(L, 2);

        AudioListener.GetOutputData(objs0, arg1);
        return(0);
    }
Beispiel #22
0
 void UpdateLoopbackBuffer()
 {
     if (loopbackBuffer1 == null || loopbackBuffer1.Length != dftPointNumber)
     {
         loopbackBuffer1 = new float[dftPointNumber];
         loopbackBuffer2 = new float[dftPointNumber];
     }
     AudioListener.GetOutputData(loopbackBuffer1, 0);
     AudioListener.GetOutputData(loopbackBuffer2, 1);
 }
Beispiel #23
0
 private float getRMS(int channel)
 {
     AudioListener.GetOutputData(samples, channel);
     float sum = 0;
     for(int i = 0;i < qSamples; i++)
     {
         sum = samples[i] * samples[i];
     }
     return Mathf.Sqrt(sum / qSamples);
 }
Beispiel #24
0
 void Visualize()
 {
     float[] audioData = new float[resolution];
     AudioListener.GetOutputData(audioData, 0);
     myLine.SetVertexCount(audioData.Length);
     for (int i = 0; i < audioData.Length; i++)
     {
         myLine.SetPosition(i, new Vector3(transform.position.x + (i * divider), transform.position.y + (audioData[i] * multiplier), 0));
     }
 }
    // Update is called once per frame
    void Update()
    {
        float[] spectrum = AudioListener.GetSpectrumData(1024, 0, FFTWindow.Hamming); //Reading the spectrum from the song put into the AudioListener

        float[] samples = AudioListener.GetOutputData(1024, 0);

        //Adding up all the samples, for approximate overall "volume"
        float vol = 0;

        foreach (float sample in samples)
        {
            if (sample >= 0)
            {
                vol += sample;
            }
            else
            {
                vol -= sample;
            }
        }



        //Rotate logo around the z-axis, based on time of the last frame and volume
        transform.Rotate(0, 0, -(Time.deltaTime * vol));

        /**
         * Scaling the logo, based on the value in the spectrum-array
         */

        Vector3 previousScale = transform.localScale;
        int     anzahl        = 10;
        float   average       = 0;

        for (int i = 0; i < anzahl; i++)
        {
            average += spectrum[i];
        }
        average = average / anzahl;

        if (average * scale > 1)       //Only update if the height is above set value (1)
        {
            previousScale.y = Mathf.Lerp(previousScale.y, average * scale, Time.deltaTime * 30);
            previousScale.x = Mathf.Lerp(previousScale.x, average * scale, Time.deltaTime * 30);
        }
        else
        {
            previousScale.y = Mathf.Lerp(previousScale.y, 1, Time.deltaTime * 30);
            previousScale.x = Mathf.Lerp(previousScale.x, 1, Time.deltaTime * 30);
        }
        transform.localScale = previousScale;

//            Debug.Log(previousScale);
    }
    // Update is called once per frame
    void Update()
    {
        AudioListener.GetOutputData(waveData, 1);
        float volume = waveData.Select(x => x * x).Sum() / waveData.Length;

        for (int i = 0; i < 4; i++)
        {
            if (1 < enhancement * volume)
            {
                spotLights[i].GetComponent <Light>().spotAngle = _angle[i] * enhancement * volume;
            }
        }

        float[] spectrum = new float[resolution];
        MusicPlayer.GetComponent <AudioSource>().GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);


        var   deltaFreq = AudioSettings.outputSampleRate / resolution;
        float low = 0f, mid = 0f, high = 0f;

        for (var i = 0; i < resolution; ++i)
        {
            var freq = deltaFreq * i;
            if (freq <= lowFreqThreshold)
            {
                low += spectrum[i];
            }
            else if (freq <= midFreqThreshold)
            {
                mid += spectrum[i];
            }
            else if (freq <= highFreqThreshold)
            {
                high += spectrum[i];
            }
        }

        low  *= lowEnhance;
        mid  *= midEnhance;
        high *= highEnhance;

        /*
         * spotLights[0].GetComponent<Light>().color = new Color32((byte)(255 * low), (byte)(255 * low), 0, 0);
         * spotLights[1].GetComponent<Light>().color = new Color32(0, 0, (byte)(255 * mid), 0);
         * spotLights[2].GetComponent<Light>().color = new Color32((byte)(255 * high), 0, 0, 0);
         * spotLights[3].GetComponent<Light>().color = new Color32(0, (byte)(255 * (high + mid + low) / 3), 0, 0);
         */
        for (int i = 0; i < 4; i++)
        {
            //spotLights[i].GetComponent<Light>().color = new Color32((byte)(255 * high), (byte)(255 * mid), (byte)(255 * low), 0);
            byte _color = (byte)(255 * (high + mid + low) / 3);
            spotLights[i].GetComponent <Light>().color = new Color32(_color, _color, _color, 0);
        }
    }
    // Update is called once per frame
    void Update()
    {
        // get raw FFT data
        //audioSourceArray[0].GetSpectrumData(sampleArrayFreqBH, 0, FFTWindow.BlackmanHarris);//Rectangular);
        AudioListener.GetSpectrumData(sampleArrayFreqBH, 0, FFTWindow.BlackmanHarris);

        // get colume data, from --> http://answers.unity3d.com/questions/157940/getoutputdata-and-getspectrumdata-they-represent-t.html
        AudioListener.GetOutputData(outputDataArray, 0);
        float outputSumSq = 0;

        for (int i = 0; i < outputDataArray.Length; i++)
        {
            outputSumSq = outputDataArray[i] * outputDataArray[i];
        }
        rmsValue = Mathf.Sqrt(outputSumSq / outputDataArray.Length);
        dbValue  = 20 * Mathf.Log10(rmsValue / refRMSValue);

        // cleanup pseudolog array first
        for (int i = 0; i < pseudoLogArray.Length; i++)
        {
            pseudoLogArray[i] = 0;
        }

        // doing the pseudo log scale
        int decadeIndex      = 0;
        int fftSampleCounter = 0;

        for (int i = 0; i < pseudoLogArray.Length; i++)
        {
            if (i != 0 && i % 10 == 0)
            {
                decadeIndex++;
            }

            for (int j = 0; j < samplesPerDecadeArray[decadeIndex]; j++)
            {
                pseudoLogArray[i] += sampleArrayFreqBH[fftSampleCounter] * scalingPerDecadeArray[decadeIndex];
                fftSampleCounter++;
            }
        }

        SpeadLocalMaxima();

        CalculateRBG();

        HandleLowPassFilter();         // does not affect the landscape


        //update buffer
        for (int i = 0; i < pseudoLogArray.Length; i++)
        {
            pseudoLogArrayBuffer[i] += pseudoLogArray[i];
        }
    }
Beispiel #28
0
        private void Update()
        {
            if (m_audioListener != null)
            {
                // Use this data to calculate the dB value

                AudioListener.GetOutputData(m_spectrum, 0);

                float sum = 0;

                for (int i = 0; i < m_spectrum.Length; i++)
                {
                    sum += m_spectrum[i] * m_spectrum[i]; // sum squared samples
                }

                float rmsValue = Mathf.Sqrt(sum / m_spectrum.Length); // rms = square root of average

                m_maxDB = 20 * Mathf.Log10(rmsValue / m_refValue);    // calculate dB

                if (m_maxDB < -80)
                {
                    m_maxDB = -80;                // clamp it to -80dB min
                }
                // Use this data to draw the spectrum in the graphs

                AudioListener.GetSpectrumData(m_spectrum, 0, m_FFTWindow);

                for (int i = 0; i < m_spectrum.Length; i++)
                {
                    // Update the highest value if its lower than the current one
                    if (m_spectrum[i] > m_spectrumHighestValues[i])
                    {
                        m_spectrumHighestValues[i] = m_spectrum[i];
                    }

                    // Slowly lower the value
                    else
                    {
                        m_spectrumHighestValues[i] = Mathf.Clamp
                                                     (
                            value: m_spectrumHighestValues[i] - m_spectrumHighestValues[i] * Time.deltaTime * 2,
                            min: 0,
                            max: 1
                                                     );
                    }
                }
            }
            else if (m_audioListener == null &&
                     m_findAudioListenerInCameraIfNull == GraphyManager.LookForAudioListener.ALWAYS)
            {
                m_audioListener = FindAudioListener();
            }
        }
Beispiel #29
0
    float GetRMS(int channel)
    {
        AudioListener.GetOutputData(samples, channel);

        float sum = 0;

        foreach (float f in samples)
        {
            sum += f * f;
        }
        return(Mathf.Sqrt(sum / qSamples));
    }
Beispiel #30
0
    float[] samples;     // audio samples

    float GetRMS(int channel)
    {
        AudioListener.GetOutputData(samples, channel);
        float sum = 0;

        for (var i = 0; i < qSamples; i++)
        {
            sum += samples[i] * samples[i];
        }

        return(Mathf.Sqrt(sum / qSamples));
    }