Search Unity

Audio OnAudioFilterRead, after fill data, time is ours?

Discussion in 'Audio & Video' started by april_4_short, Aug 25, 2021.

  1. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    Having filled up the data that OnAudioFilterRead is looking for (presumably by a hidden out or ref nature to this call, can we then use the remaining time until the next call, as we like?

    If so, and we use more time than is available, what happens, and why?
     
  2. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    You're asking whether you can perform additional tasks on the audio mixer thread apart from filtering the audio buffer?

    Yes, you can do whatever you want, but if the call blocks for too long, then you'll get dropouts in the audio signal.
    For off-main-thread tasks that aren't directly related to filtering the audio signal, I'd recommend using normal worker threads or the job system.
     
    april_4_short likes this.
  3. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    I don't yet know how to make my own threads, which is a huge part of my problems.

    And the job system... ouch. That's a harder nut to crack.

    If I don't refill the data array, does the OnAudioFilterArray resort to looking at what's already there, or does it have some kind of flag that knows when it's been refilled/edited and should therefore read from it... but waits it doesn't get that signal?
     
  4. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    The array is the data buffer for the mix. Unity passes it to your
    OnAudioFilterRead
    call, then when that completes, it passes it on to the next thing in the mixer chain, whether you've modified it or not.
     
    april_4_short likes this.