fixed sound stere in the sokol demo

This commit is contained in:
nesbox 2018-09-24 22:09:23 +03:00
parent 10cc0bb9a9
commit ca2deef8c6
3 changed files with 17 additions and 19 deletions

@ -1 +1 @@
Subproject commit f4349bec5a48b3a1261a10888edccd15aa649c4f Subproject commit 215169c035212fe09b1f31006c25fd180da98323

View File

@ -250,13 +250,13 @@ else()
set(SOKOL_SRC ${SOKOL_SRC} ${EXAMPLE_DIR}/sokol/sokol.c) set(SOKOL_SRC ${SOKOL_SRC} ${EXAMPLE_DIR}/sokol/sokol.c)
endif() endif()
add_executable(sokol ${SOKOL_SRC}) add_executable(sokol-renderer ${SOKOL_SRC})
if(APPLE) if(APPLE)
set_property (TARGET sokol APPEND_STRING PROPERTY set_property (TARGET sokol-renderer APPEND_STRING PROPERTY
COMPILE_FLAGS "-fobjc-arc") COMPILE_FLAGS "-fobjc-arc")
target_link_libraries(sokol target_link_libraries(sokol-renderer
"-framework Cocoa" "-framework Cocoa"
"-framework QuartzCore" "-framework QuartzCore"
"-framework Metal" "-framework Metal"
@ -265,19 +265,19 @@ if(APPLE)
) )
elseif(LINUX) elseif(LINUX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") 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() endif()
target_include_directories(sokol PRIVATE include) target_include_directories(sokol-renderer PRIVATE include)
target_include_directories(sokol PRIVATE 3rd-party/sokol) target_include_directories(sokol-renderer PRIVATE 3rd-party/sokol)
target_include_directories(sokol PRIVATE src) target_include_directories(sokol-renderer PRIVATE src)
if(MINGW) if(MINGW)
target_link_libraries(sokol mingw32) target_link_libraries(sokol-renderer mingw32)
endif() endif()
add_dependencies(sokol tic80core) add_dependencies(sokol-renderer tic80core)
target_link_libraries(sokol tic80core) target_link_libraries(sokol-renderer tic80core)
################################ ################################
# SDL GPU # SDL GPU

View File

@ -6,6 +6,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <tic80.h> #include <tic80.h>
static tic80* tic = NULL; static tic80* tic = NULL;
@ -254,7 +256,7 @@ void gfx_draw() {
static void app_init(void) static void app_init(void)
{ {
saudio_desc desc = {0}; saudio_desc desc = {0};
desc.num_channels = 2;
saudio_setup(&desc); saudio_setup(&desc);
FILE* file = fopen("cart.tic", "rb"); FILE* file = fopen("cart.tic", "rb");
@ -294,14 +296,10 @@ static void app_frame(void)
gfx_draw(); gfx_draw();
// TODO: Sokol doesn't support stereo at the moment static float floatSamples[44100 / 60 * 2];
// will fix it later
enum {Channels = 1};
static float floatSamples[44100/60 * Channels]; for(s32 i = 0; i < tic->sound.count; i++)
floatSamples[i] = (float)tic->sound.samples[i] / SHRT_MAX;
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); saudio_push(floatSamples, tic->sound.count / 2);
} }