aboutsummaryrefslogtreecommitdiff
path: root/src/lua/audio/luaopen_audio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/audio/luaopen_audio.cpp')
-rw-r--r--src/lua/audio/luaopen_audio.cpp73
1 files changed, 69 insertions, 4 deletions
diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/audio/luaopen_audio.cpp
index 9a6bade..4f4f955 100644
--- a/src/lua/audio/luaopen_audio.cpp
+++ b/src/lua/audio/luaopen_audio.cpp
@@ -1,15 +1,19 @@
#include "lua/luax.h"
+#include "../luaopen_types.h"
#include "libjin/jin.h"
namespace jin
{
namespace lua
{
+ using namespace jin::filesystem;
using namespace jin::audio;
static int l_init(lua_State* L)
{
SDLAudio::Setting setting;
+ setting.samplerate = 44100;
+ setting.samples = 44100;
if (! SDLAudio::get()->init(&setting))
{
luax_error(L, "could not init audio");
@@ -19,21 +23,82 @@ namespace lua
luax_pushboolean(L, true);
return 1;
}
-
+
+ static int l_play(lua_State* L)
+ {
+ SDLAudio::get()->play();
+ return 0;
+ }
+
+ static int l_stop(lua_State* L)
+ {
+ SDLAudio::get()->stop();
+ return 0;
+ }
+
+ static int l_pause(lua_State* L)
+ {
+ SDLAudio::get()->pause();
+ return 0;
+ }
+
+ static int l_resume(lua_State* L)
+ {
+ SDLAudio::get()->resume();
+ return 0;
+ }
+
+ static int l_setVolume(lua_State* L)
+ {
+ float volume = luax_checknumber(L, 1);
+ SDLAudio::get()->setVolume(volume);
+ return 0;
+ }
+
static int l_newSound(lua_State* L)
{
-
- return 0;
+ Filesystem* fs = Filesystem::get();
+ const char* f = luax_checkstring(L, 1);
+ if (!fs->exists(f))
+ {
+ printf("Error: no such image %s\n", f);
+ exit(1);
+ }
+ Buffer b;
+ fs->read(f, &b);
+
+ Proxy* proxy = (Proxy*)luax_newinstance(L, TYPE_SOURCE, sizeof(Proxy));
+ SDLSource* src = SDLSource::createSource(b.data, b.size);
+ proxy->bind(src);
+ return 1;
}
- static const luaL_Reg f[] = {
+ static int l_destroy(lua_State* L)
+ {
+ SDLAudio* audio = SDLAudio::get();
+ audio->quit();
+ return 0;
+ }
+
+ static const luaL_Reg f[] = {
{"init", l_init},
+ {"play", l_play },
+ {"stop", l_stop},
+ {"pause", l_pause},
+ {"resume", l_resume},
+ {"setVolume",l_setVolume},
{"Sound", l_newSound},
+ //
+ {"destroy",l_destroy},
{0, 0}
};
+ extern int luaopen_Source(lua_State* L);
+
int luaopen_audio(lua_State* L)
{
+ luaopen_Source(L);
+
luax_newlib(L, f);
return 1;