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

Audio When are changes to AudioSource.volume propagated to the AudioSource?

Discussion in 'Audio & Video' started by simtrip, Dec 17, 2020.

  1. simtrip

    simtrip

    Joined:
    Oct 18, 2016
    Posts:
    4
    Hi,

    Pretty simple question but I've not seen this answered in the docs or previous thread yet.

    I'm struggling to figure out at what point setting the
    AudioSource.volume
    property actually takes effect. If I were to set the volume of an
    AudioSource
    multiple times over a frame which happened to be perceptibly long enough that you would hear volume changes in that time, is the property's value taking effect instantaneously or at the end of the frame?

    For context - I've been looking at ways to make cleaner fades in Unity, particularly in situations where you may want to rapidly fade audio at a faster rate than the game's framerate (lets say for rapid crossfades that may only be 2-3 frames at 60FPS, you don't want harshly stepped volume values.) I understand that MixerGroups are a good solution to this, or in some cases you could use
    OnAudioFilterRead
    for sample-level accuracy, and I'm fairly close to using one of those methods.

    However, I was also toying with the idea of somehow being able to set
    AudioSource.volume
    in a way that responds to the DSP clock. I've noticed that this clock reports different values on the same frame (if the frame happens to take a long time for instance) so it seems like there's potential there, although how you would schedule this within a frame is something I haven't gotten into yet.

    Thanks