Last active
September 11, 2026 23:54
-
-
Save cgsdev0/5fe89c713160a2da4b8656455f7afae0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int latency = AudioSettings.outputSampleRate / 10; | |
| AudioClip clip = Microphone.Start(device, true, 1, AudioSettings.outputSampleRate); | |
| int last = 0; | |
| int dist(int samples, int start, int end) { | |
| if (end >= start) return end - start; | |
| return (end + samples) - start; // handle wrapping | |
| } | |
| while(true) { | |
| int current = Microphone.GetPosition(device); | |
| int delta = dist(clip.samples, last, current); | |
| if (delta > latency) { | |
| // get a sample | |
| clip.GetData(data, last); | |
| last = current; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment