I am working on an audio visualization generated by a script. I am programmatically creating a grid of hexagons that will each have a different range of frequencies baked to it. My question doesn't involve the hexagons, so I removed that part of my script. My method involves baking the sound to a custom property on each object so you can access the value through a driver on different properties (Location, Scale, Color, etc).
I can run the script safely creating only 2 objects. The custom properties and drivers are created, and the cubes react accordingly. But if I set my number_of_cubes
variable to more than 2, the values generated from bpy.ops.graph.sound_bake()
get really weird.
On the first 5 frames of my animation using only 3 objects, here are the values
And here is the graph editor for those frames. (Notice the vertical scale)
So I can safely assume that the baking is generating values too high for Blender to handle (-1.#IND being not a number). Because of the crazy baked values, the drivers fail and Blender crashes if you try to play the animation or change the frame. So in the script I commented out the lines
#add_driver_prop(obj, 'location', 2, '["audio_data"]', "data * " + str(multiplier))
#add_driver_prop(obj, 'scale', 2, '["audio_data"]', "data * " + str(multiplier))
so the drivers are not added. So why can't Blender handle baking to fcurves more than twice in the script? I watched the CGCookie tutorial on audio baking a few years ago, and referenced it again recently, but I can't see any difference in their methods that would make mine faulty.
I have already ruled out:
- Hardware. I tried this at home and at school on different machines
- Drivers. I disabled them and the fcurves are still going crazy. But at least Blender doesn't crash anymore.
- Weird values for the low and high frequencies. If you divide by 3 (number of cubes), the low and high frequencies become 0.0 and 33333.33333333333336 for the first cube. Dividing by 4 creates nice even numbers, but the problem persists.
Here is my script. Make sure the .blend file is saved and the audio path is relative to the .blend, or it won't work.
Here is the audio I am using. I have tried it with other songs, but it doesn't work with those either.
I have also attempted to enter the high frequency manually (I left the low at 0.0). Here are the values that did not work:
- 33333.3, 30000.0, 40000.0,
These values did work:
- 45000.0, 100.0, 300.0, 12345.0
step = 100000 / number_of_cubes
for 3 you would expect 33333.3333.. Suggest using a log scale as the step to break up your frequencies, remember in music each notes freq is double the previous. (eg 22.5, 55, 110, 220, 440, 880, 1760 Hz for A) Also what options do you have set for the bake op? Have an addon github.com/batFINGER/batFINGER-blender-addons (put sound_drivers folder in addons folder to install) which bakes to props on a speaker, and have encountered blow outs on certain audio files. $\endgroup$