# Retrieving bytes from recorded data

**URL:** <https://qa.fmod.com/t/retrieving-bytes-from-recorded-data/12302>\
**Category:** FMOD Engine\
**Created:** [February 11, 2016, 11:55am UTC](https://qa.fmod.com/t/retrieving-bytes-from-recorded-data/12302 "2016-02-11T11:55:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BasV](https://avatars.discourse-cdn.com/v4/letter/b/edb3f5/32.png) [@BasV](https://qa.fmod.com/u/BasV)\
**Post date:** [February 11, 2016, 11:55am UTC](https://qa.fmod.com/t/retrieving-bytes-from-recorded-data/12302/1 "2016-02-11T11:55:48Z")

</div>

Hi everyone,

I’m using FMOD to create a custom voice chat system for UE4, and part of this is encoding and transfering the sound data over the network. So far, I’ve studied the low-level examples of FMOD and I’m successfully recording data into a stream.  
I’m not too savvy when it comes to audio data and codecs, so I hope someone can point me in the right direction doing the following things:

1. 

Like in record.cpp, I’m recording the mic’s sound into a FMOD::Sound. I wish to encode this data using the Opus codec. UE4’s opus encoder initializes by passing it a sample rate and the number of channels, both of which are known from the recording device. For the encoding itself it needs:

const uint8\* RawPCMData

Is this what I get from FMOD:🔉:readData? How do I know how many bytes to read from my FMOD::Sound? I want to read the latest added recording data. (So, recordDelta in record.cpp)

1. 

After I have my encoded data, do I have to decode it or can FMOD play encoded Opus data?

Thanks for the help!

Bas

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [February 15, 2016, 9:00pm UTC](https://qa.fmod.com/t/retrieving-bytes-from-recorded-data/12302/2 "2016-02-15T21:00:33Z")

</div>

The API you would use to get the audio out of the FMOD::Sound object is Sound::lock and Sound::unlock.  
You can use the record position to know where FMOD is writing to and copy data out behind that position, please note that this is a ring buffer.

You can control the format of the recorded audio via FMOD\_SOUND\_FORMAT, I’m not familiar with the requirements of the UE4 encoder, but it should be documented somewhere. PCM16 is fairly common.

FMOD does not support decoding Opus, you would need to develop a custom FMOD codec to perform this step (or decode it yourself and feed it to FMOD).
