# How to save recorded sound to pcm file (Android)

**URL:** <https://qa.fmod.com/t/how-to-save-recorded-sound-to-pcm-file-android/13745>\
**Category:** FMOD Engine\
**Created:** [March 7, 2018, 7:55am UTC](https://qa.fmod.com/t/how-to-save-recorded-sound-to-pcm-file-android/13745 "2018-03-07T07:55:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yourk](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@yourk](https://qa.fmod.com/u/yourk)\
**Post date:** [March 7, 2018, 7:55am UTC](https://qa.fmod.com/t/how-to-save-recorded-sound-to-pcm-file-android/13745/1 "2018-03-07T07:55:29Z")

</div>

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！

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [March 7, 2018, 8:37am UTC](https://qa.fmod.com/t/how-to-save-recorded-sound-to-pcm-file-android/13745/2 "2018-03-07T08:37:08Z")

</div>

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/](https://www.fmod.org/questions/question/record-and-output-to-wav-file/)

---

<div class="post-metadata">

**Author:** ![yourk](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@yourk](https://qa.fmod.com/u/yourk)\
**Post date:** [March 8, 2018, 1:39am UTC](https://qa.fmod.com/t/how-to-save-recorded-sound-to-pcm-file-android/13745/3 "2018-03-08T01:39:09Z")

</div>

> [@](#):
>
> Check this thread, it has code that writes the sound to a wav file.
> 
> [record and output to .wav file - FMOD Engine - FMOD Forums](https://www.fmod.org/questions/question/record-and-output-to-wav-file/)

Thank you very much, you save my life!
