From cd4db83725d1b42ebd1fd868a4d97578dd80a965 Mon Sep 17 00:00:00 2001 From: nesbox Date: Fri, 21 Sep 2018 17:17:12 +0300 Subject: [PATCH] sokol: temporary sound fixes --- include/tic80_config.h | 8 ++++++++ sokol/main.c | 15 ++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/tic80_config.h b/include/tic80_config.h index 750dc7e..f09e854 100644 --- a/include/tic80_config.h +++ b/include/tic80_config.h @@ -22,12 +22,20 @@ #pragma once +#if !defined(TIC_BUILD_WITH_LUA) && \ + !defined(TIC_BUILD_WITH_MOON) && \ + !defined(TIC_BUILD_WITH_FENNEL) && \ + !defined(TIC_BUILD_WITH_JS) && \ + !defined(TIC_BUILD_WITH_WREN) + #define TIC_BUILD_WITH_LUA 1 #define TIC_BUILD_WITH_MOON 1 #define TIC_BUILD_WITH_FENNEL 1 #define TIC_BUILD_WITH_JS 1 #define TIC_BUILD_WITH_WREN 1 +#endif + #if defined(__APPLE__) // TODO: this disables macos config # include "AvailabilityMacros.h" diff --git a/sokol/main.c b/sokol/main.c index 41f86c2..fd1dd84 100644 --- a/sokol/main.c +++ b/sokol/main.c @@ -260,7 +260,6 @@ static tic80* tic = NULL; static void app_init(void) { saudio_desc desc = {0}; - desc.num_channels = 2; saudio_setup(&desc); @@ -307,14 +306,16 @@ static void app_frame(void) gfx_draw(); - static float floatSamples[44100/60]; + // TODO: Sokol doesn't support stereo at the moment + // will fix it later + enum {Channels = 1}; - // TODO: remove /2 for stereo sound - for(s32 i = 0; i < tic->sound.count/2; i++) - floatSamples[i] = (float)tic->sound.samples[i*2] / 32768.0f; + static float floatSamples[44100/60 * Channels]; - // TODO: remove /2 for stero sound - saudio_push(floatSamples, tic->sound.count/2); + for(s32 i = 0; i < tic->sound.count; i+=2) + floatSamples[i>>1] = (float)(tic->sound.samples[i] + tic->sound.samples[i+1]) / 65536.0f; + + saudio_push(floatSamples, tic->sound.count / 2); } static void app_input(const sapp_event* event)