예제 #1
0
    void OnOutputAnalyzed(MicrophoneFeed.MicrophoneOutput output)
    {
        // track volume
        volumeSequence.Add(output.volume);
        if (volumeSequence.Count() > VOLUME_THRESHOLD_SAMPLES)
        {
            volumeSequence.RemoveAt(0);
        }
        // count average volume

        RawVolumeEvent?.Invoke(volumeSequence.Average());

        if (IsOverVolumeThreshold && volumeSequence.Average() < volumeThreshold)
        {
            // flip if volume sequence goes under
            IsOverVolumeThreshold = false;
            ThresholdEnd?.Invoke();
        }

        if (!IsOverVolumeThreshold && volumeSequence.Average() > volumeThreshold)
        {
            // flip if volume sequence goes under
            IsOverVolumeThreshold = true;
            ThresholdStart?.Invoke();
        }

        var detectedNote = mapOutputsToNote(outputs);

        // track output cycle if we are over volume threshold
        if (IsOverVolumeThreshold)
        {
            outputs.Add(output);
        }

        /*
         * Debug.Log(new
         * {
         *  noteName = detectedNote.NoteName,
         *  musical = pitchToMusicalNote(output.pitch),
         *  volume = output.volume,
         *  IsOverVolumeThreshold,
         * });*/
    }
예제 #2
0
    void MicrophoneFeed_OutputAnalyzed(MicrophoneFeed.MicrophoneOutput output)
    {
        var sensitivity      = SequenceDetector.Instance.sensitivityValue;
        var range            = 1 - Mathf.Clamp01(sensitivity) * 0.5f;
        var volumePercentage = output.volume / range;

        var distortionAmount = distortionByVolume.Evaluate(volumePercentage);

        if (volume.profile.TryGetSettings(out distortion))
        {
            if (distortionAmount > 0)
            {
                distortion.enabled.value   = true;
                distortion.intensity.value = -distortionAmount;
            }
            else
            {
                distortion.enabled.value = false;
            }
        }
    }