From: quzar <qu...@us...> - 2024-12-25 18:19:02
|
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 3ac9880e61d086cd62d31bbad63d4998821a4858 (commit) via 2a3fa1a7554ac96db8a7ad28c7cd855707450b14 (commit) via 737f0e9cb8464ee8c575b8715d6e4b3d693a1869 (commit) via 03d84556fb3bcbda04bbd2b15f5e0404ad5bb0be (commit) via 8761ef2801cc6f764ccd562f5a62260ff3423f0b (commit) via 1fff2052019bbeb6f1a69873505c243dbe2b713a (commit) via 0fe965953efcf412c00dc6e8d7289de921f7b993 (commit) via edbdb2e78383c481568f91913359b73469015a48 (commit) via a5908659f0b8f7ee5e480c715d5895b5fb6fde80 (commit) via 3ed0eb36bd4f4218f4946d2e96f518bdcb64748a (commit) via fb4724195afd3750ff0ebd420dc25cc2c4e1c3aa (commit) via 25106a1a086e954fa2eeb2ab090d747af20493bb (commit) via fc002a381309fa4dbb494fdd45d1cb44f42a5332 (commit) via d84827a86a9ea3dd5d19455b3e341a575e64a821 (commit) from bae7adbde177c04560de31577932ace50988b238 (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 3ac9880e61d086cd62d31bbad63d4998821a4858 Merge: 2a3fa1a7 d84827a8 Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 23 23:06:11 2024 -0500 Merge pull request #818 from KallistiOS/MP_overlap Ensure the name manager selects the best match on lookup. commit 2a3fa1a7554ac96db8a7ad28c7cd855707450b14 Merge: 03d84556 737f0e9c Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 23 23:03:36 2024 -0500 Merge pull request #864 from jnmartin84/snd_sfx_buf Add snd_sfx_load functions that take pointers instead of files commit 737f0e9cb8464ee8c575b8715d6e4b3d693a1869 Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 23 23:02:50 2024 -0500 Apply suggestions from code review commit 03d84556fb3bcbda04bbd2b15f5e0404ad5bb0be Merge: 8761ef28 fc002a38 Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 23 22:56:36 2024 -0500 Merge pull request #856 from KallistiOS/v2.1.1-Docs Update the changelog and relnotes for v2.1.1 commit 8761ef2801cc6f764ccd562f5a62260ff3423f0b Merge: 1fff2052 25106a1a Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 23 22:55:03 2024 -0500 Merge pull request #863 from pcercuei/which-dc-chain dc-chain: Use "which" instead of "command" commit 1fff2052019bbeb6f1a69873505c243dbe2b713a Merge: bae7adbd 0fe96595 Author: Lawrence Sebald <ljs...@us...> Date: Mon Dec 23 22:50:29 2024 -0500 Merge pull request #872 from hcartiaux/posixify Posixify environ_*.sh files commit 0fe965953efcf412c00dc6e8d7289de921f7b993 Author: Hyacinthe Cartiaux <hya...@fr...> Date: Fri Dec 20 10:58:53 2024 +0100 Posixify environ_*.sh files commit edbdb2e78383c481568f91913359b73469015a48 Author: jnmartin84 <jnm...@gm...> Date: Fri Dec 6 09:17:51 2024 -0500 add snd_sfx_load_buf example commit a5908659f0b8f7ee5e480c715d5895b5fb6fde80 Author: jnmartin84 <jnm...@gm...> Date: Fri Dec 6 09:12:38 2024 -0500 clean up variable, function names; formatting commit 3ed0eb36bd4f4218f4946d2e96f518bdcb64748a Author: jnmartin84 <jnm...@gm...> Date: Thu Dec 5 17:39:14 2024 -0500 add new snd_sfx_load buf functions to header commit fb4724195afd3750ff0ebd420dc25cc2c4e1c3aa Author: jnmartin84 <jnm...@gm...> Date: Thu Dec 5 17:36:41 2024 -0500 add _buf methods take wav or raw sound data directly from memory and load into sfx commit 25106a1a086e954fa2eeb2ab090d747af20493bb Author: Paul Cercueil <pa...@cr...> Date: Wed Dec 4 22:06:38 2024 +0100 dc-chain: Use "which" instead of "command" "command" is technically the right one as it is recommended over "which". However, Ubuntu 20.04 does not seem to have a built-in "command", or at least it is not callable from a Makefile's $(shell). Fixes #860. Signed-off-by: Paul Cercueil <pa...@cr...> commit fc002a381309fa4dbb494fdd45d1cb44f42a5332 Author: QuzarDC <qu...@co...> Date: Sat Nov 23 00:10:51 2024 -0500 Update the changelog and relnotes for v2.1.1 commit d84827a86a9ea3dd5d19455b3e341a575e64a821 Author: QuzarDC <qu...@co...> Date: Mon Oct 14 03:01:02 2024 -0400 Ensure the name manager selects the best match on lookup. Before this it would always simply pick the first. This change allows registered names to overlap and still be found. So now you can mount something to `/c` without breaking `/cd`. ----------------------------------------------------------------------- Summary of changes: doc/CHANGELOG.md | 16 +- doc/RELNOTES.md | 15 ++ environ_base.sh | 4 +- environ_dreamcast.sh | 2 +- examples/dreamcast/sound/{sfx => sfxbuf}/Makefile | 4 +- examples/dreamcast/sound/{sfx => sfxbuf}/main.c | 41 ++-- .../sound/{sfx => sfxbuf}/romdisk/beep-1.wav | Bin .../sound/{sfx => sfxbuf}/romdisk/beep-2.wav | Bin .../sound/{sfx => sfxbuf}/romdisk/beep-3.wav | Bin .../sound/{sfx => sfxbuf}/romdisk/beep-4.wav | Bin kernel/arch/dreamcast/include/dc/sound/sfxmgr.h | 36 ++++ kernel/arch/dreamcast/sound/snd_sfxmgr.c | 216 +++++++++++++++++++++ kernel/exports/nmmgr.c | 18 +- utils/dc-chain/scripts/utils.mk | 2 +- 14 files changed, 325 insertions(+), 29 deletions(-) copy examples/dreamcast/sound/{sfx => sfxbuf}/Makefile (85%) copy examples/dreamcast/sound/{sfx => sfxbuf}/main.c (84%) copy examples/dreamcast/sound/{sfx => sfxbuf}/romdisk/beep-1.wav (100%) copy examples/dreamcast/sound/{sfx => sfxbuf}/romdisk/beep-2.wav (100%) copy examples/dreamcast/sound/{sfx => sfxbuf}/romdisk/beep-3.wav (100%) copy examples/dreamcast/sound/{sfx => sfxbuf}/romdisk/beep-4.wav (100%) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index bda36885..5dea7cd1 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -3,17 +3,22 @@ Platform-specific changes are prefixed with the platform name, otherwise the change is platform-independent. The name/initials of the person who is responsible for the change are listed in [square brackets] for most versions (where they are missing from early versions, assume that they should be attributed to Megan Potter). ## KallistiOS version 2.2.0 -- Added pvrtex utility by TapamN to utils [DF == Daniel Fairchild] -- Added . & .. directories to filesystems that lack it [AB] +- Added . & .. directories to filesystems that lack it [Andress Barajas == AB] - Replaced previous implementation of realpath() to remove license from AUTHORS [AB] -- Enabled hybrid PVR DR/DMA vertex submission in driver + sped up pvr_prim() [FG] -- Add thread priority boosting system [Paul Cercueil = PC] +- Enabled hybrid PVR DR/DMA vertex submission in driver + sped up pvr_prim() [Falco Girgis == FG] +- Add thread priority boosting system [Paul Cercueil == PC] - Add performance monitor API [PC] - Add/Fixed stat() implementations for all filesystems [AB] -- **Dreamcast**: Add network speedtest and pvr palette examples [AB] +- **Dreamcast**: Add pvr palette example [AB] - **Dreamcast**: Cleaned up, documented, and enhanced BIOS font API [FG] - Rework PVR hybrid mode + IRQ handling [PC] +## KallistiOS version 2.1.1 +- Added pvrtex utility by TapamN to utils [Daniel Fairchild == DF] +- **Dreamcast**: Added a set of known working purupuru bit patterns and a browsing mechanism to the rumble example [DF] +- **Dreamcast**: Added new example to demonstrate the use of the PVR to draw lines with quads (pvr/pvrline) [Jason Martin == JM] +- **Dreamcast**: Add network speedtest example [Andress Barajas == AB] + ## KallistiOS version 2.1.0 - Cleaned up generated stubs files on a make clean [Lawrence Sebald == LS] - **Dreamcast**: Added a function to detect if the program is being run on a retail Dreamcast or a Set5.xx device [LS] @@ -235,7 +240,6 @@ Platform-specific changes are prefixed with the platform name, otherwise the cha - **Dreamcast**: Update GCC 14.x toolchain profile to 14.2 [EF] - **Dreamcast**: Update GCC 11.x toolchain profile to 11.5, update Binutils to 2.43 [EF] - **Dreamcast**: Fix ARM toolchain build error when JIT is enabled for SH toolchain [EF] -- **Dreamcast**: Added a set of known working purupuru bit patterns and a browsing mechanism to the rumble example [DF == Daniel Fairchild] - Added full support for <time.h> additions from C23 standard. [FG] - Fixes mutexes not working properly [PC] - **Dreamcast**: fs_dcload: Set errno on error in dcload_stat() [PC] diff --git a/doc/RELNOTES.md b/doc/RELNOTES.md index e6f5cb12..91ffbab3 100644 --- a/doc/RELNOTES.md +++ b/doc/RELNOTES.md @@ -3,6 +3,21 @@ Copyright (C) 2002, 2003 Megan Potter Copyright (C) 2012-2019 Lawrence Sebald Copyright (C) 2024 Donald Haase +RELEASE NOTES for 2.1.1 +----------------------- + +This minor patch version is primarily aimed at fixing the versioning system +which simply didn't work as implemented in v2.1.0. Alongside that another few +dozen PRs were included that containing minor bugfixes and documentation updates. + +Also included is a new host-side util pvrtex which converts standard images +to formats used directly by the Dreamcast's PowerVR (utils/pvrtex), a significant +rewrite of wav2adpcm which converts standard sound data into the smaller ADPCM +format used by the Dreamcast's AICA (utils/wav2adpcm), an example that +demonstrates how to draw lines with quads via the pvr (pvr/pvrline), one for +testing network speed (network/speedtest) and another on how to use libADX +from kos-ports for audio playback (sound/libADX). + RELEASE NOTES for 2.1.0 ----------------------- diff --git a/environ_base.sh b/environ_base.sh index ca64b7b4..092d366f 100644 --- a/environ_base.sh +++ b/environ_base.sh @@ -18,12 +18,12 @@ export KOS_ARCH_DIR="${KOS_BASE}/kernel/arch/${KOS_ARCH}" . ${KOS_BASE}/environ_${KOS_ARCH}.sh # Add the compiler bins dir to the path if it is not already. -if [[ ":$PATH:" != *":${KOS_CC_BASE}/bin:"* ]]; then +if ! expr ":$PATH:" : ".*:${KOS_CC_BASE}/bin:.*" > /dev/null ; then export PATH="${PATH}:${KOS_CC_BASE}/bin" fi # Add the build wrappers dir to the path if it is not already. -if [[ ":$PATH:" != *":${KOS_BASE}/utils/build_wrappers:"* ]]; then +if ! expr ":$PATH:" : ".*:${KOS_BASE}/utils/build_wrappers:.*" > /dev/null ; then export PATH="${PATH}:${KOS_BASE}/utils/build_wrappers" fi diff --git a/environ_dreamcast.sh b/environ_dreamcast.sh index cc5d3700..2ae5ccb3 100644 --- a/environ_dreamcast.sh +++ b/environ_dreamcast.sh @@ -7,7 +7,7 @@ if [ -z "${DC_TOOLS_BASE}" ] ; then fi # Add the external DC tools dir to the path if it is not already. -if [[ ":$PATH:" != *":${DC_TOOLS_BASE}:"* ]]; then +if ! expr ":$PATH:" : ".*:${DC_TOOLS_BASE}:.*" > /dev/null ; then export PATH="${PATH}:${DC_TOOLS_BASE}" fi diff --git a/examples/dreamcast/sound/sfx/Makefile b/examples/dreamcast/sound/sfxbuf/Makefile similarity index 85% copy from examples/dreamcast/sound/sfx/Makefile copy to examples/dreamcast/sound/sfxbuf/Makefile index c2d38efb..d2b1cafb 100644 --- a/examples/dreamcast/sound/sfx/Makefile +++ b/examples/dreamcast/sound/sfxbuf/Makefile @@ -1,9 +1,9 @@ # KallistiOS ##version## # -# examples/dreamcast/sound/sfx/Makefile +# examples/dreamcast/sound/sfxbuf/Makefile # -TARGET = sfx.elf +TARGET = sfxbuf.elf OBJS = main.o romdisk.o KOS_ROMDISK_DIR = romdisk diff --git a/examples/dreamcast/sound/sfx/main.c b/examples/dreamcast/sound/sfxbuf/main.c similarity index 84% copy from examples/dreamcast/sound/sfx/main.c copy to examples/dreamcast/sound/sfxbuf/main.c index 7a4cf1a8..df7d8016 100644 --- a/examples/dreamcast/sound/sfx/main.c +++ b/examples/dreamcast/sound/sfxbuf/main.c @@ -36,12 +36,31 @@ int main(int argc, char **argv) { snd_init(); // Load wav files found in romdisk - // Beep wav files found in the romdisk where provided by + // 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"); + char *beep1buf; + char *beep2buf; + char *beep3buf; + char *beep4buf; + + fs_load("/rd/beep-1.wav", (void**)&beep1buf); + fs_load("/rd/beep-2.wav", (void**)&beep2buf); + fs_load("/rd/beep-3.wav", (void**)&beep3buf); + fs_load("/rd/beep-4.wav", (void**)&beep4buf); + + sfxhnd_t beep1 = snd_sfx_load_buf(beep1buf); + sfxhnd_t beep2 = snd_sfx_load_buf(beep2buf); + sfxhnd_t beep3 = snd_sfx_load_buf(beep3buf); + sfxhnd_t beep4 = snd_sfx_load_buf(beep4buf); + + if (beep1buf) + free(beep1buf); + if (beep2buf) + free(beep2buf); + if (beep3buf) + free(beep3buf); + if (beep4buf) + free(beep4buf); uint32_t current_buttons = 0; uint32_t changed_buttons = 0; @@ -53,7 +72,7 @@ int main(int argc, char **argv) { 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); @@ -67,7 +86,7 @@ int main(int argc, char **argv) { 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); @@ -107,12 +126,12 @@ int main(int argc, char **argv) { } // Unload all sound effects from sound RAM - snd_sfx_unload(beep1); + snd_sfx_unload(beep1); snd_sfx_unload(beep2); - snd_sfx_unload(beep3); + snd_sfx_unload(beep3); snd_sfx_unload(beep4); // OR - // snd_sfx_unload_all(); + // snd_sfx_unload_all(); snd_shutdown(); @@ -126,7 +145,7 @@ static void draw_instructions(uint8_t volume) { 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"); diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-1.wav b/examples/dreamcast/sound/sfxbuf/romdisk/beep-1.wav similarity index 100% copy from examples/dreamcast/sound/sfx/romdisk/beep-1.wav copy to examples/dreamcast/sound/sfxbuf/romdisk/beep-1.wav diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-2.wav b/examples/dreamcast/sound/sfxbuf/romdisk/beep-2.wav similarity index 100% copy from examples/dreamcast/sound/sfx/romdisk/beep-2.wav copy to examples/dreamcast/sound/sfxbuf/romdisk/beep-2.wav diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-3.wav b/examples/dreamcast/sound/sfxbuf/romdisk/beep-3.wav similarity index 100% copy from examples/dreamcast/sound/sfx/romdisk/beep-3.wav copy to examples/dreamcast/sound/sfxbuf/romdisk/beep-3.wav diff --git a/examples/dreamcast/sound/sfx/romdisk/beep-4.wav b/examples/dreamcast/sound/sfxbuf/romdisk/beep-4.wav similarity index 100% copy from examples/dreamcast/sound/sfx/romdisk/beep-4.wav copy to examples/dreamcast/sound/sfxbuf/romdisk/beep-4.wav diff --git a/kernel/arch/dreamcast/include/dc/sound/sfxmgr.h b/kernel/arch/dreamcast/include/dc/sound/sfxmgr.h index 39451dcd..7c49fb70 100644 --- a/kernel/arch/dreamcast/include/dc/sound/sfxmgr.h +++ b/kernel/arch/dreamcast/include/dc/sound/sfxmgr.h @@ -106,6 +106,42 @@ sfxhnd_t snd_sfx_load_ex(const char *fn, uint32_t rate, uint16_t bitsize, uint16 */ sfxhnd_t snd_sfx_load_fd(file_t fd, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels); +/** \brief Load a sound effect. + + This function loads a sound effect from a WAV file contained in memory and + returns a handle to it. The sound effect can be either stereo or mono, and + must either be 8-bit or 16-bit uncompressed PCM samples, or 4-bit Yamaha + ADPCM. + + \warning The sound effect you are loading must be at most 65534 samples + in length. + + \param buf The buffer to load. + \return A handle to the sound effect on success. On error, + SFXHND_INVALID is returned. +*/ +sfxhnd_t snd_sfx_load_buf(char *buf); + +/** \brief Load a sound effect without wav header from buffer. + + This function loads a sound effect from raw data contained in memory and + returns a handle to it. The sound effect can be either stereo or mono, and + must either be 8-bit or 16-bit uncompressed PCM samples, or 4-bit Yamaha + ADPCM. + + \warning The sound effect you are loading must be at most 65534 samples + in length and multiple by 32 bytes for each channel. + + \param buf The buffer. + \param len The file length. + \param rate The frequency of the sound. + \param bitsize The sample size (bits per sample). + \param channels Number of channels. + \return A handle to the sound effect on success. On error, + SFXHND_INVALID is returned. +*/ +sfxhnd_t snd_sfx_load_raw_buf(char *buf, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels); + /** \brief Unload a sound effect. This function unloads a previously loaded sound effect, and frees the memory diff --git a/kernel/arch/dreamcast/sound/snd_sfxmgr.c b/kernel/arch/dreamcast/sound/snd_sfxmgr.c index 54fae98e..1766216d 100644 --- a/kernel/arch/dreamcast/sound/snd_sfxmgr.c +++ b/kernel/arch/dreamcast/sound/snd_sfxmgr.c @@ -170,6 +170,54 @@ static int read_wav_header(file_t fd, wavhdr_t *wavhdr) { return 0; } +static int read_wav_header_buf(char *buf, wavhdr_t *wavhdr, size_t *bufidx) { + /* maintain buffer index during function */ + size_t tmp_bufidx = *bufidx; + + memcpy(&(wavhdr->magic), buf, sizeof(wavhdr->magic)); + tmp_bufidx += sizeof(wavhdr->magic); + + if(strncmp((const char*)wavhdr->magic.riff, "RIFF", 4)) { + dbglog(DBG_WARNING, "snd_sfx: sfx buffer is not RIFF\n"); + return -1; + } + + /* Check file magic */ + if(strncmp((const char*)wavhdr->magic.riff_format, "WAVE", 4)) { + dbglog(DBG_WARNING, "snd_sfx: sfx buffer is not RIFF WAVE\n"); + return -1; + } + + do { + /* Read the chunk header */ + memcpy(&(wavhdr->chunk), buf + tmp_bufidx, sizeof(wavhdr->chunk)); + tmp_bufidx += sizeof(wavhdr->chunk); + + /* If it is the fmt chunk, grab the fields we care about and skip the + rest of the section if there is more */ + if(strncmp((const char *)wavhdr->chunk.id, "fmt ", 4) == 0) { + memcpy(&(wavhdr->fmt), buf + tmp_bufidx, sizeof(wavhdr->fmt)); + tmp_bufidx += sizeof(wavhdr->fmt); + + /* Skip the rest of the fmt chunk */ + tmp_bufidx += wavhdr->chunk.size - sizeof(wavhdr->fmt); + } + /* If we found the data chunk, we are done */ + else if(strncmp((const char *)wavhdr->chunk.id, "data", 4) == 0) { + break; + } + /* Skip meta data */ + else { + tmp_bufidx += wavhdr->chunk.size; + } + } while(1); + + /* update buffer index for caller */ + *bufidx = tmp_bufidx; + + return 0; +} + static uint8_t *read_wav_data(file_t fd, wavhdr_t *wavhdr) { /* Allocate memory for WAV data */ uint8_t *wav_data = memalign(32, wavhdr->chunk.size); @@ -187,6 +235,26 @@ static uint8_t *read_wav_data(file_t fd, wavhdr_t *wavhdr) { return wav_data; } +static uint8_t *read_wav_data_buf(char *buf, wavhdr_t *wavhdr, size_t *bufidx) { + /* maintain buffer index during function */ + size_t tmp_bufidx = *bufidx; + + /* Allocate memory for WAV data */ + uint8_t *wav_data = memalign(32, wavhdr->chunk.size); + + if(wav_data == NULL) + return NULL; + + /* Read WAV data */ + memcpy(wav_data, buf + tmp_bufidx, wavhdr->chunk.size); + tmp_bufidx += wavhdr->chunk.size; + + /* update buffer index for caller */ + *bufidx = tmp_bufidx; + + return wav_data; +} + static snd_effect_t *create_snd_effect(wavhdr_t *wavhdr, uint8_t *wav_data) { snd_effect_t *effect; uint32_t len, rate; @@ -502,6 +570,154 @@ err_occurred: return SFXHND_INVALID; } +/* Load a sound effect from a WAV file and return a handle to it */ +sfxhnd_t snd_sfx_load_buf(char *buf) { + wavhdr_t wavhdr; + snd_effect_t *effect; + uint8_t *wav_data; + uint32_t sample_count; + size_t bufidx = 0; + + if(!buf) { + dbglog(DBG_ERROR, "snd_sfx_load_buf: can't read wav data from NULL"); + return SFXHND_INVALID; + } + + /* Read WAV header */ + if(read_wav_header_buf(buf, &wavhdr, &bufidx) < 0) { + dbglog(DBG_ERROR, "snd_sfx_load_buf: error reading wav header from buffer %08x\n", (uintptr_t)buf); + return SFXHND_INVALID; + } + /* + dbglog(DBG_DEBUG, "WAVE file is %s, %luHZ, %d bits/sample, " + "%u bytes total, format %d\n", + wavhdr.fmt.channels == 1 ? "mono" : "stereo", + wavhdr.fmt.sample_rate, + wavhdr.fmt.sample_size, + wavhdr.chunk.size, + wavhdr.fmt.format); + */ + sample_count = wavhdr.fmt.sample_size >= 8 ? + wavhdr.chunk.size / ((wavhdr.fmt.sample_size / 8) * wavhdr.fmt.channels) : + (wavhdr.chunk.size * 2) / wavhdr.fmt.channels; + + if(sample_count > 65534) { + dbglog(DBG_WARNING, "snd_sfx_load: WAVE file is over 65534 samples\n"); + } + + /* Read WAV data */ + wav_data = read_wav_data_buf(buf, &wavhdr, &bufidx); + /* Caller manages buffer, don't free here */ + if(!wav_data) + return SFXHND_INVALID; + + /* Create and initialize sound effect */ + effect = create_snd_effect(&wavhdr, wav_data); + if(!effect) { + free(wav_data); + return SFXHND_INVALID; + } + + /* Finish up and return the sound effect handle */ + free(wav_data); + LIST_INSERT_HEAD(&snd_effects, effect, list); + + return (sfxhnd_t)effect; +} + +sfxhnd_t snd_sfx_load_raw_buf(char *buf, size_t len, uint32_t rate, uint16_t bitsize, uint16_t channels) { + snd_effect_t *effect; + size_t chan_len, read_len; + uint8_t *tmp_buff = NULL; + size_t bufidx = 0; + + if(!buf) { + dbglog(DBG_ERROR, "snd_sfx_load_raw_buf: can't read PCM buffer from NULL"); + return SFXHND_INVALID; + } + + chan_len = len / channels; + effect = malloc(sizeof(snd_effect_t)); + + if(effect == NULL) { + return SFXHND_INVALID; + } + + memset(effect, 0, sizeof(snd_effect_t)); + + effect->rate = rate; + effect->stereo = channels > 1; + + switch(bitsize) { + case 4: + effect->fmt = AICA_SM_ADPCM; + effect->len = (len * 2) / channels; + break; + case 8: + effect->fmt = AICA_SM_8BIT; + effect->len = len / channels; + break; + case 16: + effect->fmt = AICA_SM_16BIT; + effect->len = (len / 2) / channels; + break; + default: + goto err_occurred; + } + + if(effect->len > 65534) { + dbglog(DBG_WARNING, "snd_sfx_load_raw_buf: PCM buffer is over 65534 samples\n"); + } + + effect->locl = snd_mem_malloc(chan_len); + + if(!effect->locl) { + goto err_occurred; + } + + read_len = chan_len; + if(read_len > 0) { + tmp_buff = memalign(32, read_len); + memcpy(tmp_buff, buf, read_len); + bufidx += read_len; + + spu_memload_sq(effect->locl, tmp_buff, read_len); + } + + if(channels > 1) { + effect->locr = snd_mem_malloc(chan_len); + + if(!effect->locr) { + goto err_occurred; + } + + read_len = chan_len; + if(read_len > 0) { + memcpy(tmp_buff, buf + bufidx, read_len); + bufidx += read_len; + spu_memload_sq(effect->locr, tmp_buff, read_len); + } + } + + if(tmp_buff) { + free(tmp_buff); + } + ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |