From: ljsebald <ljs...@us...> - 2023-11-11 03:34:19
|
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 4d1b67c84f5770a1eb8ddb65507751a42d0850ae (commit) from 81a4080ba17130c9c1baeca9a4381bc6452b96f8 (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 4d1b67c84f5770a1eb8ddb65507751a42d0850ae Author: Andress Barajas <and...@gm...> Date: Fri Nov 10 19:33:48 2023 -0800 Add multi-streaming example (#351) * Add multi-streaming example ----------------------------------------------------------------------- Summary of changes: .../dreamcast/sound/{sfx => multi-stream}/Makefile | 12 +- examples/dreamcast/sound/multi-stream/README | 20 +++ examples/dreamcast/sound/multi-stream/main.c | 152 +++++++++++++++++++++ .../sound/multi-stream/romdisk/brushing.wav | Bin 0 -> 1508444 bytes .../sound/multi-stream/romdisk/faucet.wav | Bin 0 -> 652380 bytes 5 files changed, 178 insertions(+), 6 deletions(-) copy examples/dreamcast/sound/{sfx => multi-stream}/Makefile (63%) create mode 100644 examples/dreamcast/sound/multi-stream/README create mode 100644 examples/dreamcast/sound/multi-stream/main.c create mode 100644 examples/dreamcast/sound/multi-stream/romdisk/brushing.wav create mode 100644 examples/dreamcast/sound/multi-stream/romdisk/faucet.wav diff --git a/examples/dreamcast/sound/sfx/Makefile b/examples/dreamcast/sound/multi-stream/Makefile similarity index 63% copy from examples/dreamcast/sound/sfx/Makefile copy to examples/dreamcast/sound/multi-stream/Makefile index c2d38ef..da2fa38 100644 --- a/examples/dreamcast/sound/sfx/Makefile +++ b/examples/dreamcast/sound/multi-stream/Makefile @@ -1,10 +1,10 @@ # KallistiOS ##version## # -# examples/dreamcast/sound/sfx/Makefile +# examples/dreamcast/sound/multi-stream/Makefile # -TARGET = sfx.elf -OBJS = main.o romdisk.o +TARGET = multistream.elf +OBJS = romdisk.o main.o KOS_ROMDISK_DIR = romdisk all: clean $(TARGET) @@ -16,12 +16,12 @@ clean: -rm -f romdisk.o romdisk.img $(TARGET): $(OBJS) - kos-cc -o $(TARGET) $(OBJS) + kos-cc -o $(TARGET) $(OBJS) $(DATAOBJS) $(OBJEXTRA) -lwav -run: $(TARGET) +run: $(KOS_LOADER) $(TARGET) -dist: $(TARGET) +dist: rm -f $(OBJS) romdisk.o romdisk.img $(KOS_STRIP) $(TARGET) diff --git a/examples/dreamcast/sound/multi-stream/README b/examples/dreamcast/sound/multi-stream/README new file mode 100644 index 0000000..7e4504f --- /dev/null +++ b/examples/dreamcast/sound/multi-stream/README @@ -0,0 +1,20 @@ +Overview +This example demonstrates audio playback using libwav (kos-port). The sounds utilized in this example were sourced from https://gamesounds.xyz/?dir=Sound%20Effects/Bathroom and converted to ADPCM format. + +Conversion to ADPCM Format +This conversion was achieved using FFmpeg, a powerful multimedia framework. The following command was used for conversion: + +ffmpeg -i PCM16_stereo.wav -acodec adpcm_yamaha -ac 2 ADPCM_stereo.wav + +This command converts a stereo PCM WAV file (PCM16_stereo.wav) to a stereo Yamaha ADPCM WAV file (ADPCM_stereo.wav). + +Playback Using libwav (kos-port) +The libwav (kos-port) library is used for audio playback in this project. It is versatile and supports all the Dreamcast +audio formats: + +4-bit ADPCM data (as demonstrated in this example) +8-bit and 16-bit uncompressed PCM data + +Use the following command to convert a 16-bit stereo PCM WAV file (PCM16_stereo.wav) to a 8-bit stero PCM WAV file (PCM8_mono.wav): + +ffmpeg -i PCM16_stereo.wav -acodec pcm_u8 -ac 1 PCM8_mono.wav diff --git a/examples/dreamcast/sound/multi-stream/main.c b/examples/dreamcast/sound/multi-stream/main.c new file mode 100644 index 0000000..bb64d32 --- /dev/null +++ b/examples/dreamcast/sound/multi-stream/main.c @@ -0,0 +1,152 @@ +/* KallistiOS ##version## + + main.c + Copyright (C) 2023 Andy Barajas + + This example program demonstrates playing two ADPCM wav stereo + streams at once using libwav. +*/ + +#include <kos.h> +#include <wav/sndwav.h> + +#define LOOP 1 + +static void draw_instructions(int faucet_vol, int brushing_vol); + +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 faucet_volume = 240; + uint8_t brushing_volume = 240; + int volume_changed = 1; + cont_state_t *cond; + uint32_t current_buttons = 0; + uint32_t changed_buttons = 0; + uint32_t previous_buttons = 0; + + vid_set_mode(DM_640x480, PM_RGB555); + // Initialize sound system and WAV + snd_stream_init(); + wav_init(); + + wav_stream_hnd_t faucet = wav_create("/rd/faucet.wav", LOOP); + wav_volume(faucet, faucet_volume); + + wav_stream_hnd_t brushing = wav_create("/rd/brushing.wav", LOOP); + wav_volume(brushing, brushing_volume); + + wav_play(faucet); + wav_play(brushing); + + + for(;;) { + cond = get_cont_state(); + current_buttons = cond->buttons; + changed_buttons = current_buttons ^ previous_buttons; + previous_buttons = current_buttons; + + // Play wav files if they arent playing already + if(button_pressed(current_buttons, changed_buttons, CONT_X)) { + if(!wav_isplaying(faucet)) + wav_play(faucet); + } + if(button_pressed(current_buttons, changed_buttons, CONT_Y)) { + if(!wav_isplaying(brushing)) + wav_play(brushing); + } + // Stop playing faucet + if(button_pressed(current_buttons, changed_buttons, CONT_A)) { + wav_stop(faucet); + } + // Stop playing brushing + if(button_pressed(current_buttons, changed_buttons, CONT_B)) { + wav_stop(brushing); + } + + // Adjust Volume + if(cond->ltrig > 0) { + if(faucet_volume < 255) + faucet_volume++; + else + faucet_volume = 0; + volume_changed = 1; + wav_volume(faucet, faucet_volume); + } + if(cond->rtrig > 0) { + if(faucet_volume < 255) + brushing_volume++; + else + brushing_volume = 0; + volume_changed = 1; + wav_volume(brushing, brushing_volume); + } + + // Exit Program + if(button_pressed(current_buttons, changed_buttons, CONT_START)) + break; + + if(volume_changed) { + volume_changed = 0; + draw_instructions(faucet_volume, brushing_volume); + } + } + + wav_shutdown(); + snd_stream_shutdown(); + + return 0; +} + +static void draw_instructions(int faucet_vol, int brushing_vol) { + int x = 20, y = 20+24; + int color = 1; + char volume_str[32]; + + bfont_draw_str(vram_s + y*640+x, 640, color, "Press X to play faucet sound"); + y += 24; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press A to stop faucet sound"); + y += 24; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press L-Trigger to increase faucet volume"); + y += 24; + memset(volume_str, 0, 32); + snprintf(volume_str, 32, "Faucet Volume: %3i", faucet_vol); + bfont_draw_str(vram_s + y*640+x, 640, color, volume_str); + + y += 48; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press Y to play brushing sound"); + y += 24; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press B to stop brushing sound"); + y += 24; + bfont_draw_str(vram_s + y*640+x, 640, color, "Press R-Trigger to increase brushing volume"); + y += 24; + memset(volume_str, 0, 32); + snprintf(volume_str, 32, "Brushing Volume: %3i", brushing_vol); + bfont_draw_str(vram_s + y*640+x, 640, color, 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/multi-stream/romdisk/brushing.wav b/examples/dreamcast/sound/multi-stream/romdisk/brushing.wav new file mode 100644 index 0000000..fb42d82 Binary files /dev/null and b/examples/dreamcast/sound/multi-stream/romdisk/brushing.wav differ diff --git a/examples/dreamcast/sound/multi-stream/romdisk/faucet.wav b/examples/dreamcast/sound/multi-stream/romdisk/faucet.wav new file mode 100644 index 0000000..05d2d65 Binary files /dev/null and b/examples/dreamcast/sound/multi-stream/romdisk/faucet.wav differ hooks/post-receive -- A pseudo Operating System for the Dreamcast. |