void Awake() { Instance = this; audioSource = GetComponent <AudioSource>(); if (Microphone.devices.Length == 0) { Debug.LogError("No microphone detected"); this.enabled = false; return; } for (int i = 0; i < Microphone.devices.Length; i++) { Debug.Log("Mic [" + i + "]: " + Microphone.devices[i]); micDeviceName = Microphone.devices[i]; } int minFreq = 1234; int maxFreq = 1234; Microphone.GetDeviceCaps(micDeviceName, out minFreq, out maxFreq); Debug.Log(micDeviceName + " Min Freq: " + minFreq + " // Max Freq: " + maxFreq); audioSource.clip = Microphone.Start( deviceName: micDeviceName, loop: true, lengthSec: 1, frequency: sampleRate ); SetupBuffers(); rmsEventList = new ArrayList(); fftIntervalDataList = new ArrayList(); voxRmsLevels = new float[System.Enum.GetValues(typeof(EVoxType)).Length]; for (int i = 0; i < voxRmsLevels.Length; i++) { string key = ((EVoxType)i).ToString(); if (PlayerPrefs.HasKey(key)) { voxRmsLevels[i] = PlayerPrefs.GetFloat(key); } else { voxRmsLevels[i] = 0; } } }
public void Initialize(MicMonitor micMonitor, Vector3 beginPosition, Vector3 endPosition, float scalar = 1, float lineWidth = 0.1f) { this.micMonitor = micMonitor; micMonitor.processNewMicrophoneBuffer += RenderLightning; this.beginPosition = beginPosition; deltaPosition = endPosition - beginPosition; Vector3 between = beginPosition - endPosition; crossVector = Quaternion.Euler(0, 0, 90) * between; lineRenderer.startWidth = lineWidth; lineRenderer.endWidth = lineWidth; }
private void Start() { monitor = new MicMonitor(); }