googlevr / tilt-brush-toolkit

Scripts and assets that help you use Tilt Brush data in your creative projects.
Apache License 2.0
737 stars 164 forks source link

Mic/line-in input for audio reactive brushes #22

Closed ibilab closed 5 years ago

ibilab commented 6 years ago

Hi there! I'd like to use my computer line in input as an audio source for the TiltBrush Audio Reactive prefab. I'm aware it uses Keijiro Reaktion which uses mic input (so it should be possible) but just don't know how to modify the Tiltbrush script, my scripting knowledge is quite limited. Could you point me a solution?

Thanks!

supkidrobot commented 5 years ago

I would like an answer to ibilab's question, as well.

I'll try diving into it myself to see what I can do, but my scripting experience is also limited

dubois commented 5 years ago

Tilt Brush Toolkit handles the audio processing (using Reaktion, among other things), but you are responsible for getting the audio data to process.

The Toolkit sample code illustrates what Tilt Brush does internally -- it takes audio data from (essentially) your computer's line out. Once you have figured out how to get at line-in or microphone data, what you want to do is replace line 40 of VisualizerAudioInput.cs:

  void Update() {
    if (m_Active) {
      // Get audio data from Unity (Hint: replace this with your own!)
      AudioListener.GetOutputData(m_WaveformFloats, 0);

      // Send audio data to be processed into the shaders
      VisualizerManager.m_Instance.ProcessAudio(m_WaveformFloats, AudioSettings.outputSampleRate);
    }
  }

Since you say Reaktion can do that, probably you can use that code as a reference. Or, check out Unity's Microphone and AudioClip classes.