Waveform data capture

As mentioned earlier, the Android Visualizer class lets us define callbacks to capture audio data. This data comes in two formats: waveform and FFT. We'll add just the waveform data to the VisualizerBox class now.

First, define the variables that we'll use for the captured audio data, as follows:

    Visualizer visualizer;
    public static int captureSize;
    public static byte[] audioBytes;

Using the API, we can determine the minimum capture size available, and then use that as our capture sample size.

Then, initialize them in the constructor as follows. First, instantiate an Android Visualizer. Then set the capture size to use, and allocate our buffers:

 public VisualizerBox(final CardboardView cardboardView){ visualizer = new Visualizer(0); ...

Get Cardboard VR Projects for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.