L3. LAB 3: ANDROID AUDIO SIGNAL SAMPLING 61
ese functions are blocking—meaning that the program flow will not continue until the desired
amount of audio data has been read into the supplied buffer. e recording loop is shown below:
loop:while(true){
if(isRecording.get()) {
out = recycleQueue.take();
recorder.read(out.getAudio(), 0, Settings.stepSize);
output.put(out);
} else {
output.put(Settings.STOP);
break loop;
}
}
In the reference code, recycleQueue is a BlockingQueue filled with a predetermined number
of WaveFrame objects. e data are then inserted into a WaveFrame structure which are passed
along to a queue for further processing in the Filter class. e output.put function attempts
to insert the frame of audio data into the output queue if there is space available. If the output
queue is full, it will wait to insert the data, effectively pausing the recording process. If the signal
processing takes too long, the internal buffer of the recorder will fill up and cause an exception
to be thrown. When audio recording is finished, the recorder object should be stopped and the
resources released.
e WaveFrame class is mainly used as a helper to convert between data types and store
diagnostic timing. BlockingQueue is configured to store up to ten frames of audio data, as
defined in the Settings.java class by the queueSize variable. ese WaveFrame objects will
remain allocated while the program is running in order to prevent excessive memory allocations
from taking place. Once they get processed and the end of the pipeline is reached, they are
reinserted into the recycling queue for reuse.
L3.4 PROCESSING.JAVA
e code that is responsible for calling the native methods is found in the Processing.java class.
When the app runs, the recorder inserts audio data into the input queue. e Processing class
polls that queue to retrieve a frame of audio data, processes it, and inserts the output data into
the output queue. e loop that accomplishes these is indicated below:
loop:while(true) {
WaveFrame currentFrame = null;
currentFrame = input.take();
if(currentFrame == Settings.STOP) {
output.put(currentFrame);
..................Content has been hidden....................

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