3
$\begingroup$

I'm doing a lot of sound baking at the moment, but it's kind of hard to work with since I don't know what kind of values to expect out of the f-curve.

Common sense would say that it would range from 0 to 1, with 0 being dead silence and 1 being as loud as it gets, but that doesn't seem to be the case. In normal cases, the limit seems to be somewhere below 2, or maybe it is equal to 2, But I haven't been able to find anything in the documentation. The docs on sound_bake() just say:

Bakes a sound wave to selected F-Curves

and don't provide any information on the output, just the parameters.

$\endgroup$
2
$\begingroup$

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.

Baking

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].

modifier settings

The channel, freqA, freqB, min, max, and baketimes

Bake Details

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.

Creating a visualizer

The amplitudes of the fcurves can now be changed on the fly

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.