volume and panning added

This commit is contained in:
p.kosyh 2011-04-15 08:12:06 +00:00
parent 98849ee488
commit 80fa273aeb
4 changed files with 43 additions and 2 deletions

View file

@ -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},

View file

@ -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)

View file

@ -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

View file

@ -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
}