aboutsummaryrefslogtreecommitdiff
path: root/src/libjin-lua/modules/audio/l_audio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin-lua/modules/audio/l_audio.cpp')
-rw-r--r--src/libjin-lua/modules/audio/l_audio.cpp216
1 files changed, 108 insertions, 108 deletions
diff --git a/src/libjin-lua/modules/audio/l_audio.cpp b/src/libjin-lua/modules/audio/l_audio.cpp
index 9ad4228..2952d2f 100644
--- a/src/libjin-lua/modules/audio/l_audio.cpp
+++ b/src/libjin-lua/modules/audio/l_audio.cpp
@@ -9,124 +9,124 @@ using namespace JinEngine::Filesystem;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- typedef SDLAudio Audio;
- typedef SDLSource Source;
+ typedef SDLAudio Audio;
+ typedef SDLSource Source;
- struct
- {
- bool initialized = false;
- } context;
+ struct
+ {
+ bool initialized = false;
+ } context;
- LUA_IMPLEMENT int l_init(lua_State* L)
- {
- if (context.initialized)
- {
- // Already initialized.
- luax_pushboolean(L, true);
- return 1;
- }
- Audio::Setting setting;
- setting.samplerate = 44100;
- setting.samples = 44100;
- Audio* audio = Audio::get();
- context.initialized = audio->start(&setting);
- if (!context.initialized)
- {
- luax_error(L, "could not init audio");
- luax_pushboolean(L, false);
- return 1;
- }
- luax_pushboolean(L, true);
- return 1;
- }
+ LUA_IMPLEMENT int l_init(lua_State* L)
+ {
+ if (context.initialized)
+ {
+ // Already initialized.
+ luax_pushboolean(L, true);
+ return 1;
+ }
+ Audio::Setting setting;
+ setting.samplerate = 44100;
+ setting.samples = 44100;
+ Audio* audio = Audio::get();
+ context.initialized = audio->start(&setting);
+ if (!context.initialized)
+ {
+ luax_error(L, "could not init audio");
+ luax_pushboolean(L, false);
+ return 1;
+ }
+ luax_pushboolean(L, true);
+ return 1;
+ }
- LUA_IMPLEMENT int l_play(lua_State* L)
- {
- Audio::get()->play();
- return 0;
- }
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ Audio::get()->play();
+ return 0;
+ }
- LUA_IMPLEMENT int l_stop(lua_State* L)
- {
- Audio::get()->stop();
- return 0;
- }
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Audio::get()->stop();
+ return 0;
+ }
- LUA_IMPLEMENT int l_pause(lua_State* L)
- {
- Audio::get()->pause();
- return 0;
- }
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ Audio::get()->pause();
+ return 0;
+ }
- LUA_IMPLEMENT int l_resume(lua_State* L)
- {
- Audio::get()->resume();
- return 0;
- }
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ Audio::get()->resume();
+ return 0;
+ }
- LUA_IMPLEMENT int l_setVolume(lua_State* L)
- {
- float volume = luax_checknumber(L, 1);
- Audio::get()->setVolume(volume);
- return 0;
- }
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ float volume = luax_checknumber(L, 1);
+ Audio::get()->setVolume(volume);
+ return 0;
+ }
- LUA_IMPLEMENT int l_newSource(lua_State* L)
- {
- AssetDatabase* fs = AssetDatabase::get();
- const char* f = luax_checkstring(L, 1);
- Buffer b;
- try
- {
- if (!fs->exists(f))
- throw Exception("No such source file %s.", f);
- fs->read(f, b);
- }
- catch (Exception& e)
- {
- luax_errorf(L, "Failed to read source file %s", f);
- luax_pushnil(L);
- return 1;
- }
- Source* src = new SDLSource((void*)&b, b.size());
- if (src == nullptr)
- {
- luax_errorf(L, "Failed to decode source file %s", f);
- luax_pushnil(L);
- return 1;
- }
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Source, new Shared(src));
- return 1;
- }
-
- LUA_IMPLEMENT int l_destroy(lua_State* L)
- {
- Audio* audio = Audio::get();
- audio->quit();
- return 0;
- }
+ LUA_IMPLEMENT int l_newSource(lua_State* L)
+ {
+ AssetDatabase* fs = AssetDatabase::get();
+ const char* f = luax_checkstring(L, 1);
+ Buffer b;
+ try
+ {
+ if (!fs->exists(f))
+ throw Exception("No such source file %s.", f);
+ fs->read(f, b);
+ }
+ catch (Exception& e)
+ {
+ luax_errorf(L, "Failed to read source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Source* src = new SDLSource((void*)&b, b.size());
+ if (src == nullptr)
+ {
+ luax_errorf(L, "Failed to decode source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Source, new Shared(src));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
+ {
+ Audio* audio = Audio::get();
+ audio->quit();
+ return 0;
+ }
- LUA_EXPORT int luaopen_audio(lua_State* L)
- {
- luaopen_Source(L);
+ LUA_EXPORT int luaopen_audio(lua_State* L)
+ {
+ luaopen_Source(L);
- luaL_Reg methods[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- return 1;
- }
+ luaL_Reg methods[] = {
+ { "init", l_init },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "setVolume", l_setVolume },
+ { "newSource", l_newSource },
+ { "destroy", l_destroy },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file