mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Merged love.audio changes.
This commit is contained in:
@@ -188,22 +188,6 @@
|
|||||||
RelativePath="..\..\..\src\modules\audio\openal\Audio.h"
|
RelativePath="..\..\..\src\modules\audio\openal\Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\openal\Music.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\openal\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\openal\Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\audio\openal\Pool.cpp"
|
RelativePath="..\..\..\src\modules\audio\openal\Pool.cpp"
|
||||||
>
|
>
|
||||||
@@ -220,22 +204,6 @@
|
|||||||
RelativePath="..\..\..\src\modules\audio\openal\Pool.h"
|
RelativePath="..\..\..\src\modules\audio\openal\Pool.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\openal\Sound.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\openal\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\openal\Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\audio\openal\Source.cpp"
|
RelativePath="..\..\..\src\modules\audio\openal\Source.cpp"
|
||||||
>
|
>
|
||||||
@@ -272,38 +240,6 @@
|
|||||||
RelativePath="..\..\..\src\modules\audio\null\Audio.h"
|
RelativePath="..\..\..\src\modules\audio\null\Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\null\Music.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\null\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\null\Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\null\Sound.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\null\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\null\Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\audio\null\Source.cpp"
|
RelativePath="..\..\..\src\modules\audio\null\Source.cpp"
|
||||||
>
|
>
|
||||||
@@ -321,22 +257,10 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\Audible.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\audio\Audio.h"
|
RelativePath="..\..\..\src\modules\audio\Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\audio\Source.cpp"
|
RelativePath="..\..\..\src\modules\audio\Source.cpp"
|
||||||
>
|
>
|
||||||
@@ -369,38 +293,6 @@
|
|||||||
RelativePath="..\..\..\src\modules\audio\wrap_Audio.h"
|
RelativePath="..\..\..\src\modules\audio\wrap_Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\wrap_Music.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\wrap_Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\wrap_Sound.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\audio\wrap_Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\audio\wrap_Source.cpp"
|
RelativePath="..\..\..\src\modules\audio\wrap_Source.cpp"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -182,14 +182,6 @@
|
|||||||
RelativePath="..\..\src\modules\audio\Audio.h"
|
RelativePath="..\..\src\modules\audio\Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\modules\audio\Source.cpp"
|
RelativePath="..\..\src\modules\audio\Source.cpp"
|
||||||
>
|
>
|
||||||
@@ -238,54 +230,6 @@
|
|||||||
RelativePath="..\..\src\modules\audio\wrap_Audio.h"
|
RelativePath="..\..\src\modules\audio\wrap_Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\wrap_Music.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\wrap_Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\wrap_Sound.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\wrap_Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\modules\audio\wrap_Source.cpp"
|
RelativePath="..\..\src\modules\audio\wrap_Source.cpp"
|
||||||
>
|
>
|
||||||
@@ -337,30 +281,6 @@
|
|||||||
RelativePath="..\..\src\modules\audio\openal\Audio.h"
|
RelativePath="..\..\src\modules\audio\openal\Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\openal\Music.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\openal\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\openal\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\openal\Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\modules\audio\openal\Pool.cpp"
|
RelativePath="..\..\src\modules\audio\openal\Pool.cpp"
|
||||||
>
|
>
|
||||||
@@ -385,30 +305,6 @@
|
|||||||
RelativePath="..\..\src\modules\audio\openal\Pool.h"
|
RelativePath="..\..\src\modules\audio\openal\Pool.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\openal\Sound.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\openal\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\openal\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\openal\Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\modules\audio\openal\Source.cpp"
|
RelativePath="..\..\src\modules\audio\openal\Source.cpp"
|
||||||
>
|
>
|
||||||
@@ -461,54 +357,6 @@
|
|||||||
RelativePath="..\..\src\modules\audio\null\Audio.h"
|
RelativePath="..\..\src\modules\audio\null\Audio.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\null\Music.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\null\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\null\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\null\Music.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\null\Sound.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\null\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\audio\null\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\modules\audio\null\Sound.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\modules\audio\null\Source.cpp"
|
RelativePath="..\..\src\modules\audio\null\Source.cpp"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="libmodplug.lib libmpg123.lib libogg.lib libvorbis.lib libvorbisfile.lib libFLAC_static_d.lib libFLAC++_static_d.lib"
|
AdditionalDependencies="libmodplug.lib libmpg123.lib libogg.lib libvorbis.lib libvorbisfile.lib"
|
||||||
OutputFile="$(OutDir)\love\$(ProjectName).dll"
|
OutputFile="$(OutDir)\love\$(ProjectName).dll"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
AdditionalLibraryDirectories="..\lib"
|
AdditionalLibraryDirectories="..\lib"
|
||||||
@@ -188,22 +188,6 @@
|
|||||||
RelativePath="..\..\..\src\modules\sound\lullaby\Decoder.h"
|
RelativePath="..\..\..\src\modules\sound\lullaby\Decoder.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\sound\lullaby\FLACDecoder.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)\sound\lullaby\"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\..\src\modules\sound\lullaby\FLACDecoder.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\modules\sound\lullaby\ModPlugDecoder.cpp"
|
RelativePath="..\..\..\src\modules\sound\lullaby\ModPlugDecoder.cpp"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include "Reference.h"
|
#include "Reference.h"
|
||||||
|
#include "StringMap.h"
|
||||||
|
|
||||||
// STD
|
// STD
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -50,6 +51,14 @@ namespace love
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int w__typeOf(lua_State * L)
|
||||||
|
{
|
||||||
|
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
||||||
|
Type t = luax_type(L, 2);
|
||||||
|
luax_pushboolean(L, p->flags.at(t));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
Reference * luax_refif(lua_State * L, int type)
|
Reference * luax_refif(lua_State * L, int type)
|
||||||
{
|
{
|
||||||
Reference * r = 0;
|
Reference * r = 0;
|
||||||
@@ -178,6 +187,15 @@ namespace love
|
|||||||
lua_pushcclosure(L, w__tostring, 1);
|
lua_pushcclosure(L, w__tostring, 1);
|
||||||
lua_setfield(L, -2, "__tostring");
|
lua_setfield(L, -2, "__tostring");
|
||||||
|
|
||||||
|
// Add tostring to as type() as well.
|
||||||
|
lua_pushstring(L, tname);
|
||||||
|
lua_pushcclosure(L, w__tostring, 1);
|
||||||
|
lua_setfield(L, -2, "type");
|
||||||
|
|
||||||
|
// Add typeOf
|
||||||
|
lua_pushcfunction(L, w__typeOf);
|
||||||
|
lua_setfield(L, -2, "typeOf");
|
||||||
|
|
||||||
if(f != 0)
|
if(f != 0)
|
||||||
luaL_register(L, 0, f);
|
luaL_register(L, 0, f);
|
||||||
|
|
||||||
@@ -316,5 +334,70 @@ namespace love
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
|
||||||
|
{
|
||||||
|
{"Invalid", INVALID_ID},
|
||||||
|
|
||||||
|
{"Object", OBJECT_ID},
|
||||||
|
{"Data", DATA_ID},
|
||||||
|
{"Module", MODULE_ID},
|
||||||
|
|
||||||
|
// Filesystem
|
||||||
|
{"File", FILESYSTEM_FILE_ID},
|
||||||
|
{"FileData", FILESYSTEM_FILE_DATA_ID},
|
||||||
|
|
||||||
|
// Font
|
||||||
|
{"GlyphData", FONT_GLYPH_DATA_ID},
|
||||||
|
{"Rasterizer", FONT_RASTERIZER_ID},
|
||||||
|
|
||||||
|
// Graphics
|
||||||
|
{"Drawable", GRAPHICS_DRAWABLE_ID},
|
||||||
|
{"Image", GRAPHICS_IMAGE_ID},
|
||||||
|
{"Quad", GRAPHICS_QUAD_ID},
|
||||||
|
{"Glyph", GRAPHICS_GLYPH_ID},
|
||||||
|
{"Font", GRAPHICS_FONT_ID},
|
||||||
|
{"ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_ID},
|
||||||
|
{"SpriteBatch", GRAPHICS_SPRITE_BATCH_ID},
|
||||||
|
{"VertexBuffer", GRAPHICS_VERTEX_BUFFER_ID},
|
||||||
|
|
||||||
|
// Image
|
||||||
|
{"ImageData", IMAGE_IMAGE_DATA_ID},
|
||||||
|
|
||||||
|
// Audio
|
||||||
|
{"Source", AUDIO_SOURCE_ID},
|
||||||
|
|
||||||
|
// Sound
|
||||||
|
{"SoundData", SOUND_SOUND_DATA_ID},
|
||||||
|
{"Decoder", SOUND_DECODER_ID},
|
||||||
|
|
||||||
|
// Physics
|
||||||
|
{"World", PHYSICS_WORLD_ID},
|
||||||
|
{"Contact", PHYSICS_CONTACT_ID},
|
||||||
|
{"Body", PHYSICS_BODY_ID},
|
||||||
|
{"Shape", PHYSICS_SHAPE_ID},
|
||||||
|
{"CircleShape", PHYSICS_CIRCLE_SHAPE_ID},
|
||||||
|
{"PolygonShape", PHYSICS_POLYGON_SHAPE_ID},
|
||||||
|
{"Joint", PHYSICS_JOINT_ID},
|
||||||
|
{"MouseJoint", PHYSICS_MOUSE_JOINT_ID},
|
||||||
|
{"DistanceJoint", PHYSICS_DISTANCE_JOINT_ID},
|
||||||
|
{"PrismaticJoint", PHYSICS_PRISMATIC_JOINT_ID},
|
||||||
|
{"RevoluteJoint", PHYSICS_REVOLUTE_JOINT_ID},
|
||||||
|
{"PulleyJoint", PHYSICS_PULLEY_JOINT_ID},
|
||||||
|
{"GearJoint", PHYSICS_GEAR_JOINT_ID},
|
||||||
|
|
||||||
|
// The modules themselves. Only add abstracted modules here.
|
||||||
|
{"filesystem", MODULE_FILESYSTEM_ID},
|
||||||
|
{"image", MODULE_IMAGE_ID},
|
||||||
|
{"sound", MODULE_SOUND_ID},
|
||||||
|
};
|
||||||
|
|
||||||
|
StringMap<Type, TYPE_MAX_ENUM> types(typeEntries, sizeof(typeEntries));
|
||||||
|
|
||||||
|
Type luax_type(lua_State * L, int idx)
|
||||||
|
{
|
||||||
|
Type t = INVALID_ID;
|
||||||
|
types.find(luaL_checkstring(L, idx), t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -252,6 +252,8 @@ namespace love
|
|||||||
**/
|
**/
|
||||||
int luax_getregistry(lua_State * L, Registry r);
|
int luax_getregistry(lua_State * L, Registry r);
|
||||||
|
|
||||||
|
Type luax_type(lua_State * L, int idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the value at idx to the specified type without checking that
|
* Converts the value at idx to the specified type without checking that
|
||||||
* this conversion is valid. If the type has been previously verified with
|
* this conversion is valid. If the type has been previously verified with
|
||||||
|
|||||||
+9
-13
@@ -28,8 +28,9 @@ namespace love
|
|||||||
{
|
{
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
|
INVALID_ID = 0,
|
||||||
// Cross-module types.
|
// Cross-module types.
|
||||||
OBJECT_ID = 0,
|
OBJECT_ID,
|
||||||
DATA_ID,
|
DATA_ID,
|
||||||
MODULE_ID,
|
MODULE_ID,
|
||||||
|
|
||||||
@@ -46,8 +47,6 @@ namespace love
|
|||||||
GRAPHICS_IMAGE_ID,
|
GRAPHICS_IMAGE_ID,
|
||||||
GRAPHICS_QUAD_ID,
|
GRAPHICS_QUAD_ID,
|
||||||
GRAPHICS_GLYPH_ID,
|
GRAPHICS_GLYPH_ID,
|
||||||
GRAPHICS_ANIMATION_ID,
|
|
||||||
GRAPHICS_COLOR_ID,
|
|
||||||
GRAPHICS_FONT_ID,
|
GRAPHICS_FONT_ID,
|
||||||
GRAPHICS_PARTICLE_SYSTEM_ID,
|
GRAPHICS_PARTICLE_SYSTEM_ID,
|
||||||
GRAPHICS_SPRITE_BATCH_ID,
|
GRAPHICS_SPRITE_BATCH_ID,
|
||||||
@@ -57,9 +56,6 @@ namespace love
|
|||||||
IMAGE_IMAGE_DATA_ID,
|
IMAGE_IMAGE_DATA_ID,
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
AUDIO_AUDIBLE_ID,
|
|
||||||
AUDIO_SOUND_ID,
|
|
||||||
AUDIO_MUSIC_ID,
|
|
||||||
AUDIO_SOURCE_ID,
|
AUDIO_SOURCE_ID,
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
@@ -87,10 +83,12 @@ namespace love
|
|||||||
MODULE_SOUND_ID,
|
MODULE_SOUND_ID,
|
||||||
|
|
||||||
// Count the number of bits needed.
|
// Count the number of bits needed.
|
||||||
BIT_SIZE
|
TYPE_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::bitset<BIT_SIZE> bits;
|
typedef std::bitset<TYPE_MAX_ENUM> bits;
|
||||||
|
|
||||||
|
const bits INVALID_T = bits(1) << INVALID_ID;
|
||||||
|
|
||||||
const bits OBJECT_T = bits(1) << OBJECT_ID;
|
const bits OBJECT_T = bits(1) << OBJECT_ID;
|
||||||
const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T;
|
const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T;
|
||||||
@@ -108,8 +106,6 @@ namespace love
|
|||||||
const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWABLE_T;
|
const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWABLE_T;
|
||||||
const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T;
|
const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T;
|
||||||
const bits GRAPHICS_GLYPH_T = (bits(1) << GRAPHICS_GLYPH_ID) | GRAPHICS_DRAWABLE_T;
|
const bits GRAPHICS_GLYPH_T = (bits(1) << GRAPHICS_GLYPH_ID) | GRAPHICS_DRAWABLE_T;
|
||||||
const bits GRAPHICS_ANIMATION_T = (bits(1) << GRAPHICS_ANIMATION_ID) | GRAPHICS_DRAWABLE_T;
|
|
||||||
const bits GRAPHICS_COLOR_T = (bits(1) << GRAPHICS_COLOR_ID) | OBJECT_T;
|
|
||||||
const bits GRAPHICS_FONT_T = (bits(1) << GRAPHICS_FONT_ID) | OBJECT_T;
|
const bits GRAPHICS_FONT_T = (bits(1) << GRAPHICS_FONT_ID) | OBJECT_T;
|
||||||
const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T;
|
const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T;
|
||||||
const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T;
|
const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T;
|
||||||
@@ -119,9 +115,6 @@ namespace love
|
|||||||
const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T;
|
const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T;
|
||||||
|
|
||||||
// Audio.
|
// Audio.
|
||||||
const bits AUDIO_AUDIBLE_T = (bits(1) << AUDIO_AUDIBLE_ID) | OBJECT_T;
|
|
||||||
const bits AUDIO_SOUND_T = (bits(1) << AUDIO_SOUND_ID) | AUDIO_AUDIBLE_T;
|
|
||||||
const bits AUDIO_MUSIC_T = (bits(1) << AUDIO_MUSIC_ID) | AUDIO_AUDIBLE_T;
|
|
||||||
const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T;
|
const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T;
|
||||||
|
|
||||||
// Sound.
|
// Sound.
|
||||||
@@ -148,6 +141,9 @@ namespace love
|
|||||||
const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T;
|
const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T;
|
||||||
const bits MODULE_SOUND_T = (bits(1) << MODULE_SOUND_ID) | MODULE_T;
|
const bits MODULE_SOUND_T = (bits(1) << MODULE_SOUND_ID) | MODULE_T;
|
||||||
|
|
||||||
|
bool getType(const char * in, Type & out);
|
||||||
|
bool getType(Type in, const char *& out);
|
||||||
|
|
||||||
} // love
|
} // love
|
||||||
|
|
||||||
#endif // LOVE_TYPES_H
|
#endif // LOVE_TYPES_H
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_AUDIBLE_H
|
|
||||||
#define LOVE_AUDIO_AUDIBLE_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include <common/Object.h>
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
class Source;
|
|
||||||
|
|
||||||
class Audible : public Object
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual ~Audible(){};
|
|
||||||
virtual void play(Source * source) = 0;
|
|
||||||
virtual void update(Source * source) = 0;
|
|
||||||
virtual void stop(Source * source) = 0;
|
|
||||||
virtual void rewind(Source * source) = 0;
|
|
||||||
|
|
||||||
}; // Audible
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_AUDIBLE_H
|
|
||||||
@@ -23,11 +23,14 @@
|
|||||||
|
|
||||||
#include <common/Module.h>
|
#include <common/Module.h>
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "Sound.h"
|
|
||||||
#include "Music.h"
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
|
namespace sound
|
||||||
|
{
|
||||||
|
class Decoder;
|
||||||
|
class SoundData;
|
||||||
|
}
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -42,25 +45,8 @@ namespace audio
|
|||||||
**/
|
**/
|
||||||
virtual ~Audio(){};
|
virtual ~Audio(){};
|
||||||
|
|
||||||
/**
|
virtual Source * newSource(love::sound::Decoder * decoder) = 0;
|
||||||
* Creates a new Sound with the specified SoundData.
|
virtual Source * newSource(love::sound::SoundData * soundData) = 0;
|
||||||
* @param data The SoundData from which to create the sound.
|
|
||||||
* @return A new Sound if successful, zero otherwise.
|
|
||||||
**/
|
|
||||||
virtual Sound * newSound(love::sound::SoundData * data) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Music (stream) using the specified SoundData.
|
|
||||||
* @param decoder The object to use to decode the sound stream.
|
|
||||||
**/
|
|
||||||
virtual Music * newMusic(love::sound::Decoder * decoder) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Source.
|
|
||||||
* @returns A new Source.
|
|
||||||
**/
|
|
||||||
virtual Source * newSource(Sound * sound) = 0;
|
|
||||||
virtual Source * newSource(Music * music) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current number of simulatenous playing sources.
|
* Gets the current number of simulatenous playing sources.
|
||||||
@@ -80,26 +66,6 @@ namespace audio
|
|||||||
**/
|
**/
|
||||||
virtual void play(Source * source) = 0;
|
virtual void play(Source * source) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Plays one Sound on the specified Source. We need separate
|
|
||||||
* Sound and Music play functions because Music must be cloned,
|
|
||||||
* whereas Sound needs not be.
|
|
||||||
*
|
|
||||||
* @param sound The Sound to play.
|
|
||||||
* @param source The Source on which to play the Sound.
|
|
||||||
**/
|
|
||||||
virtual void play(Sound * sound) = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plays one Music on the specified Source. We need separate
|
|
||||||
* Sound and Music play functions because Music must be cloned,
|
|
||||||
* whereas Sound needs not be.
|
|
||||||
*
|
|
||||||
* @param music The Music to play.
|
|
||||||
* @param source The Source on which to play the Music.
|
|
||||||
**/
|
|
||||||
virtual void play(Music * music) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops playback on the specified source.
|
* Stops playback on the specified source.
|
||||||
* @param source The source on which to stop the playback.
|
* @param source The source on which to stop the playback.
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_MUSIC_H
|
|
||||||
#define LOVE_AUDIO_MUSIC_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include "Audible.h"
|
|
||||||
#include <sound/Decoder.h>
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A Music object represents a stream of sound samples which are gradually
|
|
||||||
* acquired somehow. Compare with Sounds, which have all the needed sound
|
|
||||||
* samples pre-decoded.
|
|
||||||
*
|
|
||||||
* Typically, you would want to use love::sound::Decoder to decode samples
|
|
||||||
* from some encoded format, like OGG or MP3, however, Music can come from
|
|
||||||
* other sources as well.
|
|
||||||
**/
|
|
||||||
class Music : public Audible
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor.
|
|
||||||
**/
|
|
||||||
virtual ~Music(){};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a clone of the music stream. Music objects are gradually
|
|
||||||
* decoded, so if the client wants to play the same Music object, we can't
|
|
||||||
* use the same object. We must clone the entire stream.
|
|
||||||
* @return A clone of this object, but rewound to the start.
|
|
||||||
**/
|
|
||||||
virtual Music * clone() = 0;
|
|
||||||
|
|
||||||
}; // Music
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_MUSIC_H
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_SOUND_H
|
|
||||||
#define LOVE_AUDIO_SOUND_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include <sound/SoundData.h>
|
|
||||||
#include "Audible.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
class Sound : public Audible
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
public:
|
|
||||||
virtual ~Sound(){};
|
|
||||||
}; // Sound
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_SOUND_H
|
|
||||||
@@ -24,47 +24,32 @@ namespace love
|
|||||||
{
|
{
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
Source::Source()
|
Source::Source(Type type)
|
||||||
: audible(0), looping(false)
|
: type(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Source::~Source()
|
Source::~Source()
|
||||||
{
|
{
|
||||||
if(audible != 0)
|
|
||||||
{
|
|
||||||
audible->stop(this);
|
|
||||||
audible->release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::setAudible(Audible * audible)
|
bool Source::getConstant(const char * in, Type & out)
|
||||||
{
|
{
|
||||||
// If this source already has an audible, remove it.
|
return types.find(in, out);
|
||||||
if(this->audible != 0)
|
|
||||||
{
|
|
||||||
this->audible->stop(this);
|
|
||||||
this->audible->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->audible = audible;
|
|
||||||
audible->retain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Audible * Source::getAudible() const
|
bool Source::getConstant(Type in, const char *& out)
|
||||||
{
|
{
|
||||||
return audible;
|
return types.find(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::setLooping(bool looping)
|
StringMap<Source::Type, Source::TYPE_MAX_ENUM>::Entry Source::typeEntries[] =
|
||||||
{
|
{
|
||||||
this->looping = looping;
|
{"static", Source::TYPE_STATIC},
|
||||||
}
|
{"stream", Source::TYPE_STREAM},
|
||||||
|
};
|
||||||
|
|
||||||
bool Source::isLooping() const
|
StringMap<Source::Type, Source::TYPE_MAX_ENUM> Source::types(Source::typeEntries, sizeof(Source::typeEntries));
|
||||||
{
|
|
||||||
return looping;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include <common/Object.h>
|
#include <common/Object.h>
|
||||||
#include "Audible.h"
|
#include <common/StringMap.h>
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -31,14 +31,23 @@ namespace audio
|
|||||||
{
|
{
|
||||||
class Source : public Object
|
class Source : public Object
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
Audible * audible;
|
|
||||||
bool looping;
|
|
||||||
public:
|
public:
|
||||||
Source();
|
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
TYPE_STATIC = 1,
|
||||||
|
TYPE_STREAM,
|
||||||
|
TYPE_MAX_ENUM
|
||||||
|
}; // Type
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Type type;
|
||||||
|
public:
|
||||||
|
|
||||||
|
Source(Type type);
|
||||||
virtual ~Source();
|
virtual ~Source();
|
||||||
void setAudible(Audible * audible);
|
|
||||||
Audible * getAudible() const;
|
virtual Source * copy() = 0;
|
||||||
|
|
||||||
virtual void play() = 0;
|
virtual void play() = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
@@ -46,6 +55,7 @@ namespace audio
|
|||||||
virtual void resume() = 0;
|
virtual void resume() = 0;
|
||||||
virtual void rewind() = 0;
|
virtual void rewind() = 0;
|
||||||
virtual bool isStopped() const = 0;
|
virtual bool isStopped() const = 0;
|
||||||
|
virtual bool isFinished() const = 0;
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
|
|
||||||
virtual void setPitch(float pitch) = 0;
|
virtual void setPitch(float pitch) = 0;
|
||||||
@@ -62,8 +72,16 @@ namespace audio
|
|||||||
virtual void setDirection(float * v) = 0;
|
virtual void setDirection(float * v) = 0;
|
||||||
virtual void getDirection(float * v) const = 0;
|
virtual void getDirection(float * v) const = 0;
|
||||||
|
|
||||||
void setLooping(bool looping);
|
virtual void setLooping(bool looping) = 0;
|
||||||
bool isLooping() const;
|
virtual bool isLooping() const = 0;
|
||||||
|
|
||||||
|
static bool getConstant(const char * in, Type & out);
|
||||||
|
static bool getConstant(Type in, const char *& out);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
|
||||||
|
static StringMap<Type, TYPE_MAX_ENUM> types;
|
||||||
|
|
||||||
}; // Source
|
}; // Source
|
||||||
|
|
||||||
|
|||||||
@@ -39,22 +39,12 @@ namespace null
|
|||||||
return "love.audio.null";
|
return "love.audio.null";
|
||||||
}
|
}
|
||||||
|
|
||||||
love::audio::Sound * Audio::newSound(love::sound::SoundData * data)
|
love::audio::Source * Audio::newSource(love::sound::Decoder * decoder)
|
||||||
{
|
|
||||||
return new Sound(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::Music * Audio::newMusic(love::sound::Decoder * decoder)
|
|
||||||
{
|
|
||||||
return new Music(decoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::Source * Audio::newSource(love::audio::Sound * sound)
|
|
||||||
{
|
{
|
||||||
return new Source();
|
return new Source();
|
||||||
}
|
}
|
||||||
|
|
||||||
love::audio::Source * Audio::newSource(love::audio::Music * music)
|
love::audio::Source * Audio::newSource(love::sound::SoundData * soundData)
|
||||||
{
|
{
|
||||||
return new Source();
|
return new Source();
|
||||||
}
|
}
|
||||||
@@ -73,14 +63,6 @@ namespace null
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::play(love::audio::Sound * sound)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Audio::play(love::audio::Music * music)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Audio::play()
|
void Audio::play()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
// LOVE
|
// LOVE
|
||||||
#include <audio/Audio.h>
|
#include <audio/Audio.h>
|
||||||
|
|
||||||
#include "Sound.h"
|
|
||||||
#include "Music.h"
|
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -41,21 +39,17 @@ namespace null
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
Audio();
|
Audio();
|
||||||
~Audio();
|
virtual ~Audio();
|
||||||
|
|
||||||
// Implements Module.
|
// Implements Module.
|
||||||
const char * getName() const;
|
const char * getName() const;
|
||||||
|
|
||||||
// Implements Audio.
|
// Implements Audio.
|
||||||
love::audio::Sound * newSound(love::sound::SoundData * data);
|
love::audio::Source * newSource(love::sound::Decoder * decoder);
|
||||||
love::audio::Music * newMusic(love::sound::Decoder * decoder);
|
love::audio::Source * newSource(love::sound::SoundData * soundData);
|
||||||
love::audio::Source * newSource(love::audio::Sound * sound);
|
|
||||||
love::audio::Source * newSource(love::audio::Music * music);
|
|
||||||
int getNumSources() const;
|
int getNumSources() const;
|
||||||
int getMaxSources() const;
|
int getMaxSources() const;
|
||||||
void play(love::audio::Source * source);
|
void play(love::audio::Source * source);
|
||||||
void play(love::audio::Sound * sound);
|
|
||||||
void play(love::audio::Music * music);
|
|
||||||
void play();
|
void play();
|
||||||
void stop(love::audio::Source * source);
|
void stop(love::audio::Source * source);
|
||||||
void stop();
|
void stop();
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "Music.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace null
|
|
||||||
{
|
|
||||||
Music::Music(love::sound::Decoder * decoder)
|
|
||||||
: decoder(decoder)
|
|
||||||
{
|
|
||||||
decoder->retain();
|
|
||||||
}
|
|
||||||
|
|
||||||
Music::~Music()
|
|
||||||
{
|
|
||||||
decoder->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::Music * Music::clone()
|
|
||||||
{
|
|
||||||
return new Music(decoder->clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::play(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::update(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::stop(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::rewind(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // null
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_NULL_MUSIC_H
|
|
||||||
#define LOVE_AUDIO_NULL_MUSIC_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include <audio/Music.h>
|
|
||||||
#include <sound/Decoder.h>
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace null
|
|
||||||
{
|
|
||||||
class Music : public love::audio::Music
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
love::sound::Decoder * decoder;
|
|
||||||
public:
|
|
||||||
Music(love::sound::Decoder * decoder);
|
|
||||||
virtual ~Music();
|
|
||||||
|
|
||||||
// Implements Audible.
|
|
||||||
void play(love::audio::Source * source);
|
|
||||||
void update(love::audio::Source * source);
|
|
||||||
void stop(love::audio::Source * source);
|
|
||||||
void rewind(love::audio::Source * source);
|
|
||||||
|
|
||||||
// Implements Music.
|
|
||||||
love::audio::Music * clone();
|
|
||||||
|
|
||||||
}; // Music
|
|
||||||
|
|
||||||
} // null
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_NULL_MUSIC_H
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "Sound.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace null
|
|
||||||
{
|
|
||||||
Sound::Sound(love::sound::SoundData * data)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Sound::~Sound()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::play(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::update(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::stop(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::rewind(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // null
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_NULL_SOUND_H
|
|
||||||
#define LOVE_AUDIO_NULL_SOUND_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include <sound/SoundData.h>
|
|
||||||
#include <audio/Sound.h>
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace null
|
|
||||||
{
|
|
||||||
class Sound : public love::audio::Sound
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
Sound(love::sound::SoundData * data);
|
|
||||||
virtual ~Sound();
|
|
||||||
|
|
||||||
// Implements Audible.
|
|
||||||
void play(love::audio::Source * s);
|
|
||||||
void update(love::audio::Source * s);
|
|
||||||
void stop(love::audio::Source * s);
|
|
||||||
void rewind(love::audio::Source * s);
|
|
||||||
|
|
||||||
}; // Sound
|
|
||||||
|
|
||||||
} // null
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_NULL_SOUND_H
|
|
||||||
@@ -28,18 +28,20 @@ namespace null
|
|||||||
{
|
{
|
||||||
|
|
||||||
Source::Source()
|
Source::Source()
|
||||||
|
: love::audio::Source(Source::TYPE_STATIC)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Source::Source(Audible * audible)
|
|
||||||
{
|
|
||||||
setAudible(audible);
|
|
||||||
}
|
|
||||||
|
|
||||||
Source::~Source()
|
Source::~Source()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
love::audio::Source * Source::copy()
|
||||||
|
{
|
||||||
|
this->retain();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
void Source::play()
|
void Source::play()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -65,6 +67,11 @@ namespace null
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Source::isFinished() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Source::update()
|
void Source::update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -113,6 +120,16 @@ namespace null
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Source::setLooping(bool looping)
|
||||||
|
{
|
||||||
|
this->looping = looping;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Source::isLooping() const
|
||||||
|
{
|
||||||
|
return looping;
|
||||||
|
}
|
||||||
|
|
||||||
} // null
|
} // null
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -37,32 +37,33 @@ namespace null
|
|||||||
|
|
||||||
float pitch;
|
float pitch;
|
||||||
float volume;
|
float volume;
|
||||||
|
bool looping;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Source();
|
Source();
|
||||||
Source(Audible * audible);
|
|
||||||
virtual ~Source();
|
virtual ~Source();
|
||||||
|
|
||||||
void play();
|
virtual love::audio::Source * copy();
|
||||||
void stop();
|
virtual void play();
|
||||||
void pause();
|
virtual void stop();
|
||||||
void resume();
|
virtual void pause();
|
||||||
void rewind();
|
virtual void resume();
|
||||||
bool isStopped() const;
|
virtual void rewind();
|
||||||
void update();
|
virtual bool isStopped() const;
|
||||||
|
virtual bool isFinished() const;
|
||||||
void setPitch(float pitch);
|
virtual void update();
|
||||||
float getPitch() const;
|
virtual void setPitch(float pitch);
|
||||||
|
virtual float getPitch() const;
|
||||||
void setVolume(float volume);
|
virtual void setVolume(float volume);
|
||||||
float getVolume() const;
|
virtual float getVolume() const;
|
||||||
|
virtual void setPosition(float * v);
|
||||||
void setPosition(float * v);
|
virtual void getPosition(float * v) const;
|
||||||
void getPosition(float * v) const;
|
virtual void setVelocity(float * v);
|
||||||
void setVelocity(float * v);
|
virtual void getVelocity(float * v) const;
|
||||||
void getVelocity(float * v) const;
|
virtual void setDirection(float * v);
|
||||||
void setDirection(float * v);
|
virtual void getDirection(float * v) const;
|
||||||
void getDirection(float * v) const;
|
void setLooping(bool looping);
|
||||||
|
bool isLooping() const;
|
||||||
|
|
||||||
}; // Source
|
}; // Source
|
||||||
|
|
||||||
|
|||||||
@@ -82,24 +82,14 @@ namespace openal
|
|||||||
return "love.audio.openal";
|
return "love.audio.openal";
|
||||||
}
|
}
|
||||||
|
|
||||||
love::audio::Sound * Audio::newSound(love::sound::SoundData * data)
|
love::audio::Source * Audio::newSource(love::sound::Decoder * decoder)
|
||||||
{
|
{
|
||||||
return new Sound(pool, data);
|
return new Source(pool, decoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
love::audio::Music * Audio::newMusic(love::sound::Decoder * decoder)
|
love::audio::Source * Audio::newSource(love::sound::SoundData * soundData)
|
||||||
{
|
{
|
||||||
return new Music(pool, decoder);
|
return new Source(pool, soundData);
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::Source * Audio::newSource(love::audio::Sound * sound)
|
|
||||||
{
|
|
||||||
return new Source(pool, sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::Source * Audio::newSource(love::audio::Music * music)
|
|
||||||
{
|
|
||||||
return new Source(pool, music->clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Audio::getNumSources() const
|
int Audio::getNumSources() const
|
||||||
@@ -117,22 +107,6 @@ namespace openal
|
|||||||
source->play();
|
source->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::play(love::audio::Sound * sound)
|
|
||||||
{
|
|
||||||
Source * source = new Source(pool, sound);
|
|
||||||
play(source);
|
|
||||||
source->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Audio::play(love::audio::Music * music)
|
|
||||||
{
|
|
||||||
love::audio::Music *cloned = music->clone();
|
|
||||||
Source * source = new Source(pool, cloned);
|
|
||||||
play(source);
|
|
||||||
cloned->release();
|
|
||||||
source->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Audio::stop(love::audio::Source * source)
|
void Audio::stop(love::audio::Source * source)
|
||||||
{
|
{
|
||||||
source->stop();
|
source->stop();
|
||||||
|
|||||||
@@ -35,8 +35,6 @@
|
|||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <sound/SoundData.h>
|
#include <sound/SoundData.h>
|
||||||
|
|
||||||
#include "Sound.h"
|
|
||||||
#include "Music.h"
|
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "Pool.h"
|
#include "Pool.h"
|
||||||
|
|
||||||
@@ -86,15 +84,11 @@ namespace openal
|
|||||||
const char * getName() const;
|
const char * getName() const;
|
||||||
|
|
||||||
// Implements Audio.
|
// Implements Audio.
|
||||||
love::audio::Sound * newSound(love::sound::SoundData * data);
|
love::audio::Source * newSource(love::sound::Decoder * decoder);
|
||||||
love::audio::Music * newMusic(love::sound::Decoder * decoder);
|
love::audio::Source * newSource(love::sound::SoundData * soundData);
|
||||||
love::audio::Source * newSource(love::audio::Sound * sound);
|
|
||||||
love::audio::Source * newSource(love::audio::Music * music);
|
|
||||||
int getNumSources() const;
|
int getNumSources() const;
|
||||||
int getMaxSources() const;
|
int getMaxSources() const;
|
||||||
void play(love::audio::Source * source);
|
void play(love::audio::Source * source);
|
||||||
void play(love::audio::Sound * sound);
|
|
||||||
void play(love::audio::Music * music);
|
|
||||||
void play();
|
void play();
|
||||||
void stop(love::audio::Source * source);
|
void stop(love::audio::Source * source);
|
||||||
void stop();
|
void stop();
|
||||||
|
|||||||
@@ -1,134 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "Music.h"
|
|
||||||
|
|
||||||
// STD
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace openal
|
|
||||||
{
|
|
||||||
Music::Music(Pool * pool, love::sound::Decoder * decoder)
|
|
||||||
: pool(pool), decoder(decoder), source(0)
|
|
||||||
{
|
|
||||||
decoder->retain();
|
|
||||||
alGenBuffers(NUM_BUFFERS, buffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Music::~Music()
|
|
||||||
{
|
|
||||||
decoder->release();
|
|
||||||
alDeleteBuffers(NUM_BUFFERS, buffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::Music * Music::clone()
|
|
||||||
{
|
|
||||||
return new Music(pool, decoder->clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::play(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
source = pool->find(s);
|
|
||||||
|
|
||||||
if(source)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < NUM_BUFFERS; i++)
|
|
||||||
{
|
|
||||||
if(!stream(s, buffers[i]))
|
|
||||||
{
|
|
||||||
std::cout << "Could not stream music." << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
alSourceQueueBuffers(source, NUM_BUFFERS, buffers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::update(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
if(source)
|
|
||||||
{
|
|
||||||
// Number of processed buffers.
|
|
||||||
ALint processed;
|
|
||||||
|
|
||||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
|
||||||
|
|
||||||
while(processed--)
|
|
||||||
{
|
|
||||||
ALuint buffer;
|
|
||||||
|
|
||||||
// Get a free buffer.
|
|
||||||
alSourceUnqueueBuffers(source, 1, &buffer);
|
|
||||||
|
|
||||||
if(stream(s, buffer))
|
|
||||||
alSourceQueueBuffers(source, 1, &buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::stop(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
if(source)
|
|
||||||
{
|
|
||||||
ALuint bufs[NUM_BUFFERS];
|
|
||||||
alSourceStop(source);
|
|
||||||
alSourceUnqueueBuffers(source, NUM_BUFFERS, bufs);
|
|
||||||
source = 0;
|
|
||||||
rewind(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Music::rewind(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
decoder->rewind();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Music::stream(love::audio::Source * source, ALuint buffer)
|
|
||||||
{
|
|
||||||
if(source->isLooping() && decoder->isFinished())
|
|
||||||
decoder->rewind();
|
|
||||||
|
|
||||||
// Get more sound data.
|
|
||||||
int decoded = decoder->decode();
|
|
||||||
|
|
||||||
int fmt = pool->getFormat(decoder->getChannels(), decoder->getBits());
|
|
||||||
|
|
||||||
if(fmt == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(decoded > 0)
|
|
||||||
{
|
|
||||||
alBufferData(buffer, fmt, decoder->getBuffer(),
|
|
||||||
decoder->getSize(), decoder->getSampleRate());
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // openal
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_OPENAL_MUSIC_H
|
|
||||||
#define LOVE_AUDIO_OPENAL_MUSIC_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include <audio/Music.h>
|
|
||||||
#include <common/config.h>
|
|
||||||
#include <sound/Decoder.h>
|
|
||||||
#include "Pool.h"
|
|
||||||
|
|
||||||
// OpenAL
|
|
||||||
#ifdef LOVE_MACOSX
|
|
||||||
#include <OpenAL/alc.h>
|
|
||||||
#include <OpenAL/al.h>
|
|
||||||
#else
|
|
||||||
#include <AL/alc.h>
|
|
||||||
#include <AL/al.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace openal
|
|
||||||
{
|
|
||||||
|
|
||||||
// Forward declarations.
|
|
||||||
class Audio;
|
|
||||||
|
|
||||||
class Music : public love::audio::Music
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static const unsigned int NUM_BUFFERS = 32;
|
|
||||||
ALuint buffers[NUM_BUFFERS];
|
|
||||||
Pool * pool;
|
|
||||||
love::sound::Decoder * decoder;
|
|
||||||
ALuint source;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Music(Pool * pool, love::sound::Decoder * decoder);
|
|
||||||
virtual ~Music();
|
|
||||||
|
|
||||||
// Implements Audible.
|
|
||||||
void play(love::audio::Source * source);
|
|
||||||
void update(love::audio::Source * source);
|
|
||||||
void stop(love::audio::Source * source);
|
|
||||||
void rewind(love::audio::Source * source);
|
|
||||||
|
|
||||||
// Implements Music.
|
|
||||||
love::audio::Music * clone();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool stream(love::audio::Source * source, ALuint buffer);
|
|
||||||
}; // Sound
|
|
||||||
|
|
||||||
} // openal
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_OPENAL_MUSIC_H
|
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "Pool.h"
|
#include "Pool.h"
|
||||||
|
|
||||||
|
#include "Source.h"
|
||||||
|
|
||||||
#define MUTEX_ASSERT(fn, sval) \
|
#define MUTEX_ASSERT(fn, sval) \
|
||||||
if(fn != sval) \
|
if(fn != sval) \
|
||||||
{ \
|
{ \
|
||||||
@@ -62,20 +64,6 @@ namespace openal
|
|||||||
alDeleteSources(NUM_SOURCES, sources);
|
alDeleteSources(NUM_SOURCES, sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALenum Pool::getFormat(int channels, int bits) const
|
|
||||||
{
|
|
||||||
if(channels == 1 && bits == 8)
|
|
||||||
return AL_FORMAT_MONO8;
|
|
||||||
else if(channels == 1 && bits == 16)
|
|
||||||
return AL_FORMAT_MONO16;
|
|
||||||
else if(channels == 2 && bits == 8)
|
|
||||||
return AL_FORMAT_STEREO8;
|
|
||||||
else if(channels == 2 && bits == 16)
|
|
||||||
return AL_FORMAT_STEREO16;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pool::isAvailable() const
|
bool Pool::isAvailable() const
|
||||||
{
|
{
|
||||||
bool has = false;
|
bool has = false;
|
||||||
@@ -85,42 +73,11 @@ namespace openal
|
|||||||
return has;
|
return has;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint Pool::claim(love::audio::Source * source)
|
bool Pool::isPlaying(Source * s)
|
||||||
{
|
|
||||||
ALuint s = 0;
|
|
||||||
LOCK(mutex);
|
|
||||||
if(!available.empty())
|
|
||||||
{
|
|
||||||
// Get the first available source.
|
|
||||||
s = available.front();
|
|
||||||
|
|
||||||
// Remove it.
|
|
||||||
available.pop();
|
|
||||||
|
|
||||||
// Insert into map of playing sources.
|
|
||||||
playing.insert(std::pair<love::audio::Source *, ALuint>(source, s));
|
|
||||||
|
|
||||||
source->retain();
|
|
||||||
}
|
|
||||||
UNLOCK(mutex);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALuint Pool::find(const love::audio::Source * source) const
|
|
||||||
{
|
|
||||||
ALuint r = 0;
|
|
||||||
LOCK(mutex);
|
|
||||||
r = findi(source);
|
|
||||||
UNLOCK(mutex);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Pool::isPlaying(love::audio::Source * s)
|
|
||||||
{
|
{
|
||||||
bool p = false;
|
bool p = false;
|
||||||
LOCK(mutex);
|
LOCK(mutex);
|
||||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||||
{
|
{
|
||||||
if(i->first == s)
|
if(i->first == s)
|
||||||
p = true;
|
p = true;
|
||||||
@@ -133,13 +90,13 @@ namespace openal
|
|||||||
{
|
{
|
||||||
LOCK(mutex);
|
LOCK(mutex);
|
||||||
|
|
||||||
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
|
std::map<Source *, ALuint>::iterator i = playing.begin();
|
||||||
|
|
||||||
while(i != playing.end())
|
while(i != playing.end())
|
||||||
{
|
{
|
||||||
if(i->first->isStopped())
|
if(i->first->isStopped())
|
||||||
{
|
{
|
||||||
i->first->stop();
|
i->first->stopAtomic();
|
||||||
i->first->release();
|
i->first->release();
|
||||||
available.push(i->second);
|
available.push(i->second);
|
||||||
playing.erase(i++);
|
playing.erase(i++);
|
||||||
@@ -164,12 +121,56 @@ namespace openal
|
|||||||
return NUM_SOURCES;
|
return NUM_SOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Pool::play(Source * source, ALuint & out)
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
out = 0;
|
||||||
|
|
||||||
|
LOCK(mutex);
|
||||||
|
|
||||||
|
bool alreadyPlaying = findSource(source, out);
|
||||||
|
|
||||||
|
if(!alreadyPlaying)
|
||||||
|
{
|
||||||
|
// Try to play.
|
||||||
|
if(!available.empty())
|
||||||
|
{
|
||||||
|
// Get the first available source.
|
||||||
|
out = available.front();
|
||||||
|
|
||||||
|
// Remove it.
|
||||||
|
available.pop();
|
||||||
|
|
||||||
|
// Insert into map of playing sources.
|
||||||
|
playing.insert(std::pair<Source *, ALuint>(source, out));
|
||||||
|
|
||||||
|
source->retain();
|
||||||
|
|
||||||
|
source->playAtomic();
|
||||||
|
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNLOCK(mutex);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
void Pool::stop()
|
void Pool::stop()
|
||||||
{
|
{
|
||||||
LOCK(mutex);
|
LOCK(mutex);
|
||||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||||
{
|
{
|
||||||
i->first->stop();
|
i->first->stopAtomic();
|
||||||
available.push(i->second);
|
available.push(i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,31 +179,65 @@ namespace openal
|
|||||||
UNLOCK(mutex);
|
UNLOCK(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pool::stop(Source * source)
|
||||||
|
{
|
||||||
|
LOCK(mutex);
|
||||||
|
removeSource(source);
|
||||||
|
UNLOCK(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
void Pool::pause()
|
void Pool::pause()
|
||||||
{
|
{
|
||||||
LOCK(mutex);
|
LOCK(mutex);
|
||||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||||
i->first->pause();
|
i->first->pauseAtomic();
|
||||||
|
UNLOCK(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pool::pause(Source * source)
|
||||||
|
{
|
||||||
|
LOCK(mutex);
|
||||||
|
ALuint out;
|
||||||
|
if(findSource(source, out))
|
||||||
|
source->pauseAtomic();
|
||||||
UNLOCK(mutex);
|
UNLOCK(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pool::resume()
|
void Pool::resume()
|
||||||
{
|
{
|
||||||
LOCK(mutex);
|
LOCK(mutex);
|
||||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||||
i->first->resume();
|
i->first->resumeAtomic();
|
||||||
|
UNLOCK(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pool::resume(Source * source)
|
||||||
|
{
|
||||||
|
LOCK(mutex);
|
||||||
|
ALuint out;
|
||||||
|
if(findSource(source, out))
|
||||||
|
source->resumeAtomic();
|
||||||
UNLOCK(mutex);
|
UNLOCK(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pool::rewind()
|
void Pool::rewind()
|
||||||
{
|
{
|
||||||
LOCK(mutex);
|
LOCK(mutex);
|
||||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||||
i->first->rewind();
|
i->first->rewindAtomic();
|
||||||
UNLOCK(mutex);
|
UNLOCK(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pool::release(love::audio::Source * source)
|
void Pool::rewind(Source * source)
|
||||||
|
{
|
||||||
|
LOCK(mutex);
|
||||||
|
ALuint out;
|
||||||
|
if(findSource(source, out))
|
||||||
|
source->rewindAtomic();
|
||||||
|
UNLOCK(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pool::release(Source * source)
|
||||||
{
|
{
|
||||||
ALuint s = findi(source);
|
ALuint s = findi(source);
|
||||||
|
|
||||||
@@ -213,9 +248,9 @@ namespace openal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint Pool::findi(const love::audio::Source * source) const
|
ALuint Pool::findi(const Source * source) const
|
||||||
{
|
{
|
||||||
std::map<love::audio::Source *, ALuint>::const_iterator i = playing.find((love::audio::Source *)source);
|
std::map<Source *, ALuint>::const_iterator i = playing.find((Source *)source);
|
||||||
|
|
||||||
if(i != playing.end())
|
if(i != playing.end())
|
||||||
return i->second;
|
return i->second;
|
||||||
@@ -223,6 +258,34 @@ namespace openal
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Pool::findSource(Source * source, ALuint & out)
|
||||||
|
{
|
||||||
|
std::map<Source *, ALuint>::const_iterator i = playing.find((Source *)source);
|
||||||
|
|
||||||
|
bool found = i != playing.end();
|
||||||
|
|
||||||
|
if(found)
|
||||||
|
out = i->second;
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Pool::removeSource(Source * source)
|
||||||
|
{
|
||||||
|
std::map<Source *, ALuint>::const_iterator i = playing.find((Source *)source);
|
||||||
|
|
||||||
|
if(i != playing.end())
|
||||||
|
{
|
||||||
|
source->stopAtomic();
|
||||||
|
source->release();
|
||||||
|
available.push(i->second);
|
||||||
|
playing.erase(i++);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // openal
|
} // openal
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include <audio/Source.h>
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/Exception.h>
|
#include <common/Exception.h>
|
||||||
|
|
||||||
@@ -50,6 +49,9 @@ namespace audio
|
|||||||
{
|
{
|
||||||
namespace openal
|
namespace openal
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Source;
|
||||||
|
|
||||||
class Pool
|
class Pool
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -64,7 +66,7 @@ namespace openal
|
|||||||
std::queue<ALuint> available;
|
std::queue<ALuint> available;
|
||||||
|
|
||||||
// A map of playing sources.
|
// A map of playing sources.
|
||||||
std::map<love::audio::Source *, ALuint> playing;
|
std::map<Source *, ALuint> playing;
|
||||||
|
|
||||||
// Only one thread can access this object at the same time. This mutex will
|
// Only one thread can access this object at the same time. This mutex will
|
||||||
// make sure of that.
|
// make sure of that.
|
||||||
@@ -75,15 +77,6 @@ namespace openal
|
|||||||
Pool();
|
Pool();
|
||||||
~Pool();
|
~Pool();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the OpenAL format identifier based on number of
|
|
||||||
* channels and bits.
|
|
||||||
* @param channels Either 1 (mono) or 2 (stereo).
|
|
||||||
* @param bits Either 8-bit samples, or 16-bit samples.
|
|
||||||
* @return One of AL_FORMAT_*, or 0 if unsupported format.
|
|
||||||
**/
|
|
||||||
ALenum getFormat(int channels, int bits) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether an OpenAL source is available.
|
* Checks whether an OpenAL source is available.
|
||||||
* @return True if at least one is available, false otherwise.
|
* @return True if at least one is available, false otherwise.
|
||||||
@@ -93,26 +86,22 @@ namespace openal
|
|||||||
/**
|
/**
|
||||||
* Checks whether a Source is currently in the playing list.
|
* Checks whether a Source is currently in the playing list.
|
||||||
**/
|
**/
|
||||||
bool isPlaying(love::audio::Source * s);
|
bool isPlaying(Source * s);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an available OpenAL source identifier, or 0 if
|
|
||||||
* none is available.
|
|
||||||
* @return An OpenAL source ID, or 0 if unavailable.
|
|
||||||
**/
|
|
||||||
ALuint claim(love::audio::Source * source);
|
|
||||||
|
|
||||||
ALuint find(const love::audio::Source * source) const;
|
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
int getNumSources() const;
|
int getNumSources() const;
|
||||||
int getMaxSources() const;
|
int getMaxSources() const;
|
||||||
|
|
||||||
|
bool play(Source * source, ALuint & out);
|
||||||
void stop();
|
void stop();
|
||||||
|
void stop(Source * source);
|
||||||
void pause();
|
void pause();
|
||||||
|
void pause(Source * source);
|
||||||
void resume();
|
void resume();
|
||||||
|
void resume(Source * source);
|
||||||
void rewind();
|
void rewind();
|
||||||
|
void rewind(Source * source);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -120,9 +109,12 @@ namespace openal
|
|||||||
* Makes the specified OpenAL source available for use.
|
* Makes the specified OpenAL source available for use.
|
||||||
* @param source The OpenAL source.
|
* @param source The OpenAL source.
|
||||||
**/
|
**/
|
||||||
void release(love::audio::Source * source);
|
void release(Source * source);
|
||||||
|
|
||||||
ALuint findi(const love::audio::Source * source) const;
|
ALuint findi(const Source * source) const;
|
||||||
|
|
||||||
|
bool findSource(Source * source, ALuint & out);
|
||||||
|
bool removeSource(Source * source);
|
||||||
}; // Pool
|
}; // Pool
|
||||||
|
|
||||||
} // openal
|
} // openal
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "Sound.h"
|
|
||||||
|
|
||||||
#include <common/Exception.h>
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace openal
|
|
||||||
{
|
|
||||||
Sound::Sound(Pool * pool, love::sound::SoundData * data)
|
|
||||||
: pool(pool), buffer(0), source(source)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Generate the buffer.
|
|
||||||
alGenBuffers(1, &buffer);
|
|
||||||
|
|
||||||
int fmt = pool->getFormat(data->getChannels(), data->getBits());
|
|
||||||
|
|
||||||
if(fmt == 0)
|
|
||||||
throw love::Exception("Unsupported audio format.");
|
|
||||||
|
|
||||||
alBufferData(buffer, fmt, data->getData(), data->getSize(), data->getSampleRate());
|
|
||||||
|
|
||||||
// Note: we're done with the sound data
|
|
||||||
// at this point. No need to retain.
|
|
||||||
}
|
|
||||||
|
|
||||||
Sound::~Sound()
|
|
||||||
{
|
|
||||||
if(buffer)
|
|
||||||
alDeleteBuffers(1, &buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::play(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
// Set the buffer for the sound.
|
|
||||||
source = pool->find(s);
|
|
||||||
|
|
||||||
if(source)
|
|
||||||
{
|
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
|
||||||
alSourcei(source, AL_LOOPING, s->isLooping() ? AL_TRUE : AL_FALSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::update(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
// Looping mode could have changed.
|
|
||||||
alSourcei(source, AL_LOOPING, s->isLooping() ? AL_TRUE : AL_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::stop(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
if(source)
|
|
||||||
alSourceStop(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sound::rewind(love::audio::Source * s)
|
|
||||||
{
|
|
||||||
if(source)
|
|
||||||
alSourceRewind(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // openal
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_OPENAL_SOUND_H
|
|
||||||
#define LOVE_AUDIO_OPENAL_SOUND_H
|
|
||||||
|
|
||||||
// LOVE
|
|
||||||
#include <sound/SoundData.h>
|
|
||||||
#include <audio/Sound.h>
|
|
||||||
#include <common/config.h>
|
|
||||||
#include "Pool.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OpenAL
|
|
||||||
#ifdef LOVE_MACOSX
|
|
||||||
#include <OpenAL/alc.h>
|
|
||||||
#include <OpenAL/al.h>
|
|
||||||
#else
|
|
||||||
#include <AL/alc.h>
|
|
||||||
#include <AL/al.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
namespace openal
|
|
||||||
{
|
|
||||||
// Forward declarations.
|
|
||||||
class Audio;
|
|
||||||
|
|
||||||
class Sound : public love::audio::Sound
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
|
|
||||||
Pool * pool;
|
|
||||||
|
|
||||||
// Sounds only need one buffer.
|
|
||||||
ALuint buffer;
|
|
||||||
|
|
||||||
ALuint source;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Sound(Pool * pool, love::sound::SoundData * data);
|
|
||||||
virtual ~Sound();
|
|
||||||
|
|
||||||
// Implements Audible.
|
|
||||||
void play(love::audio::Source * s);
|
|
||||||
void update(love::audio::Source * s);
|
|
||||||
void stop(love::audio::Source * s);
|
|
||||||
void rewind(love::audio::Source * s);
|
|
||||||
|
|
||||||
}; // Sound
|
|
||||||
|
|
||||||
} // openal
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_OPENAL_SOUND_H
|
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
|
#include "Pool.h"
|
||||||
|
|
||||||
// STD
|
// STD
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -30,79 +32,64 @@ namespace audio
|
|||||||
namespace openal
|
namespace openal
|
||||||
{
|
{
|
||||||
|
|
||||||
Source::Source(Pool * pool)
|
static int acc = 0;
|
||||||
: pool(pool), source(0), pitch(1.0f), volume(1.0f)
|
|
||||||
|
Source::Source(Pool * pool, love::sound::SoundData * soundData)
|
||||||
|
: love::audio::Source(Source::TYPE_STATIC), pool(pool), pitch(1.0f),
|
||||||
|
volume(1.0f), looping(false), decoder(0), valid(false)
|
||||||
{
|
{
|
||||||
|
alGenBuffers(1, buffers);
|
||||||
|
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBits());
|
||||||
|
alBufferData(buffers[0], fmt, soundData->getData(), soundData->getSize(), soundData->getSampleRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
Source::Source(Pool * pool, Audible * audible)
|
Source::Source(Pool * pool, love::sound::Decoder * decoder)
|
||||||
: pool(pool), source(0), pitch(1.0f), volume(1.0f)
|
: love::audio::Source(Source::TYPE_STREAM), pool(pool), pitch(1.0f),
|
||||||
|
volume(1.0f), looping(false), decoder(decoder), valid(false)
|
||||||
{
|
{
|
||||||
setAudible(audible);
|
decoder->retain();
|
||||||
|
alGenBuffers(MAX_BUFFERS, buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
Source::~Source()
|
Source::~Source()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
|
alDeleteBuffers((type == TYPE_STATIC) ? 1 : MAX_BUFFERS, buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
love::audio::Source * Source::copy()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::play()
|
void Source::play()
|
||||||
{
|
{
|
||||||
if(source != 0)
|
valid = pool->play(this, source);
|
||||||
return; // Already playing.
|
|
||||||
|
|
||||||
if(pool->isAvailable())
|
|
||||||
source = pool->claim(this);
|
|
||||||
|
|
||||||
if(source != 0)
|
|
||||||
{
|
|
||||||
audible->play(this);
|
|
||||||
|
|
||||||
// Set these properties. These may have changed while we've
|
|
||||||
// been without an AL source.
|
|
||||||
alSourcef(source, AL_PITCH, pitch);
|
|
||||||
alSourcef(source, AL_GAIN, volume);
|
|
||||||
|
|
||||||
alSourcePlay(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::stop()
|
void Source::stop()
|
||||||
{
|
{
|
||||||
if(source)
|
pool->stop(this);
|
||||||
{
|
|
||||||
alSourceStop(source);
|
|
||||||
audible->stop(this);
|
|
||||||
source = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::pause()
|
void Source::pause()
|
||||||
{
|
{
|
||||||
if(source)
|
pool->pause();
|
||||||
{
|
|
||||||
alSourcePause(source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::resume()
|
void Source::resume()
|
||||||
{
|
{
|
||||||
if(source)
|
pool->resume();
|
||||||
{
|
|
||||||
alSourcePlay(source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::rewind()
|
void Source::rewind()
|
||||||
{
|
{
|
||||||
if(audible != 0)
|
pool->rewind();
|
||||||
audible->rewind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Source::isStopped() const
|
bool Source::isStopped() const
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
{
|
{
|
||||||
ALenum state;
|
ALenum state;
|
||||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
||||||
@@ -112,25 +99,49 @@ namespace openal
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Source::isFinished() const
|
||||||
|
{
|
||||||
|
return type == TYPE_STATIC ? isStopped() : isStopped() && !isLooping() && decoder->isFinished();
|
||||||
|
}
|
||||||
|
|
||||||
void Source::update()
|
void Source::update()
|
||||||
{
|
{
|
||||||
if(audible != 0)
|
if(valid && type == TYPE_STATIC)
|
||||||
audible->update(this);
|
{
|
||||||
|
// Looping mode could have changed.
|
||||||
|
alSourcei(source, AL_LOOPING, isLooping() ? AL_TRUE : AL_FALSE);
|
||||||
|
}
|
||||||
|
else if(valid && type == TYPE_STREAM)
|
||||||
|
{
|
||||||
|
// Number of processed buffers.
|
||||||
|
ALint processed;
|
||||||
|
|
||||||
|
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
||||||
|
|
||||||
|
while(processed--)
|
||||||
|
{
|
||||||
|
ALuint buffer;
|
||||||
|
|
||||||
|
// Get a free buffer.
|
||||||
|
alSourceUnqueueBuffers(source, 1, &buffer);
|
||||||
|
|
||||||
|
if(streamAtomic(buffer, decoder) > 0)
|
||||||
|
alSourceQueueBuffers(source, 1, &buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::setPitch(float pitch)
|
void Source::setPitch(float pitch)
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
{
|
|
||||||
alSourcef(source, AL_PITCH, pitch);
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
}
|
|
||||||
|
|
||||||
this->pitch = pitch;
|
this->pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Source::getPitch() const
|
float Source::getPitch() const
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
{
|
{
|
||||||
ALfloat f;
|
ALfloat f;
|
||||||
alGetSourcef(source, AL_PITCH, &f);
|
alGetSourcef(source, AL_PITCH, &f);
|
||||||
@@ -143,7 +154,7 @@ namespace openal
|
|||||||
|
|
||||||
void Source::setVolume(float volume)
|
void Source::setVolume(float volume)
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
{
|
{
|
||||||
alSourcef(source, AL_GAIN, volume);
|
alSourcef(source, AL_GAIN, volume);
|
||||||
}
|
}
|
||||||
@@ -153,7 +164,7 @@ namespace openal
|
|||||||
|
|
||||||
float Source::getVolume() const
|
float Source::getVolume() const
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
{
|
{
|
||||||
ALfloat f;
|
ALfloat f;
|
||||||
alGetSourcef(source, AL_GAIN, &f);
|
alGetSourcef(source, AL_GAIN, &f);
|
||||||
@@ -166,40 +177,185 @@ namespace openal
|
|||||||
|
|
||||||
void Source::setPosition(float * v)
|
void Source::setPosition(float * v)
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
alSourcefv(source, AL_POSITION, v);
|
alSourcefv(source, AL_POSITION, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::getPosition(float * v) const
|
void Source::getPosition(float * v) const
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
alGetSourcefv(source, AL_POSITION, v);
|
alGetSourcefv(source, AL_POSITION, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::setVelocity(float * v)
|
void Source::setVelocity(float * v)
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
alSourcefv(source, AL_VELOCITY, v);
|
alSourcefv(source, AL_VELOCITY, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::getVelocity(float * v) const
|
void Source::getVelocity(float * v) const
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
alGetSourcefv(source, AL_VELOCITY, v);
|
alGetSourcefv(source, AL_VELOCITY, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::setDirection(float * v)
|
void Source::setDirection(float * v)
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
alSourcefv(source, AL_DIRECTION, v);
|
alSourcefv(source, AL_DIRECTION, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Source::getDirection(float * v) const
|
void Source::getDirection(float * v) const
|
||||||
{
|
{
|
||||||
if(source)
|
if(valid)
|
||||||
alGetSourcefv(source, AL_DIRECTION, v);
|
alGetSourcefv(source, AL_DIRECTION, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Source::setLooping(bool looping)
|
||||||
|
{
|
||||||
|
this->looping = looping;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Source::isLooping() const
|
||||||
|
{
|
||||||
|
return looping;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::playAtomic()
|
||||||
|
{
|
||||||
|
if(type == TYPE_STATIC)
|
||||||
|
{
|
||||||
|
alSourcei(source, AL_BUFFER, buffers[0]);
|
||||||
|
alSourcei(source, AL_LOOPING, isLooping() ? AL_TRUE : AL_FALSE);
|
||||||
|
}
|
||||||
|
else if(type == TYPE_STREAM)
|
||||||
|
{
|
||||||
|
int usedBuffers = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < MAX_BUFFERS; i++)
|
||||||
|
{
|
||||||
|
int decoded = streamAtomic(buffers[i], decoder);
|
||||||
|
++usedBuffers;
|
||||||
|
if(decoded < decoder->getSize())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(usedBuffers > 0)
|
||||||
|
alSourceQueueBuffers(source, usedBuffers, buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set these properties. These may have changed while we've
|
||||||
|
// been without an AL source.
|
||||||
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
|
alSourcef(source, AL_GAIN, volume);
|
||||||
|
|
||||||
|
alSourcePlay(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::stopAtomic()
|
||||||
|
{
|
||||||
|
if(valid)
|
||||||
|
{
|
||||||
|
if(type == TYPE_STATIC)
|
||||||
|
{
|
||||||
|
alSourceStop(source);
|
||||||
|
}
|
||||||
|
else if(type == TYPE_STREAM)
|
||||||
|
{
|
||||||
|
alSourceStop(source);
|
||||||
|
|
||||||
|
int queued = 0;
|
||||||
|
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
|
||||||
|
|
||||||
|
while(queued--)
|
||||||
|
{
|
||||||
|
ALuint buffer;
|
||||||
|
alSourceUnqueueBuffers(source, 1, &buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reset(source);
|
||||||
|
}
|
||||||
|
rewindAtomic();
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::pauseAtomic()
|
||||||
|
{
|
||||||
|
if(valid)
|
||||||
|
{
|
||||||
|
alSourcePause(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::resumeAtomic()
|
||||||
|
{
|
||||||
|
if(valid)
|
||||||
|
{
|
||||||
|
alSourcePlay(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::rewindAtomic()
|
||||||
|
{
|
||||||
|
if(valid && type == TYPE_STATIC)
|
||||||
|
{
|
||||||
|
alSourceRewind(source);
|
||||||
|
}
|
||||||
|
else if(valid && type == TYPE_STREAM)
|
||||||
|
{
|
||||||
|
decoder->rewind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Source::reset(ALenum source)
|
||||||
|
{
|
||||||
|
alSourcei(source, AL_BUFFER, AL_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ALenum Source::getFormat(int channels, int bits) const
|
||||||
|
{
|
||||||
|
if(channels == 1 && bits == 8)
|
||||||
|
return AL_FORMAT_MONO8;
|
||||||
|
else if(channels == 1 && bits == 16)
|
||||||
|
return AL_FORMAT_MONO16;
|
||||||
|
else if(channels == 2 && bits == 8)
|
||||||
|
return AL_FORMAT_STEREO8;
|
||||||
|
else if(channels == 2 && bits == 16)
|
||||||
|
return AL_FORMAT_STEREO16;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Source::streamAtomic(ALuint buffer, love::sound::Decoder * d)
|
||||||
|
{
|
||||||
|
//if(isLooping() && d->isFinished())
|
||||||
|
// d->rewind();
|
||||||
|
|
||||||
|
// Get more sound data.
|
||||||
|
int decoded = d->decode();
|
||||||
|
|
||||||
|
int fmt = getFormat(d->getChannels(), d->getBits());
|
||||||
|
|
||||||
|
//printf("Decoded %i ( %i )", decoded, d->getSize());
|
||||||
|
|
||||||
|
if(decoded > 0 && fmt != 0)
|
||||||
|
{
|
||||||
|
alBufferData(buffer, fmt, d->getBuffer(), decoded, d->getSampleRate());
|
||||||
|
acc++;
|
||||||
|
//printf(" [%i] ", acc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(decoded < d->getSize() && isLooping())
|
||||||
|
{
|
||||||
|
printf(" Rewinding at %i.\n", acc);
|
||||||
|
d->rewind();
|
||||||
|
acc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
|
||||||
} // openal
|
} // openal
|
||||||
} // audio
|
} // audio
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/Object.h>
|
#include <common/Object.h>
|
||||||
#include <audio/Source.h>
|
#include <audio/Source.h>
|
||||||
#include "Pool.h"
|
#include <sound/SoundData.h>
|
||||||
|
#include <sound/Decoder.h>
|
||||||
|
|
||||||
// OpenAL
|
// OpenAL
|
||||||
#ifdef LOVE_MACOSX
|
#ifdef LOVE_MACOSX
|
||||||
@@ -43,6 +44,7 @@ namespace audio
|
|||||||
namespace openal
|
namespace openal
|
||||||
{
|
{
|
||||||
class Audio;
|
class Audio;
|
||||||
|
class Pool;
|
||||||
|
|
||||||
class Source : public love::audio::Source
|
class Source : public love::audio::Source
|
||||||
{
|
{
|
||||||
@@ -50,35 +52,63 @@ namespace openal
|
|||||||
|
|
||||||
Pool * pool;
|
Pool * pool;
|
||||||
ALuint source;
|
ALuint source;
|
||||||
|
bool valid;
|
||||||
|
static const unsigned int MAX_BUFFERS = 32;
|
||||||
|
ALuint buffers[MAX_BUFFERS];
|
||||||
|
|
||||||
float pitch;
|
float pitch;
|
||||||
float volume;
|
float volume;
|
||||||
|
bool looping;
|
||||||
|
|
||||||
|
love::sound::Decoder * decoder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Source(Pool * pool);
|
Source(Pool * pool, love::sound::SoundData * soundData);
|
||||||
Source(Pool * pool, Audible * audible);
|
Source(Pool * pool, love::sound::Decoder * decoder);
|
||||||
virtual ~Source();
|
virtual ~Source();
|
||||||
|
|
||||||
void play();
|
virtual love::audio::Source * copy();
|
||||||
void stop();
|
virtual void play();
|
||||||
void pause();
|
virtual void stop();
|
||||||
void resume();
|
virtual void pause();
|
||||||
void rewind();
|
virtual void resume();
|
||||||
bool isStopped() const;
|
virtual void rewind();
|
||||||
void update();
|
virtual bool isStopped() const;
|
||||||
|
virtual bool isFinished() const;
|
||||||
|
virtual void update();
|
||||||
|
virtual void setPitch(float pitch);
|
||||||
|
virtual float getPitch() const;
|
||||||
|
virtual void setVolume(float volume);
|
||||||
|
virtual float getVolume() const;
|
||||||
|
virtual void setPosition(float * v);
|
||||||
|
virtual void getPosition(float * v) const;
|
||||||
|
virtual void setVelocity(float * v);
|
||||||
|
virtual void getVelocity(float * v) const;
|
||||||
|
virtual void setDirection(float * v);
|
||||||
|
virtual void getDirection(float * v) const;
|
||||||
|
void setLooping(bool looping);
|
||||||
|
bool isLooping() const;
|
||||||
|
|
||||||
void setPitch(float pitch);
|
void playAtomic();
|
||||||
float getPitch() const;
|
void stopAtomic();
|
||||||
|
void pauseAtomic();
|
||||||
|
void resumeAtomic();
|
||||||
|
void rewindAtomic();
|
||||||
|
|
||||||
void setVolume(float volume);
|
private:
|
||||||
float getVolume() const;
|
|
||||||
|
|
||||||
void setPosition(float * v);
|
void reset(ALenum source);
|
||||||
void getPosition(float * v) const;
|
|
||||||
void setVelocity(float * v);
|
/**
|
||||||
void getVelocity(float * v) const;
|
* Gets the OpenAL format identifier based on number of
|
||||||
void setDirection(float * v);
|
* channels and bits.
|
||||||
void getDirection(float * v) const;
|
* @param channels Either 1 (mono) or 2 (stereo).
|
||||||
|
* @param bits Either 8-bit samples, or 16-bit samples.
|
||||||
|
* @return One of AL_FORMAT_*, or 0 if unsupported format.
|
||||||
|
**/
|
||||||
|
ALenum getFormat(int channels, int bits) const;
|
||||||
|
|
||||||
|
int streamAtomic(ALuint buffer, love::sound::Decoder * d);
|
||||||
|
|
||||||
}; // Source
|
}; // Source
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include "openal/Audio.h"
|
#include "openal/Audio.h"
|
||||||
#include "null/Audio.h"
|
#include "null/Audio.h"
|
||||||
|
|
||||||
|
#include <scripts/audio.lua.h>
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace audio
|
namespace audio
|
||||||
@@ -36,81 +38,31 @@ namespace audio
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_newSound(lua_State * L)
|
int w_newSource1(lua_State * L)
|
||||||
{
|
|
||||||
// Convert to File, if necessary.
|
|
||||||
if(lua_isstring(L, 1))
|
|
||||||
luax_convobj(L, 1, "filesystem", "newFile");
|
|
||||||
|
|
||||||
// Convert to SoundData, if necessary.
|
|
||||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
|
|
||||||
luax_convobj(L, 1, "sound", "newSoundData");
|
|
||||||
|
|
||||||
love::sound::SoundData * data = luax_checktype<love::sound::SoundData>(L, 1, "SoundData", SOUND_SOUND_DATA_T);
|
|
||||||
Sound * t = instance->newSound(data);
|
|
||||||
luax_newtype(L, "Sound", AUDIO_SOUND_T, (void*)t);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int w_newMusic(lua_State * L)
|
|
||||||
{
|
|
||||||
// Convert to Decoder, if necessary.
|
|
||||||
if(!luax_istype(L, 1, SOUND_DECODER_T))
|
|
||||||
luax_convobj(L, 1, "sound", "newDecoder");
|
|
||||||
|
|
||||||
love::sound::Decoder * decoder = luax_checktype<love::sound::Decoder>(L, 1, "Decoder", SOUND_DECODER_T);
|
|
||||||
Music * t = instance->newMusic(decoder);
|
|
||||||
luax_newtype(L, "Music", AUDIO_MUSIC_T, (void*)t);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_newSource(lua_State * L)
|
|
||||||
{
|
{
|
||||||
Source * t = 0;
|
Source * t = 0;
|
||||||
|
|
||||||
if(luax_istype(L, 1, AUDIO_SOUND_T))
|
if(luax_istype(L, 1, SOUND_SOUND_DATA_T))
|
||||||
{
|
t = instance->newSource(luax_totype<love::sound::SoundData>(L, 1, "SoundData", SOUND_SOUND_DATA_T));
|
||||||
Sound * s = luax_checksound(L, 1);
|
else if(luax_istype(L, 1, SOUND_DECODER_T))
|
||||||
t = instance->newSource(s);
|
t = instance->newSource(luax_totype<love::sound::Decoder>(L, 1, "Decoder", SOUND_DECODER_T));
|
||||||
}
|
|
||||||
else if(luax_istype(L, 1, AUDIO_MUSIC_T))
|
|
||||||
{
|
|
||||||
Music * m = luax_checkmusic(L, 1);
|
|
||||||
t = instance->newSource(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!t)
|
if(t)
|
||||||
|
{
|
||||||
|
luax_newtype(L, "Source", AUDIO_SOURCE_T, (void*)t);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
return luaL_error(L, "No matching overload");
|
return luaL_error(L, "No matching overload");
|
||||||
|
|
||||||
luax_newtype(L, "Source", AUDIO_SOURCE_T, (void*)t);
|
return 0;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_play(lua_State * L)
|
int w_play(lua_State * L)
|
||||||
{
|
{
|
||||||
int argn = lua_gettop(L);
|
Source * s = luax_checksource(L, 1);
|
||||||
|
instance->play(s);
|
||||||
if(luax_istype(L, 1, AUDIO_SOUND_T))
|
return 0;
|
||||||
{
|
|
||||||
Sound * s = luax_checksound(L, 1);
|
|
||||||
instance->play(s);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if(luax_istype(L, 1, AUDIO_MUSIC_T))
|
|
||||||
{
|
|
||||||
Music * m = luax_checkmusic(L, 1);
|
|
||||||
instance->play(m);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if(luax_istype(L, 1, AUDIO_SOURCE_T))
|
|
||||||
{
|
|
||||||
Source * s = luax_checksource(L, 1);
|
|
||||||
instance->play(s);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return luaL_error(L, "No matching overload");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_stop(lua_State * L)
|
int w_stop(lua_State * L)
|
||||||
@@ -252,9 +204,7 @@ namespace audio
|
|||||||
// List of functions to wrap.
|
// List of functions to wrap.
|
||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
{ "getNumSources", w_getNumSources },
|
{ "getNumSources", w_getNumSources },
|
||||||
{ "newSound", w_newSound },
|
{ "newSource1", w_newSource1 },
|
||||||
{ "newMusic", w_newMusic },
|
|
||||||
{ "newSource", w_newSource },
|
|
||||||
{ "play", w_play },
|
{ "play", w_play },
|
||||||
{ "stop", w_stop },
|
{ "stop", w_stop },
|
||||||
{ "pause", w_pause },
|
{ "pause", w_pause },
|
||||||
@@ -273,8 +223,6 @@ namespace audio
|
|||||||
|
|
||||||
static const lua_CFunction types[] = {
|
static const lua_CFunction types[] = {
|
||||||
luaopen_source,
|
luaopen_source,
|
||||||
luaopen_music,
|
|
||||||
luaopen_sound,
|
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -316,7 +264,12 @@ namespace audio
|
|||||||
w.functions = functions;
|
w.functions = functions;
|
||||||
w.types = types;
|
w.types = types;
|
||||||
|
|
||||||
return luax_register_module(L, w);
|
luax_register_module(L, w);
|
||||||
|
|
||||||
|
if (luaL_loadbuffer(L, (const char *)audio_lua, sizeof(audio_lua), "audio.lua") == 0)
|
||||||
|
lua_call(L, 0, 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // audio
|
} // audio
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
#define LOVE_AUDIO_WRAP_AUDIO_H
|
#define LOVE_AUDIO_WRAP_AUDIO_H
|
||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
|
#include <common/config.h>
|
||||||
|
#include <common/runtime.h>
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
#include "wrap_Sound.h"
|
|
||||||
#include "wrap_Music.h"
|
|
||||||
#include "wrap_Source.h"
|
#include "wrap_Source.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -32,9 +32,7 @@ namespace love
|
|||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
int w_getNumSources(lua_State * L);
|
int w_getNumSources(lua_State * L);
|
||||||
int w_newSound(lua_State * L);
|
int w_newSource1(lua_State * L);
|
||||||
int w_newMusic(lua_State * L);
|
|
||||||
int w_newSource(lua_State * L);
|
|
||||||
int w_play(lua_State * L);
|
int w_play(lua_State * L);
|
||||||
int w_stop(lua_State * L);
|
int w_stop(lua_State * L);
|
||||||
int w_pause(lua_State * L);
|
int w_pause(lua_State * L);
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "wrap_Music.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
Music * luax_checkmusic(lua_State * L, int idx)
|
|
||||||
{
|
|
||||||
return luax_checktype<Music>(L, idx, "Music", AUDIO_MUSIC_T);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const luaL_Reg functions[] = {
|
|
||||||
{ 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
int luaopen_music(lua_State * L)
|
|
||||||
{
|
|
||||||
return luax_register_type(L, "Music", functions);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_WRAP_MUSIC_H
|
|
||||||
#define LOVE_AUDIO_WRAP_MUSIC_H
|
|
||||||
|
|
||||||
#include <common/runtime.h>
|
|
||||||
#include "Music.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
Music * luax_checkmusic(lua_State * L, int idx);
|
|
||||||
int luaopen_music(lua_State * L);
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_WRAP_MUSIC_H
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#include "wrap_Sound.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
Sound * luax_checksound(lua_State * L, int idx)
|
|
||||||
{
|
|
||||||
return luax_checktype<Sound>(L, idx, "Sound", AUDIO_SOUND_T);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const luaL_Reg functions[] = {
|
|
||||||
{ 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
int luaopen_sound(lua_State * L)
|
|
||||||
{
|
|
||||||
return luax_register_type(L, "Sound", functions);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2006-2009 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 source 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 source distribution.
|
|
||||||
**/
|
|
||||||
|
|
||||||
#ifndef LOVE_AUDIO_WRAP_SOUND_H
|
|
||||||
#define LOVE_AUDIO_WRAP_SOUND_H
|
|
||||||
|
|
||||||
#include <common/runtime.h>
|
|
||||||
#include "Sound.h"
|
|
||||||
|
|
||||||
namespace love
|
|
||||||
{
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
Sound * luax_checksound(lua_State * L, int idx);
|
|
||||||
int luaopen_sound(lua_State * L);
|
|
||||||
|
|
||||||
} // audio
|
|
||||||
} // love
|
|
||||||
|
|
||||||
#endif // LOVE_AUDIO_WRAP_SOUND_H
|
|
||||||
@@ -139,6 +139,13 @@ namespace audio
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Source_isStopped(lua_State * L)
|
||||||
|
{
|
||||||
|
Source * t = luax_checksource(L, 1);
|
||||||
|
luax_pushboolean(L, t->isStopped());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg functions[] = {
|
static const luaL_Reg functions[] = {
|
||||||
{ "setPitch", w_Source_setPitch },
|
{ "setPitch", w_Source_setPitch },
|
||||||
{ "getPitch", w_Source_getPitch },
|
{ "getPitch", w_Source_getPitch },
|
||||||
@@ -146,6 +153,7 @@ namespace audio
|
|||||||
{ "getVolume", w_Source_getVolume },
|
{ "getVolume", w_Source_getVolume },
|
||||||
{ "setLooping", w_Source_setLooping },
|
{ "setLooping", w_Source_setLooping },
|
||||||
{ "isLooping", w_Source_isLooping },
|
{ "isLooping", w_Source_isLooping },
|
||||||
|
{ "isStopped", w_Source_isStopped },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ namespace audio
|
|||||||
int w_Source_getDirection(lua_State * L);
|
int w_Source_getDirection(lua_State * L);
|
||||||
int w_Source_setLooping(lua_State * L);
|
int w_Source_setLooping(lua_State * L);
|
||||||
int w_Source_isLooping(lua_State * L);
|
int w_Source_isLooping(lua_State * L);
|
||||||
|
int w_Source_isStopped(lua_State * L);
|
||||||
int luaopen_source(lua_State * L);
|
int luaopen_source(lua_State * L);
|
||||||
|
|
||||||
} // audio
|
} // audio
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace sound
|
|||||||
* Indicates how many bytes of raw data should be generated at each
|
* Indicates how many bytes of raw data should be generated at each
|
||||||
* call to Decode.
|
* call to Decode.
|
||||||
**/
|
**/
|
||||||
static const int DEFAULT_BUFFER_SIZE = 1024;
|
static const int DEFAULT_BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates the quality of the sound.
|
* Indicates the quality of the sound.
|
||||||
@@ -55,7 +55,7 @@ namespace sound
|
|||||||
/**
|
/**
|
||||||
* 16 bit audio is the default.
|
* 16 bit audio is the default.
|
||||||
**/
|
**/
|
||||||
static const int DEFAULT_T = 16;
|
static const int DEFAULT_BITS = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a deep of itself. The sound stream can (and should) be
|
* Creates a deep of itself. The sound stream can (and should) be
|
||||||
|
|||||||
@@ -60,7 +60,11 @@ namespace lullaby
|
|||||||
bool ModPlugDecoder::accepts(const std::string & ext)
|
bool ModPlugDecoder::accepts(const std::string & ext)
|
||||||
{
|
{
|
||||||
static const std::string supported[] = {
|
static const std::string supported[] = {
|
||||||
"it", "xm", "mod", "wav", ""
|
"699", "abc", "amf", "ams", "dbm", "dmf",
|
||||||
|
"dsm", "far", "it", "j2b", "mdl", "med",
|
||||||
|
"mid", "mod", "mt2", "mtm", "okt", "pat",
|
||||||
|
"psm", "s3m", "stm", "ult", "umx", "wav",
|
||||||
|
"xm", ""
|
||||||
};
|
};
|
||||||
|
|
||||||
for(int i = 0; !(supported[i].empty()); i++)
|
for(int i = 0; !(supported[i].empty()); i++)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace lullaby
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ModPlugDecoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
ModPlugDecoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
||||||
~ModPlugDecoder();
|
virtual ~ModPlugDecoder();
|
||||||
|
|
||||||
static bool accepts(const std::string & ext);
|
static bool accepts(const std::string & ext);
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,12 @@ namespace lullaby
|
|||||||
bool Mpg123Decoder::inited = false;
|
bool Mpg123Decoder::inited = false;
|
||||||
|
|
||||||
Mpg123Decoder::Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate)
|
Mpg123Decoder::Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate)
|
||||||
: Decoder(data, ext, bufferSize, sampleRate), handle(0), islooping(false)
|
: Decoder(data, ext, bufferSize, sampleRate), handle(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
data_size = data->getSize();
|
||||||
|
data_offset = 0;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(!inited)
|
if(!inited)
|
||||||
@@ -57,21 +60,11 @@ namespace lullaby
|
|||||||
ret = mpg123_format(handle, sampleRate, MPG123_STEREO, MPG123_ENC_SIGNED_16);
|
ret = mpg123_format(handle, sampleRate, MPG123_STEREO, MPG123_ENC_SIGNED_16);
|
||||||
if (ret != MPG123_OK)
|
if (ret != MPG123_OK)
|
||||||
throw love::Exception("Could not set output format.");
|
throw love::Exception("Could not set output format.");
|
||||||
size_t numbytes = 0;
|
|
||||||
ret = mpg123_decode(handle, (unsigned char*)data->getData(), data->getSize(), NULL, 0, &numbytes);
|
|
||||||
|
|
||||||
if(ret == MPG123_NEW_FORMAT)
|
ret = feed(16384);
|
||||||
{
|
|
||||||
long rate;
|
|
||||||
int channels;
|
|
||||||
int encoding;
|
|
||||||
mpg123_getformat(handle, &rate, &channels, &encoding);
|
|
||||||
}
|
|
||||||
else if(ret != 0)
|
|
||||||
{
|
|
||||||
throw love::Exception(mpg123_strerror(handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (ret != MPG123_OK && ret != MPG123_DONE)
|
||||||
|
throw love::Exception("Could not feed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Mpg123Decoder::~Mpg123Decoder()
|
Mpg123Decoder::~Mpg123Decoder()
|
||||||
@@ -108,26 +101,51 @@ namespace lullaby
|
|||||||
|
|
||||||
int Mpg123Decoder::decode()
|
int Mpg123Decoder::decode()
|
||||||
{
|
{
|
||||||
size_t numbytes;
|
int size = 0;
|
||||||
int r = mpg123_read(handle, (unsigned char*) buffer, bufferSize, &numbytes);
|
bool done = false;
|
||||||
|
|
||||||
if (r == MPG123_DONE || r != MPG123_OK)
|
while(size < bufferSize && !done && !eof)
|
||||||
{
|
{
|
||||||
if ( r == MPG123_NEED_MORE && islooping )
|
size_t numbytes = 0;
|
||||||
{
|
|
||||||
islooping = false;
|
int r = mpg123_read(handle, (unsigned char*) buffer + size, bufferSize - size, &numbytes);
|
||||||
size_t numbytes = 0;
|
|
||||||
mpg123_decode(handle, (unsigned char*) data->getData(), data->getSize(), (unsigned char*) buffer, bufferSize, &numbytes);
|
switch(r)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
case MPG123_NEW_FORMAT:
|
||||||
|
continue;
|
||||||
|
case MPG123_NEED_MORE:
|
||||||
|
{
|
||||||
|
int v = feed(8192);
|
||||||
|
|
||||||
|
switch(v)
|
||||||
|
{
|
||||||
|
case MPG123_OK:
|
||||||
|
continue;
|
||||||
|
case MPG123_DONE:
|
||||||
|
if(numbytes == 0)
|
||||||
|
eof = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case MPG123_OK:
|
||||||
|
size += numbytes;
|
||||||
|
continue;
|
||||||
|
case MPG123_DONE:
|
||||||
|
// Apparently, mpg123_read does not return MPG123_DONE, but
|
||||||
|
// let's keep it here anyway.
|
||||||
eof = true;
|
eof = true;
|
||||||
numbytes = 0;
|
default:
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
return numbytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mpg123Decoder::seek(float s)
|
bool Mpg123Decoder::seek(float s)
|
||||||
@@ -139,11 +157,16 @@ namespace lullaby
|
|||||||
|
|
||||||
bool Mpg123Decoder::rewind()
|
bool Mpg123Decoder::rewind()
|
||||||
{
|
{
|
||||||
if(mpg123_seek(handle, 0, SEEK_SET) >= 0)
|
|
||||||
return false;
|
|
||||||
islooping = true;
|
|
||||||
eof = false;
|
eof = false;
|
||||||
return true;
|
off_t offset;
|
||||||
|
|
||||||
|
if(mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0)
|
||||||
|
{
|
||||||
|
data_offset = offset;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mpg123Decoder::isSeekable()
|
bool Mpg123Decoder::isSeekable()
|
||||||
@@ -161,6 +184,22 @@ namespace lullaby
|
|||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Mpg123Decoder::feed(int bytes)
|
||||||
|
{
|
||||||
|
int remaining = data_size - data_offset;
|
||||||
|
|
||||||
|
if(remaining <= 0)
|
||||||
|
return MPG123_DONE;
|
||||||
|
|
||||||
|
int feed_bytes = remaining < bytes ? remaining : bytes;
|
||||||
|
|
||||||
|
int r = mpg123_feed(handle, (unsigned char*)data->getData() + data_offset, feed_bytes);
|
||||||
|
|
||||||
|
if(r == MPG123_OK || r == MPG123_DONE)
|
||||||
|
data_offset += feed_bytes;
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
} // lullaby
|
} // lullaby
|
||||||
} // sound
|
} // sound
|
||||||
|
|||||||
@@ -43,13 +43,15 @@ namespace lullaby
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
mpg123_handle * handle;
|
mpg123_handle * handle;
|
||||||
bool islooping;
|
|
||||||
static bool inited;
|
static bool inited;
|
||||||
|
|
||||||
|
int data_offset;
|
||||||
|
int data_size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
||||||
~Mpg123Decoder();
|
virtual ~Mpg123Decoder();
|
||||||
|
|
||||||
static bool accepts(const std::string & ext);
|
static bool accepts(const std::string & ext);
|
||||||
static void quit();
|
static void quit();
|
||||||
@@ -62,6 +64,10 @@ namespace lullaby
|
|||||||
int getChannels() const;
|
int getChannels() const;
|
||||||
int getBits() const;
|
int getBits() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int feed(int bytes);
|
||||||
|
|
||||||
}; // Decoder
|
}; // Decoder
|
||||||
|
|
||||||
} // lullaby
|
} // lullaby
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ namespace lullaby
|
|||||||
// Find a suitable decoder here, and return it.
|
// Find a suitable decoder here, and return it.
|
||||||
if(ModPlugDecoder::accepts(ext))
|
if(ModPlugDecoder::accepts(ext))
|
||||||
decoder = new ModPlugDecoder(data, ext, bufferSize, sampleRate);
|
decoder = new ModPlugDecoder(data, ext, bufferSize, sampleRate);
|
||||||
else if (Mpg123Decoder::accepts(ext))
|
else if(Mpg123Decoder::accepts(ext))
|
||||||
decoder = new Mpg123Decoder(data, ext, bufferSize, sampleRate);
|
decoder = new Mpg123Decoder(data, ext, bufferSize, sampleRate);
|
||||||
else if (VorbisDecoder::accepts(ext))
|
else if(VorbisDecoder::accepts(ext))
|
||||||
decoder = new VorbisDecoder(data, ext, bufferSize, sampleRate);
|
decoder = new VorbisDecoder(data, ext, bufferSize, sampleRate);
|
||||||
/*else if (FLACDecoder::accepts(ext))
|
/*else if (FLACDecoder::accepts(ext))
|
||||||
decoder = new FLACDecoder(data, ext, bufferSize, sampleRate);*/
|
decoder = new FLACDecoder(data, ext, bufferSize, sampleRate);*/
|
||||||
|
|||||||
@@ -182,42 +182,20 @@ namespace lullaby
|
|||||||
|
|
||||||
int VorbisDecoder::decode()
|
int VorbisDecoder::decode()
|
||||||
{
|
{
|
||||||
int bits = this->getBits();
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
int section;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
if(bits == 16)
|
|
||||||
bits = 2;
|
|
||||||
else
|
|
||||||
bits = 1;
|
|
||||||
|
|
||||||
while(size < bufferSize)
|
while(size < bufferSize)
|
||||||
{
|
{
|
||||||
result = ov_read(&handle, (char*) buffer + size, bufferSize - size, endian, bits, 1, §ion);
|
int result = ov_read(&handle, (char*) buffer + size, bufferSize - size, endian, (getBits() == 16 ? 2 : 1), 1, 0);
|
||||||
|
|
||||||
if(result > 0)
|
if(result == OV_HOLE)
|
||||||
size += result;
|
continue;
|
||||||
else if(result < 0)
|
else if(result <= OV_EREAD)
|
||||||
{
|
return -1;
|
||||||
switch(result)
|
else if(result == 0)
|
||||||
{
|
|
||||||
case OV_EREAD:
|
|
||||||
throw love::Exception("Vorbis read: Read from media");
|
|
||||||
case OV_ENOTVORBIS:
|
|
||||||
throw love::Exception("Vorbis read: Not Vorbis data");
|
|
||||||
case OV_EVERSION:
|
|
||||||
throw love::Exception("Vorbis read: Vorbis version mismatch");
|
|
||||||
case OV_EBADHEADER:
|
|
||||||
throw love::Exception("Vorbis read: Invalid Vorbis header");
|
|
||||||
case OV_EFAULT:
|
|
||||||
throw love::Exception("Vorbis read: Internal logic fault (bug or heap/stack corruption)");
|
|
||||||
default:
|
|
||||||
throw love::Exception("Vorbis read: Unknown error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
|
else if(result > 0)
|
||||||
|
size += result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(oggFile.dataSize - oggFile.dataRead == 0)
|
if(oggFile.dataSize - oggFile.dataRead == 0)
|
||||||
@@ -256,7 +234,8 @@ namespace lullaby
|
|||||||
bool VorbisDecoder::rewind()
|
bool VorbisDecoder::rewind()
|
||||||
{
|
{
|
||||||
eof = false;
|
eof = false;
|
||||||
return this->seek(0);
|
ov_pcm_seek(&handle, 0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VorbisDecoder::isSeekable()
|
bool VorbisDecoder::isSeekable()
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace lullaby
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
VorbisDecoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
VorbisDecoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
||||||
~VorbisDecoder();
|
virtual ~VorbisDecoder();
|
||||||
|
|
||||||
static bool accepts(const std::string & ext);
|
static bool accepts(const std::string & ext);
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace sound
|
|||||||
{
|
{
|
||||||
int samples = luaL_checkint(L, 1);
|
int samples = luaL_checkint(L, 1);
|
||||||
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
|
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
|
||||||
int bits = luaL_optint(L, 3, Decoder::DEFAULT_T);
|
int bits = luaL_optint(L, 3, Decoder::DEFAULT_BITS);
|
||||||
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
|
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
--[[
|
||||||
|
Copyright (c) 2006-2010 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 source 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 source distribution.
|
||||||
|
--]]
|
||||||
|
|
||||||
|
function love.audio.newSource(a, b)
|
||||||
|
if type(a) == "string" then
|
||||||
|
a = love.filesystem.newFile(a)
|
||||||
|
end
|
||||||
|
if type(a) == "userdata" then
|
||||||
|
if a:typeOf("File") then
|
||||||
|
a = love.sound.newDecoder(a)
|
||||||
|
end
|
||||||
|
|
||||||
|
if a:typeOf("Decoder") then
|
||||||
|
if b == "static" then
|
||||||
|
a = love.sound.newSoundData(a)
|
||||||
|
end
|
||||||
|
return love.audio.newSource1(a)
|
||||||
|
end
|
||||||
|
if a:typeOf("SoundData") then
|
||||||
|
return love.audio.newSource1(a)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error("No matching overload")
|
||||||
|
end
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2006-2010 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 source 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 source distribution.
|
||||||
|
**/
|
||||||
|
|
||||||
|
namespace love
|
||||||
|
{
|
||||||
|
|
||||||
|
// [audio.lua]
|
||||||
|
const unsigned char audio_lua[] =
|
||||||
|
{
|
||||||
|
0x1B,0x4C,0x75,0x61,0x51,0x00,0x01,0x04,0x04,0x04,0x08,0x00,0x0B,0x00,0x00,
|
||||||
|
0x00,0x40,0x61,0x75,0x64,0x69,0x6F,0x2E,0x6C,0x75,0x61,0x00,0x00,0x00,0x00,
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x05,0x00,0x00,0x00,0x05,0x00,
|
||||||
|
0x00,0x00,0x06,0x40,0x40,0x00,0x64,0x00,0x00,0x00,0x09,0x40,0x00,0x81,0x1E,
|
||||||
|
0x00,0x80,0x00,0x03,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x6C,0x6F,0x76,
|
||||||
|
0x65,0x00,0x04,0x06,0x00,0x00,0x00,0x61,0x75,0x64,0x69,0x6F,0x00,0x04,0x0A,
|
||||||
|
0x00,0x00,0x00,0x6E,0x65,0x77,0x53,0x6F,0x75,0x72,0x63,0x65,0x00,0x01,0x00,
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x00,
|
||||||
|
0x02,0x00,0x05,0x3D,0x00,0x00,0x00,0x85,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,
|
||||||
|
0x9C,0x80,0x00,0x01,0x17,0x40,0x40,0x01,0x16,0x40,0x01,0x80,0x85,0x80,0x00,
|
||||||
|
0x00,0x86,0xC0,0x40,0x01,0x86,0x00,0x41,0x01,0xC0,0x00,0x00,0x00,0x9C,0x80,
|
||||||
|
0x00,0x01,0x00,0x00,0x00,0x01,0x85,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x9C,
|
||||||
|
0x80,0x00,0x01,0x17,0x40,0x41,0x01,0x16,0x00,0x0A,0x80,0x8B,0x80,0x41,0x00,
|
||||||
|
0x01,0xC1,0x01,0x00,0x9C,0x80,0x80,0x01,0x9A,0x00,0x00,0x00,0x16,0x40,0x01,
|
||||||
|
0x80,0x85,0x80,0x00,0x00,0x86,0x00,0x42,0x01,0x86,0x40,0x42,0x01,0xC0,0x00,
|
||||||
|
0x00,0x00,0x9C,0x80,0x00,0x01,0x00,0x00,0x00,0x01,0x8B,0x80,0x41,0x00,0x01,
|
||||||
|
0x81,0x02,0x00,0x9C,0x80,0x80,0x01,0x9A,0x00,0x00,0x00,0x16,0x40,0x03,0x80,
|
||||||
|
0x17,0xC0,0xC2,0x00,0x16,0x40,0x01,0x80,0x85,0x80,0x00,0x00,0x86,0x00,0x42,
|
||||||
|
0x01,0x86,0x00,0x43,0x01,0xC0,0x00,0x00,0x00,0x9C,0x80,0x00,0x01,0x00,0x00,
|
||||||
|
0x00,0x01,0x85,0x80,0x00,0x00,0x86,0x40,0x43,0x01,0x86,0x80,0x43,0x01,0xC0,
|
||||||
|
0x00,0x00,0x00,0x9D,0x00,0x00,0x01,0x9E,0x00,0x00,0x00,0x8B,0x80,0x41,0x00,
|
||||||
|
0x01,0xC1,0x03,0x00,0x9C,0x80,0x80,0x01,0x9A,0x00,0x00,0x00,0x16,0x40,0x01,
|
||||||
|
0x80,0x85,0x80,0x00,0x00,0x86,0x40,0x43,0x01,0x86,0x80,0x43,0x01,0xC0,0x00,
|
||||||
|
0x00,0x00,0x9D,0x00,0x00,0x01,0x9E,0x00,0x00,0x00,0x85,0x00,0x04,0x00,0xC1,
|
||||||
|
0x40,0x04,0x00,0x9C,0x40,0x00,0x01,0x1E,0x00,0x80,0x00,0x12,0x00,0x00,0x00,
|
||||||
|
0x04,0x05,0x00,0x00,0x00,0x74,0x79,0x70,0x65,0x00,0x04,0x07,0x00,0x00,0x00,
|
||||||
|
0x73,0x74,0x72,0x69,0x6E,0x67,0x00,0x04,0x05,0x00,0x00,0x00,0x6C,0x6F,0x76,
|
||||||
|
0x65,0x00,0x04,0x0B,0x00,0x00,0x00,0x66,0x69,0x6C,0x65,0x73,0x79,0x73,0x74,
|
||||||
|
0x65,0x6D,0x00,0x04,0x08,0x00,0x00,0x00,0x6E,0x65,0x77,0x46,0x69,0x6C,0x65,
|
||||||
|
0x00,0x04,0x09,0x00,0x00,0x00,0x75,0x73,0x65,0x72,0x64,0x61,0x74,0x61,0x00,
|
||||||
|
0x04,0x07,0x00,0x00,0x00,0x74,0x79,0x70,0x65,0x4F,0x66,0x00,0x04,0x05,0x00,
|
||||||
|
0x00,0x00,0x46,0x69,0x6C,0x65,0x00,0x04,0x06,0x00,0x00,0x00,0x73,0x6F,0x75,
|
||||||
|
0x6E,0x64,0x00,0x04,0x0B,0x00,0x00,0x00,0x6E,0x65,0x77,0x44,0x65,0x63,0x6F,
|
||||||
|
0x64,0x65,0x72,0x00,0x04,0x08,0x00,0x00,0x00,0x44,0x65,0x63,0x6F,0x64,0x65,
|
||||||
|
0x72,0x00,0x04,0x07,0x00,0x00,0x00,0x73,0x74,0x61,0x74,0x69,0x63,0x00,0x04,
|
||||||
|
0x0D,0x00,0x00,0x00,0x6E,0x65,0x77,0x53,0x6F,0x75,0x6E,0x64,0x44,0x61,0x74,
|
||||||
|
0x61,0x00,0x04,0x06,0x00,0x00,0x00,0x61,0x75,0x64,0x69,0x6F,0x00,0x04,0x0B,
|
||||||
|
0x00,0x00,0x00,0x6E,0x65,0x77,0x53,0x6F,0x75,0x72,0x63,0x65,0x31,0x00,0x04,
|
||||||
|
0x0A,0x00,0x00,0x00,0x53,0x6F,0x75,0x6E,0x64,0x44,0x61,0x74,0x61,0x00,0x04,
|
||||||
|
0x06,0x00,0x00,0x00,0x65,0x72,0x72,0x6F,0x72,0x00,0x04,0x15,0x00,0x00,0x00,
|
||||||
|
0x4E,0x6F,0x20,0x6D,0x61,0x74,0x63,0x68,0x69,0x6E,0x67,0x20,0x6F,0x76,0x65,
|
||||||
|
0x72,0x6C,0x6F,0x61,0x64,0x00,0x00,0x00,0x00,0x00,0x3D,0x00,0x00,0x00,0x16,
|
||||||
|
0x00,0x00,0x00,0x16,0x00,0x00,0x00,0x16,0x00,0x00,0x00,0x16,0x00,0x00,0x00,
|
||||||
|
0x16,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x17,0x00,0x00,
|
||||||
|
0x00,0x17,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x19,0x00,
|
||||||
|
0x00,0x00,0x19,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x19,
|
||||||
|
0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,
|
||||||
|
0x1A,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1B,0x00,0x00,0x00,0x1B,0x00,0x00,
|
||||||
|
0x00,0x1B,0x00,0x00,0x00,0x1B,0x00,0x00,0x00,0x1B,0x00,0x00,0x00,0x1B,0x00,
|
||||||
|
0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,
|
||||||
|
0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,
|
||||||
|
0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,
|
||||||
|
0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x22,0x00,
|
||||||
|
0x00,0x00,0x22,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x22,
|
||||||
|
0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x24,0x00,0x00,0x00,
|
||||||
|
0x24,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x25,0x00,0x00,
|
||||||
|
0x00,0x25,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x25,0x00,
|
||||||
|
0x00,0x00,0x28,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x29,
|
||||||
|
0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x61,0x00,0x00,0x00,
|
||||||
|
0x00,0x00,0x3C,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x62,0x00,0x00,0x00,0x00,
|
||||||
|
0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x15,0x00,
|
||||||
|
0x00,0x00,0x15,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x29,
|
||||||
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||||
|
};
|
||||||
|
// [/audio.lua]
|
||||||
|
|
||||||
|
} // love
|
||||||
@@ -1,3 +1,22 @@
|
|||||||
|
--[[
|
||||||
|
Copyright (c) 2006-2010 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 source 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 source distribution.
|
||||||
|
--]]
|
||||||
|
|
||||||
-- Make sure love table exists.
|
-- Make sure love table exists.
|
||||||
if not love then love = {} end
|
if not love then love = {} end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
--[[
|
--[[
|
||||||
Copyright (c) 2006-2009 LOVE Development Team
|
Copyright (c) 2006-2010 LOVE Development Team
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
Reference in New Issue
Block a user