Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float[] waveData = new float[1024];
        MasterInput.RetrieveWaveform(FilterType.Bypass, waveData);

        for (int i = 0; i < 1024; i++)
        {
            objects[i].position = new Vector3(objects[i].position.x, waveData[i], 0);
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 1024, j = 0; i < fakeSize; i++, j++)
        {
            lastsamples[j] = lastsamples[i];
        }
        for (int i = 0, j = fakeSize - 1024; j < fakeSize; i++, j++)
        {
            lastsamples[j] = samples[i];
        }


        MasterInput.RetrieveWaveform(FilterType.Bypass, samples);

        for (int i = 0; i < lastsamples.Length; i++)
        {
            freq[i] = new Complex(lastsamples[i], 0);
        }
        for (int i = 0; i < samples.Length; i++)
        {
            freq[lastsamples.Length + i] = new Complex(samples[i], 0);
        }

        for (int i = 0; i < samples.Length; i++)
        {
            Debug.DrawLine(new Vector3(i, 0), new Vector3(i, samples[i] * 20), Color.cyan);
        }

        FFT.CalculateFFT(freq, false);

        for (int i = 0; i < freq.Length / 2; i++) // plot only the first half
        {
            // multiply the magnitude of each value by 2
            Debug.DrawLine(new Vector3(i, 200), new Vector3(i, 200 + (float)freq[i].magnitude * 200), Color.white);
        }

        List <FreqData> maximas = new List <FreqData>();

        for (int i = imin; i < imax; i++)
        {
            if (freq[i].magnitude > noteThreshold)
            {
                if (freq[i].magnitude > freq[i - 1].magnitude && freq[i].magnitude > freq[i + 1].magnitude)
                {
                    FreqData temp = new FreqData();
                    temp.location = i;
                    temp.mag      = freq[i].magnitude;
                    maximas.Add(temp);
                }
            }
        }

        if (maximas.Count > 0)
        {
            maximas.Sort((s1, s2) => s1.mag.CompareTo(s2.mag));
            float    maxFreq = maximas[0].location * freqStep;
            int      closest = (int)FreqToNumber(maxFreq);
            float    closestFreq = NumberToFreq(closest);
            ColorHSV colorA = Colors[closest % 12], colorB;
            if (maxFreq - closestFreq > 0)
            {
                colorB = Colors[(closest + 1) % 12];
            }
            else
            {
                colorB = Colors[(closest - 1) % 12];
            }

            var   mainModule = objectToColorChange.main;
            Color x = ColorHSV.Lerp(colorA, colorB, Mathf.Abs(maxFreq - closestFreq) / maxFreq).ToColor();
            mainModule.startColor = x;
        }
    }
Exemplo n.º 3
0
    // 現在までのオーディオ入力を取得しフレーム情報にデコードしていく
    public void DecodeAudioToTCFrames()
    {
        float[] waveData = new float[1024];
        MasterInput.RetrieveWaveform(FilterType.Bypass, waveData);

        int pos = 0;

        while (pos < waveData.Length)
        {
            int count = CheckAudioSign(waveData, ref pos);

            if (count > 0)
            {
                if (count < bitThreshold)
                {
                    // 「レベル変化までが短い」パターンが2回続くと1
                    if (lastBitCount < bitThreshold)
                    {
                        bitPattern  += "1";
                        lastBitCount = bitThreshold; // 次はここを通らないように
                    }
                    else
                    {
                        lastBitCount = count;
                    }
                }
                else
                {
                    // Long pattern
                    bitPattern  += "0";
                    lastBitCount = count;
                }
            }
        }

        // Almost 1frame length ?
        if (bitPattern.Length >= 80)
        {
            // Finc sync word
            int syncWordIndex = bitPattern.IndexOf(SYNC_WORD);

            if (syncWordIndex > 0)
            {
                // get all bits including sync word
                string timeCodeBits = bitPattern.Substring(0, syncWordIndex + 16);

                if (timeCodeBits.Length >= 80)
                {
                    // get last 80 bits (Timecode signal group)
                    timeCodeBits = timeCodeBits.Substring(timeCodeBits.Length - 80);
                    Debug.Log($"Timecode bots : {timeCodeBits}");

                    OnReceiveTimecode(StringToBitDecoder.decodeBitsToFrame(timeCodeBits));
                }

                bitPattern = bitPattern.Substring(syncWordIndex + 16);
            }
        }

        // パターンマッチしなさすぎてビットパターンバッファ長くなっちゃったら削る
        if (bitPattern.Length > 160)
        {
            bitPattern = bitPattern.Substring(80);
        }
    }