From 10f3f56692cee2a071792baad26fba6c78b665b6 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Thu, 28 Apr 2022 22:02:25 +1000 Subject: Split out sound logic (for xplatform) --- clak.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/clak.c b/clak.c index 5e947e9..d6ad034 100644 --- a/clak.c +++ b/clak.c @@ -1,7 +1,10 @@ #include +#include #include +#define VOLUME 0.05 + #include "board/boards.h" #define BOARD(str, buf) { .name = str, .wav = buf }, @@ -15,16 +18,25 @@ Board boards[] = { }; int const boards_n = sizeof(boards) / sizeof(boards[0]); -int main(void) +void sound_init(void) { - float volume = 0.05; - DWORD channel_volume = volume * 0xFFFF; + DWORD channel_volume = VOLUME * 0xFFFF; waveOutSetVolume(NULL, (channel_volume << 16) | channel_volume); +} + +void sound_play(unsigned char* buffer) +{ + PlaySound((const char *) buffer, NULL, SND_MEMORY | SND_SYNC | SND_NODEFAULT); +} + +int main(void) +{ + sound_init(); for (int i = 0; i < boards_n; ++i) { printf("name: %s\n", boards[i].name); - PlaySound((const char *) boards[i].wav, NULL, SND_MEMORY | SND_SYNC | SND_NODEFAULT); - Sleep(500); + sound_play(boards[i].wav); + sleep(0.5); } return 0; -- cgit