From: ljsebald <ljs...@us...> - 2023-11-09 04:02:27
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 9c23016db56a8ca885765c115e8742cae65d0506 (commit) from a6fbf57e281b4cb231fe3a3f4bb68e57df58ecf8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9c23016db56a8ca885765c115e8742cae65d0506 Author: Andress Barajas <and...@gm...> Date: Wed Nov 8 19:40:33 2023 -0800 Add sound effects example (#343) Add sound effects example ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/sound/Makefile | 3 + .../yuv_converter/YUV422 => sound/sfx}/Makefile | 25 ++-- examples/dreamcast/sound/sfx/main.c | 166 +++++++++++++++++++++ examples/dreamcast/sound/sfx/romdisk/beep-1.wav | Bin 0 -> 63128 bytes examples/dreamcast/sound/sfx/romdisk/beep-2.wav | Bin 0 -> 26876 bytes examples/dreamcast/sound/sfx/romdisk/beep-3.wav | Bin 0 -> 20196 bytes examples/dreamcast/sound/sfx/romdisk/beep-4.wav | Bin 0 -> 52634 bytes 7 files changed, 181 insertions(+), 13 deletions(-) copy examples/dreamcast/{pvr/yuv_converter/YUV422 => sound/sfx}/Makefile (54%) create mode 100644 examples/dreamcast/sound/sfx/main.c create mode 100644 examples/dreamcast/sound/sfx/romdisk/beep-1.wav create mode 100644 examples/dreamcast/sound/sfx/romdisk/beep-2.wav create mode 100644 examples/dreamcast/sound/sfx/romdisk/beep-3.wav create mode 100644 examples/dreamcast/sound/sfx/romdisk/beep-4.wav diff --git a/examples/dreamcast/sound/Makefile b/examples/dreamcast/sound/Makefile index e07f635..0ab4e7c 100644 --- a/examples/dreamcast/sound/Makefile +++ b/examples/dreamcast/sound/Makefile @@ -10,6 +10,7 @@ all: $(KOS_MAKE) -C hello-mp3 $(KOS_MAKE) -C cdda $(KOS_MAKE) -C hello-opus + $(KOS_MAKE) -C sfx clean: $(KOS_MAKE) -C ghettoplay-vorbis clean @@ -17,6 +18,7 @@ clean: $(KOS_MAKE) -C hello-mp3 clean $(KOS_MAKE) -C cdda clean $(KOS_MAKE) -C hello-opus clean + $(KOS_MAKE) -C sfx clean dist: $(KOS_MAKE) -C ghettoplay-vorbis dist @@ -24,5 +26,6 @@ dist: $(KOS_MAKE) -C hello-mp3 dist $(KOS_MAKE) -C cdda dist $(KOS_MAKE) -C hello-opus dist + $(KOS_MAKE) -C sfx dist diff --git a/examples/dreamcast/pvr/yuv_converter/YUV422/Makefile b/examples/dreamcast/sound/sfx/Makefile similarity index 54% copy from examples/dreamcast/pvr/yuv_converter/YUV422/Makefile copy to examples/dreamcast/sound/sfx/Makefile index bc02280..cbfea26 100644 --- a/examples/dreamcast/pvr/yuv_converter/YUV422/Makefile +++ b/examples/dreamcast/sound/sfx/Makefile @@ -1,22 +1,20 @@ +# KallistiOS ##version## +# +# examples/dreamcast/sound/sfx/Makefile # -# YUV422 Converter example -# (c)2023 Andy Barajas -# -TARGET = yuv422.elf -OBJS = yuv422.o romdisk.o +TARGET = sfx.elf +OBJS = romdisk.o main.o -all: rm-elf $(TARGET) +all: clean $(TARGET) include $(KOS_BASE)/Makefile.rules -clean: rm-elf - -rm -f $(OBJS) romdisk.* - -rm-elf: - -rm -f $(TARGET) romdisk.* +clean: + -rm -f $(TARGET) $(OBJS) + -rm -f romdisk.o romdisk.img -$(TARGET): $(OBJS) +$(TARGET): $(OBJS) kos-cc -o $(TARGET) $(OBJS) romdisk.img: @@ -29,5 +27,6 @@ run: $(TARGET) $(KOS_LOADER) $(TARGET) dist: $(TARGET) - -rm -f $(OBJS) + rm -f $(OBJS) romdisk.o romdisk.img $(KOS_STRIP) $(TARGET) + diff --git a/examples/dreamcast/sound/sfx/main.c b/examples/dreamcast/sound/sfx/main.c new file mode 100644 index 0000000..22f140b --- /dev/null +++ b/examples/dreamcast/sound/sfx/main.c @@ -0,0 +1,166 @@ +/* KallistiOS ##version## + + main.c + Copyright (C) 2023 Andy Barajas + + This example program simply demonstrations how to load and play + sound effects on their own channels as well as on the same channel. +*/ + +#include <stdio.h> +#include <string.h> +#include <kos/init.h> +#include <dc/biosfont.h> +#include <dc/video.h> +#include <dc/sound/sound.h> +#include <dc/sound/sfxmgr.h> +#include <dc/maple.h> +#include <dc/maple/controller.h> + +#define LEFT 0 +#define CENTER 128 +#define RIGHT 255 + +extern uint8 romdisk[]; +KOS_INIT_ROMDISK(romdisk); + +static void draw_instructions(uint8_t volume); + +static cont_state_t *get_cont_state(); +static int button_pressed(uint32_t current_buttons, uint32_t changed_buttons, uint32_t button); + +int main(int argc, char **argv) { + uint8_t volume = 128; + int volume_changed = 1; + cont_state_t *cond; + + vid_set_mode(DM_640x480, PM_RGB555); + // Initialize sound system + snd_init(); + + // Load wav files found in romdisk + // Beep wav files found in the romdisk where provided by + // https://gamesounds.xyz/?dir=Sound%20Effects/Beeps + sfxhnd_t beep1 = snd_sfx_load("/rd/beep-1.wav"); + sfxhnd_t beep2 = snd_sfx_load("/rd/beep-2.wav"); + sfxhnd_t beep3 = snd_sfx_load("/rd/beep-3.wav"); + sfxhnd_t beep4 = snd_sfx_load("/rd/beep-4.wav"); + + uint32_t current_buttons = 0; + uint32_t changed_buttons = 0; + uint32_t previous_buttons = 0; + + for(;;) { + cond = get_cont_state(); + current_buttons = cond->buttons; + changed_buttons = current_buttons ^ previous_buttons; + previous_buttons = current_buttons; + + // Play sounds on different channels + if(button_pressed(current_buttons, changed_buttons, CONT_A)) { + snd_sfx_play(beep1, volume, CENTER); + } + if(button_pressed(current_buttons, changed_buttons, CONT_B)) { + snd_sfx_play(beep2, volume, RIGHT); + } + if(button_pressed(current_buttons, changed_buttons, CONT_X)) { + snd_sfx_play(beep3, volume, LEFT); + } + if(button_pressed(current_buttons, changed_buttons, CONT_Y)) { + snd_sfx_play(beep4, volume, CENTER); + } + + // Play sounds on same channel + if(button_pressed(current_buttons, changed_buttons, CONT_DPAD_DOWN)) { + snd_sfx_play_chn(0, beep1, volume, CENTER); + } + if(button_pressed(current_buttons, changed_buttons, CONT_DPAD_RIGHT)) { + snd_sfx_play_chn(0, beep2, volume, RIGHT); + } + if(button_pressed(current_buttons, changed_buttons, CONT_DPAD_LEFT)) { + snd_sfx_play_chn(0, beep3, volume, LEFT); + } + if(button_pressed(current_buttons, changed_buttons, CONT_DPAD_UP)) { + snd_sfx_play_chn(0, beep4, volume, CENTER); + } + + // Adjust Volume + if(cond->ltrig > 0) { + volume_changed = 1; + + if(volume < 255) + volume++; + } + if(cond->rtrig > 0) { + volume_changed = 1; + + if(volume > 0) + volume--; + } + + // Exit Program + if(button_pressed(current_buttons, changed_buttons, CONT_START)) + break; + + if(volume_changed) { + volume_changed = 0; + draw_instructions(volume); + } + } + + // Unload all sound effects from sound RAM + snd_sfx_unload(beep1); + snd_sfx_unload(beep2); + snd_sfx_unload(beep3); + snd_sfx_unload(beep4); + // OR + // snd_sfx_unload_all(); + + snd_shutdown(); + + return 0; +} + +static void draw_instructions(uint8_t volume) { + int x = 20, y = 20+24; + int color = 1; + char current_volume_str[32]; + + memset(current_volume_str, 0, 32); + snprintf(current_volume_str, 32, "Current Volume: %3i", volume); + + bfont_draw_str(vram_s + y*640+x, 640, color, "Press A,B,X,Y to play beeps on separate channels"); + y += 48; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press UP,DOWN,LEFT,RIGHT on D-Pad to play beeps"); + y += 24; + bfont_draw_str(vram_s + y*640+x, 640, color, "on the same channel"); + y += 48; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press L-Trigger/R-Trigger to +/- volume"); + y += 24; + bfont_draw_str(vram_s + y*640+x, 640, color, current_volume_str); + y += 48; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press Start to exit program"); +} + +static cont_state_t *get_cont_state() { + maple_device_t *cont; + cont_state_t *state; + + cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER); + if(cont) { + state = (cont_state_t*)maple_dev_status(cont); + return state; + } + + return NULL; +} + +static int button_pressed(uint32_t current_buttons, uint32_t changed_buttons, uint32_t button) { + if(changed_buttons & button) { + if (current_buttons & button) + return 1; + } + + return 0; +} + diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-1.wav b/examples/dreamcast/sound/sfx/romdisk/beep-1.wav new file mode 100644 index 0000000..f224049 Binary files /dev/null and b/examples/dreamcast/sound/sfx/romdisk/beep-1.wav differ diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-2.wav b/examples/dreamcast/sound/sfx/romdisk/beep-2.wav new file mode 100644 index 0000000..8343a63 Binary files /dev/null and b/examples/dreamcast/sound/sfx/romdisk/beep-2.wav differ diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-3.wav b/examples/dreamcast/sound/sfx/romdisk/beep-3.wav new file mode 100644 index 0000000..9227a3f Binary files /dev/null and b/examples/dreamcast/sound/sfx/romdisk/beep-3.wav differ diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-4.wav b/examples/dreamcast/sound/sfx/romdisk/beep-4.wav new file mode 100644 index 0000000..90b1287 Binary files /dev/null and b/examples/dreamcast/sound/sfx/romdisk/beep-4.wav differ hooks/post-receive -- A pseudo Operating System for the Dreamcast. |