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>2011-08-03 13:25:40 +0400
committerJoerg Mueller <nexyon@gmail.com>2011-08-03 13:25:40 +0400
commit6d7490632f13f9744c6b3e507c838a34f3481846 (patch)
tree941fa3faa93beb2fbb63798b2c1c416a5c3821f1 /intern/audaspace
parent2b446aa280af60aefd304aae904bc16b1b15f373 (diff)
3D Audio GSoC:
* Minor audaspace library improvements. * Considering location, velocity and orientation in AUD_SequencerReader and AUD_SequencerHandle. * Bugfix: Maximum and Minimum volume weren't used before in the software device. * Bugfix: Adding speaker objects via info space crashed. * Listener settings now get updated in the audio system.
Diffstat (limited to 'intern/audaspace')
-rw-r--r--intern/audaspace/intern/AUD_3DMath.h26
-rw-r--r--intern/audaspace/intern/AUD_C-API.cpp75
-rw-r--r--intern/audaspace/intern/AUD_C-API.h19
-rw-r--r--intern/audaspace/intern/AUD_SequencerEntry.cpp67
-rw-r--r--intern/audaspace/intern/AUD_SequencerEntry.h4
-rw-r--r--intern/audaspace/intern/AUD_SequencerHandle.cpp15
-rw-r--r--intern/audaspace/intern/AUD_SequencerReader.cpp18
-rw-r--r--intern/audaspace/intern/AUD_SoftwareDevice.cpp5
8 files changed, 211 insertions, 18 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;