From ca2deef8c6d48354ee73a84cb6482e6bad025900 Mon Sep 17 00:00:00 2001 From: nesbox Date: Mon, 24 Sep 2018 22:09:23 +0300 Subject: [PATCH] fixed sound stere in the sokol demo --- 3rd-party | 2 +- CMakeLists.txt | 20 ++++++++++---------- examples/sokol/main.c | 14 ++++++-------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/3rd-party b/3rd-party index f4349be..215169c 160000 --- a/3rd-party +++ b/3rd-party @@ -1 +1 @@ -Subproject commit f4349bec5a48b3a1261a10888edccd15aa649c4f +Subproject commit 215169c035212fe09b1f31006c25fd180da98323 diff --git a/CMakeLists.txt b/CMakeLists.txt index 194a97c..bbafa7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,13 +250,13 @@ else() set(SOKOL_SRC ${SOKOL_SRC} ${EXAMPLE_DIR}/sokol/sokol.c) endif() -add_executable(sokol ${SOKOL_SRC}) +add_executable(sokol-renderer ${SOKOL_SRC}) if(APPLE) - set_property (TARGET sokol APPEND_STRING PROPERTY + set_property (TARGET sokol-renderer APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc") - target_link_libraries(sokol + target_link_libraries(sokol-renderer "-framework Cocoa" "-framework QuartzCore" "-framework Metal" @@ -265,19 +265,19 @@ if(APPLE) ) elseif(LINUX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") - target_link_libraries(sokol X11 GL m dl asound) + target_link_libraries(sokol-renderer X11 GL m dl asound) endif() -target_include_directories(sokol PRIVATE include) -target_include_directories(sokol PRIVATE 3rd-party/sokol) -target_include_directories(sokol PRIVATE src) +target_include_directories(sokol-renderer PRIVATE include) +target_include_directories(sokol-renderer PRIVATE 3rd-party/sokol) +target_include_directories(sokol-renderer PRIVATE src) if(MINGW) - target_link_libraries(sokol mingw32) + target_link_libraries(sokol-renderer mingw32) endif() -add_dependencies(sokol tic80core) -target_link_libraries(sokol tic80core) +add_dependencies(sokol-renderer tic80core) +target_link_libraries(sokol-renderer tic80core) ################################ # SDL GPU diff --git a/examples/sokol/main.c b/examples/sokol/main.c index c1fc619..631f4db 100644 --- a/examples/sokol/main.c +++ b/examples/sokol/main.c @@ -6,6 +6,8 @@ #include #include #include +#include + #include static tic80* tic = NULL; @@ -254,7 +256,7 @@ void gfx_draw() { static void app_init(void) { saudio_desc desc = {0}; - + desc.num_channels = 2; saudio_setup(&desc); FILE* file = fopen("cart.tic", "rb"); @@ -294,14 +296,10 @@ static void app_frame(void) gfx_draw(); - // TODO: Sokol doesn't support stereo at the moment - // will fix it later - enum {Channels = 1}; + static float floatSamples[44100 / 60 * 2]; - static float floatSamples[44100/60 * Channels]; - - 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; + for(s32 i = 0; i < tic->sound.count; i++) + floatSamples[i] = (float)tic->sound.samples[i] / SHRT_MAX; saudio_push(floatSamples, tic->sound.count / 2); }