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); captureSize = Visualizer.getCaptureSizeRange()[0]; visualizer.setCaptureSize(captureSize); // capture audio data // Visualizer.OnDataCaptureListener captureListener = ... ...