How to save recorded sound to pcm file (Android)


(yourks) #1

Hello, when I use the demo code “record.cpp” to record sound, it can record, the main code is these:
result = system->createSound(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);

result = system->recordStart(DEVICE_INDEX, sound, true);

But, I need to save sound to pcm file, I have used these code to save to file:
void *ptr1, *ptr2;
unsigned int lenbytes, len1, len2;
sound->lock(0, lenbytes, &ptr1, &ptr2, &len1, &len2);
fwrite(ptr1, lenbytes, 1, fp);
sound->unlock(ptr1, ptr2, len1, len2);

It didn’t works, is someone has met this problem? hope you can tell me how to save sound to file, it is appreciate!


(Brett Paterson) #2

Check this thread, it has code that writes the sound to a wav file.

https://www.fmod.org/questions/question/record-and-output-to-wav-file/


(yourks) #3

Thank you very much, you save my life!