# Detect Starvation in DSP

**URL:** <https://qa.fmod.com/t/detect-starvation-in-dsp/20998>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [December 15, 2023, 9:08am UTC](https://qa.fmod.com/t/detect-starvation-in-dsp/20998 "2023-12-15T09:08:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xhento](https://avatars.discourse-cdn.com/v4/letter/x/ea5d25/32.png) [@Xhento](https://qa.fmod.com/u/Xhento)\
**Post date:** [December 15, 2023, 9:08am UTC](https://qa.fmod.com/t/detect-starvation-in-dsp/20998/1 "2023-12-15T09:08:20Z")

</div>

Hello! Im programming an ingame recording software. While video recording is working perfectly the audio isn’t. Our loading screen has incredible heavy CPU usage and game freezes sometimes, this produces Starvation ( [FMOD] OutputWASAPI::mixerThread : Starvation detected in WASAPI output buffer!) which results in shorter audio files. Is there any way to guarantee this starvation dont happen or even detect this starvation and how it affects the final audio file output?  
Thanks in advance.

The code of my DSP is this

```auto
[MonoPInvokeCallback(typeof(DSP_READ_CALLBACK))]
        private static RESULT CaptureDSPReadCallback(ref DSP_STATE dspState, IntPtr incomingBuffer, IntPtr outputBuffer, uint length,
            int incomingChannels, ref int outputChannels)
        {
            DSP_STATE_FUNCTIONS functions = (DSP_STATE_FUNCTIONS)Marshal.PtrToStructure(dspState.functions, typeof(DSP_STATE_FUNCTIONS));
            functions.getuserdata(ref dspState, out IntPtr userData);

            GCHandle objHandle = GCHandle.FromIntPtr(userData);

            if (objHandle.Target is BugRecorder bugRecorder)
            {
                // Save the channel count out for the update function
                bugRecorder._channels = incomingChannels;

                // Copy the incomingBuffer to process later
                int bufferLength = (int)length * incomingChannels;
                Marshal.Copy(incomingBuffer, bugRecorder._audioFrameDataBuffer, 0, bufferLength);

                // Copy the incomingBuffer to the outputBuffer so we can still hear it
                Marshal.Copy(bugRecorder._audioFrameDataBuffer, 0, outputBuffer, bufferLength);

                if (bugRecorder._isRecording)
                {
                   bugRecorder.WriteAudioSampleToDisk(bugRecorder._audioFrameDataBuffer, bufferLength);
                }

                return RESULT.OK;
            }

            return RESULT.ERR_INTERNAL;
        }

```

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [December 17, 2023, 9:44pm UTC](https://qa.fmod.com/t/detect-starvation-in-dsp/20998/2 "2023-12-17T21:44:44Z")

</div>

Hi,

What version of FMOD are you using? Could you record a [Profiler](https://fmod.com/docs/2.02/studio/profiling.html) session and upload it to your [profile](https://fmod.com/profile) with the following settings:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/ac3f88c8c292bc57e8d1f29d78a0c33e3a74337e.png)  
Please note you will have to register a project with us before you can upload files.

Instructions for connecting Live Update to Unity can be found here: [Unity Integration | User Guide - Connecting Live Update](https://fmod.com/docs/2.02/unity/user-guide.html#connecting-using-live-update).
