Beispiel #1
0
    void Update()
    {
//		if (!hasBegun) {
//			return;
//		}

//		if (musicInstance == null) {
//			musicInstance = emitter.GetInstance();
//			//musicInstance.start();
//		}

        IntPtr unmanagedData;
        uint   length;

        fft.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out length);
        FMOD.DSP_PARAMETER_FFT fftData = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
        var spectrum = fftData.spectrum;

        if (fftData.numchannels > 0)
        {
            var pos = Vector3.zero;
            pos.x = WIDTH * -0.5f;

            for (int i = 0; i < WindowSize; ++i)
            {
                pos.x += (WIDTH / WindowSize);

                float level = lin2dB(spectrum[0][i]);
                pos.y = (80 + level) * HEIGHT;

                lineRenderer.SetPosition(i, pos);
            }
        }
    }
    private void GetSpectrumData()
    {
        System.IntPtr _data;
        uint          _length;

        _dsp.getParameterData(2, out _data, out _length);
        _fftparam = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(_data, typeof(FMOD.DSP_PARAMETER_FFT));


        if (_fftparam.numchannels == 0)
        {
            SongPlaylist.getChannelGroup(out _channelGroup);
            _channelGroup.addDSP(0, _dsp);
        }
        else if (_fftparam.numchannels >= 1)
        {
            for (int s = 0; s < _windowSize; s++)
            {
                float _totalChannelData = 0f;
                for (int c = 0; c < _fftparam.numchannels; c++)
                {
                    _totalChannelData += _fftparam.spectrum[c][s];
                }
                _samples[s] = _totalChannelData / _fftparam.numchannels;
            }
        }
    }
Beispiel #3
0
    void Update()
    {
        if (IsPlaying(musicInstance))
        {
            IntPtr unmanagedData;
            uint   length;
            fft.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out length);
            FMOD.DSP_PARAMETER_FFT fftData = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
            var spectrum = fftData.spectrum;

            if (fftData.numchannels > 0)
            {
                for (int i = 0; i < WindowSize; ++i)
                {
                    level = lin2dB(spectrum[0][i]);
                    if (selfLight.intensity < maxIntensity)
                    {
                        selfLight.intensity += (level + 80) / diviseur;
                    }
                }
            }
        }
        db.decibel      = level;
        selfLight.range = selfLight.intensity * 5;
        gameObject.GetComponent <SphereCollider>().radius = selfLight.range;
        if (selfLight.intensity > 0)
        {
            selfLight.intensity -= degressif * Time.deltaTime;
        }
    }
    // Update is called once per frame
    void Update()
    {
        IntPtr unmanagedData;
        uint   length;

        fft.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out length);
        FMOD.DSP_PARAMETER_FFT fftData = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
        var spectrum = _spectrum = fftData.spectrum;

        // Draw line
        if (fftData.numchannels > 0)
        {
            var pos = Vector3.zero;
            pos.x = WIDTH * -0.5f + 6;

            for (int i = 0; i < WindowSize - (int)(WindowSize * 0.2); ++i)
            {
                pos.x += (WIDTH / WindowSize);

                float level = lin2dB(spectrum[0][i]);
                pos.y = (80 + level) * HEIGHT;

                lineRenderer.SetPosition(i, pos);
            }
        }
    }
Beispiel #5
0
    void UpdateFFT()
    {
        IntPtr unmanagedData;
        uint   length;

        fft.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out length);
        FMOD.DSP_PARAMETER_FFT fftData = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
        spectrum = fftData.spectrum;
    }
Beispiel #6
0
    public float[] GetSpectrum()
    {
        IntPtr unmanagedData;
        uint   length;

        fftDSP.getParameterData(2, out unmanagedData, out length);

        FMOD.DSP_PARAMETER_FFT fftData = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
        var spectrum = fftData.spectrum;

        return(spectrum[0]);
    }
Beispiel #7
0
    // Update is called once per frame
    void Update()
    {
        IntPtr unmanagedData;
        uint   length;

        if (debugDrawFFT)
        {
            fft.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out length);
            //Musimy zrzutować dane z pointera unmanagedData na typ DSP_PARAMETER_FFT
            FMOD.DSP_PARAMETER_FFT fftData =
                (FMOD.DSP_PARAMETER_FFT)System.Runtime.InteropServices.Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
            var spectrum = fftData.spectrum;
            //UnityEngine.Debug.Log("Number of channels in track:" + fftData.numchannels);

            //Wrzucamy dane do linerenderera
            if (fftData.numchannels > 0)
            {
                float width  = 80.0f;
                float height = 0.1f;
                var   pos    = Vector3.zero;
                pos.x = width * -0.5f;

                for (int i = 0; i < windowSize; ++i)
                {
                    pos.x += (width / windowSize);
                    //Elementy tablicy spectrum zwracane sa w log dB
                    //TODO: fft w skali logarytmicznej a nie liniowej
                    float level = Lin2dB(spectrum[0][i]);
                    pos.y = (80 + level) * height - 20;

                    lineRendererFFT.SetPosition(i, pos);
                }
            }
        }

        if (sampleCreated)
        {
            lineRendererSamples.positionCount = lineRendererSamplesData.Length;
            for (int i = 0; i < lineRendererSamplesData.Length; i++)
            {
                try
                {
                    lineRendererSamples.SetPosition(i, new Vector3(-40 + i * 0.5f, lineRendererSamplesData[i] - 25, 0));
                } catch (IndexOutOfRangeException ex)
                {
                    UnityEngine.Debug.Log("Oops xD" + ex.Message);
                }
            }
        }
    }