Audaspace: Refactored the complete 3D Device code giving a nicer API.

This commit is contained in:
2010-07-30 22:20:08 +00:00
parent 3ff872bf59
commit c59b930d13
12 changed files with 1738 additions and 796 deletions

View File

@@ -1099,214 +1099,447 @@ bool AUD_OpenALDevice::bufferFactory(void *value)
/**************************** 3D Device Code **********************************/
/******************************************************************************/
AUD_Handle* AUD_OpenALDevice::play3D(AUD_IFactory* factory, bool keep)
AUD_Vector3 AUD_OpenALDevice::getListenerLocation() const
{
AUD_OpenALHandle* handle = (AUD_OpenALHandle*)play(factory, keep);
if(handle)
alSourcei(handle->source, AL_SOURCE_RELATIVE, 0);
return handle;
ALfloat p[3];
alGetListenerfv(AL_POSITION, p);
return AUD_Vector3(p[0], p[1], p[2]);
}
bool AUD_OpenALDevice::updateListener(AUD_3DData &data)
void AUD_OpenALDevice::setListenerLocation(const AUD_Vector3& location)
{
alListenerfv(AL_POSITION, (ALfloat*)data.position);
alListenerfv(AL_VELOCITY, (ALfloat*)data.velocity);
alListenerfv(AL_ORIENTATION, (ALfloat*)&(data.orientation[3]));
return true;
alListenerfv(AL_POSITION, (ALfloat*)location.get());
}
bool AUD_OpenALDevice::setSetting(AUD_3DSetting setting, float value)
AUD_Vector3 AUD_OpenALDevice::getListenerVelocity() const
{
switch(setting)
ALfloat v[3];
alGetListenerfv(AL_VELOCITY, v);
return AUD_Vector3(v[0], v[1], v[2]);
}
void AUD_OpenALDevice::setListenerVelocity(const AUD_Vector3& velocity)
{
alListenerfv(AL_VELOCITY, (ALfloat*)velocity.get());
}
AUD_Quaternion AUD_OpenALDevice::getListenerOrientation() const
{
// AUD_XXX not implemented yet
return AUD_Quaternion(0, 0, 0, 0);
}
void AUD_OpenALDevice::setListenerOrientation(const AUD_Quaternion& orientation)
{
ALfloat direction[6];
direction[0] = -2 * (orientation.w() * orientation.y() +
orientation.x() * orientation.z());
direction[1] = 2 * (orientation.x() * orientation.w() -
orientation.z() * orientation.y());
direction[2] = 2 * (orientation.x() * orientation.x() +
orientation.y() * orientation.y()) - 1;
direction[3] = 2 * (orientation.x() * orientation.y() -
orientation.w() * orientation.z());
direction[4] = 1 - 2 * (orientation.x() * orientation.x() +
orientation.z() * orientation.z());
direction[5] = 2 * (orientation.w() * orientation.x() +
orientation.y() * orientation.z());
alListenerfv(AL_ORIENTATION, direction);
}
float AUD_OpenALDevice::getSpeedOfSound() const
{
return alGetFloat(AL_SPEED_OF_SOUND);
}
void AUD_OpenALDevice::setSpeedOfSound(float speed)
{
alSpeedOfSound(speed);
}
float AUD_OpenALDevice::getDopplerFactor() const
{
return alGetFloat(AL_DOPPLER_FACTOR);
}
void AUD_OpenALDevice::setDopplerFactor(float factor)
{
alDopplerFactor(factor);
}
AUD_DistanceModel AUD_OpenALDevice::getDistanceModel() const
{
switch(alGetInteger(AL_DISTANCE_MODEL))
{
case AUD_3DS_DISTANCE_MODEL:
if(value == AUD_DISTANCE_MODEL_NONE)
alDistanceModel(AL_NONE);
else if(value == AUD_DISTANCE_MODEL_INVERSE)
alDistanceModel(AL_INVERSE_DISTANCE);
else if(value == AUD_DISTANCE_MODEL_INVERSE_CLAMPED)
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
else if(value == AUD_DISTANCE_MODEL_LINEAR)
alDistanceModel(AL_LINEAR_DISTANCE);
else if(value == AUD_DISTANCE_MODEL_LINEAR_CLAMPED)
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
else if(value == AUD_DISTANCE_MODEL_EXPONENT)
alDistanceModel(AL_EXPONENT_DISTANCE);
else if(value == AUD_DISTANCE_MODEL_EXPONENT_CLAMPED)
alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
else
return false;
return true;
case AUD_3DS_DOPPLER_FACTOR:
alDopplerFactor(value);
return true;
case AUD_3DS_SPEED_OF_SOUND:
alSpeedOfSound(value);
return true;
case AL_INVERSE_DISTANCE:
return AUD_DISTANCE_MODEL_INVERSE;
case AL_INVERSE_DISTANCE_CLAMPED:
return AUD_DISTANCE_MODEL_INVERSE_CLAMPED;
case AL_LINEAR_DISTANCE:
return AUD_DISTANCE_MODEL_LINEAR;
case AL_LINEAR_DISTANCE_CLAMPED:
return AUD_DISTANCE_MODEL_LINEAR_CLAMPED;
case AL_EXPONENT_DISTANCE:
return AUD_DISTANCE_MODEL_EXPONENT;
case AL_EXPONENT_DISTANCE_CLAMPED:
return AUD_DISTANCE_MODEL_EXPONENT_CLAMPED;
default:
return false;
return AUD_DISTANCE_MODEL_INVALID;
}
}
float AUD_OpenALDevice::getSetting(AUD_3DSetting setting)
void AUD_OpenALDevice::setDistanceModel(AUD_DistanceModel model)
{
switch(setting)
switch(model)
{
case AUD_3DS_DISTANCE_MODEL:
switch(alGetInteger(AL_DISTANCE_MODEL))
{
case AL_NONE:
return AUD_DISTANCE_MODEL_NONE;
case AL_INVERSE_DISTANCE:
return AUD_DISTANCE_MODEL_INVERSE;
case AL_INVERSE_DISTANCE_CLAMPED:
return AUD_DISTANCE_MODEL_INVERSE_CLAMPED;
case AL_LINEAR_DISTANCE:
return AUD_DISTANCE_MODEL_LINEAR;
case AL_LINEAR_DISTANCE_CLAMPED:
return AUD_DISTANCE_MODEL_LINEAR_CLAMPED;
case AL_EXPONENT_DISTANCE:
return AUD_DISTANCE_MODEL_EXPONENT;
case AL_EXPONENT_DISTANCE_CLAMPED:
return AUD_DISTANCE_MODEL_EXPONENT_CLAMPED;
}
case AUD_3DS_DOPPLER_FACTOR:
return alGetFloat(AL_DOPPLER_FACTOR);
case AUD_3DS_SPEED_OF_SOUND:
return alGetFloat(AL_SPEED_OF_SOUND);
case AUD_DISTANCE_MODEL_INVERSE:
alDistanceModel(AL_INVERSE_DISTANCE);
break;
case AUD_DISTANCE_MODEL_INVERSE_CLAMPED:
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
break;
case AUD_DISTANCE_MODEL_LINEAR:
alDistanceModel(AL_LINEAR_DISTANCE);
break;
case AUD_DISTANCE_MODEL_LINEAR_CLAMPED:
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
break;
case AUD_DISTANCE_MODEL_EXPONENT:
alDistanceModel(AL_EXPONENT_DISTANCE);
break;
case AUD_DISTANCE_MODEL_EXPONENT_CLAMPED:
alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
break;
default:
return std::numeric_limits<float>::quiet_NaN();
alDistanceModel(AL_NONE);
}
}
bool AUD_OpenALDevice::updateSource(AUD_Handle* handle, AUD_3DData &data)
AUD_Vector3 AUD_OpenALDevice::getSourceLocation(AUD_Handle* handle)
{
bool result = false;
AUD_Vector3 result = AUD_Vector3(0, 0, 0);
ALfloat p[3];
lock();
if(isValid(handle))
{
int source = ((AUD_OpenALHandle*)handle)->source;
alSourcefv(source, AL_POSITION, (ALfloat*)data.position);
alSourcefv(source, AL_VELOCITY, (ALfloat*)data.velocity);
alSourcefv(source, AL_DIRECTION, (ALfloat*)&(data.orientation[3]));
result = true;
}
unlock();
return result;
}
bool AUD_OpenALDevice::setSourceSetting(AUD_Handle* handle,
AUD_3DSourceSetting setting,
float value)
{
lock();
bool result = false;
if(isValid(handle))
{
int source = ((AUD_OpenALHandle*)handle)->source;
switch(setting)
{
case AUD_3DSS_CONE_INNER_ANGLE:
alSourcef(source, AL_CONE_INNER_ANGLE, value);
result = true;
break;
case AUD_3DSS_CONE_OUTER_ANGLE:
alSourcef(source, AL_CONE_OUTER_ANGLE, value);
result = true;
break;
case AUD_3DSS_CONE_OUTER_GAIN:
alSourcef(source, AL_CONE_OUTER_GAIN, value);
result = true;
break;
case AUD_3DSS_IS_RELATIVE:
alSourcei(source, AL_SOURCE_RELATIVE, value > 0.0f);
result = true;
break;
case AUD_3DSS_MAX_DISTANCE:
alSourcef(source, AL_MAX_DISTANCE, value);
result = true;
break;
case AUD_3DSS_MAX_GAIN:
alSourcef(source, AL_MAX_GAIN, value);
result = true;
break;
case AUD_3DSS_MIN_GAIN:
alSourcef(source, AL_MIN_GAIN, value);
result = true;
break;
case AUD_3DSS_REFERENCE_DISTANCE:
alSourcef(source, AL_REFERENCE_DISTANCE, value);
result = true;
break;
case AUD_3DSS_ROLLOFF_FACTOR:
alSourcef(source, AL_ROLLOFF_FACTOR, value);
result = true;
break;
default:
break;
}
alGetSourcefv(((AUD_OpenALHandle*)handle)->source, AL_POSITION, p);
result = AUD_Vector3(p[0], p[1], p[2]);
}
unlock();
return result;
}
float AUD_OpenALDevice::getSourceSetting(AUD_Handle* handle,
AUD_3DSourceSetting setting)
bool AUD_OpenALDevice::setSourceLocation(AUD_Handle* handle, const AUD_Vector3& location)
{
lock();
bool result = isValid(handle);
if(result)
alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_POSITION,
(ALfloat*)location.get());
unlock();
return result;
}
AUD_Vector3 AUD_OpenALDevice::getSourceVelocity(AUD_Handle* handle)
{
AUD_Vector3 result = AUD_Vector3(0, 0, 0);
ALfloat v[3];
lock();
if(isValid(handle))
{
alGetSourcefv(((AUD_OpenALHandle*)handle)->source, AL_VELOCITY, v);
result = AUD_Vector3(v[0], v[1], v[2]);
}
unlock();
return result;
}
bool AUD_OpenALDevice::setSourceVelocity(AUD_Handle* handle, const AUD_Vector3& velocity)
{
lock();
bool result = isValid(handle);
if(result)
alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_VELOCITY,
(ALfloat*)velocity.get());
unlock();
return result;
}
AUD_Quaternion AUD_OpenALDevice::getSourceOrientation(AUD_Handle* handle)
{
// AUD_XXX not implemented yet
return AUD_Quaternion(0, 0, 0, 0);
}
bool AUD_OpenALDevice::setSourceOrientation(AUD_Handle* handle, const AUD_Quaternion& orientation)
{
lock();
bool result = isValid(handle);
if(result)
{
ALfloat direction[3];
direction[0] = -2 * (orientation.w() * orientation.y() +
orientation.x() * orientation.z());
direction[1] = 2 * (orientation.x() * orientation.w() -
orientation.z() * orientation.y());
direction[2] = 2 * (orientation.x() * orientation.x() +
orientation.y() * orientation.y()) - 1;
alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_DIRECTION,
direction);
}
unlock();
return result;
}
bool AUD_OpenALDevice::isRelative(AUD_Handle* handle)
{
int result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcei(((AUD_OpenALHandle*)handle)->source, AL_SOURCE_RELATIVE,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setRelative(AUD_Handle* handle, bool relative)
{
lock();
bool result = isValid(handle);
if(result)
alSourcei(((AUD_OpenALHandle*)handle)->source, AL_SOURCE_RELATIVE,
relative);
unlock();
return result;
}
float AUD_OpenALDevice::getVolumeMaximum(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
{
int source = ((AUD_OpenALHandle*)handle)->source;
switch(setting)
{
case AUD_3DSS_CONE_INNER_ANGLE:
alGetSourcef(source, AL_CONE_INNER_ANGLE, &result);
break;
case AUD_3DSS_CONE_OUTER_ANGLE:
alGetSourcef(source, AL_CONE_OUTER_ANGLE, &result);
break;
case AUD_3DSS_CONE_OUTER_GAIN:
alGetSourcef(source, AL_CONE_OUTER_GAIN, &result);
break;
case AUD_3DSS_IS_RELATIVE:
{
ALint i;
alGetSourcei(source, AL_SOURCE_RELATIVE, &i);
result = i ? 1.0f : 0.0f;
break;
}
case AUD_3DSS_MAX_DISTANCE:
alGetSourcef(source, AL_MAX_DISTANCE, &result);
break;
case AUD_3DSS_MAX_GAIN:
alGetSourcef(source, AL_MAX_GAIN, &result);
break;
case AUD_3DSS_MIN_GAIN:
alGetSourcef(source, AL_MIN_GAIN, &result);
break;
case AUD_3DSS_REFERENCE_DISTANCE:
alGetSourcef(source, AL_REFERENCE_DISTANCE, &result);
break;
case AUD_3DSS_ROLLOFF_FACTOR:
alGetSourcef(source, AL_ROLLOFF_FACTOR, &result);
break;
default:
break;
}
}
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_GAIN,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setVolumeMaximum(AUD_Handle* handle, float volume)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_GAIN,
volume);
unlock();
return result;
}
float AUD_OpenALDevice::getVolumeMinimum(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_MIN_GAIN,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setVolumeMinimum(AUD_Handle* handle, float volume)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_MIN_GAIN,
volume);
unlock();
return result;
}
float AUD_OpenALDevice::getDistanceMaximum(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_DISTANCE,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setDistanceMaximum(AUD_Handle* handle, float distance)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_MAX_DISTANCE,
distance);
unlock();
return result;
}
float AUD_OpenALDevice::getDistanceReference(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_REFERENCE_DISTANCE,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setDistanceReference(AUD_Handle* handle, float distance)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_REFERENCE_DISTANCE,
distance);
unlock();
return result;
}
float AUD_OpenALDevice::getAttenuation(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_ROLLOFF_FACTOR,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setAttenuation(AUD_Handle* handle, float factor)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_ROLLOFF_FACTOR,
factor);
unlock();
return result;
}
float AUD_OpenALDevice::getConeAngleOuter(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_ANGLE,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setConeAngleOuter(AUD_Handle* handle, float angle)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_ANGLE,
angle);
unlock();
return result;
}
float AUD_OpenALDevice::getConeAngleInner(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_INNER_ANGLE,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setConeAngleInner(AUD_Handle* handle, float angle)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_INNER_ANGLE,
angle);
unlock();
return result;
}
float AUD_OpenALDevice::getConeVolumeOuter(AUD_Handle* handle)
{
float result = std::numeric_limits<float>::quiet_NaN();;
lock();
if(isValid(handle))
alGetSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_GAIN,
&result);
unlock();
return result;
}
bool AUD_OpenALDevice::setConeVolumeOuter(AUD_Handle* handle, float volume)
{
lock();
bool result = isValid(handle);
if(result)
alSourcef(((AUD_OpenALHandle*)handle)->source, AL_CONE_OUTER_GAIN,
volume);
unlock();
return result;

View File

@@ -159,15 +159,42 @@ public:
virtual float getPitch(AUD_Handle* handle);
virtual bool setPitch(AUD_Handle* handle, float pitch);
virtual AUD_Handle* play3D(AUD_IFactory* factory, bool keep = false);
virtual bool updateListener(AUD_3DData &data);
virtual bool setSetting(AUD_3DSetting setting, float value);
virtual float getSetting(AUD_3DSetting setting);
virtual bool updateSource(AUD_Handle* handle, AUD_3DData &data);
virtual bool setSourceSetting(AUD_Handle* handle,
AUD_3DSourceSetting setting, float value);
virtual float getSourceSetting(AUD_Handle* handle,
AUD_3DSourceSetting setting);
virtual AUD_Vector3 getListenerLocation() const;
virtual void setListenerLocation(const AUD_Vector3& location);
virtual AUD_Vector3 getListenerVelocity() const;
virtual void setListenerVelocity(const AUD_Vector3& velocity);
virtual AUD_Quaternion getListenerOrientation() const;
virtual void setListenerOrientation(const AUD_Quaternion& orientation);
virtual float getSpeedOfSound() const;
virtual void setSpeedOfSound(float speed);
virtual float getDopplerFactor() const;
virtual void setDopplerFactor(float factor);
virtual AUD_DistanceModel getDistanceModel() const;
virtual void setDistanceModel(AUD_DistanceModel model);
virtual AUD_Vector3 getSourceLocation(AUD_Handle* handle);
virtual bool setSourceLocation(AUD_Handle* handle, const AUD_Vector3& location);
virtual AUD_Vector3 getSourceVelocity(AUD_Handle* handle);
virtual bool setSourceVelocity(AUD_Handle* handle, const AUD_Vector3& velocity);
virtual AUD_Quaternion getSourceOrientation(AUD_Handle* handle);
virtual bool setSourceOrientation(AUD_Handle* handle, const AUD_Quaternion& orientation);
virtual bool isRelative(AUD_Handle* handle);
virtual bool setRelative(AUD_Handle* handle, bool relative);
virtual float getVolumeMaximum(AUD_Handle* handle);
virtual bool setVolumeMaximum(AUD_Handle* handle, float volume);
virtual float getVolumeMinimum(AUD_Handle* handle);
virtual bool setVolumeMinimum(AUD_Handle* handle, float volume);
virtual float getDistanceMaximum(AUD_Handle* handle);
virtual bool setDistanceMaximum(AUD_Handle* handle, float distance);
virtual float getDistanceReference(AUD_Handle* handle);
virtual bool setDistanceReference(AUD_Handle* handle, float distance);
virtual float getAttenuation(AUD_Handle* handle);
virtual bool setAttenuation(AUD_Handle* handle, float factor);
virtual float getConeAngleOuter(AUD_Handle* handle);
virtual bool setConeAngleOuter(AUD_Handle* handle, float angle);
virtual float getConeAngleInner(AUD_Handle* handle);
virtual bool setConeAngleInner(AUD_Handle* handle, float angle);
virtual float getConeVolumeOuter(AUD_Handle* handle);
virtual bool setConeVolumeOuter(AUD_Handle* handle, float volume);
};
#endif //AUD_OPENALDEVICE

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,189 @@
/*
* $Id$
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AudaSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_3DMATH
#define AUD_3DMATH
class AUD_Quaternion
{
private:
union
{
float m_v[4];
struct
{
const float m_w;
const float m_x;
const float m_y;
const float m_z;
};
};
public:
/**
* Creates a new quaternion.
* \param w The w component.
* \param x The x component.
* \param y The y component.
* \param z The z component.
*/
inline AUD_Quaternion(float w, float x, float y, float z) :
m_w(w), m_x(x), m_y(y), m_z(z)
{
}
/**
* Retrieves the w component of the quarternion.
* \return The w component.
*/
inline const float& w() const
{
return m_w;
}
/**
* Retrieves the x component of the quarternion.
* \return The x component.
*/
inline const float& x() const
{
return m_x;
}
/**
* Retrieves the y component of the quarternion.
* \return The y component.
*/
inline const float& y() const
{
return m_y;
}
/**
* Retrieves the z component of the quarternion.
* \return The z component.
*/
inline const float& z() const
{
return m_z;
}
/**
* Retrieves the components of the vector.
* \param destination Where the 4 float values should be saved to.
*/
inline void get(float* destination) const
{
destination[0] = m_w;
destination[1] = m_x;
destination[2] = m_y;
destination[3] = m_z;
}
/**
* Retrieves the components of the vector.
* \return The components as float[4].
*/
inline const float* get() const
{
return m_v;
}
};
class AUD_Vector3
{
private:
union
{
float m_v[3];
struct
{
const float m_x;
const float m_y;
const float m_z;
};
};
public:
/**
* Creates a new 3 dimensional vector.
* \param x The x component.
* \param y The y component.
* \param z The z component.
*/
inline AUD_Vector3(float x, float y, float z) :
m_x(x), m_y(y), m_z(z)
{
}
/**
* Retrieves the x component of the vector.
* \return The x component.
*/
inline const float& x() const
{
return m_x;
}
/**
* Retrieves the y component of the vector.
* \return The y component.
*/
inline const float& y() const
{
return m_y;
}
/**
* Retrieves the z component of the vector.
* \return The z component.
*/
inline const float& z() const
{
return m_z;
}
/**
* Retrieves the components of the vector.
* \param destination Where the 3 float values should be saved to.
*/
inline void get(float* destination) const
{
destination[0] = m_x;
destination[1] = m_y;
destination[2] = m_z;
}
/**
* Retrieves the components of the vector.
* \return The components as float[3].
*/
inline const float* get() const
{
return m_v;
}
};
#endif //AUD_3DMATH

View File

@@ -443,124 +443,244 @@ AUD_Status AUD_getStatus(AUD_Channel* handle)
return AUD_device->getStatus(handle);
}
AUD_Channel* AUD_play3D(AUD_Sound* sound, int keep)
{
assert(AUD_device);
assert(sound);
try
{
if(AUD_3ddevice)
return AUD_3ddevice->play3D(sound, keep);
else
return AUD_device->play(sound, keep);
}
catch(AUD_Exception&)
{
return NULL;
}
}
int AUD_updateListener(AUD_3DData* data)
{
assert(AUD_device);
assert(data);
try
{
if(AUD_3ddevice)
return AUD_3ddevice->updateListener(*data);
}
catch(AUD_Exception&)
{
}
return false;
}
int AUD_set3DSetting(AUD_3DSetting setting, float value)
int AUD_setListenerLocation(const float* location)
{
assert(AUD_device);
try
{
if(AUD_3ddevice)
return AUD_3ddevice->setSetting(setting, value);
}
catch(AUD_Exception&)
if(AUD_3ddevice)
{
AUD_Vector3 v(location[0], location[1], location[2]);
AUD_3ddevice->setListenerLocation(v);
return true;
}
return false;
}
float AUD_get3DSetting(AUD_3DSetting setting)
int AUD_setListenerVelocity(const float* velocity)
{
assert(AUD_device);
try
if(AUD_3ddevice)
{
if(AUD_3ddevice)
return AUD_3ddevice->getSetting(setting);
AUD_Vector3 v(velocity[0], velocity[1], velocity[2]);
AUD_3ddevice->setListenerVelocity(v);
return true;
}
catch(AUD_Exception&)
{
}
return 0.0f;
}
int AUD_update3DSource(AUD_Channel* handle, AUD_3DData* data)
{
if(handle)
{
assert(AUD_device);
assert(data);
try
{
if(AUD_3ddevice)
return AUD_3ddevice->updateSource(handle, *data);
}
catch(AUD_Exception&)
{
}
}
return false;
}
int AUD_set3DSourceSetting(AUD_Channel* handle,
AUD_3DSourceSetting setting, float value)
int AUD_setListenerOrientation(const float* orientation)
{
if(handle)
{
assert(AUD_device);
assert(AUD_device);
try
{
if(AUD_3ddevice)
return AUD_3ddevice->setSourceSetting(handle, setting, value);
}
catch(AUD_Exception&)
{
}
if(AUD_3ddevice)
{
AUD_Quaternion q(orientation[0], orientation[1], orientation[2], orientation[3]);
AUD_3ddevice->setListenerOrientation(q);
return true;
}
return false;
}
float AUD_get3DSourceSetting(AUD_Channel* handle, AUD_3DSourceSetting setting)
int AUD_setSpeedOfSound(float speed)
{
if(handle)
{
assert(AUD_device);
assert(AUD_device);
try
{
if(AUD_3ddevice)
return AUD_3ddevice->getSourceSetting(handle, setting);
}
catch(AUD_Exception&)
{
}
if(AUD_3ddevice)
{
AUD_3ddevice->setSpeedOfSound(speed);
return true;
}
return 0.0f;
return false;
}
int AUD_setDopplerFactor(float factor)
{
assert(AUD_device);
if(AUD_3ddevice)
{
AUD_3ddevice->setDopplerFactor(factor);
return true;
}
return false;
}
int AUD_setDistanceModel(AUD_DistanceModel model)
{
assert(AUD_device);
if(AUD_3ddevice)
{
AUD_3ddevice->setDistanceModel(model);
return true;
}
return false;
}
int AUD_setSourceLocation(AUD_Channel* handle, const float* location)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
AUD_Vector3 v(location[0], location[1], location[2]);
return AUD_3ddevice->setSourceLocation(handle, v);
}
return false;
}
int AUD_setSourceVelocity(AUD_Channel* handle, const float* velocity)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
AUD_Vector3 v(velocity[0], velocity[1], velocity[2]);
return AUD_3ddevice->setSourceVelocity(handle, v);
}
return false;
}
int AUD_setSourceOrientation(AUD_Channel* handle, const float* orientation)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
AUD_Quaternion q(orientation[0], orientation[1], orientation[2], orientation[3]);
return AUD_3ddevice->setSourceOrientation(handle, q);
}
return false;
}
int AUD_setRelative(AUD_Channel* handle, int relative)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setRelative(handle, relative);
}
return false;
}
int AUD_setVolumeMaximum(AUD_Channel* handle, float volume)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setVolumeMaximum(handle, volume);
}
return false;
}
int AUD_setVolumeMinimum(AUD_Channel* handle, float volume)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setVolumeMinimum(handle, volume);
}
return false;
}
int AUD_setDistanceMaximum(AUD_Channel* handle, float distance)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setDistanceMaximum(handle, distance);
}
return false;
}
int AUD_setDistanceReference(AUD_Channel* handle, float distance)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setDistanceReference(handle, distance);
}
return false;
}
int AUD_setAttenuation(AUD_Channel* handle, float factor)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setAttenuation(handle, factor);
}
return false;
}
int AUD_setConeAngleOuter(AUD_Channel* handle, float angle)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setConeAngleOuter(handle, angle);
}
return false;
}
int AUD_setConeAngleInner(AUD_Channel* handle, float angle)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setConeAngleInner(handle, angle);
}
return false;
}
int AUD_setConeVolumeOuter(AUD_Channel* handle, float volume)
{
assert(AUD_device);
assert(handle);
if(AUD_3ddevice)
{
return AUD_3ddevice->setConeVolumeOuter(handle, volume);
}
return false;
}
int AUD_setSoundVolume(AUD_Channel* handle, float volume)

View File

@@ -246,64 +246,145 @@ extern float AUD_getPosition(AUD_Channel* handle);
extern AUD_Status AUD_getStatus(AUD_Channel* handle);
/**
* Plays a 3D sound.
* \param sound The handle of the sound file.
* \param keep When keep is true the sound source will not be deleted but set to
* paused when its end has been reached.
* \return A handle to the played back sound.
* \note The factory must provide a mono (single channel) source and the device
* must support 3D audio, otherwise the sound is played back normally.
* Sets the listener location.
* \param location The new location.
*/
extern AUD_Channel* AUD_play3D(AUD_Sound* sound, int keep);
extern int AUD_setListenerLocation(const float* location);
/**
* Updates the listener 3D data.
* \param data The 3D data.
* Sets the listener velocity.
* \param velocity The new velocity.
*/
extern int AUD_setListenerVelocity(const float* velocity);
/**
* Sets the listener orientation.
* \param orientation The new orientation as quaternion.
*/
extern int AUD_setListenerOrientation(const float* orientation);
/**
* Sets the speed of sound.
* This value is needed for doppler effect calculation.
* \param speed The new speed of sound.
*/
extern int AUD_setSpeedOfSound(float speed);
/**
* Sets the doppler factor.
* This value is a scaling factor for the velocity vectors of sources and
* listener which is used while calculating the doppler effect.
* \param factor The new doppler factor.
*/
extern int AUD_setDopplerFactor(float factor);
/**
* Sets the distance model.
* \param model distance model.
*/
extern int AUD_setDistanceModel(AUD_DistanceModel model);
/**
* Sets the location of a source.
* \param handle The handle of the source.
* \param location The new location.
* \return Whether the action succeeded.
*/
extern int AUD_updateListener(AUD_3DData* data);
extern int AUD_setSourceLocation(AUD_Channel* handle, const float* location);
/**
* Sets a 3D device setting.
* \param setting The setting type.
* \param value The new setting value.
* Sets the velocity of a source.
* \param handle The handle of the source.
* \param velocity The new velocity.
* \return Whether the action succeeded.
*/
extern int AUD_set3DSetting(AUD_3DSetting setting, float value);
extern int AUD_setSourceVelocity(AUD_Channel* handle, const float* velocity);
/**
* Retrieves a 3D device setting.
* \param setting The setting type.
* \return The setting value.
*/
extern float AUD_get3DSetting(AUD_3DSetting setting);
/**
* Updates a listeners 3D data.
* \param handle The source handle.
* \param data The 3D data.
* Sets the orientation of a source.
* \param handle The handle of the source.
* \param orientation The new orientation as quaternion.
* \return Whether the action succeeded.
*/
extern int AUD_update3DSource(AUD_Channel* handle, AUD_3DData* data);
extern int AUD_setSourceOrientation(AUD_Channel* handle, const float* orientation);
/**
* Sets a 3D source setting.
* \param handle The source handle.
* \param setting The setting type.
* \param value The new setting value.
* Sets whether the source location, velocity and orientation are relative
* to the listener.
* \param handle The handle of the source.
* \param relative Whether the source is relative.
* \return Whether the action succeeded.
*/
extern int AUD_set3DSourceSetting(AUD_Channel* handle,
AUD_3DSourceSetting setting, float value);
extern int AUD_setRelative(AUD_Channel* handle, int relative);
/**
* Retrieves a 3D source setting.
* \param handle The source handle.
* \param setting The setting type.
* \return The setting value.
* Sets the maximum volume of a source.
* \param handle The handle of the source.
* \param volume The new maximum volume.
* \return Whether the action succeeded.
*/
extern float AUD_get3DSourceSetting(AUD_Channel* handle,
AUD_3DSourceSetting setting);
extern int AUD_setVolumeMaximum(AUD_Channel* handle, float volume);
/**
* Sets the minimum volume of a source.
* \param handle The handle of the source.
* \param volume The new minimum volume.
* \return Whether the action succeeded.
*/
extern int AUD_setVolumeMinimum(AUD_Channel* handle, float volume);
/**
* Sets the maximum distance of a source.
* If a source is further away from the reader than this distance, the
* volume will automatically be set to 0.
* \param handle The handle of the source.
* \param distance The new maximum distance.
* \return Whether the action succeeded.
*/
extern int AUD_setDistanceMaximum(AUD_Channel* handle, float distance);
/**
* Sets the reference distance of a source.
* \param handle The handle of the source.
* \param distance The new reference distance.
* \return Whether the action succeeded.
*/
extern int AUD_setDistanceReference(AUD_Channel* handle, float distance);
/**
* Sets the attenuation of a source.
* This value is used for distance calculation.
* \param handle The handle of the source.
* \param factor The new attenuation.
* \return Whether the action succeeded.
*/
extern int AUD_setAttenuation(AUD_Channel* handle, float factor);
/**
* Sets the outer angle of the cone of a source.
* \param handle The handle of the source.
* \param angle The new outer angle of the cone.
* \return Whether the action succeeded.
*/
extern int AUD_setConeAngleOuter(AUD_Channel* handle, float angle);
/**
* Sets the inner angle of the cone of a source.
* \param handle The handle of the source.
* \param angle The new inner angle of the cone.
* \return Whether the action succeeded.
*/
extern int AUD_setConeAngleInner(AUD_Channel* handle, float angle);
/**
* Sets the outer volume of the cone of a source.
* The volume between inner and outer angle is interpolated between inner
* volume and this value.
* \param handle The handle of the source.
* \param volume The new outer volume of the cone.
* \return Whether the action succeeded.
*/
extern int AUD_setConeVolumeOuter(AUD_Channel* handle, float volume);
/**
* Sets the volume of a played back sound.

View File

@@ -27,6 +27,9 @@
#define AUD_I3DDEVICE
#include "AUD_Space.h"
#include "AUD_3DMath.h"
struct AUD_Handle;
/**
* This class represents an output device for 3D sound.
@@ -35,67 +38,277 @@ class AUD_I3DDevice
{
public:
/**
* Plays a 3D sound source.
* \param factory The factory to create the reader for the sound source.
* \param keep When keep is true the sound source will not be deleted but
* set to paused when its end has been reached.
* \return Returns a handle with which the playback can be controlled.
* This is NULL if the sound couldn't be played back.
* \exception AUD_Exception Thrown if there's an unexpected (from the
* device side) error during creation of the reader.
* \note The factory must provide a mono (single channel) source otherwise
* the sound is played back normally.
* Retrieves the listener location.
* \return The listener location.
*/
virtual AUD_Handle* play3D(AUD_IFactory* factory, bool keep = false)=0;
virtual AUD_Vector3 getListenerLocation() const=0;
/**
* Updates a listeners 3D data.
* \param data The 3D data.
* Sets the listener location.
* \param location The new location.
*/
virtual void setListenerLocation(const AUD_Vector3& location)=0;
/**
* Retrieves the listener velocity.
* \return The listener velocity.
*/
virtual AUD_Vector3 getListenerVelocity() const=0;
/**
* Sets the listener velocity.
* \param velocity The new velocity.
*/
virtual void setListenerVelocity(const AUD_Vector3& velocity)=0;
/**
* Retrieves the listener orientation.
* \return The listener orientation as quaternion.
*/
virtual AUD_Quaternion getListenerOrientation() const=0;
/**
* Sets the listener orientation.
* \param orientation The new orientation as quaternion.
*/
virtual void setListenerOrientation(const AUD_Quaternion& orientation)=0;
/**
* Retrieves the speed of sound.
* This value is needed for doppler effect calculation.
* \return The speed of sound.
*/
virtual float getSpeedOfSound() const=0;
/**
* Sets the speed of sound.
* This value is needed for doppler effect calculation.
* \param speed The new speed of sound.
*/
virtual void setSpeedOfSound(float speed)=0;
/**
* Retrieves the doppler factor.
* This value is a scaling factor for the velocity vectors of sources and
* listener which is used while calculating the doppler effect.
* \return The doppler factor.
*/
virtual float getDopplerFactor() const=0;
/**
* Sets the doppler factor.
* This value is a scaling factor for the velocity vectors of sources and
* listener which is used while calculating the doppler effect.
* \param factor The new doppler factor.
*/
virtual void setDopplerFactor(float factor)=0;
/**
* Retrieves the distance model.
* \return The distance model.
*/
virtual AUD_DistanceModel getDistanceModel() const=0;
/**
* Sets the distance model.
* \param model distance model.
*/
virtual void setDistanceModel(AUD_DistanceModel model)=0;
/**
* Retrieves the location of a source.
* \param handle The handle of the source.
* \return The location.
*/
virtual AUD_Vector3 getSourceLocation(AUD_Handle* handle)=0;
/**
* Sets the location of a source.
* \param handle The handle of the source.
* \param location The new location.
* \return Whether the action succeeded.
*/
virtual bool updateListener(AUD_3DData &data)=0;
virtual bool setSourceLocation(AUD_Handle* handle, const AUD_Vector3& location)=0;
/**
* Sets a 3D device setting.
* \param setting The setting type.
* \param value The new setting value.
* Retrieves the velocity of a source.
* \param handle The handle of the source.
* \return The velocity.
*/
virtual AUD_Vector3 getSourceVelocity(AUD_Handle* handle)=0;
/**
* Sets the velocity of a source.
* \param handle The handle of the source.
* \param velocity The new velocity.
* \return Whether the action succeeded.
*/
virtual bool setSetting(AUD_3DSetting setting, float value)=0;
virtual bool setSourceVelocity(AUD_Handle* handle, const AUD_Vector3& velocity)=0;
/**
* Retrieves a 3D device setting.
* \param setting The setting type.
* \return The setting value.
* Retrieves the orientation of a source.
* \param handle The handle of the source.
* \return The orientation as quaternion.
*/
virtual float getSetting(AUD_3DSetting setting)=0;
virtual AUD_Quaternion getSourceOrientation(AUD_Handle* handle)=0;
/**
* Updates a listeners 3D data.
* \param handle The source handle.
* \param data The 3D data.
* Sets the orientation of a source.
* \param handle The handle of the source.
* \param orientation The new orientation as quaternion.
* \return Whether the action succeeded.
*/
virtual bool updateSource(AUD_Handle* handle, AUD_3DData &data)=0;
virtual bool setSourceOrientation(AUD_Handle* handle, const AUD_Quaternion& orientation)=0;
/**
* Sets a 3D source setting.
* \param handle The source handle.
* \param setting The setting type.
* \param value The new setting value.
* Checks whether the source location, velocity and orientation are relative
* to the listener.
* \param handle The handle of the source.
* \return Whether the source is relative.
*/
virtual bool isRelative(AUD_Handle* handle)=0;
/**
* Sets whether the source location, velocity and orientation are relative
* to the listener.
* \param handle The handle of the source.
* \param relative Whether the source is relative.
* \return Whether the action succeeded.
*/
virtual bool setSourceSetting(AUD_Handle* handle,
AUD_3DSourceSetting setting, float value)=0;
virtual bool setRelative(AUD_Handle* handle, bool relative)=0;
/**
* Retrieves a 3D source setting.
* \param handle The source handle.
* \param setting The setting type.
* \return The setting value.
* Retrieves the maximum volume of a source.
* \param handle The handle of the source.
* \return The maximum volume.
*/
virtual float getSourceSetting(AUD_Handle* handle,
AUD_3DSourceSetting setting)=0;
virtual float getVolumeMaximum(AUD_Handle* handle)=0;
/**
* Sets the maximum volume of a source.
* \param handle The handle of the source.
* \param volume The new maximum volume.
* \return Whether the action succeeded.
*/
virtual bool setVolumeMaximum(AUD_Handle* handle, float volume)=0;
/**
* Retrieves the minimum volume of a source.
* \param handle The handle of the source.
* \return The minimum volume.
*/
virtual float getVolumeMinimum(AUD_Handle* handle)=0;
/**
* Sets the minimum volume of a source.
* \param handle The handle of the source.
* \param volume The new minimum volume.
* \return Whether the action succeeded.
*/
virtual bool setVolumeMinimum(AUD_Handle* handle, float volume)=0;
/**
* Retrieves the maximum distance of a source.
* If a source is further away from the reader than this distance, the
* volume will automatically be set to 0.
* \param handle The handle of the source.
* \return The maximum distance.
*/
virtual float getDistanceMaximum(AUD_Handle* handle)=0;
/**
* Sets the maximum distance of a source.
* If a source is further away from the reader than this distance, the
* volume will automatically be set to 0.
* \param handle The handle of the source.
* \param distance The new maximum distance.
* \return Whether the action succeeded.
*/
virtual bool setDistanceMaximum(AUD_Handle* handle, float distance)=0;
/**
* Retrieves the reference distance of a source.
* \param handle The handle of the source.
* \return The reference distance.
*/
virtual float getDistanceReference(AUD_Handle* handle)=0;
/**
* Sets the reference distance of a source.
* \param handle The handle of the source.
* \param distance The new reference distance.
* \return Whether the action succeeded.
*/
virtual bool setDistanceReference(AUD_Handle* handle, float distance)=0;
/**
* Retrieves the attenuation of a source.
* \param handle The handle of the source.
* \return The attenuation.
*/
virtual float getAttenuation(AUD_Handle* handle)=0;
/**
* Sets the attenuation of a source.
* This value is used for distance calculation.
* \param handle The handle of the source.
* \param factor The new attenuation.
* \return Whether the action succeeded.
*/
virtual bool setAttenuation(AUD_Handle* handle, float factor)=0;
/**
* Retrieves the outer angle of the cone of a source.
* \param handle The handle of the source.
* \return The outer angle of the cone.
*/
virtual float getConeAngleOuter(AUD_Handle* handle)=0;
/**
* Sets the outer angle of the cone of a source.
* \param handle The handle of the source.
* \param angle The new outer angle of the cone.
* \return Whether the action succeeded.
*/
virtual bool setConeAngleOuter(AUD_Handle* handle, float angle)=0;
/**
* Retrieves the inner angle of the cone of a source.
* \param handle The handle of the source.
* \return The inner angle of the cone.
*/
virtual float getConeAngleInner(AUD_Handle* handle)=0;
/**
* Sets the inner angle of the cone of a source.
* \param handle The handle of the source.
* \param angle The new inner angle of the cone.
* \return Whether the action succeeded.
*/
virtual bool setConeAngleInner(AUD_Handle* handle, float angle)=0;
/**
* Retrieves the outer volume of the cone of a source.
* The volume between inner and outer angle is interpolated between inner
* volume and this value.
* \param handle The handle of the source.
* \return The outer volume of the cone.
*/
virtual float getConeVolumeOuter(AUD_Handle* handle)=0;
/**
* Sets the outer volume of the cone of a source.
* The volume between inner and outer angle is interpolated between inner
* volume and this value.
* \param handle The handle of the source.
* \param volume The new outer volume of the cone.
* \return Whether the action succeeded.
*/
virtual bool setConeVolumeOuter(AUD_Handle* handle, float volume)=0;
};
#endif //AUD_I3DDEVICE

View File

@@ -30,9 +30,9 @@
class AUD_IFactory;
/// Handle structure, for inherition.
typedef struct
struct AUD_Handle
{
} AUD_Handle;
};
/**
* This class represents an output device for sound sources.

View File

@@ -124,39 +124,17 @@ typedef enum
AUD_FADE_OUT
} AUD_FadeType;
/// 3D device settings.
typedef enum
{
AUD_3DS_NONE, /// No setting.
AUD_3DS_SPEED_OF_SOUND, /// Speed of sound.
AUD_3DS_DOPPLER_FACTOR, /// Doppler factor.
AUD_3DS_DISTANCE_MODEL /// Distance model.
} AUD_3DSetting;
/// Possible distance models for the 3D device.
#define AUD_DISTANCE_MODEL_NONE 0.0f
#define AUD_DISTANCE_MODEL_INVERSE 1.0f
#define AUD_DISTANCE_MODEL_INVERSE_CLAMPED 2.0f
#define AUD_DISTANCE_MODEL_LINEAR 3.0f
#define AUD_DISTANCE_MODEL_LINEAR_CLAMPED 4.0f
#define AUD_DISTANCE_MODEL_EXPONENT 5.0f
#define AUD_DISTANCE_MODEL_EXPONENT_CLAMPED 6.0f
/// 3D source settings.
typedef enum
{
AUD_3DSS_NONE, /// No setting.
AUD_3DSS_IS_RELATIVE, /// > 0 tells that the sound source is
/// relative to the listener
AUD_3DSS_MIN_GAIN, /// Minimum gain.
AUD_3DSS_MAX_GAIN, /// Maximum gain.
AUD_3DSS_REFERENCE_DISTANCE, /// Reference distance.
AUD_3DSS_MAX_DISTANCE, /// Maximum distance.
AUD_3DSS_ROLLOFF_FACTOR, /// Rolloff factor.
AUD_3DSS_CONE_INNER_ANGLE, /// Cone inner angle.
AUD_3DSS_CONE_OUTER_ANGLE, /// Cone outer angle.
AUD_3DSS_CONE_OUTER_GAIN /// Cone outer gain.
} AUD_3DSourceSetting;
AUD_DISTANCE_MODEL_INVALID = 0,
AUD_DISTANCE_MODEL_INVERSE,
AUD_DISTANCE_MODEL_INVERSE_CLAMPED,
AUD_DISTANCE_MODEL_LINEAR,
AUD_DISTANCE_MODEL_LINEAR_CLAMPED,
AUD_DISTANCE_MODEL_EXPONENT,
AUD_DISTANCE_MODEL_EXPONENT_CLAMPED,
} AUD_DistanceModel;
/// Sample type.(float samples)
typedef float sample_t;
@@ -206,17 +184,4 @@ typedef struct
// void* userData; - for the case it is needed someday
} AUD_Exception;
/// Handle structure, for inherition.
typedef struct
{
/// x, y and z coordinates of the object.
float position[3];
/// x, y and z coordinates telling the velocity and direction of the object.
float velocity[3];
/// 3x3 matrix telling the orientation of the object.
float orientation[9];
} AUD_3DData;
#endif //AUD_SPACE

View File

@@ -388,9 +388,9 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
ketsjiengine->InitDome(scene->gm.dome.res, scene->gm.dome.mode, scene->gm.dome.angle, scene->gm.dome.resbuf, scene->gm.dome.tilt, scene->gm.dome.warptext);
// initialize 3D Audio Settings
AUD_set3DSetting(AUD_3DS_SPEED_OF_SOUND, scene->audio.speed_of_sound);
AUD_set3DSetting(AUD_3DS_DOPPLER_FACTOR, scene->audio.doppler_factor);
AUD_set3DSetting(AUD_3DS_DISTANCE_MODEL, scene->audio.distance_model);
AUD_setSpeedOfSound(scene->audio.speed_of_sound);
AUD_setDopplerFactor(scene->audio.doppler_factor);
AUD_setDistanceModel(AUD_DistanceModel(scene->audio.distance_model));
// from see blender.c:
// FIXME: this version patching should really be part of the file-reading code,

View File

@@ -966,44 +966,17 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene)
KX_Camera* cam = scene->GetActiveCamera();
if (!cam)
return;
MT_Point3 listenerposition = cam->NodeGetWorldPosition();
MT_Vector3 listenervelocity = cam->GetLinearVelocity();
MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation();
{
AUD_3DData data;
float f;
float f[4];
listenerorientation.getValue3x3(data.orientation);
listenerposition.getValue(data.position);
listenervelocity.getValue(data.velocity);
cam->NodeGetWorldPosition().getValue(f);
AUD_setListenerLocation(f);
f = data.position[1];
data.position[1] = data.position[2];
data.position[2] = -f;
cam->GetLinearVelocity().getValue(f);
AUD_setListenerVelocity(f);
f = data.velocity[1];
data.velocity[1] = data.velocity[2];
data.velocity[2] = -f;
f = data.orientation[1];
data.orientation[1] = data.orientation[2];
data.orientation[2] = -f;
f = data.orientation[3];
data.orientation[3] = -data.orientation[6];
data.orientation[6] = f;
f = data.orientation[4];
data.orientation[4] = -data.orientation[8];
data.orientation[8] = -f;
f = data.orientation[5];
data.orientation[5] = data.orientation[7];
data.orientation[7] = f;
AUD_updateListener(&data);
}
cam->NodeGetWorldOrientation().getRotation().getValue(f);
AUD_setListenerOrientation(f);
}

View File

@@ -31,6 +31,7 @@
*/
#include "KX_SoundActuator.h"
#include "AUD_C-API.h"
#include "KX_GameObject.h"
#include "KX_PyMath.h" // needed for PyObjectFrom()
#include <iostream>
@@ -102,16 +103,17 @@ void KX_SoundActuator::play()
if(m_is3d)
{
// sound shall be played 3D
m_handle = AUD_play3D(sound, 0);
m_handle = AUD_play(sound, 0);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_MAX_GAIN, m_3d.max_gain);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_MIN_GAIN, m_3d.min_gain);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_REFERENCE_DISTANCE, m_3d.reference_distance);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_MAX_DISTANCE, m_3d.max_distance);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_ROLLOFF_FACTOR, m_3d.rolloff_factor);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_INNER_ANGLE, m_3d.cone_inner_angle);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_OUTER_ANGLE, m_3d.cone_outer_angle);
AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_OUTER_GAIN, m_3d.cone_outer_gain);
AUD_setRelative(m_handle, true);
AUD_setVolumeMaximum(m_handle, m_3d.max_gain);
AUD_setVolumeMinimum(m_handle, m_3d.min_gain);
AUD_setDistanceReference(m_handle, m_3d.reference_distance);
AUD_setDistanceMaximum(m_handle, m_3d.max_distance);
AUD_setAttenuation(m_handle, m_3d.rolloff_factor);
AUD_setConeAngleInner(m_handle, m_3d.cone_inner_angle);
AUD_setConeAngleOuter(m_handle, m_3d.cone_outer_angle);
AUD_setConeVolumeOuter(m_handle, m_3d.cone_outer_gain);
}
else
m_handle = AUD_play(sound, 0);
@@ -215,39 +217,15 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
{
if(m_is3d)
{
AUD_3DData data;
float f;
((KX_GameObject*)this->GetParent())->NodeGetWorldPosition().getValue(data.position);
((KX_GameObject*)this->GetParent())->GetLinearVelocity().getValue(data.velocity);
((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation().getValue3x3(data.orientation);
KX_GameObject* obj = (KX_GameObject*)this->GetParent();
float f[4];
/*
* The 3D data from blender has to be transformed for OpenAL:
* - In blender z is up and y is forwards
* - In OpenAL y is up and z is backwards
* We have to do that for all 5 vectors.
*/
f = data.position[1];
data.position[1] = data.position[2];
data.position[2] = -f;
f = data.velocity[1];
data.velocity[1] = data.velocity[2];
data.velocity[2] = -f;
f = data.orientation[1];
data.orientation[1] = data.orientation[2];
data.orientation[2] = -f;
f = data.orientation[4];
data.orientation[4] = data.orientation[5];
data.orientation[5] = -f;
f = data.orientation[7];
data.orientation[7] = data.orientation[8];
data.orientation[8] = -f;
AUD_update3DSource(m_handle, &data);
obj->NodeGetWorldPosition().getValue(f);
AUD_setSourceLocation(m_handle, f);
obj->GetLinearVelocity().getValue(f);
AUD_setSourceVelocity(m_handle, f);
obj->NodeGetWorldOrientation().getRotation().getValue(f);
AUD_setSourceOrientation(m_handle, f);
}
result = true;
}
@@ -300,19 +278,18 @@ PyMethodDef KX_SoundActuator::Methods[] = {
PyAttributeDef KX_SoundActuator::Attributes[] = {
KX_PYATTRIBUTE_BOOL_RO("is3D", KX_SoundActuator, m_is3d),
KX_PYATTRIBUTE_RW_FUNCTION("maxGain3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("minGain3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("referenceDistance3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("maxDistance3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("rolloffFactor3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("coneInnerAngle3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("coneOuterAngle3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("coneOuterGain3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("volume_maximum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("volume_minimum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("distance_reference", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("distance_maximum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("attenuation", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_inner", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("cone_volume_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
KX_PYATTRIBUTE_RW_FUNCTION("time", KX_SoundActuator, pyattr_get_audposition, pyattr_set_audposition),
KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain),
KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch),
KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor),
KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type),
{ NULL } //Sentinel
};
@@ -358,28 +335,28 @@ PyObject* KX_SoundActuator::pyattr_get_3d_property(void *self, const struct KX_P
const char* prop = attrdef->m_name;
float result_value = 0.0;
if(!strcmp(prop, "maxGain3D")) {
if(!strcmp(prop, "volume_maximum")) {
result_value = actuator->m_3d.max_gain;
} else if (!strcmp(prop, "minGain3D")) {
} else if (!strcmp(prop, "volume_minimum")) {
result_value = actuator->m_3d.min_gain;
} else if (!strcmp(prop, "referenceDistance3D")) {
} else if (!strcmp(prop, "distance_reference")) {
result_value = actuator->m_3d.reference_distance;
} else if (!strcmp(prop, "maxDistance3D")) {
} else if (!strcmp(prop, "distance_maximum")) {
result_value = actuator->m_3d.max_distance;
} else if (!strcmp(prop, "rolloffFactor3D")) {
} else if (!strcmp(prop, "attenuation")) {
result_value = actuator->m_3d.rolloff_factor;
} else if (!strcmp(prop, "coneInnerAngle3D")) {
} else if (!strcmp(prop, "cone_angle_inner")) {
result_value = actuator->m_3d.cone_inner_angle;
} else if (!strcmp(prop, "coneOuterAngle3D")) {
} else if (!strcmp(prop, "cone_angle_outer")) {
result_value = actuator->m_3d.cone_outer_angle;
} else if (!strcmp(prop, "coneOuterGain3D")) {
} else if (!strcmp(prop, "cone_volume_outer")) {
result_value = actuator->m_3d.cone_outer_gain;
} else {
@@ -423,66 +400,63 @@ PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRI
return result;
}
PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float rollofffactor = actuator->m_3d.rolloff_factor;
PyObject* result = PyFloat_FromDouble(rollofffactor);
return result;
}
int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
const char* prop = attrdef->m_name;
float prop_value = 0.0;
AUD_3DSourceSetting setting = AUD_3DSS_NONE;
if (!PyArg_Parse(value, "f", &prop_value))
return PY_SET_ATTR_FAIL;
// update the internal value
if(!strcmp(prop, "maxGain3D")) {
// if sound is working and 3D, set the new setting
if(!actuator->m_is3d)
return PY_SET_ATTR_FAIL;
if(!strcmp(prop, "volume_maximum")) {
actuator->m_3d.max_gain = prop_value;
setting = AUD_3DSS_MAX_GAIN;
if(actuator->m_handle)
AUD_setVolumeMaximum(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "minGain3D")) {
} else if (!strcmp(prop, "volume_minimum")) {
actuator->m_3d.min_gain = prop_value;
setting = AUD_3DSS_MIN_GAIN;
if(actuator->m_handle)
AUD_setVolumeMinimum(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "referenceDistance3D")) {
} else if (!strcmp(prop, "distance_reference")) {
actuator->m_3d.reference_distance = prop_value;
setting = AUD_3DSS_REFERENCE_DISTANCE;
if(actuator->m_handle)
AUD_setDistanceReference(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "maxDistance3D")) {
} else if (!strcmp(prop, "distance_maximum")) {
actuator->m_3d.max_distance = prop_value;
setting = AUD_3DSS_MAX_DISTANCE;
if(actuator->m_handle)
AUD_setDistanceMaximum(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "rolloffFactor3D")) {
} else if (!strcmp(prop, "attenuation")) {
actuator->m_3d.rolloff_factor = prop_value;
setting = AUD_3DSS_ROLLOFF_FACTOR;
if(actuator->m_handle)
AUD_setAttenuation(actuator->m_handle, prop_value);
} else if (!!strcmp(prop, "coneInnerAngle3D")) {
} else if (!!strcmp(prop, "cone_angle_inner")) {
actuator->m_3d.cone_inner_angle = prop_value;
setting = AUD_3DSS_CONE_INNER_ANGLE;
if(actuator->m_handle)
AUD_setConeAngleInner(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "coneOuterAngle3D")) {
} else if (!strcmp(prop, "cone_angle_outer")) {
actuator->m_3d.cone_outer_angle = prop_value;
setting = AUD_3DSS_CONE_OUTER_ANGLE;
if(actuator->m_handle)
AUD_setConeAngleOuter(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "coneOuterGain3D")) {
} else if (!strcmp(prop, "cone_volume_outer")) {
actuator->m_3d.cone_outer_gain = prop_value;
setting = AUD_3DSS_CONE_OUTER_GAIN;
if(actuator->m_handle)
AUD_setConeVolumeOuter(actuator->m_handle, prop_value);
} else {
return PY_SET_ATTR_FAIL;
}
}
// if sound is working and 3D, set the new setting
if(actuator->m_handle && actuator->m_is3d && setting != AUD_3DSS_NONE)
AUD_set3DSourceSetting(actuator->m_handle, setting, prop_value);
return PY_SET_ATTR_SUCCESS;
}
@@ -527,18 +501,4 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D
return PY_SET_ATTR_SUCCESS;
}
int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float rollofffactor = 1.0;
if (!PyArg_Parse(value, "f", &rollofffactor))
return PY_SET_ATTR_FAIL;
actuator->m_3d.rolloff_factor = rollofffactor;
if(actuator->m_handle)
AUD_set3DSourceSetting(actuator->m_handle, AUD_3DSS_ROLLOFF_FACTOR, rollofffactor);
return PY_SET_ATTR_SUCCESS;
}
#endif // DISABLE_PYTHON