L3. LAB 3: ANDROID AUDIO SIGNAL SAMPLING 67
inputBufferFloat = (float *)malloc(buffersize * sizeof(float) *
2 + 128);
leftInputBuffer = (float *)malloc(buffersize * sizeof(float) +
128);
rightInputBuffer = (float *)malloc(buffersize * sizeof(float) +
128);
leftOutputBuffer = (float *)malloc(buffersize * sizeof(float) +
128);
rightOutputBuffer = (float *)malloc(buffersize * sizeof(float) +
128);
SuperpoweredCPU::setSustainedPerformanceMode(true);
new SuperpoweredAndroidAudioIO(samplerate, buffersize, true,
true, audioProcessing, NULL, -1, SL_ANDROID_STREAM_MEDIA,
buffersize * 2);
// Start audio input/output.
}
In the above code, the SuperpoweredAudioIO session is initialized and then in
audioProcessing the audio data are processed. e audio received is interleaved and
it is deinterleaved before processing. After the processing is complete, the audio is inter-
leaved again and stored back in the original buffer audioInputOutput . When true is
returned in the method, it sends the buffer to the speaker.
• Run the app and listen to the audio path. Similar to FIR.c, one can add other audio pro-
cessing algorithms to process audio data.
L3.7 MULTI-THREADING
e audio processing in Android can be run on a separate thread allowing the audio to be pro-
cessed uninterrupted. Any computation that takes more time to run than the minimum allotted
frame time can cause frames to get skipped. e use of Java Virtual Machine ( JVM) allows
having multiple threads in apps. is means that one canoffload processes that do not need to
be run at frame rate to concurrent threads and thus allowing the audio to run without interrup-
tions. Android has a thread class in Java (https://developer.android.com/reference/ja
va/lang/Thread) that allows creating and monitoring threads for concurrently processing data.
As a simple example, let us create a multi-threading app that counts the number of frames
processed by the Superpowered app in the previous section.