From 80fa273aebdc30af58cf7199101b85daa36a1678 Mon Sep 17 00:00:00 2001
From: "p.kosyh"
Date: Fri, 15 Apr 2011 08:12:06 +0000
Subject: [PATCH] volume and panning added
---
src/sdl-instead/instead.c | 19 +++++++++++++++++++
src/sdl-instead/sound.c | 9 +++++++++
src/sdl-instead/sound.h | 1 +
stead/sound.lua | 16 ++++++++++++++--
4 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c
index 35b2b4a..31e6d41 100644
--- a/src/sdl-instead/instead.c
+++ b/src/sdl-instead/instead.c
@@ -1248,6 +1248,23 @@ static int luaB_free_sounds(lua_State *L) {
return 0;
}
+static int luaB_panning_sound(lua_State *L) {
+ int chan = luaL_optnumber(L, 1, -1);
+ int left = luaL_optnumber(L, 2, 255);
+ int right = luaL_optnumber(L, 3, 255);
+ snd_panning(chan, left, right);
+ return 0;
+}
+
+static int luaB_volume_sound(lua_State *L) {
+ int vol = luaL_optnumber(L, 1, -1);
+ if (vol != -1)
+ game_change_vol(0, vol);
+ vol = snd_volume_mus(-1);
+ lua_pushnumber(L, vol);
+ return 1;
+}
+
static int luaB_channel_sound(lua_State *L) {
const char *s;
int ch = luaL_optnumber(L, 1, 0);
@@ -1289,6 +1306,8 @@ static const luaL_Reg base_funcs[] = {
{"sound_load", luaB_load_sound},
{"sound_free", luaB_free_sound},
{"sound_channel", luaB_channel_sound},
+ {"sound_panning", luaB_panning_sound},
+ {"sound_volume", luaB_volume_sound},
{"sounds_free", luaB_free_sounds},
{"mouse_pos", luaB_mouse_pos},
diff --git a/src/sdl-instead/sound.c b/src/sdl-instead/sound.c
index 9212f8f..16edf7e 100644
--- a/src/sdl-instead/sound.c
+++ b/src/sdl-instead/sound.c
@@ -234,6 +234,15 @@ int snd_playing(int channel)
return Mix_Playing(channel);
}
+int snd_panning(int channel, int left, int right)
+{
+ if (channel >= MIX_CHANNELS)
+ channel %= MIX_CHANNELS;
+ if (channel < 0)
+ channel = -1;
+ return Mix_SetPanning(channel, left, right);
+}
+
void snd_free_mus(mus_t mus)
{
if (!sound_on)
diff --git a/src/sdl-instead/sound.h b/src/sdl-instead/sound.h
index 20f98c3..a9f6484 100644
--- a/src/sdl-instead/sound.h
+++ b/src/sdl-instead/sound.h
@@ -28,5 +28,6 @@ extern int snd_vol_from_pcn(int v);
extern int snd_vol_to_pcn(int v);
extern int snd_playing(int channel);
extern void snd_pause(int on);
+extern int snd_panning(int channel, int left, int right);
#endif
diff --git a/stead/sound.lua b/stead/sound.lua
index 4d50735..852d222 100644
--- a/stead/sound.lua
+++ b/stead/sound.lua
@@ -2,6 +2,9 @@ stead.sound_load = sound_load
stead.sound_free = sound_free
stead.sounds_free = sounds_free
stead.sound_channel = sound_channel
+stead.sound_volume = sound_volume
+stead.sound_panning = sound_panning
+
sound = {
nam = 'sound';
object_type = true;
@@ -18,8 +21,17 @@ sound = {
stop = function(...)
stead.stop_sound(...);
end;
- channel = function(...)
- return stead.sound_channel(...)
+ playing = function(s,...)
+ if type(s) ~= 'number' then
+ return stead.is_sound()
+ end
+ return stead.sound_channel(s,...)
+ end;
+ pan = function(...)
+ return stead.sound_panning(...)
+ end;
+ vol = function(...)
+ return stead.sound_volume(...)
end
}