How process audio while recording realtime on android?


(flyswan) #1

I want to process audio stream add some custom dsp while recording real time.
I can only see api for play or convert a file?
Could someone help me or show me some example ?

#android


(Cameron Baron) #2

Have you had a look at our ‘Record’ project in the Lowlevel examples?

This example shows how to record continuously and play back the same data while, although the recording it does is from a microphone.

You might have to make your own dsp that writes out to a file, see the DSP_Custom example. This would allow you to add the write-to-file dsp after your custom dsp to get the final sound with the DSP effect.


(flyswan) #3

Thanks for your anserwer!

I have mentioned the record demo in low level examples. It’s record via fmod system record api.

Now my impletation is recording via android original AudioRecord.startRecording api, and set listener via AudioRecord.setRecordPositionUpdateListener, and then read buffer when onPeriodicNotification called, and save buffer to my record audio file.

What I want to do is process the buffer via adding fmod dsp in onPeriodicNotification before the buffer written into file?

Here is my code:
private AudioRecord audioRecorder = new AudioRecord(AudioSource.MIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
private byte[] buffer;
audioRecorder.setRecordPositionUpdateListener(updateListener);
private AudioRecord.OnRecordPositionUpdateListener updateListener = new AudioRecord.OnRecordPositionUpdateListener() {
@Override
public void onPeriodicNotification(AudioRecord recorder) {
audioRecorder.read(buffer, 0, buffer.length); // Fill buffer
//TODO: process buffer here via fmod dsp
try {
randomAccessWriter.write(buffer); // Write buffer to file
} catch (IOException e) {
Log.e(tag,“Error occured in updateListener, recording is aborted”);
}
}