mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add control to the sound attenuation by distance.
This commit is contained in:
@@ -110,6 +110,7 @@
|
|||||||
<ClCompile Include="..\..\src\love.cpp">
|
<ClCompile Include="..\..\src\love.cpp">
|
||||||
<ShowIncludes Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ShowIncludes>
|
<ShowIncludes Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ShowIncludes>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\modules\audio\Audio.cpp" />
|
||||||
<ClCompile Include="..\..\src\modules\audio\null\Audio.cpp" />
|
<ClCompile Include="..\..\src\modules\audio\null\Audio.cpp" />
|
||||||
<ClCompile Include="..\..\src\modules\audio\null\Source.cpp" />
|
<ClCompile Include="..\..\src\modules\audio\null\Source.cpp" />
|
||||||
<ClCompile Include="..\..\src\modules\audio\openal\Audio.cpp" />
|
<ClCompile Include="..\..\src\modules\audio\openal\Audio.cpp" />
|
||||||
@@ -249,6 +250,8 @@
|
|||||||
<ClCompile Include="..\..\src\modules\thread\wrap_Thread.cpp" />
|
<ClCompile Include="..\..\src\modules\thread\wrap_Thread.cpp" />
|
||||||
<ClCompile Include="..\..\src\modules\timer\sdl\Timer.cpp" />
|
<ClCompile Include="..\..\src\modules\timer\sdl\Timer.cpp" />
|
||||||
<ClCompile Include="..\..\src\modules\timer\wrap_Timer.cpp" />
|
<ClCompile Include="..\..\src\modules\timer\wrap_Timer.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\modules\window\sdl\Window.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\modules\window\Window.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\common\b64.h" />
|
<ClInclude Include="..\..\src\common\b64.h" />
|
||||||
@@ -451,6 +454,8 @@
|
|||||||
<ClInclude Include="..\..\src\modules\timer\sdl\Timer.h" />
|
<ClInclude Include="..\..\src\modules\timer\sdl\Timer.h" />
|
||||||
<ClInclude Include="..\..\src\modules\timer\Timer.h" />
|
<ClInclude Include="..\..\src\modules\timer\Timer.h" />
|
||||||
<ClInclude Include="..\..\src\modules\timer\wrap_Timer.h" />
|
<ClInclude Include="..\..\src\modules\timer\wrap_Timer.h" />
|
||||||
|
<ClInclude Include="..\..\src\modules\window\sdl\Window.h" />
|
||||||
|
<ClInclude Include="..\..\src\modules\window\Window.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="app.rc" />
|
<ResourceCompile Include="app.rc" />
|
||||||
@@ -530,6 +535,7 @@
|
|||||||
<AdditionalDependencies>opengl32.lib;glu32.lib;DevIL.lib;freetype244MT.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;lua.lib;modplug.lib;OpenAL32.lib;physfs.lib;SDL.lib;SDLmain.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>opengl32.lib;glu32.lib;DevIL.lib;freetype244MT.lib;libmpg123.lib;libogg.lib;libvorbis.lib;libvorbisfile.lib;lua.lib;modplug.lib;OpenAL32.lib;physfs.lib;SDL.lib;SDLmain.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>lib</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>lib</AdditionalLibraryDirectories>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<AdditionalOptions>/FORCE:MULTIPLE %(AdditionalOptions)</AdditionalOptions>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|||||||
@@ -130,6 +130,9 @@
|
|||||||
<Filter Include="modules\physics\box2d">
|
<Filter Include="modules\physics\box2d">
|
||||||
<UniqueIdentifier>{9282b1b4-0df5-4180-8840-ea58561dc7b8}</UniqueIdentifier>
|
<UniqueIdentifier>{9282b1b4-0df5-4180-8840-ea58561dc7b8}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="modules\window">
|
||||||
|
<UniqueIdentifier>{1ef7f9ba-1fc3-4d88-b3fd-8ff0f34a0cc6}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\love.cpp" />
|
<ClCompile Include="..\..\src\love.cpp" />
|
||||||
@@ -286,9 +289,6 @@
|
|||||||
<ClCompile Include="..\..\src\modules\joystick\sdl\wrap_Joystick.cpp">
|
<ClCompile Include="..\..\src\modules\joystick\sdl\wrap_Joystick.cpp">
|
||||||
<Filter>modules\joystick\sdl</Filter>
|
<Filter>modules\joystick\sdl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\modules\sound\Sound.cpp">
|
|
||||||
<Filter>modules\sound</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\modules\sound\SoundData.cpp">
|
<ClCompile Include="..\..\src\modules\sound\SoundData.cpp">
|
||||||
<Filter>modules\sound</Filter>
|
<Filter>modules\sound</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -727,6 +727,18 @@
|
|||||||
<ClCompile Include="..\..\src\modules\keyboard\sdl\Keyboard.cpp">
|
<ClCompile Include="..\..\src\modules\keyboard\sdl\Keyboard.cpp">
|
||||||
<Filter>modules\keyboard\sdl</Filter>
|
<Filter>modules\keyboard\sdl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\modules\sound\Sound.cpp">
|
||||||
|
<Filter>modules\sound</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\modules\window\sdl\Window.cpp">
|
||||||
|
<Filter>modules\window</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\modules\window\Window.cpp">
|
||||||
|
<Filter>modules\window</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\modules\audio\Audio.cpp">
|
||||||
|
<Filter>modules\audio</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\modules\audio\Audio.h">
|
<ClInclude Include="..\..\src\modules\audio\Audio.h">
|
||||||
@@ -1302,6 +1314,12 @@
|
|||||||
<ClInclude Include="..\..\src\modules\keyboard\sdl\Keyboard.h">
|
<ClInclude Include="..\..\src\modules\keyboard\sdl\Keyboard.h">
|
||||||
<Filter>modules\keyboard\sdl</Filter>
|
<Filter>modules\keyboard\sdl</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\modules\window\Window.h">
|
||||||
|
<Filter>modules\window</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\modules\window\sdl\Window.h">
|
||||||
|
<Filter>modules\window</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="app.rc" />
|
<ResourceCompile Include="app.rc" />
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2006-2011 LOVE Development Team
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
* 2. Altered Audio versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
* 3. This notice may not be removed or altered from any Audio distribution.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "Audio.h"
|
||||||
|
|
||||||
|
namespace love
|
||||||
|
{
|
||||||
|
namespace audio
|
||||||
|
{
|
||||||
|
StringMap<Audio::DistanceModel, Audio::DISTANCE_MAX_ENUM>::Entry Audio::distanceModelEntries[] =
|
||||||
|
{
|
||||||
|
{"none", Audio::DISTANCE_NONE},
|
||||||
|
{"inverse", Audio::DISTANCE_INVERSE},
|
||||||
|
{"inverse clamped", Audio::DISTANCE_INVERSE_CLAMPED},
|
||||||
|
{"linear", Audio::DISTANCE_LINEAR},
|
||||||
|
{"linear clamped", Audio::DISTANCE_LINEAR},
|
||||||
|
{"exponent", Audio::DISTANCE_EXPONENT},
|
||||||
|
{"exponent clamped", Audio::DISTANCE_EXPONENT}
|
||||||
|
};
|
||||||
|
|
||||||
|
StringMap<Audio::DistanceModel, Audio::DISTANCE_MAX_ENUM> Audio::distanceModels(Audio::distanceModelEntries, sizeof(Audio::distanceModelEntries));
|
||||||
|
|
||||||
|
bool Audio::getConstant(const char * in, DistanceModel & out)
|
||||||
|
{
|
||||||
|
return distanceModels.find(in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Audio::getConstant(DistanceModel in, const char *& out)
|
||||||
|
{
|
||||||
|
return distanceModels.find(in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // audio
|
||||||
|
} // love
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#define LOVE_AUDIO_AUDIO_H
|
#define LOVE_AUDIO_AUDIO_H
|
||||||
|
|
||||||
#include <common/Module.h>
|
#include <common/Module.h>
|
||||||
|
#include <common/StringMap.h>
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -40,6 +41,24 @@ namespace audio
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attenuation by distance.
|
||||||
|
*/
|
||||||
|
enum DistanceModel
|
||||||
|
{
|
||||||
|
DISTANCE_NONE = 1,
|
||||||
|
DISTANCE_INVERSE,
|
||||||
|
DISTANCE_INVERSE_CLAMPED,
|
||||||
|
DISTANCE_LINEAR,
|
||||||
|
DISTANCE_LINEAR_CLAMPED,
|
||||||
|
DISTANCE_EXPONENT,
|
||||||
|
DISTANCE_EXPONENT_CLAMPED,
|
||||||
|
DISTANCE_MAX_ENUM
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool getConstant(const char * in, DistanceModel & out);
|
||||||
|
static bool getConstant(DistanceModel in, const char *& out);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
**/
|
**/
|
||||||
@@ -191,6 +210,22 @@ namespace audio
|
|||||||
**/
|
**/
|
||||||
virtual bool canRecord() = 0;
|
virtual bool canRecord() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the distance model used for attenuation.
|
||||||
|
* @return Distance model.
|
||||||
|
*/
|
||||||
|
virtual DistanceModel getDistanceModel() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the distance model used for attenuation.
|
||||||
|
* @param distanceModel Distance model.
|
||||||
|
*/
|
||||||
|
virtual void setDistanceModel(DistanceModel distanceModel) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static StringMap<DistanceModel, DISTANCE_MAX_ENUM>::Entry distanceModelEntries[];
|
||||||
|
static StringMap<DistanceModel, DISTANCE_MAX_ENUM> distanceModels;
|
||||||
}; // Audio
|
}; // Audio
|
||||||
|
|
||||||
} // audio
|
} // audio
|
||||||
|
|||||||
@@ -87,6 +87,18 @@ namespace audio
|
|||||||
virtual bool isLooping() const = 0;
|
virtual bool isLooping() const = 0;
|
||||||
virtual bool isStatic() const = 0;
|
virtual bool isStatic() const = 0;
|
||||||
|
|
||||||
|
virtual void setMinVolume(float volume) = 0;
|
||||||
|
virtual float getMinVolume() const = 0;
|
||||||
|
virtual void setMaxVolume(float volume) = 0;
|
||||||
|
virtual float getMaxVolume() const = 0;
|
||||||
|
|
||||||
|
virtual void setReferenceDistance(float distance) = 0;
|
||||||
|
virtual float getReferenceDistance() const = 0;
|
||||||
|
virtual void setRolloffFactor(float factor) = 0;
|
||||||
|
virtual float getRolloffFactor() const = 0;
|
||||||
|
virtual void setMaxDistance(float distance) = 0;
|
||||||
|
virtual float getMaxDistance() const = 0;
|
||||||
|
|
||||||
static bool getConstant(const char * in, Type & out);
|
static bool getConstant(const char * in, Type & out);
|
||||||
static bool getConstant(Type in, const char *& out);
|
static bool getConstant(Type in, const char *& out);
|
||||||
static bool getConstant(const char * in, Unit & out);
|
static bool getConstant(const char * in, Unit & out);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace audio
|
|||||||
{
|
{
|
||||||
namespace null
|
namespace null
|
||||||
{
|
{
|
||||||
Audio::Audio()
|
Audio::Audio() : distanceModel(DISTANCE_NONE)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +152,16 @@ namespace null
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Audio::DistanceModel Audio::getDistanceModel() const
|
||||||
|
{
|
||||||
|
return this->distanceModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::setDistanceModel(DistanceModel distanceModel)
|
||||||
|
{
|
||||||
|
this->distanceModel = distanceModel;
|
||||||
|
}
|
||||||
|
|
||||||
} // null
|
} // null
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace null
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
float volume;
|
float volume;
|
||||||
|
DistanceModel distanceModel;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Audio();
|
Audio();
|
||||||
@@ -74,6 +75,9 @@ namespace null
|
|||||||
love::sound::SoundData * stopRecording(bool returnData);
|
love::sound::SoundData * stopRecording(bool returnData);
|
||||||
bool canRecord();
|
bool canRecord();
|
||||||
|
|
||||||
|
DistanceModel getDistanceModel() const;
|
||||||
|
void setDistanceModel(DistanceModel distanceModel);
|
||||||
|
|
||||||
}; // Audio
|
}; // Audio
|
||||||
|
|
||||||
} // null
|
} // null
|
||||||
|
|||||||
@@ -150,6 +150,56 @@ namespace null
|
|||||||
return (type == TYPE_STATIC);
|
return (type == TYPE_STATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Source::setMinVolume(float volume)
|
||||||
|
{
|
||||||
|
this->minVolume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getMinVolume() const
|
||||||
|
{
|
||||||
|
return this->minVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setMaxVolume(float volume)
|
||||||
|
{
|
||||||
|
this->maxVolume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getMaxVolume() const
|
||||||
|
{
|
||||||
|
return this->maxVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setReferenceDistance(float distance)
|
||||||
|
{
|
||||||
|
this->referenceDistance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getReferenceDistance() const
|
||||||
|
{
|
||||||
|
return this->referenceDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setRolloffFactor(float factor)
|
||||||
|
{
|
||||||
|
this->rolloffFactor = factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getRolloffFactor() const
|
||||||
|
{
|
||||||
|
return this->rolloffFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setMaxDistance(float distance)
|
||||||
|
{
|
||||||
|
this->maxDistance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getMaxDistance() const
|
||||||
|
{
|
||||||
|
return this->maxDistance;
|
||||||
|
}
|
||||||
|
|
||||||
} // null
|
} // null
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ namespace null
|
|||||||
float pitch;
|
float pitch;
|
||||||
float volume;
|
float volume;
|
||||||
bool looping;
|
bool looping;
|
||||||
|
float minVolume;
|
||||||
|
float maxVolume;
|
||||||
|
float referenceDistance;
|
||||||
|
float rolloffFactor;
|
||||||
|
float maxDistance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Source();
|
Source();
|
||||||
@@ -68,6 +73,16 @@ namespace null
|
|||||||
void setLooping(bool looping);
|
void setLooping(bool looping);
|
||||||
bool isLooping() const;
|
bool isLooping() const;
|
||||||
bool isStatic() const;
|
bool isStatic() const;
|
||||||
|
virtual void setMinVolume(float volume);
|
||||||
|
virtual float getMinVolume() const;
|
||||||
|
virtual void setMaxVolume(float volume);
|
||||||
|
virtual float getMaxVolume() const;
|
||||||
|
virtual void setReferenceDistance(float distance);
|
||||||
|
virtual float getReferenceDistance() const;
|
||||||
|
virtual void setRolloffFactor(float factor);
|
||||||
|
virtual float getRolloffFactor() const;
|
||||||
|
virtual void setMaxDistance(float distance);
|
||||||
|
virtual float getMaxDistance() const;
|
||||||
|
|
||||||
}; // Source
|
}; // Source
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace openal
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Audio::Audio()
|
Audio::Audio() : distanceModel(DISTANCE_INVERSE_CLAMPED)
|
||||||
{
|
{
|
||||||
// Passing zero for default device.
|
// Passing zero for default device.
|
||||||
device = alcOpenDevice(0);
|
device = alcOpenDevice(0);
|
||||||
@@ -268,6 +268,49 @@ namespace openal
|
|||||||
return (capture != NULL);
|
return (capture != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Audio::DistanceModel Audio::getDistanceModel() const
|
||||||
|
{
|
||||||
|
return this->distanceModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::setDistanceModel(DistanceModel distanceModel)
|
||||||
|
{
|
||||||
|
this->distanceModel = distanceModel;
|
||||||
|
|
||||||
|
switch (distanceModel)
|
||||||
|
{
|
||||||
|
case DISTANCE_NONE:
|
||||||
|
alDistanceModel(AL_NONE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISTANCE_INVERSE:
|
||||||
|
alDistanceModel(AL_INVERSE_DISTANCE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISTANCE_INVERSE_CLAMPED:
|
||||||
|
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISTANCE_LINEAR:
|
||||||
|
alDistanceModel(AL_LINEAR_DISTANCE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISTANCE_LINEAR_CLAMPED:
|
||||||
|
alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISTANCE_EXPONENT:
|
||||||
|
alDistanceModel(AL_EXPONENT_DISTANCE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISTANCE_EXPONENT_CLAMPED:
|
||||||
|
alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // openal
|
} // openal
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ namespace openal
|
|||||||
|
|
||||||
PoolThread* poolThread;
|
PoolThread* poolThread;
|
||||||
|
|
||||||
|
DistanceModel distanceModel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Audio();
|
Audio();
|
||||||
@@ -127,6 +129,8 @@ namespace openal
|
|||||||
love::sound::SoundData * stopRecording(bool returnData);
|
love::sound::SoundData * stopRecording(bool returnData);
|
||||||
bool canRecord();
|
bool canRecord();
|
||||||
|
|
||||||
|
DistanceModel getDistanceModel() const;
|
||||||
|
void setDistanceModel(DistanceModel distanceModel);
|
||||||
}; // Audio
|
}; // Audio
|
||||||
|
|
||||||
} // openal
|
} // openal
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
// STD
|
// STD
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -34,8 +35,9 @@ namespace openal
|
|||||||
|
|
||||||
Source::Source(Pool * pool, love::sound::SoundData * soundData)
|
Source::Source(Pool * pool, love::sound::SoundData * soundData)
|
||||||
: love::audio::Source(Source::TYPE_STATIC), pool(pool), valid(false),
|
: love::audio::Source(Source::TYPE_STATIC), pool(pool), valid(false),
|
||||||
pitch(1.0f), volume(1.0f), looping(false), paused(false), offsetSamples(0),
|
pitch(1.0f), volume(1.0f), looping(false), paused(false), minVolume(0.0f),
|
||||||
offsetSeconds(0), decoder(0), toLoop(0)
|
maxVolume(1.0f), referenceDistance(1.0f), rolloffFactor(1.0f), maxDistance(FLT_MAX),
|
||||||
|
offsetSamples(0), offsetSeconds(0), decoder(0), toLoop(0)
|
||||||
{
|
{
|
||||||
alGenBuffers(1, buffers);
|
alGenBuffers(1, buffers);
|
||||||
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBits());
|
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBits());
|
||||||
@@ -50,8 +52,9 @@ namespace openal
|
|||||||
|
|
||||||
Source::Source(Pool * pool, love::sound::Decoder * decoder)
|
Source::Source(Pool * pool, love::sound::Decoder * decoder)
|
||||||
: love::audio::Source(Source::TYPE_STREAM), pool(pool), valid(false),
|
: love::audio::Source(Source::TYPE_STREAM), pool(pool), valid(false),
|
||||||
pitch(1.0f), volume(1.0f), looping(false), paused(false), offsetSamples(0),
|
pitch(1.0f), volume(1.0f), looping(false), paused(false), minVolume(0.0f),
|
||||||
offsetSeconds(0), decoder(decoder), toLoop(0)
|
maxVolume(1.0f), referenceDistance(1.0f), rolloffFactor(1.0f), maxDistance(FLT_MAX),
|
||||||
|
offsetSamples(0), offsetSeconds(0), decoder(decoder), toLoop(0)
|
||||||
{
|
{
|
||||||
decoder->retain();
|
decoder->retain();
|
||||||
alGenBuffers(MAX_BUFFERS, buffers);
|
alGenBuffers(MAX_BUFFERS, buffers);
|
||||||
@@ -415,6 +418,11 @@ namespace openal
|
|||||||
// been without an AL source.
|
// been without an AL source.
|
||||||
alSourcef(source, AL_PITCH, pitch);
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
alSourcef(source, AL_GAIN, volume);
|
alSourcef(source, AL_GAIN, volume);
|
||||||
|
alSourcef(source, AL_MIN_GAIN, minVolume);
|
||||||
|
alSourcef(source, AL_MAX_GAIN, maxVolume);
|
||||||
|
alSourcef(source, AL_REFERENCE_DISTANCE, referenceDistance);
|
||||||
|
alSourcef(source, AL_ROLLOFF_FACTOR, rolloffFactor);
|
||||||
|
alSourcef(source, AL_MAX_DISTANCE, maxDistance);
|
||||||
|
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
|
|
||||||
@@ -503,6 +511,11 @@ namespace openal
|
|||||||
alSourcefv(source, AL_DIRECTION, direction);
|
alSourcefv(source, AL_DIRECTION, direction);
|
||||||
alSourcef(source, AL_PITCH, pitch);
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
alSourcef(source, AL_GAIN, volume);
|
alSourcef(source, AL_GAIN, volume);
|
||||||
|
alSourcef(source, AL_MIN_GAIN, minVolume);
|
||||||
|
alSourcef(source, AL_MAX_GAIN, maxVolume);
|
||||||
|
alSourcef(source, AL_REFERENCE_DISTANCE, referenceDistance);
|
||||||
|
alSourcef(source, AL_ROLLOFF_FACTOR, rolloffFactor);
|
||||||
|
alSourcef(source, AL_MAX_DISTANCE, maxDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::setFloatv(float * dst, const float * src) const
|
void Source::setFloatv(float * dst, const float * src) const
|
||||||
@@ -565,6 +578,121 @@ namespace openal
|
|||||||
return (type == TYPE_STATIC);
|
return (type == TYPE_STATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Source::setMinVolume(float volume)
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
alSourcef(source, AL_MIN_GAIN, volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->minVolume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getMinVolume() const
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
ALfloat f;
|
||||||
|
alGetSourcef(source, AL_MIN_GAIN, &f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case the Source isn't playing.
|
||||||
|
return this->minVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setMaxVolume(float volume)
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
alSourcef(source, AL_MAX_GAIN, volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->maxVolume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getMaxVolume() const
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
ALfloat f;
|
||||||
|
alGetSourcef(source, AL_MAX_GAIN, &f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case the Source isn't playing.
|
||||||
|
return this->maxVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setReferenceDistance(float distance)
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
alSourcef(source, AL_REFERENCE_DISTANCE, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->referenceDistance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getReferenceDistance() const
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
ALfloat f;
|
||||||
|
alGetSourcef(source, AL_REFERENCE_DISTANCE, &f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case the Source isn't playing.
|
||||||
|
return this->referenceDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setRolloffFactor(float factor)
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
alSourcef(source, AL_ROLLOFF_FACTOR, factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->rolloffFactor = factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getRolloffFactor() const
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
ALfloat f;
|
||||||
|
alGetSourcef(source, AL_ROLLOFF_FACTOR, &f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case the Source isn't playing.
|
||||||
|
return this->rolloffFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::setMaxDistance(float distance)
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
alSourcef(source, AL_MAX_DISTANCE, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->maxDistance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Source::getMaxDistance() const
|
||||||
|
{
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
ALfloat f;
|
||||||
|
alGetSourcef(source, AL_MAX_DISTANCE, &f);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case the Source isn't playing.
|
||||||
|
return this->maxDistance;
|
||||||
|
}
|
||||||
|
|
||||||
} // openal
|
} // openal
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ namespace openal
|
|||||||
float direction[3];
|
float direction[3];
|
||||||
bool looping;
|
bool looping;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
float minVolume;
|
||||||
|
float maxVolume;
|
||||||
|
float referenceDistance;
|
||||||
|
float rolloffFactor;
|
||||||
|
float maxDistance;
|
||||||
|
|
||||||
float offsetSamples;
|
float offsetSamples;
|
||||||
float offsetSeconds;
|
float offsetSeconds;
|
||||||
@@ -103,6 +108,16 @@ namespace openal
|
|||||||
void setLooping(bool looping);
|
void setLooping(bool looping);
|
||||||
bool isLooping() const;
|
bool isLooping() const;
|
||||||
bool isStatic() const;
|
bool isStatic() const;
|
||||||
|
virtual void setMinVolume(float volume);
|
||||||
|
virtual float getMinVolume() const;
|
||||||
|
virtual void setMaxVolume(float volume);
|
||||||
|
virtual float getMaxVolume() const;
|
||||||
|
virtual void setReferenceDistance(float distance);
|
||||||
|
virtual float getReferenceDistance() const;
|
||||||
|
virtual void setRolloffFactor(float factor);
|
||||||
|
virtual float getRolloffFactor() const;
|
||||||
|
virtual void setMaxDistance(float distance);
|
||||||
|
virtual float getMaxDistance() const;
|
||||||
|
|
||||||
void playAtomic();
|
void playAtomic();
|
||||||
void stopAtomic();
|
void stopAtomic();
|
||||||
|
|||||||
@@ -237,6 +237,23 @@ namespace audio
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_setDistanceModel(lua_State * L)
|
||||||
|
{
|
||||||
|
const char *modelStr = luaL_checkstring(L, 1);
|
||||||
|
Audio::DistanceModel distanceModel;
|
||||||
|
Audio::getConstant(modelStr, distanceModel);
|
||||||
|
instance->setDistanceModel(distanceModel);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_getDistanceModel(lua_State * L)
|
||||||
|
{
|
||||||
|
Audio::DistanceModel distanceModel = instance->getDistanceModel();
|
||||||
|
const char *modelStr;
|
||||||
|
Audio::getConstant(distanceModel, modelStr);
|
||||||
|
lua_pushstring(L, modelStr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// List of functions to wrap.
|
// List of functions to wrap.
|
||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
@@ -258,6 +275,8 @@ namespace audio
|
|||||||
/*{ "record", w_record },
|
/*{ "record", w_record },
|
||||||
{ "getRecordedData", w_getRecordedData },
|
{ "getRecordedData", w_getRecordedData },
|
||||||
{ "stopRecording", w_stopRecording },*/
|
{ "stopRecording", w_stopRecording },*/
|
||||||
|
{ "setDistanceModel", w_setDistanceModel },
|
||||||
|
{ "getDistanceModel", w_getDistanceModel },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ namespace audio
|
|||||||
int w_getRecordedData(lua_State * L);
|
int w_getRecordedData(lua_State * L);
|
||||||
int w_stopRecording(lua_State * L);
|
int w_stopRecording(lua_State * L);
|
||||||
int w_canRecord(lua_State * L);
|
int w_canRecord(lua_State * L);
|
||||||
|
int w_setDistanceModel(lua_State * L);
|
||||||
|
int w_getDistanceModel(lua_State * L);
|
||||||
extern "C" LOVE_EXPORT int luaopen_love_audio(lua_State * L);
|
extern "C" LOVE_EXPORT int luaopen_love_audio(lua_State * L);
|
||||||
|
|
||||||
} // audio
|
} // audio
|
||||||
|
|||||||
@@ -211,11 +211,82 @@ namespace audio
|
|||||||
|
|
||||||
int w_Source_isStatic(lua_State * L)
|
int w_Source_isStatic(lua_State * L)
|
||||||
{
|
{
|
||||||
Source * t= luax_checksource(L, 1);
|
Source * t = luax_checksource(L, 1);
|
||||||
luax_pushboolean(L, t->isStatic());
|
luax_pushboolean(L, t->isStatic());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Source_setMinVolume(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
t->setMinVolume((float)luaL_checknumber(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_getMinVolume(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
lua_pushnumber(L, t->getMinVolume());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_setMaxVolume(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
t->setMaxVolume((float)luaL_checknumber(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_getMaxVolume(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
lua_pushnumber(L, t->getMaxVolume());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_setReferenceDistance(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
t->setReferenceDistance((float)luaL_checknumber(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_getReferenceDistance(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
lua_pushnumber(L, t->getReferenceDistance());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_setRolloffFactor(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
t->setRolloffFactor((float)luaL_checknumber(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_getRolloffFactor(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
lua_pushnumber(L, t->getRolloffFactor());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_setMaxDistance(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
t->setMaxDistance((float)luaL_checknumber(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_Source_getMaxDistance(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
lua_pushnumber(L, t->getMaxDistance());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
{ "play", w_Source_play },
|
{ "play", w_Source_play },
|
||||||
{ "stop", w_Source_stop },
|
{ "stop", w_Source_stop },
|
||||||
@@ -241,6 +312,18 @@ namespace audio
|
|||||||
{ "isStopped", w_Source_isStopped },
|
{ "isStopped", w_Source_isStopped },
|
||||||
{ "isPaused", w_Source_isPaused },
|
{ "isPaused", w_Source_isPaused },
|
||||||
{ "isStatic", w_Source_isStatic },
|
{ "isStatic", w_Source_isStatic },
|
||||||
|
|
||||||
|
{ "setMinVolume", w_Source_setMinVolume },
|
||||||
|
{ "getMinVolume", w_Source_getMinVolume },
|
||||||
|
{ "setMaxVolume", w_Source_setMaxVolume },
|
||||||
|
{ "getMaxVolume", w_Source_getMaxVolume },
|
||||||
|
{ "setReferenceDistance", w_Source_setReferenceDistance },
|
||||||
|
{ "getReferenceDistance", w_Source_getReferenceDistance },
|
||||||
|
{ "setRolloffFactor", w_Source_setRolloffFactor },
|
||||||
|
{ "getRolloffFactor", w_Source_getRolloffFactor },
|
||||||
|
{ "setMaxDistance", w_Source_setMaxDistance },
|
||||||
|
{ "getMaxDistance", w_Source_getMaxDistance },
|
||||||
|
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ namespace audio
|
|||||||
int w_Source_isStopped(lua_State * L);
|
int w_Source_isStopped(lua_State * L);
|
||||||
int w_Source_isPaused(lua_State * L);
|
int w_Source_isPaused(lua_State * L);
|
||||||
int w_Source_isStatic(lua_State * L);
|
int w_Source_isStatic(lua_State * L);
|
||||||
|
int w_Source_setMinVolume(lua_State * L);
|
||||||
|
int w_Source_getMinVolume(lua_State * L);
|
||||||
|
int w_Source_setMaxVolume(lua_State * L);
|
||||||
|
int w_Source_getMinVolume(lua_State * L);
|
||||||
|
int w_Source_setReferenceDistance(lua_State * L);
|
||||||
|
int w_Source_getReferenceDistance(lua_State * L);
|
||||||
|
int w_Source_setRolloffFactor(lua_State * L);
|
||||||
|
int w_Source_getRolloffFactor(lua_State * L);
|
||||||
|
int w_Source_setMaxDistance(lua_State * L);
|
||||||
|
int w_Source_getMaxDistance(lua_State * L);
|
||||||
int luaopen_source(lua_State * L);
|
int luaopen_source(lua_State * L);
|
||||||
|
|
||||||
} // audio
|
} // audio
|
||||||
|
|||||||
Reference in New Issue
Block a user