How to control scene lighting based on amplitude of AudioSource?

Hi!

In my game I want to control scene lightning based on player’s heartbeat (amplitude of heartbeat sound). My idea was find all max and min amplitudes in curve of heartbeat sound (I grabbed sound samples with method AudioClip.GetData), found all max and min values and after that during playing of sound in Update method I’m checking if current sample is equal to founded max and min values (for getting index of current sample I used method AudioSource.timeSamples) and based on that fade in or faded out scene lightning. But this solution looks isn’t very reliable. Is there some better solution how do that? Is possible to add listeners on max and min samples of sound curve? Thank you for any ideas and advices.

Hm, you can do it during the runtime, adjusting settings at any given instance:

look at the pitch and as long as u have an array of light references in your script, you can set the brightness / color based on the sound.

Or access the volume. Check out all the variables in here (including pitch, volume, etc)