Sound Drivers
Been doing a lot of sound baking lately too. You'll find different audio files have different levels, so unless you normalize them first using ffmpeg or similar you will have to find a way to deal with them.
What I have done in sound drivers is added a minmax property to each fcurve and using those values added an envelope modifier. (Had to add the control point code to the python API.. that took a while..)
def fcurve_minmax(self):
# return ((min, max), (min_index, max_index))
# it thru keyframe_points
if len(self.keyframe_points):
col = self.keyframe_points
elif len(self.sampled_points):
col = self.sampled_points
else:
return ((0, 0), (0, 0))
return(driver_minmax(self))
# check for modifiers
mods = [mod for mod in self.modifiers if not mod.mute and mod.is_valid]
if len(mods):
v = [self.evaluate(p.co[0]) for p in col]
else:
v = [p.co[1] for p in col]
_min = min(v)
_max = max(v)
return ((_min, _max), (v.index(_min), v.index(_max)))
bpy.types.FCurve.minmax = property(fcurve_minmax)
After baking, cleaning, smoothing etc I can call
(_min, _max), (min_at_frame, max_at_frame) = fc.minmax
Noticed your other post re driver. I am baking to a set of custom properties on a speaker object. I chose the speaker as it a convenient way to handle sounds and playback, and somewhere to hang the props that doesn't render. These properties are then used to drive animations / create visualisers.
Here is what a 16 channel bake looks like on a small wav file.
You'll notice there are 2 envelope modifiers. One maps each fcurve to its percentage of the maximum action range (Action), the other maps each fcurve across its baked range (Channel) to the mapped range..
Close up of how to set up the modifiers, channel CS8 range [0, 0.246]
and the action from [0, 0.305]
, being mapped to [0, 1]
. Top modifier will map it to [0, 0.246 / 0.305]
the second to [0, 1]
.
The channel, freqA, freqB, min, max, and baketimes
I bake first and last in case there is no level at either end.
Ok now I have baked the animation, I can add a driver to any object(s) drive by channel 0 and create a visualizer. Here is a very simple, and very quick, visualizer on the default cube by animating z-scale with channel0 then selecting grid visualizer.
The amplitudes of the fcurves can now be changed on the fly