コード例 #1
0
    private Beat[] ProcessStereo(float[] samples, int numOfSamples, int frequency)
    {
        Debug.Log("Processing Stereo Song");

        float[] rightSamples = new float[numOfSamples];
        float[] leftSamples  = new float[numOfSamples];
        for (int i = 0; i < numOfSamples; i += 1)
        {
            rightSamples[i] = samples[i * 2];
            leftSamples[i]  = samples[(i * 2) + 1];
        }

        Beat[] beatTrack = new Beat[windowIterations + 1];

        for (int i = 0; i < beatTrack.Length; i += 1)
        {
            float[] tempRight = new float[windowInterval];
            float[] tempLeft  = new float[windowInterval];
            if (i < windowIterations)
            {
                for (int j = 0; j < windowInterval; j += 1)
                {
                    tempRight[j] = rightSamples[(windowInterval * i) + j];
                    tempLeft[j]  = leftSamples[(windowInterval * i) + j];
                }
            }
            else
            {
                for (int j = 0; j < lastWindowSize; j += 1)
                {
                    tempRight[j] = rightSamples[(windowInterval * i) + j];
                    tempLeft[j]  = leftSamples[(windowInterval * i) + j];
                }
            }
            List <float[]> bandsRight = AudioAnalyser.GetDistinctBands(FastFourierTransform.FftMag(tempRight), frequency, windowInterval / 2.0f);
            List <float[]> bandsLeft  = AudioAnalyser.GetDistinctBands(FastFourierTransform.FftMag(tempLeft), frequency, windowInterval / 2.0f);
            if (energyHistories.Count == 0)
            {
                Debug.Log("Creating histories");
                energyHistories = new List <float[]>();
                for (int b = 0; b < bandsRight.Count; b += 1)
                {
                    energyHistories.Add(new float[historyBufferLength]);
                    bandVariances.Add(new float[historyBufferLength]);
                }
            }
            beatTrack[i] = CheckForBeatBands(bandsRight, bandsLeft);
            if (beatTrack[i] != null)
            {
                beatTrack[i].windowNumber = i;
                beatTrack[i].timeStamp    = WindowPositionToTime(i);
            }
        }

        return(beatTrack);
    }
コード例 #2
0
    private Beat[] ProcessMono(float[] samples, int frequency)
    {
        Debug.Log("Processing Mono Song");

        Beat[] beatTrack = new Beat[windowIterations + 1];

        for (int i = 0; i < beatTrack.Length; i += 1)
        {
            float[] temp = new float[windowInterval];
            if (i < windowIterations)
            {
                for (int j = 0; j < windowInterval; j += 1)
                {
                    temp[j] = samples[(windowInterval * i) + j];
                }
            }
            else
            {
                for (int j = 0; j < lastWindowSize; j += 1)
                {
                    temp[j] = samples[(windowInterval * i) + j];
                }
            }
            List <float[]> bands = AudioAnalyser.GetDistinctBands(FastFourierTransform.FftMag(temp), frequency, windowInterval / 2.0f);
            if (energyHistories.Count == 0)
            {
                Debug.Log("Creating histories");
                energyHistories = new List <float[]>();
                for (int b = 0; b < bands.Count - 1; b += 1)
                {
                    energyHistories.Add(new float[historyBufferLength]);
                    bandVariances.Add(new float[historyBufferLength]);
                }
            }
            beatTrack[i] = CheckForBeatBands(bands, null);
            if (beatTrack[i] != null)
            {
                beatTrack[i].windowNumber = i;
                beatTrack[i].timeStamp    = WindowPositionToTime(i);
            }
        }

        return(beatTrack);
    }