diff options
author | Joerg Mueller <nexyon@gmail.com> | 2011-08-09 12:38:14 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2011-08-09 12:38:14 +0400 |
commit | 13249b925eda7752b65a36d8270a3af3bdc02981 (patch) | |
tree | 7fd483e84f29e09bbc4cd2c6e226fc7cf7a6f722 /source/blender | |
parent | 802f69df78a937cd94d855264c658212e3467c2a (diff) |
3D Audio GSoC:
Speaker objects fully functional!
Minor changes:
* Fixed three memory bugs found via valgrind.
* Fixed bug with jack transport crashing after file loading.
* Sound NLA Strips now start at CFRA instead of 0.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_sound.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 88 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 3 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_anim_types.h | 2 |
7 files changed, 103 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 2cd006385e0..c36532ee4cc 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -46,6 +46,8 @@ void sound_init_once(void); void sound_init(struct Main *main); +void sound_init_main(struct Main *bmain); + void sound_exit(void); void sound_force_device(int device); @@ -124,6 +126,8 @@ int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, flo int sound_get_channels(struct bSound* sound); +void sound_update_scene(struct Main* bmain, struct Scene* scene); + void* sound_get_factory(void* sound); #endif diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index a3a4c5b555b..5f33059e117 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -82,6 +82,7 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_sequencer.h" +#include "BKE_sound.h" #include "BLO_undofile.h" @@ -247,6 +248,8 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath G.main= bfd->main; CTX_data_main_set(C, G.main); + + sound_init_main(G.main); if (bfd->user) { diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 8668168936b..c362f3eb2fe 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -533,7 +533,6 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a++]= &(main->latt); lb[a++]= &(main->lamp); lb[a++]= &(main->camera); - lb[a++]= &(main->speaker); lb[a++]= &(main->text); lb[a++]= &(main->sound); @@ -541,6 +540,7 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a++]= &(main->brush); lb[a++]= &(main->script); lb[a++]= &(main->particle); + lb[a++]= &(main->speaker); lb[a++]= &(main->world); lb[a++]= &(main->screen); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 74126fd57a1..12e81e8296e 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -966,6 +966,9 @@ static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scen /* scene drivers... */ scene_update_drivers(bmain, scene); + + /* update sound system animation */ + sound_update_scene(bmain, scene); } /* this is called in main loop, doing tagged updates before redraw */ diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 890fc114e68..17df6ba23cb 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -13,13 +13,16 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" +#include "BLI_math.h" #include "DNA_anim_types.h" +#include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" #include "DNA_packedFile_types.h" #include "DNA_screen_types.h" #include "DNA_sound_types.h" +#include "DNA_speaker_types.h" #ifdef WITH_AUDASPACE # include "AUD_C-API.h" @@ -175,7 +178,12 @@ void sound_init(struct Main *bmain) if(!AUD_init(device, specs, buffersize)) AUD_init(AUD_NULL_DEVICE, specs, buffersize); - + + sound_init_main(bmain); +} + +void sound_init_main(struct Main *bmain) +{ #ifdef WITH_JACK AUD_setSyncCallback(sound_sync_callback, bmain); #else @@ -617,6 +625,84 @@ int sound_get_channels(struct bSound* sound) return info.specs.channels; } +void sound_update_scene(struct Main* bmain, struct Scene* scene) +{ + Object* ob; + NlaTrack* track; + NlaStrip* strip; + Speaker* speaker; + + void* new_set = AUD_createSet(); + void* handle; + float quat[4]; + + for(ob = bmain->object.first; ob; ob = ob->id.next) + { + if(ob->type == OB_SPEAKER) + { + if(ob->adt) + { + for(track = ob->adt->nla_tracks.first; track; track = track->next) + { + for(strip = track->strips.first; strip; strip = strip->next) + { + if(strip->type == NLASTRIP_TYPE_SOUND) + { + speaker = (Speaker*)ob->data; + + if(AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) + { + AUD_moveSequence(strip->speaker_handle, strip->start / FPS, -1, 0); + } + else + { + if(speaker && speaker->sound) + { + strip->speaker_handle = AUD_addSequence(scene->sound_scene, speaker->sound->playback_handle, strip->start / FPS, -1, 0); + AUD_setRelativeSequence(strip->speaker_handle, 0); + } + } + + if(strip->speaker_handle) + { + AUD_addSet(new_set, strip->speaker_handle); + AUD_updateSequenceData(strip->speaker_handle, speaker->volume_max, + speaker->volume_min, speaker->distance_max, + speaker->distance_reference, speaker->attenuation, + speaker->cone_angle_outer, speaker->cone_angle_inner, + speaker->cone_volume_outer); + + mat4_to_quat(quat, ob->obmat); + AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1); + AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1); + AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1); + AUD_setSequenceAnimData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1); + AUD_updateSequenceSound(strip->speaker_handle, speaker->sound->playback_handle); + AUD_muteSequence(strip->speaker_handle, ((strip->flag & NLASTRIP_FLAG_MUTED) != 0) || ((speaker->flag & SPK_MUTED) != 0)); + } + } + } + } + } + } + } + + while((handle = AUD_getSet(scene->speaker_handles))) + { + AUD_removeSequence(scene->sound_scene, handle); + } + + if(scene->camera) + { + mat4_to_quat(quat, scene->camera->obmat); + AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_LOCATION, CFRA, scene->camera->obmat[3], 1); + AUD_setSequencerAnimData(scene->sound_scene, AUD_AP_ORIENTATION, CFRA, quat, 1); + } + + AUD_destroySet(scene->speaker_handles); + scene->speaker_handles = new_set; +} + void* sound_get_factory(void* sound) { return ((struct bSound*) sound)->playback_handle; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 97d109118d1..09ce2562e3b 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -774,6 +774,7 @@ static int object_speaker_add_exec(bContext *C, wmOperator *op) int enter_editmode; unsigned int layer; float loc[3], rot[3]; + Scene *scene = CTX_data_scene(C); object_add_generic_invoke_options(C, op); if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) @@ -789,6 +790,8 @@ static int object_speaker_add_exec(bContext *C, wmOperator *op) AnimData *adt = BKE_id_add_animdata(&ob->id); NlaTrack *nlt = add_nlatrack(adt, NULL); NlaStrip *strip = add_nla_soundstrip(CTX_data_scene(C), ob->data); + strip->start = CFRA; + strip->end += strip->start; /* hook them up */ BKE_nlatrack_add_strip(nlt, strip); diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index 5a031e04fe4..c0030cd0e5e 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -585,6 +585,8 @@ typedef struct NlaStrip { short type; /* type of NLA strip */ + void *speaker_handle; /* handle for speaker objects */ + int flag; /* settings */ int pad2; } NlaStrip; |