Drive animations with sound. Copy the sound_drivers folder into one of your addon folders.
LATEST VERSION HERE
GITHUB: https://github.com/batFINGER/sound-bake-drivers
ZIP: https://github.com/batFINGER/sound-bake-drivers/archive/master.zip
For an addon i’m running needed to play around with bake sound to fcurves… here is a little test script that creates an n channel graphic eq. baked to custom properties Channel0,Channel1… onto the context object. These can then be used as targets for drivers.
Does anyone know if a glob/filetype can be set using the FILE_PATH subtype?
import bpy
from bpy.props import *
from math import log10
def fetch(collection,name,create=False,**newargs):
# returns item from collection , None if not there, creates if create is True passes newargs to new method.
if name in collection:
return collection[name]
# maybe put in code for replace too.
if create:
if len(newargs):
try:
newitem = collection.new(**newargs)
newitem.name = name
except:
newitem = collection.new(name=name,**newargs)
else:
try:
newitem = collection.new(name=name) #for things like scene objects
except:
newItem = None
return newitem
return None
class SoundTestPanel(bpy.types.Panel):
bl_label = "Sound Test"
bl_space_type = "GRAPH_EDITOR"
bl_region_type = "UI"
def draw(self, context):
sce = context.scene
layout = self.layout
layout.prop(sce,"SoundFile")
if sce.SoundFile != "":
layout.operator("sound.test")
@classmethod
def poll(self,context):
return context.object is not None
class SoundTestOp(bpy.types.Operator):
'''Sound Test'''
bl_idname = "sound.test"
bl_label = "Sound Test"
channels = IntProperty(name="Channels",default=3,description="Number of frequencies to split",min=0,max=24)
minf = FloatProperty(name="Min Freq",default=0.0,description="Minimum Freq",min=0,max=10000.0)
maxf = FloatProperty(name="Max Freq",default=10000.0,description="Maximum Freq",min=100.0,max=1000000.0)
use_log = BoolProperty(name="Log Scale",default=False,description="Use Log scale for channels")
def invoke(self, context, event):
#create a Sounds action
context.scene.frame_set(1)
wm = context.window_manager
return wm.invoke_props_dialog(self)
def draw(self,context):
sce = context.scene
layout = self.layout
layout.label("test")
layout.prop(self,"channels")
layout.prop(self,"minf")
layout.prop(self,"maxf")
layout.prop(self,"use_log")
def execute(self, context):
# set to frame 1
ob = context.object
soundaction = bpy.data.actions.new("%dChannelEQ"%self.channels)
#soundaction = fetch(bpy.data.actions,"Sounds",True) #need to delete baked curves to use
print(soundaction)
if not ob.animation_data:
ob.animation_data_create()
ob.animation_data.action = soundaction
if not soundaction:
print("NO ACTION")
return{'CANCELLED'}
#CHANGE CAPS TO OP PROPS
use_log = self.use_log
if use_log:
if self.minf == 0:
self.minf =1
LOW = log10(self.minf)
HIGH = log10(self.maxf)
RANGE = HIGH-LOW
else:
LOW = self.minf
HIGH = self.maxf
RANGE = HIGH-LOW
file = context.scene["SoundFile"] # do some proper file check here.
n = self.channels
for i in range(0,n):
freq = 'Channel%d'%i
ob[freq] = 0.0
ob.keyframe_insert('["%s"]'%freq)
low = LOW + (i)*RANGE/n
high = LOW + (i+1)*RANGE/n
if use_log:
low = 10**low
high = 10**high
soundaction.fcurves[i].select = True
bpy.ops.graph.sound_bake(filepath=file, low=low, high=high, attack=0.005, release=0.2, threshold=0, accumulate=False, use_additive=False, square=False, sthreshold=0.1)
soundaction.fcurves[i].select = False
return{'FINISHED'}
def register():
bpy.types.Scene.SoundFile = StringProperty(name="SoundFile",
description="Sound File for Equaliser Input",
maxlen= 1024,
subtype='FILE_PATH',
default= "")
bpy.context.scene["SoundFile"] = ""
bpy.utils.register_class(SoundTestOp)
bpy.utils.register_class(SoundTestPanel)
def unregister():
bpy.utils.unregister_class(SoundTestOp)
bpy.utils.unregister_class(SoundTestPanel)
'''
bpy.ops.graph.sound_bake(filepath="C:\\Documents and Settings\\batFinger\\My Documents\\Downloads\\burnout.wav", filter_blender=False, filter_image=False, filter_movie=True, filter_python=False, filter_font=False, filter_sound=True, filter_text=False, filter_btx=False, filter_collada=False, filter_folder=True, filemode=9, low=0, high=100000, attack=0.005, release=0.2, threshold=0, accumulate=False, use_additive=False, square=False, sthreshold=0.1)
'''
register()
Added log scale.
To do… file checking and setting up other props to pass to the sound_bake op. Unbake option.
Attachments
speaker_tools_2.63_r50555.zip (27.2 KB)