Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Mueller <nexyon@gmail.com>2009-11-22 15:10:45 +0300
committerJoerg Mueller <nexyon@gmail.com>2009-11-22 15:10:45 +0300
commit8e877c1f9ff8d20037299a93dbf8489d2bc9eb98 (patch)
tree855d45a88388f5086a3c9a7df257d72df702b726 /source/blender/blenkernel/intern/fmodifier.c
parent8b84cc2ab65790604722eeaba89a34095d2e7259 (diff)
Added a first version of the Sound F-Curve Modifier, not really usable yet, but you can play around with it.
Diffstat (limited to 'source/blender/blenkernel/intern/fmodifier.c')
-rw-r--r--source/blender/blenkernel/intern/fmodifier.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c
index 5daa2ed1924..fba15075bdb 100644
--- a/source/blender/blenkernel/intern/fmodifier.c
+++ b/source/blender/blenkernel/intern/fmodifier.c
@@ -53,6 +53,8 @@
#include "RNA_access.h"
#include "RNA_types.h"
+#include "AUD_C-API.h"
+
#ifndef DISABLE_PYTHON
#include "BPY_extern.h" /* for BPY_pydriver_eval() */
#endif
@@ -871,6 +873,91 @@ static FModifierTypeInfo FMI_LIMITS = {
fcm_limits_evaluate /* evaluate */
};
+/* Sound F-Curve Modifier --------------------------- */
+
+static void fcm_sound_new_data (void *mdata)
+{
+ FMod_Sound *data= (FMod_Sound *)mdata;
+
+ /* defaults */
+ data->strength= 1.0f;
+ data->delay = 0.0f;
+ data->modification = FCM_SOUND_MODIF_REPLACE;
+ data->sound = NULL;
+}
+
+static void fcm_sound_evaluate (FCurve *fcu, FModifier *fcm, float *cvalue, float evaltime)
+{
+ FMod_Sound *data= (FMod_Sound *)fcm->data;
+ float amplitude;
+
+ AUD_Device* device;
+ SoundHandle* handle;
+ AUD_Sound* limiter;
+ AUD_SoundInfo info;
+
+// evaltime = FRA2TIME(evaltime);
+ evaltime -= data->delay;
+
+ if(evaltime < 0.0f || data->sound == NULL || data->sound->cache == NULL)
+ return;
+
+ info = AUD_getInfo(data->sound->cache);
+ info.specs.channels = 1;
+ info.specs.format = AUD_FORMAT_FLOAT32;
+ device = AUD_openReadDevice(info.specs);
+ limiter = AUD_limitSound(data->sound->cache, evaltime, evaltime + 1);
+ AUD_playDevice(device, limiter);
+ AUD_unload(limiter);
+ AUD_readDevice(device, &amplitude, 1);
+ AUD_closeReadDevice(device);
+
+ /* combine the amplitude with existing motion data */
+ switch (data->modification) {
+ case FCM_SOUND_MODIF_ADD:
+ *cvalue= *cvalue + amplitude * data->strength;
+ break;
+ case FCM_SOUND_MODIF_SUBTRACT:
+ *cvalue= *cvalue - amplitude * data->strength;
+ break;
+ case FCM_SOUND_MODIF_MULTIPLY:
+ *cvalue= *cvalue * amplitude * data->strength;
+ break;
+ case FCM_SOUND_MODIF_REPLACE:
+ default:
+ *cvalue= *cvalue + amplitude * data->strength;
+ break;
+ }
+}
+
+static float fcm_sound_time (FCurve *fcu, FModifier *fcm, float cvalue, float evaltime)
+{
+ FMod_Sound *data= (FMod_Sound *)fcm->data;
+
+ /* check for the time delay */
+// evaltime = FRA2TIME(evaltime);
+ if(evaltime < data->delay)
+ return data->delay;
+
+ /* modifier doesn't change time */
+ return evaltime;
+}
+
+static FModifierTypeInfo FMI_SOUND = {
+ FMODIFIER_TYPE_SOUND, /* type */
+ sizeof(FMod_Sound), /* size */
+ FMI_TYPE_REPLACE_VALUES, /* action type */
+ 0, /* requirements */
+ "Sound", /* name */
+ "FMod_Sound", /* struct name */
+ NULL, /* free data */
+ NULL, /* copy data */
+ fcm_sound_new_data, /* new data */
+ NULL, /* verify */
+ fcm_sound_time, /* evaluate time */
+ fcm_sound_evaluate /* evaluate */
+};
+
/* F-Curve Modifier API --------------------------- */
/* All of the F-Curve Modifier api functions use FModifierTypeInfo structs to carry out
* and operations that involve F-Curve modifier specific code.
@@ -892,6 +979,7 @@ static void fmods_init_typeinfo ()
fmodifiersTypeInfo[6]= NULL/*&FMI_FILTER*/; /* Filter F-Curve Modifier */ // XXX unimplemented
fmodifiersTypeInfo[7]= &FMI_PYTHON; /* Custom Python F-Curve Modifier */
fmodifiersTypeInfo[8]= &FMI_LIMITS; /* Limits F-Curve Modifier */
+ fmodifiersTypeInfo[9]= &FMI_SOUND; /* Sound F-Curve Modifier */
}
/* This function should be used for getting the appropriate type-info when only