# Adding DSP Causes WASAPI Starvation

**URL:** <https://qa.fmod.com/t/adding-dsp-causes-wasapi-starvation/16393>\
**Category:** FMOD Engine\
**Created:** [November 2, 2020, 2:47pm UTC](https://qa.fmod.com/t/adding-dsp-causes-wasapi-starvation/16393 "2020-11-02T14:47:27Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![niccoloabate](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@niccoloabate](https://qa.fmod.com/u/niccoloabate)\
**Post date:** [December 12, 2023, 11:35pm UTC](https://qa.fmod.com/t/adding-dsp-causes-wasapi-starvation/16393/22 "2023-12-12T23:35:59Z")

</div>

Just as a follow up: it seems the errors periodically happen even while simply just letting the game play in the editor.

This happens with the code from [https://www.fmod.com/docs/2.02/unity/examples-dsp-capture.html](https://www.fmod.com/docs/2.02/unity/examples-dsp-capture.html) so I don’t think it comes from any coding error, unless the example is incorrect.

---

<div class="post-metadata">

**Author:** ![30to1](https://avatars.discourse-cdn.com/v4/letter/3/db5fbb/32.png) [@30to1](https://qa.fmod.com/u/30to1)\
**Post date:** [August 4, 2024, 2:00pm UTC](https://qa.fmod.com/t/adding-dsp-causes-wasapi-starvation/16393/23 "2024-08-04T14:00:26Z")

</div>

I’m getting the starvation warning from the following code run in unity specifically on ending playmode. No actual audio needs to be played.

```auto

using System;
using FMOD;
using FMODUnity;
using UnityEngine;

class ExactExample : MonoBehaviour
{
  private DSP mCaptureDSP;
  private uint mBufferLength;
  private int mChannels = 0;
  
  void Start()
  {
    
    DSP_DESCRIPTION desc = new DSP_DESCRIPTION
    {
      numinputbuffers = 1,
      numoutputbuffers = 1,
      // most other callbacks will not produce the starvation warning
      // although process callback fires a raw exception even when empty
      read = CaptureDSPReadCallback 
    };

    RuntimeManager.CoreSystem.getMasterChannelGroup( out var masterCG );
    RuntimeManager.CoreSystem.createDSP( ref desc, out mCaptureDSP );
    masterCG.addDSP( 0, mCaptureDSP );
  }

  [AOT.MonoPInvokeCallback( typeof(DSP_READ_CALLBACK) )]
  static RESULT CaptureDSPReadCallback( ref DSP_STATE dsp_state, IntPtr inbuffer, IntPtr outbuffer, uint length, int inchannels, ref int outchannels )
  {
    return RESULT.OK;
  }

  private void OnDisable()
  {
    if( mCaptureDSP.hasHandle() )
    {
      if( RuntimeManager.CoreSystem.getMasterChannelGroup( out var channelGroup ) == RESULT.OK ) 
        channelGroup.removeDSP( mCaptureDSP );
      
      mCaptureDSP.release();
      mCaptureDSP.clearHandle();
    }
  }
}

```

If the read callback is set, the warning will fire when exiting playmode.

I’ve tried a bunch of variations. None will prevent the warning on shutdown.

Worth noting that assigning the **process** callback will throw a marshal type exception and lock the editor:

```auto

  [AOT.MonoPInvokeCallback( typeof(DSP_PROCESS_CALLBACK) )]
  private RESULT ProcessCallback( ref DSP_STATE dsp_state, uint length, ref DSP_BUFFER_ARRAY inbufferarray, ref DSP_BUFFER_ARRAY outbufferarray, bool inputsidle, DSP_PROCESS_OPERATION op )
  {
    return RESULT.OK;
  }

.....
MarshalDirectiveException: Structure field of type Int32[] can't be marshalled as LPArray
  at (wrapper native-to-managed) ExactExample.ProcessCallback(FMOD.DSP_STATE&,uint,FMOD.DSP_BUFFER_ARRAY&,FMOD.DSP_BUFFER_ARRAY&,int,FMOD.DSP_PROCESS_OPERATION)

```

Super annoying.

Am I doing something incredibly wrong here or is this just a bug in fmod’s unity api?

EDIT:  
Tested with an older project and the starvation warning does not happen with 2.02.15 it does happen with 2.02.22.

---

<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:** [October 11, 2024, 4:21am UTC](https://qa.fmod.com/t/adding-dsp-causes-wasapi-starvation/16393/25 "2024-10-11T04:21:18Z")

</div>

For anyone following this response follow through to [Adding signal DSP causes starvation - Unity - FMOD Forums](https://qa.fmod.com/t/adding-signal-dsp-causes-starvation/22011)

[Previous page](https://qa.fmod.com/t/adding-dsp-causes-wasapi-starvation/16393.md?page=1)
