3
$\begingroup$

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

Crazy values gif

And here is the graph editor for those frames. (Notice the vertical scale)

Graph editor

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
$\endgroup$
  • $\begingroup$ Can you provide a link to the audio file & maybe an image of graph editor. You have 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$ – batFINGER Mar 19 '16 at 14:04
  • $\begingroup$ @batFINGER I have edited my question. If I figure this out I will look into logarithms for the step, but for now an even scale will do. I only modified the low and high frequency. I left the other values at default. $\endgroup$ – Nathan Craddock Mar 19 '16 at 18:06
  • $\begingroup$ Maybe related: blender.stackexchange.com/questions/47804/… $\endgroup$ – Samoth Mar 19 '16 at 22:14
3
$\begingroup$

If your sound bake is showing that behaviour try reducing your baking frequency High and Low to within the audible frequency range.

20 to 20,000 Hz

The SI unit of audio frequency is the hertz (Hz). It is the property of sound that most determines pitch. The generally accepted standard range of audible frequencies is 20 to 20,000 Hz, although the range of frequencies individuals hear is greatly influenced by environmental factors.

Audio frequency - Wikipedia, the free encyclopedia https://en.wikipedia.org/wiki/Audio_frequency

Which is likely why the bakes returned rubbish on some audio formats.

The sound drivers addon bakes n frequencies over a channel range. I've also put in the ability to bake on music note frequencies. Here is a screenshot of rainbow_road.mp3 baked to the 88 notes of the keys on a piano.

enter image description here

Baked as custom properties on the speaker (data part) object. Fcurve modifiers are used to map the range of the fcurve. A simple driver can be added to any object, and if using channel 0, in the case of image AH0 is used as a driver on the cone, a simple grid visualiser can be created.

$\endgroup$
  • $\begingroup$ Well that makes sense. But why does blender default to low-0 and high-100000? $\endgroup$ – Nathan Craddock Mar 20 '16 at 17:28
  • 2
    $\begingroup$ What would be good is if the bake op threw up an error message to the console when it's returning monster numbers. Converted to a wav file it might bake fine over 0, to 100,000 Hz. Some formats do bake ok over large ranges, some don't, in my experience... staying within audible range and most formats bake ok. Will edit answer later to say as such, ie if you see this try within audible. $\endgroup$ – batFINGER Mar 20 '16 at 17:47

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.