diff options
-rw-r--r-- | intern/audaspace/intern/AUD_3DMath.h | 26 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_C-API.cpp | 75 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_C-API.h | 19 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SequencerEntry.cpp | 67 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SequencerEntry.h | 4 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SequencerHandle.cpp | 15 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SequencerReader.cpp | 18 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SoftwareDevice.cpp | 5 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_info.py | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_sound.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 11 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 14 |
14 files changed, 240 insertions, 27 deletions
diff --git a/intern/audaspace/intern/AUD_3DMath.h b/intern/audaspace/intern/AUD_3DMath.h index 3a6abf811ce..007682df291 100644 --- a/intern/audaspace/intern/AUD_3DMath.h +++ b/intern/audaspace/intern/AUD_3DMath.h @@ -102,6 +102,15 @@ public: * Retrieves the components of the vector. * \return The components as float[3]. */ + inline float* get() + { + return m_v; + } + + /** + * Retrieves the components of the vector. + * \return The components as float[3]. + */ inline const float* get() const { return m_v; @@ -152,6 +161,14 @@ public: { return AUD_Vector3(-m_x, -m_y, -m_z); } + + inline AUD_Vector3& operator-=(const AUD_Vector3& op) + { + m_x -= op.m_x; + m_y -= op.m_y; + m_z -= op.m_z; + return *this; + } }; class AUD_Quaternion @@ -234,6 +251,15 @@ public: * Retrieves the components of the vector. * \return The components as float[4]. */ + inline float* get() + { + return m_v; + } + + /** + * Retrieves the components of the vector. + * \return The components as float[4]. + */ inline const float* get() const { return m_v; diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index c365f8b9c5e..23245b56b20 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -39,6 +39,7 @@ #include "AUD_PyAPI.h" #endif +#include <set> #include <cstdlib> #include <cstring> #include <cmath> @@ -898,12 +899,12 @@ void AUD_destroySequencer(AUD_Sound* sequencer) void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted) { - ((AUD_SequencerFactory*)sequencer->get())->mute(muted); + dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->mute(muted); } void AUD_setSequencerFPS(AUD_Sound* sequencer, float fps) { - ((AUD_SequencerFactory*)sequencer->get())->setFPS(fps); + dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setFPS(fps); } AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound, @@ -916,7 +917,7 @@ AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound, void AUD_removeSequence(AUD_Sound* sequencer, AUD_SEntry* entry) { - ((AUD_SequencerFactory*)sequencer->get())->remove(*entry); + dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->remove(*entry); delete entry; } @@ -930,6 +931,11 @@ void AUD_muteSequence(AUD_SEntry* entry, char mute) (*entry)->mute(mute); } +void AUD_setRelativeSequence(AUD_SEntry* entry, char relative) +{ + (*entry)->setRelative(relative); +} + void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound) { if(sound) @@ -949,21 +955,38 @@ void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType type void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateablePropertyType type, int frame, float* data, char animated) { - AUD_AnimateableProperty* prop = ((AUD_SequencerFactory*)sequencer->get())->getAnimProperty(type); + AUD_AnimateableProperty* prop = dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->getAnimProperty(type); if(animated) prop->write(data, frame, 1); else prop->write(data); } +void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float volume_min, + float distance_max, float distance_reference, float attenuation, + float cone_angle_outer, float cone_angle_inner, float cone_volume_outer) +{ + (*entry)->updateAll(volume_max, volume_min, distance_max, distance_reference, attenuation, + cone_angle_outer, cone_angle_inner, cone_volume_outer); +} + +void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound, + float factor, AUD_DistanceModel model) +{ + AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sequencer->get()); + f->setSpeedOfSound(speed_of_sound); + f->setDopplerFactor(factor); + f->setDistanceModel(model); +} + void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer) { - ((AUD_SequencerFactory*)sequencer->get())->setSpecs(AUD_device->getSpecs().specs); + dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(AUD_device->getSpecs().specs); } void AUD_setSequencerSpecs(AUD_Sound* sequencer, AUD_Specs specs) { - ((AUD_SequencerFactory*)sequencer->get())->setSpecs(specs); + dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(specs); } void AUD_seekSequencer(AUD_Handle* handle, float time) @@ -1090,3 +1113,43 @@ void AUD_freeHandle(AUD_Handle* handle) { delete handle; } + +void* AUD_createSet() +{ + return new std::set<void*>(); +} + +void AUD_destroySet(void* set) +{ + delete reinterpret_cast<std::set<void*>*>(set); +} + +char AUD_removeSet(void* set, void* entry) +{ + if(set) + return reinterpret_cast<std::set<void*>*>(set)->erase(entry); + return 0; +} + +void AUD_addSet(void* set, void* entry) +{ + if(entry) + reinterpret_cast<std::set<void*>*>(set)->insert(entry); +} + +void* AUD_getSet(void* set) +{ + if(set) + { + std::set<void*>* rset = reinterpret_cast<std::set<void*>*>(set); + if(!rset->empty()) + { + std::set<void*>::iterator it = rset->begin(); + void* result = *it; + rset->erase(it); + return result; + } + } + + return NULL; +} diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h index 8b7112bfa3f..a6ef34280c2 100644 --- a/intern/audaspace/intern/AUD_C-API.h +++ b/intern/audaspace/intern/AUD_C-API.h @@ -469,12 +469,21 @@ extern void AUD_moveSequence(AUD_SEntry* entry, float begin, float end, float sk extern void AUD_muteSequence(AUD_SEntry* entry, char mute); +extern void AUD_setRelativeSequence(AUD_SEntry* entry, char relative); + extern void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound); extern void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType type, int frame, float* data, char animated); extern void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateablePropertyType type, int frame, float* data, char animated); +extern void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float volume_min, + float distance_max, float distance_reference, float attenuation, + float cone_angle_outer, float cone_angle_inner, float cone_volume_outer); + +extern void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound, + float factor, AUD_DistanceModel model); + extern void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer); extern void AUD_setSequencerSpecs(AUD_Sound* sequencer, AUD_Specs specs); @@ -499,6 +508,16 @@ extern AUD_Sound* AUD_copy(AUD_Sound* sound); extern void AUD_freeHandle(AUD_Handle* channel); +extern void* AUD_createSet(); + +extern void AUD_destroySet(void* set); + +extern char AUD_removeSet(void* set, void* entry); + +extern void AUD_addSet(void* set, void* entry); + +extern void* AUD_getSet(void* set); + #ifdef WITH_PYTHON extern PyObject* AUD_getPythonFactory(AUD_Sound* sound); diff --git a/intern/audaspace/intern/AUD_SequencerEntry.cpp b/intern/audaspace/intern/AUD_SequencerEntry.cpp index 5ba35955f3c..54993befb41 100644 --- a/intern/audaspace/intern/AUD_SequencerEntry.cpp +++ b/intern/audaspace/intern/AUD_SequencerEntry.cpp @@ -66,8 +66,11 @@ AUD_SequencerEntry::AUD_SequencerEntry(AUD_Reference<AUD_IFactory> sound, float void AUD_SequencerEntry::setSound(AUD_Reference<AUD_IFactory> sound) { - m_sound = sound; - m_sound_status++; + if(m_sound.get() != sound.get()) + { + m_sound = sound; + m_sound_status++; + } } void AUD_SequencerEntry::move(float begin, float end, float skip) @@ -110,6 +113,59 @@ AUD_AnimateableProperty* AUD_SequencerEntry::getAnimProperty(AUD_AnimateableProp } } +void AUD_SequencerEntry::updateAll(float volume_max, float volume_min, float distance_max, + float distance_reference, float attenuation, float cone_angle_outer, + float cone_angle_inner, float cone_volume_outer) +{ + if(volume_max != m_volume_max) + { + m_volume_max = volume_max; + m_status++; + } + + if(volume_min != m_volume_min) + { + m_volume_min = volume_min; + m_status++; + } + + if(distance_max != m_distance_max) + { + m_distance_max = distance_max; + m_status++; + } + + if(distance_reference != m_distance_reference) + { + m_distance_reference = distance_reference; + m_status++; + } + + if(attenuation != m_attenuation) + { + m_attenuation = attenuation; + m_status++; + } + + if(cone_angle_outer != m_cone_angle_outer) + { + m_cone_angle_outer = cone_angle_outer; + m_status++; + } + + if(cone_angle_inner != m_cone_angle_inner) + { + m_cone_angle_inner = cone_angle_inner; + m_status++; + } + + if(cone_volume_outer != m_cone_volume_outer) + { + m_cone_volume_outer = cone_volume_outer; + m_status++; + } +} + bool AUD_SequencerEntry::isRelative() { return m_relative; @@ -117,8 +173,11 @@ bool AUD_SequencerEntry::isRelative() void AUD_SequencerEntry::setRelative(bool relative) { - m_relative = relative; - m_status++; + if(m_relative != relative) + { + m_relative = relative; + m_status++; + } } float AUD_SequencerEntry::getVolumeMaximum() diff --git a/intern/audaspace/intern/AUD_SequencerEntry.h b/intern/audaspace/intern/AUD_SequencerEntry.h index 950e0fd9550..5c68b4c7ab2 100644 --- a/intern/audaspace/intern/AUD_SequencerEntry.h +++ b/intern/audaspace/intern/AUD_SequencerEntry.h @@ -78,6 +78,10 @@ public: AUD_AnimateableProperty* getAnimProperty(AUD_AnimateablePropertyType type); + void updateAll(float volume_max, float volume_min, float distance_max, + float distance_reference, float attenuation, float cone_angle_outer, + float cone_angle_inner, float cone_volume_outer); + /** * Checks whether the source location, velocity and orientation are relative * to the listener. diff --git a/intern/audaspace/intern/AUD_SequencerHandle.cpp b/intern/audaspace/intern/AUD_SequencerHandle.cpp index dead6fdf07b..006dafe2026 100644 --- a/intern/audaspace/intern/AUD_SequencerHandle.cpp +++ b/intern/audaspace/intern/AUD_SequencerHandle.cpp @@ -70,7 +70,7 @@ void AUD_SequencerHandle::update(float position, float frame) { if(!m_handle.isNull()) { - if(position >= m_entry->m_end) + if(position >= m_entry->m_end && m_entry->m_end >= 0) m_handle->pause(); else if(position >= m_entry->m_begin) m_handle->resume(); @@ -120,7 +120,16 @@ void AUD_SequencerHandle::update(float position, float frame) m_entry->m_panning.read(frame, &value); AUD_SoftwareDevice::setPanning(m_handle.get(), value); - // AUD_XXX: TODO: animation data + AUD_Vector3 v, v2; + AUD_Quaternion q; + + m_entry->m_orientation.read(frame, q.get()); + m_3dhandle->setSourceOrientation(q); + m_entry->m_location.read(frame, v.get()); + m_3dhandle->setSourceLocation(v); + m_entry->m_location.read(frame + 1, v2.get()); + v2 -= v; + m_3dhandle->setSourceVelocity(v2); if(m_entry->m_muted) m_handle->setVolume(0); @@ -131,7 +140,7 @@ void AUD_SequencerHandle::seek(float position) { if(!m_handle.isNull()) { - if(position >= m_entry->m_end) + if(position >= m_entry->m_end && m_entry->m_end >= 0) { m_handle->pause(); return; diff --git a/intern/audaspace/intern/AUD_SequencerReader.cpp b/intern/audaspace/intern/AUD_SequencerReader.cpp index c20132e27e1..e01da34651f 100644 --- a/intern/audaspace/intern/AUD_SequencerReader.cpp +++ b/intern/audaspace/intern/AUD_SequencerReader.cpp @@ -139,13 +139,14 @@ void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer) m_entry_status = m_factory->m_entry_status; } - // AUD_XXX: TODO: animation data - AUD_Specs specs = m_factory->m_specs; int pos = 0; float time = float(m_position) / float(specs.rate); - float value, frame; + float volume, frame; int len, cfra; + AUD_Vector3 v, v2; + AUD_Quaternion q; + while(pos < length) { @@ -161,9 +162,16 @@ void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer) (*it)->update(time, frame); } - m_factory->m_volume.read(frame, &value); + m_factory->m_volume.read(frame, &volume); + m_device.setVolume(volume); - m_device.setVolume(value); + m_factory->m_orientation.read(frame, q.get()); + m_device.setListenerOrientation(q); + m_factory->m_location.read(frame, v.get()); + m_device.setListenerLocation(v); + m_factory->m_location.read(frame + 1, v2.get()); + v2 -= v; + m_device.setListenerVelocity(v2); m_device.read(reinterpret_cast<data_t*>(buffer + specs.channels * pos), len); diff --git a/intern/audaspace/intern/AUD_SoftwareDevice.cpp b/intern/audaspace/intern/AUD_SoftwareDevice.cpp index 1c93ebe9ad0..bc041eb97e3 100644 --- a/intern/audaspace/intern/AUD_SoftwareDevice.cpp +++ b/intern/audaspace/intern/AUD_SoftwareDevice.cpp @@ -184,6 +184,11 @@ void AUD_SoftwareDevice::AUD_SoftwareHandle::update() } } + if(m_volume > m_volume_max) + m_volume = m_volume_max; + else if(m_volume < m_volume_min) + m_volume = m_volume_min; + // Volume m_volume *= m_user_volume; diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py index eba2581252a..6c3dc7517c5 100644 --- a/release/scripts/startup/bl_ui/space_info.py +++ b/release/scripts/startup/bl_ui/space_info.py @@ -287,14 +287,14 @@ class INFO_MT_add(bpy.types.Menu): layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY' layout.separator() + layout.operator("object.speaker_add", text="Speaker", icon='SPEAKER') + layout.separator() + layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA') layout.operator_context = 'EXEC_SCREEN' layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP') layout.separator() - layout.operator("object.speaker_add", text="Speaker", icon='SPEAKER') - layout.separator() - layout.operator_menu_enum("object.effector_add", "type", text="Force Field", icon='OUTLINER_OB_EMPTY') layout.separator() diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 5ccb34338af..632a2a0bb3b 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -84,6 +84,8 @@ void sound_mute_scene(struct Scene *scene, int muted); void sound_update_fps(struct Scene *scene); +void sound_update_scene_listener(struct Scene *scene); + void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip); void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 6e8b26c6ca6..59f5cdb678e 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -354,8 +354,11 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, void sound_create_scene(struct Scene *scene) { scene->sound_scene = AUD_createSequencer(FPS, scene->audio.flag & AUDIO_MUTE); + AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, + scene->audio.doppler_factor, scene->audio.distance_model); scene->sound_scene_handle = NULL; scene->sound_scrub_handle = NULL; + scene->speaker_handles = NULL; } void sound_destroy_scene(struct Scene *scene) @@ -366,6 +369,8 @@ void sound_destroy_scene(struct Scene *scene) AUD_stop(scene->sound_scrub_handle); if(scene->sound_scene) AUD_destroySequencer(scene->sound_scene); + if(scene->speaker_handles) + AUD_destroySet(scene->speaker_handles); } void sound_mute_scene(struct Scene *scene, int muted) @@ -380,6 +385,12 @@ void sound_update_fps(struct Scene *scene) AUD_setSequencerFPS(scene->sound_scene, FPS); } +void sound_update_scene_listener(struct Scene *scene) +{ + AUD_updateSequencerData(scene->sound_scene, scene->audio.speed_of_sound, + scene->audio.doppler_factor, scene->audio.distance_model); +} + void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip) { if(scene != sequence->scene) diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 48e138dfcdc..97a98d2017f 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -789,14 +789,13 @@ void OBJECT_OT_speaker_add(wmOperatorType *ot) ot->idname= "OBJECT_OT_speaker_add"; /* api callbacks */ - ot->invoke= WM_menu_invoke; ot->exec= object_speaker_add_exec; ot->poll= ED_operator_objectmode; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - ED_object_add_generic_props(ot, FALSE); + ED_object_add_generic_props(ot, TRUE); } /* only used as menu */ @@ -1636,7 +1635,6 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base } break; case OB_SPEAKER: - // AUD_XXX TODO: always duplicate Speakers on speaker object duplication? if(dupflag!=0) { ID_NEW_US2(obn->data ) else { diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 7a5d417b59c..542aea00b00 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -806,6 +806,7 @@ typedef struct Scene { void *sound_scene; void *sound_scene_handle; void *sound_scrub_handle; + void *speaker_handles; void *fps_info; /* (runtime) info/cache used for presenting playback framerate info to the user */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 0a97344928f..f2618280fa2 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -337,6 +337,11 @@ static void rna_Scene_fps_update(Main *UNUSED(bmain), Scene *scene, PointerRNA * sound_update_fps(scene); } +static void rna_Scene_listener_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) +{ + sound_update_scene_listener(scene); +} + static void rna_Scene_volume_set(PointerRNA *ptr, float value) { Scene *scene= (Scene*)(ptr->data); @@ -3462,21 +3467,24 @@ void RNA_def_scene(BlenderRNA *brna) prop= RNA_def_property(srna, "audio_doppler_speed", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "audio.speed_of_sound"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_range(prop, 0.01f, FLT_MAX); RNA_def_property_ui_text(prop, "Speed of Sound", "Speed of sound for Doppler effect calculation"); - RNA_def_property_update(prop, NC_SCENE, NULL); + RNA_def_property_update(prop, NC_SCENE, "rna_Scene_listener_update"); prop= RNA_def_property(srna, "audio_doppler_factor", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "audio.doppler_factor"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_range(prop, 0.0, FLT_MAX); RNA_def_property_ui_text(prop, "Doppler Factor", "Pitch factor for Doppler effect calculation"); - RNA_def_property_update(prop, NC_SCENE, NULL); + RNA_def_property_update(prop, NC_SCENE, "rna_Scene_listener_update"); prop= RNA_def_property(srna, "audio_distance_model", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "audio.distance_model"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_enum_items(prop, audio_distance_model_items); RNA_def_property_ui_text(prop, "Distance Model", "Distance model for distance attenuation calculation"); - RNA_def_property_update(prop, NC_SCENE, NULL); + RNA_def_property_update(prop, NC_SCENE, "rna_Scene_listener_update"); prop= RNA_def_property(srna, "audio_volume", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "audio.volume"); |