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.
68 4. ANALOG-TO-DIGITAL SIGNAL CONVERSION
First, create a hook to the TextView on the main page of the GUI via assigning an id to
it. is can be done by going to activity_main.xml and adding the following code line to
the TextView layout:
android:id=''@+id/mainactivityTextView''
After providing the TextView with an id, instantiate it in the MainActivity.java file by
adding the following code line in the MainActivity class:
TextView mainActivityTv;
and linking it with the GUI element by adding the following code line in the onCreate
function:
mainActivityTv = (TextView) findViewById(R.id.mainActivityTextView);
To update the TextView with the number of frames that are processed, a JNI function
needs to be created. In the FrequencyDomain.cpp, create this static global variable
static int frameCount = 0;
and update it in the audioProcessing function this way
frameCount++;
e frameCount variable can be accessed via TextView by creating the following JNI
function:
extern ``C''
JNIEXPORT jint JNICALL
Java_com_superpowered_frequencydomain_MainActivity_GetFrameCount(
JNIEnv*env, jobject instance) {
return frameCount;
}
After the JNI function is created, declare it as a native function in the MainActivity.java
file in the MainActivity class as noted below:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.160.156