Search Unity

Audio Get Audio Attenuation during Timeline

Discussion in 'Audio & Video' started by HulloImJay, Jul 25, 2020.

  1. HulloImJay

    HulloImJay

    Joined:
    Mar 26, 2012
    Posts:
    89
    I'm looking to control a simple 2D animation based on the attenuation of audio clips being played on an audio source.

    Ordinarily, I'd do something like...
    Code (CSharp):
    1. audioSource.clip.GetData (audioData, audioSource.timeSamples)
    ...and then check the largest value in audioData and use that as the approximate current attenuation. That's crude, but suits my purposes and can be used to flap a mouth to a variety of audio without manual animation work.

    However, it looks like audioSource.clip is never assigned when audio is played using Timeline, even if the audioSource is assigned to the track (this is optional but impacts settings). Does anyone know an alternative approach which would work with Timeline? I really want to avoid adding a new custom Timeline track to control this animation manually.

    Any suggestions welcome :)
     
  2. HulloImJay

    HulloImJay

    Joined:
    Mar 26, 2012
    Posts:
    89
    Silly of me not to have found this earlier: https://docs.unity3d.com/ScriptReference/AudioSource.GetOutputData.html

    Very similar call made to the AudioSource itself WORKS! Automatic mouth-flapping success!

    However, one issue which I suppose is more of a Timeline problem: This call ONLY works at runtime, and returns empty when the Timeline is playing during edit time.