Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Nov 12, 2024
1 parent 271a7e5 commit 9783a3d
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions Quake/ls_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,24 +285,29 @@ static const sfxcache_t* LS_GetCachedSoundFromUserData(lua_State* state)
return sound ? LS_GetCachedSound(*sound) : nullptr;
}

static int LS_GetSoundSize(const sfxcache_t& cachedsound)
static int LS_value_sound_channels(lua_State* state)
{
return cachedsound.length * cachedsound.width * (cachedsound.stereo + 1);
if (const sfxcache_t* const cachedsound = LS_GetCachedSoundFromUserData(state))
{
lua_pushinteger(state, cachedsound->stereo + 1);
return 1;
}

return 0;
}

static int LS_value_sound_channels(lua_State* state)
static int LS_value_sound_framerate(lua_State* state)
{
if (const sfxcache_t* const cachedsound = LS_GetCachedSoundFromUserData(state))
{
lua_pushinteger(state, cachedsound->stereo);
lua_pushinteger(state, cachedsound->speed);
return 1;
}

return 0;
}


static int LS_value_sound_length(lua_State* state)
static int LS_value_sound_frames(lua_State* state)
{
if (const sfxcache_t* const cachedsound = LS_GetCachedSoundFromUserData(state))
{
Expand All @@ -313,6 +318,17 @@ static int LS_value_sound_length(lua_State* state)
return 0;
}

static int LS_value_sound_loopstart(lua_State* state)
{
if (const sfxcache_t* const cachedsound = LS_GetCachedSoundFromUserData(state))
{
lua_pushinteger(state, cachedsound->loopstart);
return 1;
}

return 0;
}

static int LS_value_sound_name(lua_State* state)
{
if (const sfx_t* const sound = LS_GetSoundFromUserData(state))
Expand All @@ -324,23 +340,28 @@ static int LS_value_sound_name(lua_State* state)
return 0;
}

static int LS_value_sound_size(lua_State* state)
static int LS_value_sound_samplesize(lua_State* state)
{
if (const sfxcache_t* const cachedsound = LS_GetCachedSoundFromUserData(state))
{
const int soundsize = LS_GetSoundSize(*cachedsound);
lua_pushinteger(state, soundsize);
lua_pushinteger(state, cachedsound->width);
return 1;
}

return 0;
}

static int LS_value_sound_speed(lua_State* state)
static int LS_GetSoundSize(const sfxcache_t& cachedsound)
{
return cachedsound.length * cachedsound.width * (cachedsound.stereo + 1);
}

static int LS_value_sound_size(lua_State* state)
{
if (const sfxcache_t* const cachedsound = LS_GetCachedSoundFromUserData(state))
{
lua_pushinteger(state, cachedsound->speed);
const int soundsize = LS_GetSoundSize(*cachedsound);
lua_pushinteger(state, soundsize);
return 1;
}

Expand All @@ -354,7 +375,7 @@ static int LS_value_sound_tostring(lua_State* state)
if (sound)
{
if (const sfxcache_t* const cachedsound = LS_GetCachedSound(*sound))
lua_pushfstring(state, "sound %s (%i bytes)", sound->name, LS_GetSoundSize(*cachedsound));
lua_pushfstring(state, "sound %s (%d bytes)", sound->name, LS_GetSoundSize(*cachedsound));
else
lua_pushfstring(state, "sound %s (not loaded)", sound->name);
}
Expand Down Expand Up @@ -385,10 +406,12 @@ static int LS_global_sounds_index(lua_State* state)
static const luaL_Reg members[] =
{
{ "channels", LS_value_sound_channels },
{ "length", LS_value_sound_length },
{ "framerate", LS_value_sound_framerate },
{ "frames", LS_value_sound_frames },
{ "loopstart", LS_value_sound_loopstart },
{ "name", LS_value_sound_name },
{ "samplesize", LS_value_sound_samplesize },
{ "size", LS_value_sound_size },
{ "speed", LS_value_sound_speed },
{ nullptr, nullptr }
};

Expand Down

0 comments on commit 9783a3d

Please sign in to comment.