Accessing samples from fmod recording buffer (Unity)

Is there any example of accessing samples from the buffer that fmod records in?
ive been looking at this example: examples-record
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:

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 :frowning:
(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

do i need to use the DSPCallback for this?

Thanks for reading :slight_smile:

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?

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

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:

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

I feel very dumb right now :sweat_smile:

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

Cheers :slight_smile:

Happy to hear that you managed to resolve the issue.