# How do I record audio to file?(Android)

**URL:** <https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730>\
**Category:** FMOD Engine\
**Created:** [March 1, 2018, 5:26am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730 "2018-03-01T05:26:39Z")\
**Posts on this page:** 7\
**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 1, 2018, 5:26am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/1 "2018-03-01T05:26:39Z")

</div>

I used the following method to write butter to a file, but the file is corrupt. How can I solve it?  
sound -\>readData(&irData[1], irdatalength-sizeof (short), &irDataRead);  
Fwrite (& irData [1], irDataLength, sizeof (short), FPW);

---

<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 1, 2018, 5:36am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/2 "2018-03-01T05:36:01Z")

</div>

> [@](#):
>
> I used the following method to write butter to a file, but the file is corrupt. How can I solve it?  
> sound -\>readData(&irData[1], irdatalength-sizeof (short), &irDataRead);  
> Fwrite (& irData [1], irDataLength, sizeof (short), FPW);

Do you need to set system-\>setOutput(FMOD\_OUTPUTTYPE\_WAVWRITER)？  
But if you set up the FMOD\_OUTPUTTYPE\_WAVWRITER, you will not be able to run.

---

<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 1, 2018, 9:29am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/3 "2018-03-01T09:29:44Z")

</div>

How does the FMOD\_OUTPUTTYPE\_OPENSL mode output sound to a file?

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [March 4, 2018, 10:58pm UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/4 "2018-03-04T22:58:51Z")

</div>

To access the data from a recorded sound, you are best off using Sound::lock & Sound::unlock.  
[https://fmod.com/resources/documentation-api?page=content/generated/FMOD\_Sound\_Lock.html#/](https://fmod.com/resources/documentation-api?page=content/generated/FMOD_Sound_Lock.html#/)

The data from FMOD should not corrupt the file, it would be more likely to do with the writing of the file. eg. Make sure the file is being closed after writing to it.

---

<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 5, 2018, 1:31am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/5 "2018-03-05T01:31:11Z")

</div>

> [@](#):
>
> To access the data from a recorded sound, you are best off using Sound::lock & Sound::unlock.  
> [https://fmod.com/resources/documentation-api?page=content/generated/FMOD\_Sound\_Lock.html#/](https://fmod.com/resources/documentation-api?page=content/generated/FMOD_Sound_Lock.html#/)
> 
> The data from FMOD should not corrupt the file, it would be more likely to do with the writing of the file. eg. Make sure the file is being closed after writing to it.

Is there a simple learning example?

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [March 5, 2018, 1:46am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/6 "2018-03-05T01:46:18Z")

</div>

At the moment we don’t have any examples using lock/unlock, although we are planning on adding some.

It just needs to be used in place of system-\>readData().  
ReadData will attempt to decode the data, store it in memory and internally call system-\>lock() to get the data buffer. If you are trying to access the recorded data, before it is written to file, it does not need to be decoded.

---

<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 5, 2018, 2:50am UTC](https://qa.fmod.com/t/how-do-i-record-audio-to-file-android/13730/7 "2018-03-05T02:50:18Z")

</div>

Thank you for your help. Now I still don’t understand the specific process. Could you please write the main steps?
