Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom "OnAudioFilterRead" Audio - Not Panned?

Discussion in 'Audio & Video' started by PhobicGunner, Feb 22, 2016.

  1. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Hello. Working on a custom audio system in Unity and noticed something a bit strange. When I generate custom audio data via OnAudioFilterRead, the sound properly fades with distance when set to 3D, but it does not pan. When set to 2D, the pan slider does nothing whatsoever.

    Is this supposed to be intended behavior? My understanding was that if there was no audio clip and my custom script was first in the chain, it would be "played" as if it was an audio clip. It's going to kind of suck if I have to manually calculate panning myself... lots of switch/case code for handling mono vs stereo vs surround sound setups. Would rather let Unity do that for me if at all possible.
     
  2. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    OK, so I finally got around this by generating an audio clip at runtime which is just filled with 1.0f. Then my filter actually reads the first number of samples from the destination array as defined by number of channels, and uses those values as a per-channel gain. Now it supports distance AND panning. Yay! The one thing it doesn't support is doppler, which is OK since I can probably just figure out how to calculate that myself and apply a pitch/time multiplier in my own code.
     
  3. Rom1

    Rom1

    Joined:
    Mar 17, 2013
    Posts:
    2
    Hi there,
    I'm new to audio programming but eager to learn.
    I understand your solution for the panning problem is a good one, but i don't get how it work and how to implement it. I've searched the internet in vain.
    Could you tell me more?
    Since i still don't quite get how everything work i don't know :
    -if i have to make two differents filters (one with my pink noise and one with the 1f), or everything in the same OnAudioFilterRead function.
    -How to multiply those

    Thanks for your help!
     
  4. Rom1

    Rom1

    Joined:
    Mar 17, 2013
    Posts:
    2
    Nevermind i found it!