# Accessing samples from fmod recording buffer (Unity)

**URL:** <https://qa.fmod.com/t/accessing-samples-from-fmod-recording-buffer-unity/21447>\
**Category:** Unity\
**Created:** [April 3, 2024, 11:59pm UTC](https://qa.fmod.com/t/accessing-samples-from-fmod-recording-buffer-unity/21447 "2024-04-03T23:59:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozey](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@ozey](https://qa.fmod.com/u/ozey)\
**Post date:** [April 3, 2024, 11:59pm UTC](https://qa.fmod.com/t/accessing-samples-from-fmod-recording-buffer-unity/21447/1 "2024-04-03T23:59:39Z")

</div>

Is there any example of accessing samples from the buffer that fmod records in?  
ive been looking at this example: [examples-record](https://fmod.com/docs/2.02/unity/examples-record.html)  
but this just routs the recorded signal straight into the output. i’m interested in getting the samples as small buffers for further computation, so far ive been using this:

```auto
recSound.@lock(byteOffset, lengthInBytes, out dataPtr1, out dataPtr2, out length1, out length2);

            // Copy from the first block of data
            if (dataPtr1 != IntPtr.Zero && length1 > 0)
            {
                Marshal.Copy(dataPtr1, audioData, 0, (int)length1);
            }

            // If there's a second block of data due to wrap-around, copy it immediately after the first block
            if (dataPtr2 != IntPtr.Zero && length2 > 0)
            {
                Marshal.Copy(dataPtr2, audioData, (int)length1, (int)length2); 
            }
            // Unlock the sound object
            recSound.unlock(dataPtr1, dataPtr2, length1, length2);

```

this is inside my update() but the audio buffer i’m getting is just filled with zeros ☹  
(ive confirmed my mic works with fmod and unity with the official record example i linked to earlier)

i can’t find anything online except this one forum post:  
[Accessing real-time audio samples of incoming mic capture via DSPCallback](https://qa.fmod.com/t/accessing-real-time-audio-samples-of-incoming-mic-capture-via-dspcallback/18467)

do i need to use the DSPCallback for this?

Thanks for reading 🙂

---

<div class="post-metadata">

**Author:** ![ozey](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@ozey](https://qa.fmod.com/u/ozey)\
**Post date:** [April 8, 2024, 1:19pm UTC](https://qa.fmod.com/t/accessing-samples-from-fmod-recording-buffer-unity/21447/2 "2024-04-08T13:19:34Z")

</div>

I narrowed the problem down to my global sound object becoming invalid as soon as the code leaves the method where i create it. whenever i try do do something with the sound object outside the method i create it in i get this error: ERR\_INVALID\_PARAM  
I have the object declared globally though so it should be accessible and valid, right?

---

<div class="post-metadata">

**Author:** ![ozey](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@ozey](https://qa.fmod.com/u/ozey)\
**Post date:** [April 8, 2024, 1:45pm UTC](https://qa.fmod.com/t/accessing-samples-from-fmod-recording-buffer-unity/21447/3 "2024-04-08T13:45:21Z")

</div>

Nevermind, i redeclared the variable in the createSound() method therefore overriding it locally and invalidating the global variable:

```auto
FMOD.RESULT result = FMODUnity.RuntimeManager.CoreSystem.createSound("", FMOD.MODE.OPENUSER | FMOD.MODE.LOOP_NORMAL, ref soundInfo, out FMOD.Sound recSound);

```

this is what i changed it to:

```auto
FMOD.RESULT result = FMODUnity.RuntimeManager.CoreSystem.createSound("", FMOD.MODE.OPENUSER | FMOD.MODE.LOOP_NORMAL, ref soundInfo, out recSound);

```

I feel very dumb right now 😅

I’ll leave this thread here, maybe it helps someone.

Cheers 🙂

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [April 9, 2024, 12:27am UTC](https://qa.fmod.com/t/accessing-samples-from-fmod-recording-buffer-unity/21447/4 "2024-04-09T00:27:35Z")

</div>

Happy to hear that you managed to resolve the issue.
