3D Audio GSoC:

Final GSoC commit.

* Bugfix: Negative frames crashed
* Bugfix: JOS sample buffer size prediction error (wasted memory)
* Optimisation: for JOS upsampling (around 12 % difference measured here)
* Optimisation: Better filter for JOS resampling
* Bugfix: Error in relative 3D audio code.
* Removed Attenuation
* Bugfix: Multiple scenes in BGE lead to errors, BGE audio now all relative, to support multiple scenes.
This commit is contained in:
Joerg Mueller 2011-08-22 18:59:56 +00:00
parent ee40894c05
commit a71c215f22
8 changed files with 32641 additions and 29386 deletions

@ -967,7 +967,10 @@ void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType type
{
AUD_AnimateableProperty* prop = (*entry)->getAnimProperty(type);
if(animated)
prop->write(data, frame, 1);
{
if(frame >= 0)
prop->write(data, frame, 1);
}
else
prop->write(data);
}
@ -976,7 +979,10 @@ void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateablePropertyType
{
AUD_AnimateableProperty* prop = dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->getAnimProperty(type);
if(animated)
prop->write(data, frame, 1);
{
if(frame >= 0)
prop->write(data, frame, 1);
}
else
prop->write(data);
}

@ -100,7 +100,7 @@ void AUD_JOSResampleReader::updateBuffer(int size, double factor, int samplesize
// then check if afterwards the length is enough for the maximum rate
if(len + size < num_samples * AUD_RATE_MAX)
len = size - num_samples * AUD_RATE_MAX;
len = num_samples * AUD_RATE_MAX - size;
if(m_n > len)
{
@ -130,58 +130,101 @@ void AUD_JOSResampleReader::updateBuffer(int size, double factor, int samplesize
\
for(unsigned int t = 0; t < length; t++)\
{\
factor = (m_last_factor * (length - t) + target_factor * t) / length;\
\
if(factor >= 1)\
f_increment = m_L;\
else\
f_increment = factor * m_L;\
\
P_increment = double_to_fp(f_increment);\
P = double_to_fp(m_P * f_increment);\
\
end = (int_to_fp(m_len) - P) / P_increment - 1;\
if(m_n < end)\
end = m_n;\
factor = (m_last_factor * (length - t - 1) + target_factor * (t + 1)) / length;\
\
memset(sums, 0, sizeof(double) * m_channels);\
\
P += P_increment * end;\
data = buf + (m_n - end) * m_channels;\
l = fp_to_int(P);\
\
for(i = 0; i <= end; i++)\
if(factor >= 1)\
{\
eta = fp_rest_to_double(P);\
v = coeff[l] + eta * (coeff[l+1] - coeff[l]);\
P -= P_increment;\
P = double_to_fp(m_P * m_L);\
\
end = floor(m_len / double(m_L) - m_P) - 1;\
if(m_n < end)\
end = m_n;\
\
data = buf + (m_n - end) * m_channels;\
l = fp_to_int(P);\
left\
}\
\
P = -P;\
\
end = (int_to_fp(m_len) - P) / P_increment - 1;\
if(m_cache_valid - m_n - 2 < end)\
end = m_cache_valid - m_n - 2;\
\
P += P_increment * end;\
data = buf + (m_n + 2 + end) * m_channels - 1;\
l = fp_to_int(P);\
\
for(i = 0; i <= end; i++)\
{\
eta = fp_rest_to_double(P);\
v = coeff[l] + eta * (coeff[l+1] - coeff[l]);\
P -= P_increment;\
l = fp_to_int(P);\
right\
}\
l += m_L * end;\
\
for(channel = 0; channel < m_channels; channel++)\
for(i = 0; i <= end; i++)\
{\
v = coeff[l] + eta * (coeff[l+1] - coeff[l]);\
l -= m_L;\
left\
}\
\
P = int_to_fp(m_L) - P;\
\
end = floor((m_len - 1) / double(m_L) + m_P) - 1;\
if(m_cache_valid - m_n - 2 < end)\
end = m_cache_valid - m_n - 2;\
\
data = buf + (m_n + 2 + end) * m_channels - 1;\
l = fp_to_int(P);\
eta = fp_rest_to_double(P);\
l += m_L * end;\
\
for(i = 0; i <= end; i++)\
{\
v = coeff[l] + eta * (coeff[l+1] - coeff[l]);\
l -= m_L;\
right\
}\
\
for(channel = 0; channel < m_channels; channel++)\
{\
*buffer = sums[channel];\
buffer++;\
}\
}\
else\
{\
*buffer = f_increment / m_L * sums[channel];\
buffer++;\
f_increment = factor * m_L;\
P_increment = double_to_fp(f_increment);\
P = double_to_fp(m_P * f_increment);\
\
end = (int_to_fp(m_len) - P) / P_increment - 1;\
if(m_n < end)\
end = m_n;\
\
P += P_increment * end;\
data = buf + (m_n - end) * m_channels;\
l = fp_to_int(P);\
\
for(i = 0; i <= end; i++)\
{\
eta = fp_rest_to_double(P);\
v = coeff[l] + eta * (coeff[l+1] - coeff[l]);\
P -= P_increment;\
l = fp_to_int(P);\
left\
}\
\
P = -P;\
\
end = (int_to_fp(m_len) - P) / P_increment - 1;\
if(m_cache_valid - m_n - 2 < end)\
end = m_cache_valid - m_n - 2;\
\
P += P_increment * end;\
data = buf + (m_n + 2 + end) * m_channels - 1;\
l = fp_to_int(P);\
\
for(i = 0; i <= end; i++)\
{\
eta = fp_rest_to_double(P);\
v = coeff[l] + eta * (coeff[l+1] - coeff[l]);\
P -= P_increment;\
l = fp_to_int(P);\
right\
}\
\
for(channel = 0; channel < m_channels; channel++)\
{\
*buffer = f_increment / m_L * sums[channel];\
buffer++;\
}\
}\
\
m_P += fmod(1.0 / factor, 1.0);\

File diff suppressed because it is too large Load Diff

@ -72,7 +72,7 @@ void AUD_SoftwareDevice::AUD_SoftwareHandle::update()
AUD_Vector3 SL;
if(m_relative)
SL = m_location;
SL = -m_location;
else
SL = m_device->m_location - m_location;
float distance = SL * SL;

@ -653,7 +653,6 @@ class SEQUENCER_PT_sound(SequencerButtonsPanel, Panel):
layout.prop(strip, "waveform")
layout.prop(strip, "volume")
layout.prop(strip, "attenuation")
layout.prop(strip, "pitch")
layout.prop(strip, "pan")

@ -52,16 +52,6 @@
#ifdef RNA_RUNTIME
static float to_dB(float x)
{
return logf(x * x + 1e-30f) * 4.34294480f;
}
static float from_dB(float x)
{
return expf(x * 0.11512925f);
}
/* build a temp referene to the parent */
static void meta_tmp_ref(Sequence *seq_par, Sequence *seq)
{
@ -514,20 +504,6 @@ static int rna_Sequence_proxy_filepath_length(PointerRNA *ptr)
return strlen(path)+1;
}
static float rna_Sequence_attenuation_get(PointerRNA *ptr)
{
Sequence *seq= (Sequence*)(ptr->data);
return to_dB(seq->volume);
}
static void rna_Sequence_attenuation_set(PointerRNA *ptr, float value)
{
Sequence *seq= (Sequence*)(ptr->data);
seq->volume = from_dB(value);
}
static void rna_Sequence_volume_set(PointerRNA *ptr, float value)
{
Sequence *seq= (Sequence*)(ptr->data);
@ -1401,12 +1377,6 @@ static void rna_def_sound(BlenderRNA *brna)
RNA_def_property_float_funcs(prop, NULL, "rna_Sequence_volume_set", NULL);
RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, "rna_Sequence_update");
prop= RNA_def_property(srna, "attenuation", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, -100.0f, +40.0f);
RNA_def_property_ui_text(prop, "Attenuation/dB", "Attenuation in decibel");
RNA_def_property_float_funcs(prop, "rna_Sequence_attenuation_get", "rna_Sequence_attenuation_set", NULL);
RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, "rna_Sequence_update");
prop= RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "pitch");
RNA_def_property_range(prop, 0.1f, 10.0f);

@ -1008,7 +1008,8 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene)
{
m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true);
KX_Camera* cam = scene->GetActiveCamera();
// nothing to do here, everything relative now...
/*KX_Camera* cam = scene->GetActiveCamera();
if (!cam)
return;
@ -1016,16 +1017,17 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene)
if(dev)
{
AUD_Vector3 v;
float q[4];
cam->NodeGetWorldPosition().getValue(v.get());
//float q[4];
//cam->NodeGetWorldPosition().getValue(v.get());
dev->setListenerLocation(v);
cam->GetLinearVelocity().getValue(v.get());
//cam->GetLinearVelocity().getValue(v.get());
dev->setListenerVelocity(v);
cam->NodeGetWorldOrientation().getRotation().getValue(q);
dev->setListenerOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2]));
}
//cam->NodeGetWorldOrientation().getRotation().getValue(q);
//dev->setListenerOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2]));
dev->setListenerOrientation(AUD_Quaternion());
}*/
}

@ -46,6 +46,8 @@
#include "KX_GameObject.h"
#include "KX_PyMath.h" // needed for PyObjectFrom()
#include "KX_PythonInit.h"
#include "KX_Camera.h"
#include <iostream>
/* ------------------------------------------------------------------------- */
@ -112,7 +114,7 @@ void KX_SoundActuator::play()
if(m_is3d && !handle3d.isNull())
{
handle3d->setRelative(false);
handle3d->setRelative(true);
handle3d->setVolumeMaximum(m_3d.max_gain);
handle3d->setVolumeMinimum(m_3d.min_gain);
handle3d->setDistanceReference(m_3d.reference_distance);
@ -222,16 +224,27 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
if(m_is3d && !handle3d.isNull())
{
KX_GameObject* obj = (KX_GameObject*)this->GetParent();
AUD_Vector3 v;
float q[4];
KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera();
if (cam)
{
KX_GameObject* obj = (KX_GameObject*)this->GetParent();
MT_Point3 p;
MT_Matrix3x3 Mo;
AUD_Vector3 v;
float q[4];
obj->NodeGetWorldPosition().getValue(v.get());
handle3d->setSourceLocation(v);
obj->GetLinearVelocity().getValue(v.get());
handle3d->setSourceVelocity(v);
obj->NodeGetWorldOrientation().getRotation().getValue(q);
handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2]));
Mo = cam->NodeGetWorldOrientation().inverse();
p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition());
p = Mo * p;
p.getValue(v.get());
handle3d->setSourceLocation(v);
p = (obj->GetLinearVelocity() - cam->GetLinearVelocity());
p = Mo * p;
p.getValue(v.get());
handle3d->setSourceVelocity(v);
(Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(q);
handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2]));
}
}
result = true;
}