示例#1
0
    public void InitializeNote(GameObject thresholdSliderPanel, GameObject thresholdSliderParent, SoundAnalyzer soundAnalyzer, int minFramesBeforRegister, int minRetriggerTimeoutFrames, float minRetriggerLevel)
    {
        // This function is executed after loading or creating of notes
        this.thresholdSliderPanel      = thresholdSliderPanel;
        this.thresholdSliderParent     = thresholdSliderParent;
        this.soundAnalyzer             = soundAnalyzer;
        this.numberOfValuesToAverage   = minFramesBeforRegister;
        this.minRetriggerTimeoutFrames = minRetriggerTimeoutFrames;
        this.minRetriggerLevel         = minRetriggerLevel;

        // The thresholdSliderParent has just been created, therefore set a usefull name
        thresholdSliderParent.name = caption + " " + " Threshold Slider";

        // Also set an initial position within the valid range
        SetThresholdSliderParentPosition();

        // And get the references to the slider and the background that we use as sound level
        thresholdSlider = thresholdSliderParent.GetComponentInChildren <Slider>();
        thresholdBackgroundPanelImage = thresholdSliderParent.transform.GetChild(0).transform.GetComponent <Image>();

        // We need set the maxValue to thresholdValue * 1.5f that there is some way to increase the thresholdValue with the slider
        this.maxValue            = thresholdValue * 1.5f;
        thresholdSlider.maxValue = thresholdValue * 1.5f;
        thresholdSlider.value    = thresholdValue;

        // Also we need to attach a listener to the notes slider
        thresholdSlider.onValueChanged.AddListener(delegate {
            TresholdSliderValueChanged(thresholdSlider);
        });

        values = new Queue <float>();
    }
示例#2
0
    void Update()
    {
        // 基本周波数の取得
        float freq = SoundAnalyzer.GetFundamentalFrequency(mic);

        // マイク秒数の取得
        int now = (int)(mic.time * 100.0f);

        // 基本周波数の描画
        int vertexCount       = now % NumTimes;
        int beforeVertexCount = beforeTime % NumTimes;

        if (vertexCount < beforeVertexCount)
        {
            // 表示がループした時は、頂点0から描画を開始
            beforeVertexCount = 0;
        }
        lineRenderer.SetVertexCount(vertexCount);
        for (int i = beforeVertexCount; i < vertexCount; i++)
        {
            float x = PositionTime + i * RateTime / NumTimes;
            float y = PositionHertz + freq * RateHertz / (AudioSettings.outputSampleRate / 2.0f);
            lineRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        beforeTime = now;
    }
示例#3
0
    void Start()
    {
        buffer        = new float[nSamples];
        fs            = AudioSettings.outputSampleRate;
        soundAnalyzer = new SoundAnalyzer(fs);

        SetMicrophone();
    }
示例#4
0
    //IEnumerator DetectClap(bool result)
    //{

    //    while(true)
    //    {
    //        result = SAnalyzer.isClap;
    //        yield return null;
    //    }
    //}

    private void Awake()
    {
        _dataSet  = FindObjectOfType <MetronomeDataSet>();
        SAnalyzer = GetComponent <SoundAnalyzer>();
        //decisionimage.color = new Color(1, 1, 1);
        defColor     = new Color(1, 1, 1);
        correctColor = new Color(0, 1, 0);
        wrongColor   = new Color(1, 0, 0);
    }
示例#5
0
    void Update()
    {
        List <KeyValuePair <float, float> > spectrum = SoundAnalyzer.GetSpectrumData(file);

        // 対数振幅スペクトルの描画
        lineRenderer.SetVertexCount(spectrum.Count);
        for (int i = 0; i < spectrum.Count; i++)
        {
            float x = PositionHertz + i * RateHertz / spectrum.Count;
            float y = PositionPower + RatePower * (float)Math.Log(spectrum[i].Value + 1.0);
            lineRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        Debug.Log(SoundAnalyzer.GetFundamentalFrequency(file));
    }
示例#6
0
    public void SetThresholdSliderParentPosition()
    {
        // Update the notes threshold slider position according to the lower bound, the upper bound and the width of the parent container
        Vector3 localPosition  = thresholdSliderParent.GetComponent <RectTransform>().anchoredPosition;
        float   containerWidth = thresholdSliderPanel.GetComponent <RectTransform>().rect.width;

        // Map the lower and upper bounds to positions
        float lowerPos = SoundAnalyzer.MapRange(lowerBound, 0, 512, 0, containerWidth);
        float upperPos = SoundAnalyzer.MapRange(upperBound, 0, 512, 0, containerWidth);

        // Then calculate the center of these two positions
        localPosition.x = lowerPos + ((upperPos - lowerPos) / 2);

        // Finally set the slider to this center
        thresholdSliderParent.GetComponent <RectTransform>().anchoredPosition = localPosition;
    }
示例#7
0
    void Update()
    {
        // 対数振幅スペクトルの描画
        List <KeyValuePair <float, float> > spectrum = SoundAnalyzer.GetSpectrumData(mic);
        LineRenderer FFTRenderer = FFTObject.GetComponent <LineRenderer>();

        FFTRenderer.SetVertexCount(spectrum.Count);
        for (int i = 0; i < spectrum.Count; i++)
        {
            float x = PositionTime + i * RateFFTHertz / spectrum.Count;
            float y = PositionHertz + RateFFTPower * (float)Math.Log(spectrum[i].Value + 1.0);
            FFTRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        // 基本周波数の取得
        float freq = SoundAnalyzer.GetFundamentalFrequency(mic);

        // マイク秒数の取得
        int now = (int)(mic.time * 100.0f);

        // 基本周波数の描画
        int vertexCount       = now % NumTimes;
        int beforeVertexCount = beforeTime % NumTimes;

        if (vertexCount < beforeVertexCount)
        {
            // 表示がループした時は、頂点0から描画を開始
            beforeVertexCount = 0;
        }
        lineRenderer.SetVertexCount(vertexCount);
        for (int i = beforeVertexCount; i < vertexCount; i++)
        {
            float x = PositionTime + i * RateTime / NumTimes;
            float y = PositionHertz + freq * RateHertz / (AudioSettings.outputSampleRate / 2.0f);
            lineRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        beforeTime = now;
    }