Unverified Commit f3468c5d authored by Jake Stine's avatar Jake Stine Committed by GitHub
Browse files

makefile: fix typos that made player build not really do what was intended (#202)



* makefile: fix typos that made player build not really do what was intended.

 * audio: add a guardband to test for mixer memory corruption. Enabled only in debug/tooling builds.

* 2 typo

* Fix for missing sound generation.

(left over from an earier sound-crash debugging session)
Co-authored-by: Jean-Andre Santoni's avatarJean-André Santoni <jean.andre.santoni@gmail.com>
parent 67f0aca9
Pipeline #23077 passed with stages
in 1 minute and 36 seconds
......@@ -362,22 +362,28 @@ endif
CFLAGS += -g
LUA_MYCFLAGS += -g
DEFINES_DEBUG += -DLUTRO_BUILD_IS_PLAYER=0
DEFINES_DEBUG += -DLUTRO_BUILD_IS_TOOL=1
DEFINES_DEBUG += -DLUTRO_ENABLE_ERROR=1
DEFINES_DEBUG += -DLUTRO_ENABLE_ALERT=1
DEFINES_DEBUG += -DLUTRO_ENABLE_ASSERT_TOOL=1
DEFINES_DEBUG += -DLUTRO_ENABLE_ASSERT_DBG=1
DEFINES_TOOL += -DNDEBUG
DEFINES_TOOL += -DLUTRO_BUILD_IS_PLAYER=0
DEFINES_TOOL += -DLUTRO_BUILD_IS_TOOL=1
DEFINES_TOOL += -DLUTRO_ENABLE_ERROR=1
DEFINES_TOOL += -DLUTRO_ENABLE_ALERT=1
DEFINES_TOOL += -DLUTRO_ENABLE_ASSERT_TOOL=1
DEFINES_TOOL += -DLUTRO_ENABLE_ASSERT_DBG=0
DEFINES_PLAYER += -DNDEBUG
DEFINES_TOOL += -DLUTRO_ENABLE_ERROR=1
DEFINES_TOOL += -DLUTRO_ENABLE_ALERT=0
DEFINES_TOOL += -DLUTRO_ENABLE_ASSERT_TOOL=0
DEFINES_TOOL += -DLUTRO_ENABLE_ASSERT_DBG=0
DEFINES_PLAYER += -DLUTRO_BUILD_IS_PLAYER=1
DEFINES_PLAYER += -DLUTRO_BUILD_IS_TOOL=0
DEFINES_PLAYER += -DLUTRO_ENABLE_ERROR=1
DEFINES_PLAYER += -DLUTRO_ENABLE_ALERT=0
DEFINES_PLAYER += -DLUTRO_ENABLE_ASSERT_TOOL=0
DEFINES_PLAYER += -DLUTRO_ENABLE_ASSERT_DBG=0
ifeq ($(LUTRO_CONFIG), debug)
DEFINES += $(DEFINES_DEBUG)
......
......@@ -87,14 +87,38 @@ void lutro_audio_stop_all(lua_State* L)
}
}
#if LUTRO_BUILD_IS_TOOL
# define mixer_buffer_guardband 64
#else
# define mixer_buffer_guardband 0
#endif
typedef struct mixer_presaturate_t_guarded
{
#if mixer_buffer_guardband
uint8_t guard_f[mixer_buffer_guardband];
#endif
mixer_presaturate_t presaturated[(AUDIO_FRAMES * CHANNELS)];
#if mixer_buffer_guardband
uint8_t guard_b[mixer_buffer_guardband];
#endif
} mixer_presaturate_t_guarded;
void mixer_render(lua_State* L, int16_t *buffer)
{
static mixer_presaturate_t presaturateBuffer[AUDIO_FRAMES * CHANNELS];
static mixer_presaturate_t_guarded localbuffer;
memset(presaturateBuffer, 0, AUDIO_FRAMES * CHANNELS * sizeof(mixer_presaturate_t));
memset(localbuffer.presaturated, 0, sizeof(localbuffer.presaturated));
#if mixer_buffer_guardband
memset(localbuffer.guard_f, 0xcd, sizeof(localbuffer.guard_f));
memset(localbuffer.guard_b, 0xcd, sizeof(localbuffer.guard_f));
#endif
presaturate_buffer_desc bufdesc;
bufdesc.data = presaturateBuffer;
bufdesc.data = localbuffer.presaturated;
bufdesc.channels = CHANNELS;
bufdesc.samplelen = AUDIO_FRAMES;
......@@ -166,8 +190,8 @@ void mixer_render(lua_State* L, int16_t *buffer)
{
for (int j = 0; j < mixchunksz; ++j, ++total_mixed, ++source->sndpos)
{
presaturateBuffer[(total_mixed*2) + 0] += sndta->data[source->sndpos] * srcvol;
presaturateBuffer[(total_mixed*2) + 1] += sndta->data[source->sndpos] * srcvol;
localbuffer.presaturated[(total_mixed*2) + 0] += sndta->data[source->sndpos] * srcvol;
localbuffer.presaturated[(total_mixed*2) + 1] += sndta->data[source->sndpos] * srcvol;
}
}
......@@ -175,8 +199,8 @@ void mixer_render(lua_State* L, int16_t *buffer)
{
for (int j = 0; j < mixchunksz; ++j, ++total_mixed, ++source->sndpos)
{
presaturateBuffer[(total_mixed*2) + 0] += sndta->data[(source->sndpos*2) + 0] * srcvol;
presaturateBuffer[(total_mixed*2) + 1] += sndta->data[(source->sndpos*2) + 1] * srcvol;
localbuffer.presaturated[(total_mixed*2) + 0] += sndta->data[(source->sndpos*2) + 0] * srcvol;
localbuffer.presaturated[(total_mixed*2) + 1] += sndta->data[(source->sndpos*2) + 1] * srcvol;
}
}
......@@ -205,8 +229,19 @@ void mixer_render(lua_State* L, int16_t *buffer)
float mastervol_and_scale_to_int16 = volume * 32767;
for (int j = 0; j < AUDIO_FRAMES * CHANNELS; j++)
{
buffer[j] = saturate(presaturateBuffer[j] * mastervol_and_scale_to_int16);
buffer[j] = saturate(localbuffer.presaturated[j] * mastervol_and_scale_to_int16);
}
#if mixer_buffer_guardband
if (mixer_buffer_guardband > 0) {
int bi;
for (bi=0; bi < mixer_buffer_guardband; ++bi)
{
tool_assert(localbuffer.guard_f[bi] == 0xcd);
tool_assert(localbuffer.guard_b[bi] == 0xcd);
}
}
#endif
}
int lutro_audio_preload(lua_State *L)
......
......@@ -8,9 +8,6 @@
#include <stdlib.h>
#include <string.h>
static unsigned num_imgdatas = 0;
static bitmap_t** imgdatas = NULL;
static int l_newImageData(lua_State *L);
static int l_getWidth(lua_State *L);
static int l_getHeight(lua_State *L);
......@@ -40,10 +37,6 @@ void lutro_image_init()
void *image_data_create(lua_State *L, bitmap_t* self)
{
num_imgdatas++;
imgdatas = (bitmap_t**)realloc(imgdatas, num_imgdatas * sizeof(bitmap_t));
imgdatas[num_imgdatas-1] = self;
if (luaL_newmetatable(L, "ImageData") != 0)
{
static luaL_Reg imgdata_funcs[] = {
......
......@@ -13,15 +13,15 @@
#define LUTRO_ENABLE_ALERT 1
#endif
#ifndef LUTRO_ENABLE_TOOL_ASSERT
#define LUTRO_ENABLE_TOOL_ASSERT 1
#ifndef LUTRO_ENABLE_ASSERT_TOOL
#define LUTRO_ENABLE_ASSERT_TOOL 1
#endif
#if !defined(LUTRO_ENABLE_DBG_ASSERT)
#if !defined(LUTRO_ENABLE_ASSERT_DBG)
# if defined(NDEBUG)
# define LUTRO_ENABLE_DBG_ASSERT 0
# define LUTRO_ENABLE_ASSERT_DBG 0
# else
# define LUTRO_ENABLE_DBG_ASSERT 1
# define LUTRO_ENABLE_ASSERT_DBG 1
# endif
#endif
......@@ -117,7 +117,7 @@ extern int _lutro_assertf_internal(int ignorable, const char *fmt, ...);
// make sense in the context of the player
//
// tool_assume is a "hardened" version of assert, and is not ignorable.
#if LUTRO_ENABLE_TOOL_ASSERT
#if LUTRO_ENABLE_ASSERT_TOOL
# define tool_assert(cond) _base_soft_assert (cond)
# define tool_assertf(cond, msg, ...) _base_soft_assertf(cond, msg, ## __VA_ARGS__)
# define tool_assume(cond) _base_hard_assert (cond)
......@@ -135,7 +135,7 @@ extern int _lutro_assertf_internal(int ignorable, const char *fmt, ...);
// obvious that it might do so (a good example would be assertions within the audio mixer loop).
//
// dbg_assume is a "hardened" version of assert, and is not ignorable.
#if LUTRO_ENABLE_DBG_ASSERT
#if LUTRO_ENABLE_ASSERT_DBG
# define dbg_assert(cond) _base_soft_assert (cond)
# define dbg_assertf(cond, msg, ...) _base_soft_assertf(cond, msg, ## __VA_ARGS__)
# define dbg_assume(cond) _base_hard_assert (cond)
......
......@@ -336,6 +336,8 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_BUILD_IS_PLAYER=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_BUILD_IS_TOOL=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ERROR=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ALERT=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_TOOL=1</PreprocessorDefinitions>
......@@ -345,19 +347,23 @@
<ItemDefinitionGroup Condition="'$(Configuration)'=='Tool'">
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_BUILD_IS_PLAYER=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_BUILD_IS_TOOL=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ERROR=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ALERT=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_TOOL=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_DBG=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ERROR=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ALERT=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_TOOL=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_DBG=0</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Player'">
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_BUILD_IS_PLAYER=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_BUILD_IS_TOOL=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ERROR=1</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ALERT=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_TOOL=0</PreprocessorDefinitions>
<PreprocessorDefinitions>%(PreprocessorDefinitions);LUTRO_ENABLE_ASSERT_DBG=0</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
</Project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment