Save recorded audio to file - OpenSL ES - Android -
i'm trying record microphone, add effects, , save file
i've started example native-audio included in android ndk. i'va managed add reverb , play haven't found examples or on how accomplish this.
any , welcome.
opensl not framework file formats , access. if want raw pcm file, open writing , put buffers opensl callback file. if want encoded audio, need own codec , format handler. can use ffmpeg libraries, or built-in stagefright.
update write playback buffers local raw pcm file
we start native-audio-jni.c
#include <stdio.h> file* rawfile = null; int bclosing = 0;
...
void bqplayercallback(slandroidsimplebufferqueueitf bq, void *context) { assert(bq == bqplayerbufferqueue); assert(null == context); // streaming playback, replace test logic find , fill next buffer if (--nextcount > 0 && null != nextbuffer && 0 != nextsize) { slresult result; // enqueue buffer result = (*bqplayerbufferqueue)->enqueue(bqplayerbufferqueue, nextbuffer, nextsize); // other result sl_result_buffer_insufficient, // code example indicate programming error assert(sl_result_success == result); (void)result; // alexc: here write: if (rawfile) { fwrite(nextbuffer, nextsize, 1, rawfile); } } if (bclosing) { // important in callback, on correct thread fclose(rawfile); rawfile = null; } // alexc: end of changes }
...
void java_com_example_nativeaudio_nativeaudio_startrecording(jnienv* env, jclass clazz) { bclosing = 0; rawfile = fopen("/sdcard/rawfile.pcm", "wb");
...
void java_com_example_nativeaudio_nativeaudio_shutdown(jnienv* env, jclass clazz) { bclosing = 1;
...
Comments
Post a Comment