mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
Added Source:setCone(innerAngle, outerAngle, outerVolume). Resolves issue #643.
When combined with Source:setDirection (and Source:setPosition or love.audio.setPosition), the cone parameters allow for directional sound output from a Source.
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
#include "Pool.h"
|
||||
#include "common/math.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
@@ -47,6 +47,7 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
|
||||
, referenceDistance(1.0f)
|
||||
, rolloffFactor(1.0f)
|
||||
, maxDistance(FLT_MAX)
|
||||
, cone()
|
||||
, offsetSamples(0)
|
||||
, offsetSeconds(0)
|
||||
, decoder(0)
|
||||
@@ -77,6 +78,7 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder)
|
||||
, referenceDistance(1.0f)
|
||||
, rolloffFactor(1.0f)
|
||||
, maxDistance(FLT_MAX)
|
||||
, cone()
|
||||
, offsetSamples(0)
|
||||
, offsetSeconds(0)
|
||||
, decoder(decoder)
|
||||
@@ -404,6 +406,27 @@ void Source::getDirection(float *v) const
|
||||
setFloatv(v, direction);
|
||||
}
|
||||
|
||||
void Source::setCone(float innerAngle, float outerAngle, float outerVolume)
|
||||
{
|
||||
cone.innerAngle = LOVE_TODEG(innerAngle);
|
||||
cone.outerAngle = LOVE_TODEG(outerAngle);
|
||||
cone.outerVolume = outerVolume;
|
||||
|
||||
if (valid)
|
||||
{
|
||||
alSourcei(source, AL_CONE_INNER_ANGLE, cone.innerAngle);
|
||||
alSourcei(source, AL_CONE_OUTER_ANGLE, cone.outerAngle);
|
||||
alSourcef(source, AL_CONE_OUTER_GAIN, cone.outerVolume);
|
||||
}
|
||||
}
|
||||
|
||||
void Source::getCone(float &innerAngle, float &outerAngle, float &outerVolume) const
|
||||
{
|
||||
innerAngle = LOVE_TORAD(cone.innerAngle);
|
||||
outerAngle = LOVE_TORAD(cone.outerAngle);
|
||||
outerVolume = cone.outerVolume;
|
||||
}
|
||||
|
||||
void Source::setRelativePosition(bool relative)
|
||||
{
|
||||
if (valid)
|
||||
@@ -551,6 +574,9 @@ void Source::reset()
|
||||
alSourcef(source, AL_MAX_DISTANCE, maxDistance);
|
||||
alSourcei(source, AL_LOOPING, isStatic() && isLooping() ? AL_TRUE : AL_FALSE);
|
||||
alSourcei(source, AL_SOURCE_RELATIVE, relativePosition ? AL_TRUE : AL_FALSE);
|
||||
alSourcei(source, AL_CONE_INNER_ANGLE, cone.innerAngle);
|
||||
alSourcei(source, AL_CONE_OUTER_ANGLE, cone.outerAngle);
|
||||
alSourcef(source, AL_CONE_OUTER_GAIN, cone.outerVolume);
|
||||
}
|
||||
|
||||
void Source::setFloatv(float *dst, const float *src) const
|
||||
|
||||
@@ -78,6 +78,8 @@ public:
|
||||
virtual void getVelocity(float *v) const;
|
||||
virtual void setDirection(float *v);
|
||||
virtual void getDirection(float *v) const;
|
||||
virtual void setCone(float innerAngle, float outerAngle, float outerVolume);
|
||||
virtual void getCone(float &innerAngle, float &outerAngle, float &outerVolume) const;
|
||||
virtual void setRelativePosition(bool relative);
|
||||
virtual bool hasRelativePosition() const;
|
||||
void setLooping(bool looping);
|
||||
@@ -137,6 +139,19 @@ private:
|
||||
float rolloffFactor;
|
||||
float maxDistance;
|
||||
|
||||
struct Cone
|
||||
{
|
||||
int innerAngle; // degrees
|
||||
int outerAngle; // degrees
|
||||
float outerVolume;
|
||||
|
||||
Cone()
|
||||
: innerAngle(360)
|
||||
, outerAngle(360)
|
||||
, outerVolume(0.0f)
|
||||
{}
|
||||
} cone;
|
||||
|
||||
float offsetSamples;
|
||||
float offsetSeconds;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user