Пример #1
0
    private void Update()
    {
        audioSource.GetOutputData(sampleData, 1);
        double?dfreq = PitchAccord.EstimateBasicFrequency(AudioSettings.outputSampleRate, sampleData, powerAverageValue);

        if (dfreq.HasValue)
        {
            int freq = (int)dfreq;

            freqText.text = string.Format("Freq {0}Hz\nMax {1}Hz\nMin {2}Hz", freq, max, min);
            freq          = Mathf.Clamp(freq, min, max);
            pC.Movement   = (float)(freq - min) / (max - min);

            //パワースペクトルからデシベルを呼び出す
            dB = PitchAccord.GetDB();
            if (dB.HasValue)
            {
                normalizedValue = (float)(dB.Value - powerAverageValue) / (maxPowerValue - powerAverageValue);
                var speed = (Mathf.Clamp(normalizedValue, 0f, 1f)) * (maxspeed - minspeed) + minspeed;
                sC.SetFreqSpeed(Mathf.Lerp(sC.GetFreqSpeed(),
                                           speed, Time.deltaTime * 1.5f));
            }
        }
        else
        {
            sC.SetFreqSpeed(Mathf.Lerp(sC.GetFreqSpeed(),
                                       minspeed, Time.deltaTime * 1.5f));

            freqText.text = string.Format("Freq 0Hz\nMax {0}Hz\nMin {1}Hz", max, min);
        }
    }