diff --git a/config/GM8E01_00/splits.txt b/config/GM8E01_00/splits.txt index 2864e74b..f2d7ed6e 100644 --- a/config/GM8E01_00/splits.txt +++ b/config/GM8E01_00/splits.txt @@ -4248,7 +4248,7 @@ musyx/runtime/s_data.c: .bss start:0x8055EC60 end:0x8055F260 .sbss start:0x805A9AD8 end:0x805A9AE0 -musyx/runtime/dolphin/hw_dspctrl.c: +musyx/runtime/hw_dspctrl.c: .text start:0x803AACFC end:0x803AE110 .rodata start:0x803D8A68 end:0x803D8AC0 .data start:0x803F3FA8 end:0x803F3FC0 @@ -4284,23 +4284,23 @@ musyx/runtime/snd_service.c: .data start:0x803F4278 end:0x803F4A80 .sdata start:0x805A8BD0 end:0x805A8BD8 -musyx/runtime/dolphin/hardware.c: +musyx/runtime/hardware.c: .text start:0x803B2F4C end:0x803B3F70 .rodata start:0x803D8BD0 end:0x803D8CD0 .sdata start:0x805A8BD8 end:0x805A8BE8 .sbss start:0x805A9B40 end:0x805A9B50 .sdata2 start:0x805AF398 end:0x805AF3B0 -musyx/runtime/dolphin/dsp_import.c: +musyx/runtime/dsp_import.c: .data start:0x803F4A80 end:0x803F6460 .sdata start:0x805A8BE8 end:0x805A8BF0 -musyx/runtime/dolphin/hw_aramdma.c: +musyx/runtime/hw_aramdma.c: .text start:0x803B3F70 end:0x803B4C3C .bss start:0x80566F90 end:0x805678A0 .sbss start:0x805A9B50 end:0x805A9B70 -musyx/runtime/dolphin/hw_dolphin.c: +musyx/runtime/hw_dolphin.c: .text start:0x803B4C3C end:0x803B5134 .bss start:0x805678A0 end:0x80569900 .sbss start:0x805A9B70 end:0x805A9B98 diff --git a/configure.py b/configure.py index 2f2c776a..5bb55aca 100755 --- a/configure.py +++ b/configure.py @@ -187,6 +187,7 @@ cflags_retro = [ "-gccinc", "-inline deferred,noauto", "-common on", + "-DMUSY_TARGET=MUSY_TARGET_DOLPHIN" ] cflags_musyx = [ @@ -1194,17 +1195,17 @@ config.libs = [ Object(Matching, "musyx/runtime/synth_vsamples.c"), Object(Matching, "musyx/runtime/synth_dbtab.c"), Object(Matching, "musyx/runtime/s_data.c"), - Object(NonMatching, "musyx/runtime/dolphin/hw_dspctrl.c"), + Object(NonMatching, "musyx/runtime/hw_dspctrl.c"), Object(Matching, "musyx/runtime/hw_volconv.c"), Object(Matching, "musyx/runtime/snd3d.c"), Object(Matching, "musyx/runtime/snd_init.c"), Object(Matching, "musyx/runtime/snd_math.c"), Object(NonMatching, "musyx/runtime/snd_midictrl.c"), Object(Matching, "musyx/runtime/snd_service.c"), - Object(Matching, "musyx/runtime/dolphin/hardware.c"), - Object(Matching, "musyx/runtime/dolphin/hw_aramdma.c"), - Object(Matching, "musyx/runtime/dolphin/dsp_import.c"), - Object(Matching, "musyx/runtime/dolphin/hw_dolphin.c"), + Object(Matching, "musyx/runtime/hardware.c"), + Object(Matching, "musyx/runtime/hw_aramdma.c"), + Object(Matching, "musyx/runtime/dsp_import.c"), + Object(Matching, "musyx/runtime/hw_dolphin.c"), Object(Matching, "musyx/runtime/hw_memory.c"), Object(Matching, "musyx/runtime/hw_lib_dummy.c"), Object(Matching, "musyx/runtime/CheapReverb/creverb_fx.c"), diff --git a/include/musyx/adsr.h b/include/musyx/adsr.h index 162b2dcd..0fb9dff0 100644 --- a/include/musyx/adsr.h +++ b/include/musyx/adsr.h @@ -56,7 +56,7 @@ extern "C" { #endif u32 adsrHandleLowPrecision(ADSR_VARS* adsr, u16* adsr_start, u16* adsr_delta); bool adsrRelease(ADSR_VARS* adsr); - +u32 adsrConvertTimeCents(s32 tc); #ifdef __cplusplus } #endif diff --git a/include/musyx/assert.h b/include/musyx/assert.h index adcd9ad0..b0e6a824 100644 --- a/include/musyx/assert.h +++ b/include/musyx/assert.h @@ -1,7 +1,8 @@ #ifndef _ASSERT #define _ASSERT -#include "musyx/version.h" #include "musyx/platform.h" +#include "musyx/version.h" + #if MUSY_TARGET == MUSY_TARGET_DOLPHIN extern void OSPanic(const char* file, int line, const char* msg, ...); @@ -15,9 +16,21 @@ extern void OSReport(const char* msg, ...); #endif #elif MUSY_TARGET == MUSY_TARGET_PC #include +#include +#include +#include + +static inline void panic(const char* file, int line, const char* msg, ...) { + va_list list; + va_start(list); + vprintf(msg, list); + va_end(list); + printf(" in \"%s\" on line %d.\n", file, line); + abort(); +} #ifndef MUSY_PANIC -#define MUSY_PANIC assert +#define MUSY_PANIC panic #endif #ifndef MUSY_REPORT #define MUSY_REPORT printf diff --git a/include/musyx/dsp_import.h b/include/musyx/dsp_import.h index d113f1b5..b009d756 100644 --- a/include/musyx/dsp_import.h +++ b/include/musyx/dsp_import.h @@ -1,6 +1,8 @@ #ifndef _MUSYX_DSP_IMPORT #define _MUSYX_DSP_IMPORT +#include "musyx/platform.h" +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN #include "musyx/musyx.h" #ifdef __cplusplus @@ -14,4 +16,6 @@ extern u16 dspSlaveLength; } #endif +#endif + #endif // _MUSYX_DSP_IMPORT diff --git a/include/musyx/hardware.h b/include/musyx/hardware.h index 0aa2c7a8..72a4ab36 100644 --- a/include/musyx/hardware.h +++ b/include/musyx/hardware.h @@ -2,6 +2,7 @@ #define _MUSYX_HARDWARE #include "musyx/musyx.h" +#include #ifdef __cplusplus extern "C" { @@ -14,11 +15,10 @@ extern SND_HOOKS salHooks; extern u32 dspHRTFOn; -extern u16* dspCmdList; +extern s16* dspCmdList; extern u16 dspCmdFirstSize; extern u8 dspScale2IndexTab[1024]; - u32 hwFrq2Pitch(u32 frq); void hwOff(s32 vid); bool hwIsStudioActive(u8 studio); @@ -29,6 +29,8 @@ void hwInitSamplePlayback(u32 v, u16 smpID, void* newsmp, u32 set_defadsr, u32 p u32 callbackUserValue, u32 setSRC, u8 itdMode); void hwSetVolume(u32 v, u8 table, float vol, u32 pan, u32 span, float auxa, float auxb); void hwSetPitch(u32 v, u16 speed); +void hwInitIrq(); +void hwExitIrq(); void hwEnableIrq(); void hwDisableIrq(); void* hwTransAddr(void* samples); @@ -46,8 +48,8 @@ u16 hwGetSampleID(u32 voice); u8 hwGetSampleType(u32 voice); void hwChangeStudioMix(u8 studio, u32 isMaster); void hwSetStreamLoopPS(u32 voice, u8 ps); -void hwFlushStream(void* base, u32 offset, u32 bytes, unsigned char hwStreamHandle, - void (*callback)(u32), u32 user); +void hwFlushStream(void* base, u32 offset, u32 bytes, u8 hwStreamHandle, void (*callback)(size_t), + u32 user); void hwSetSaveSampleCallback(ARAMUploadCallback callback, unsigned long chunckSize); void hwSyncSampleMem(); void hwSetAUXProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA, @@ -67,7 +69,7 @@ void hwDisableHRTF(); void hwStart(u32 v, u8 studio); void hwKeyOff(u32 v); void hwFrameDone(); -void hwActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type); +void hwActivateStudio(u8 studio, bool isMaster, SND_STUDIO_TYPE type); void hwDeactivateStudio(u8); void hwSetPriority(u32 v, u32 prio); u32 hwIsActive(u32); @@ -82,13 +84,17 @@ void hwIRQLeaveCritical(); extern u32 aramSize; extern u8* aramBase; -unsigned long aramGetStreamBufferAddress(unsigned char id, unsigned long* len); -u32 aramGetStreamBufferAddress(u8 id, u32* len); -void aramUploadData(void* mram, u32 aram, u32 len, u32 highPrio, void (*callback)(u32), u32 user); +void aramInit(u32 length); +void aramExit(); +size_t aramGetStreamBufferAddress(u8 id, size_t* len); +void aramUploadData(void* mram, u32 aram, u32 len, u32 highPrio, void (*callback)(size_t), u32 user); void aramFreeStreamBuffer(u8 id); void* aramStoreData(void* src, u32 len); void aramRemoveData(void* aram, u32 len); u8 aramAllocateStreamBuffer(u32 len); +unsigned long aramGetZeroBuffer(); +void aramSetUploadCallback(ARAMUploadCallback callback, u32 chunckSize); +void aramSyncTransferQueue(); #ifdef __cplusplus } diff --git a/include/musyx/musyx.h b/include/musyx/musyx.h index ccf39eed..a8b9ff89 100644 --- a/include/musyx/musyx.h +++ b/include/musyx/musyx.h @@ -1,15 +1,17 @@ #ifndef _MUSYX_MUSYX #define _MUSYX_MUSYX -#include "musyx/version.h" #include "musyx/platform.h" +#include "musyx/version.h" #include +#include #ifdef __cplusplus extern "C" { #endif +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN typedef signed char s8; typedef unsigned char u8; typedef signed short s16; @@ -19,6 +21,17 @@ typedef unsigned long u32; typedef unsigned long long u64; typedef float f32; typedef double f64; +#elif MUSY_TARGET == MUSY_TARGET_PC +typedef signed char s8; +typedef unsigned char u8; +typedef signed short s16; +typedef unsigned short u16; +typedef signed int s32; +typedef unsigned int u32; +typedef unsigned long long u64; +typedef float f32; +typedef double f64; +#endif #ifndef NULL #define NULL 0 @@ -28,10 +41,17 @@ typedef double f64; typedef unsigned char bool8; #endif #ifndef __cplusplus +#if __STDC_VERSION__ <= 199901L typedef unsigned long bool; +#endif + +#ifndef FALSE #define FALSE 0 +#endif +#ifndef TRUE #define TRUE 1 #endif +#endif #define SND_STUDIO_MAXNUM 8 @@ -40,10 +60,6 @@ typedef unsigned long bool; #define SYNTH_MAX_VOICES 64 -typedef struct SND_ADPCMSTREAM_INFO { - s16 coefTab[8][2]; // Table of coef. pairs -} SND_ADPCMSTREAM_INFO; - typedef u32 SND_SEQID; typedef u32 SND_VOICEID; typedef u32 SND_STREAMID; @@ -54,7 +70,7 @@ typedef u16 SND_FXID; typedef enum { SND_OUTPUTMODE_MONO = 0, SND_OUTPUTMODE_STEREO, - SND_OUTPUTMODE_SURROUND, + SND_OUTPUTMODE_SURROUND } SND_OUTPUTMODE; typedef struct SND_PLAYBACKINFO { @@ -78,172 +94,52 @@ typedef struct SND_SEQVOLDEF { #define SND_PLAYPARA_PAUSE 0x00000010 typedef struct SND_PLAYPARA { - u32 flags; - u32 trackMute[2]; - u16 speed; - struct { + u32 flags; // Enable features by using these flags + u32 trackMute[2]; // Initial mute settings + u16 speed; // Initial speed factor (0x100 = 1:1) + struct { // Start volume information u16 time; u8 target; } volume; - u8 numSeqVolDef; - SND_SEQVOLDEF* seqVolDef; - u8 numFaded; - u8* faded; + u8 numSeqVolDef; // Number of non-standart volume group tracks + SND_SEQVOLDEF* seqVolDef; // List of tracks and the volume groups to be assigned to them + u8 numFaded; // Number of entries to the fade list + u8* faded; // Array of u8s containing the volume group IDs that should be affected by the initial + // volume setting (default will always be affected) } SND_PLAYPARA; -typedef struct SND_HOOKS { - void* (*malloc)(u32 len); - void (*free)(void* addr); -} SND_HOOKS; +#define SND_CROSSFADE_STOP 0 // Stop old song after fadedown +#define SND_CROSSFADE_PAUSE 1 // Pause old song after fadedown +#define SND_CROSSFADE_CONTINUE 2 // Continue previously paused song as new one +#define SND_CROSSFADE_START 0 // Start new song (no continue) +#define SND_CROSSFADE_SYNC 4 // Crossfade should start syncronized by sync-controller (104) +#define SND_CROSSFADE_PAUSENEW 8 // Pause new song before even starting it +#define SND_CROSSFADE_TRACKMUTE 16 // Use trackmute informtion +#define SND_CROSSFADE_SPEED 32 // Use speed informtion +#define SND_CROSSFADE_MUTE 64 // Old song continues playing & gets muted after fade down +#define SND_CROSSFADE_MUTENEW 128 // Mute new song after starting it -void sndSetHooks(SND_HOOKS* hooks); +#define SND_CROSSFADE_DEFAULT 0 -typedef struct SND_FVECTOR { - f32 x; - f32 y; - f32 z; -} SND_FVECTOR; +typedef struct SND_CROSSFADE { + SND_SEQID seqId1; + u16 time1; -typedef struct SND_FMATRIX { - f32 m[3][3]; - f32 t[3]; -} SND_FMATRIX; + SND_SEQID seqId2; + u16 time2; + void* arr2; + SND_GROUPID gid2; + SND_SONGID sid2; + u8 vol2; + u8 studio2; -typedef struct SND_PARAMETER { - u8 ctrl; - union { - u8 value7; - u16 value14; - } paraData; -} SND_PARAMETER; + u32 trackMute2[2]; // Mute bits (see sndMute()) + u16 speed2; // Initial speed (of new song) -typedef struct SND_PARAMETER_INFO { - u8 numPara; - SND_PARAMETER* paraArray; + u8 flags; +} SND_CROSSFADE; -} SND_PARAMETER_INFO; - -typedef struct SND_STUDIO_INPUT { - // total size: 0x4 - u8 vol; // offset 0x0, size 0x1 - u8 volA; // offset 0x1, size 0x1 - u8 volB; // offset 0x2, size 0x1 - u8 srcStudio; // offset 0x3, size 0x1 -} SND_STUDIO_INPUT; - -typedef struct SND_ROOM { - struct SND_ROOM* next; - struct SND_ROOM* prev; - - u32 flags; - SND_FVECTOR pos; - f32 distance; - - u8 studio; - - void (*activateReverb)(u8 studio, void* para); - void (*deActivateReverb)(u8 studio); - void* user; - - u32 curMVol; -} SND_ROOM; - -typedef struct SND_DOOR { - struct SND_DOOR* next; - struct SND_DOOR* prev; - - SND_FVECTOR pos; - - f32 open; - f32 dampen; - u8 fxVol; - - u8 destStudio; - - SND_ROOM* a; - SND_ROOM* b; - - u32 flags; - - s16 filterCoef[4]; - SND_STUDIO_INPUT input; -} SND_DOOR; - -#define SND_DOOR_A2B 0x00000000 -#define SND_DOOR_B2A 0x00000001 - -#define SND_DOOR_DEFAULT SND_DOOR_A2B - -typedef struct SND_LISTENER { - struct SND_LISTENER* next; - struct SND_LISTENER* prev; - SND_ROOM* room; - - u32 flags; - SND_FVECTOR pos; - f32 volPosOff; - SND_FVECTOR dir; - SND_FVECTOR heading; - SND_FVECTOR right; - SND_FVECTOR up; - SND_FMATRIX mat; - f32 surroundDisFront; - f32 surroundDisBack; - f32 soundSpeed; - f32 vol; -} SND_LISTENER; - -#define SND_LISTENER_DEFAULT 0x00000000 -#define SND_LISTENER_DOPPLERFX 0x00000001 - -typedef struct SND_EMITTER { - struct SND_EMITTER* next; - struct SND_EMITTER* prev; - SND_ROOM* room; - - SND_PARAMETER_INFO* paraInfo; - - u32 flags; - SND_FVECTOR pos; - SND_FVECTOR dir; - f32 maxDis; - f32 maxVol; - f32 minVol; - f32 volPush; - SND_VOICEID vid; - u32 group; - SND_FXID fxid; - - u8 studio; - - u8 maxVoices; - - u16 VolLevelCnt; - f32 fade; - -} SND_EMITTER; - -#define SND_EMITTER_DEFAULTKEY 0xFF -#define SND_EMITTER_DEFAULTVOL 0xFF - -#define SND_EMITTER_DEFAULT 0x00000000 -#define SND_EMITTER_CONTINOUS 0x00000001 -#define SND_EMITTER_CONTINUOUS 0x00000001 -#define SND_EMITTER_RESTARTABLE 0x00000002 -#define SND_EMITTER_PAUSABLE 0x00000004 -#define SND_EMITTER_DOPPLERFX 0x00000008 -#define SND_EMITTER_ITD 0x00000010 -#define SND_EMITTER_HARDSTART 0x00000020 -#define SND_EMITTER_NOSILENTSTART 0x00000040 - -s32 sndInit(u8 voices, u8 music, u8 sfx, u8 studios, u32 flags, u32 aramSize); -void sndQuit(void); - -bool sndIsInstalled(); -u32 sndIsIdle(); -SND_PLAYBACKINFO* sndGetPlayBackInfo(); - -void sndSetMaxVoices(u8 music, u8 sfx); +#define SND_ID_ERROR 0xFFFFFFFF // ID is invalid #define SND_USERMUSIC_VOLGROUPS 0xFA #define SND_USERFX_VOLGROUPS 0xFB @@ -254,22 +150,263 @@ void sndSetMaxVoices(u8 music, u8 sfx); #define SND_MAX_USER_VOLGROUP 20 +bool sndPushGroup(void* prj_data, SND_GROUPID gid, void* samples, void* sampdir, void* pool); +bool sndPopGroup(void); + +void sndSetSampleDataUploadCallback(void* (*callback)(u32 offset, u32 bytes), u32 chunkSize); + +typedef struct SND_HOOKS { + void* (*malloc)(size_t addr); + void (*free)(void* addr); +} SND_HOOKS; + +void sndSetHooks(SND_HOOKS* hooks); + +// Misc flags to influence the way the sound system works internally +// (support may vary from platform to platform) + +#define SND_FLAGS_DEFAULT 0x00000000 +#define SND_FLAGS_DEFAULT_STUDIO_DPL2 0x00000001 // Use DPL2 encoding for default studio +#define SND_FLAGS_EMITTERGROUPSUSEMAXVOICES \ + 0x00000002 // define this to enable usage of max. voices from FX table for emitter group start + // management + +// Platform dependend flags : PC + +#define SND_FLAGS_PC_USE_TIMER \ + 0x00000000 // Use timer driven update system (less performance hit, larger latency) +#define SND_FLAGS_PC_USE_THREAD \ + 0x00010000 // Use thread driven update system (larger performance hit, shorter latency) +#define SND_FLAGS_PC_USE_PRIMARY 0x00020000 // Use a primary sound buffer for mixing (Win95/98 only) + +#define SND_FLAGS_PC_LATENCY0 0x00000000 // Latency values (see documentation) +#define SND_FLAGS_PC_LATENCY1 0x10000000 +#define SND_FLAGS_PC_LATENCY2 0x20000000 +#define SND_FLAGS_PC_LATENCY3 0x30000000 +#define SND_FLAGS_PC_LATENCY4 0x40000000 +#define SND_FLAGS_PC_LATENCY5 0x50000000 +#define SND_FLAGS_PC_LATENCY6 0x60000000 +#define SND_FLAGS_PC_LATENCY7 0x70000000 + +s32 sndInit(u8 voices, u8 music, u8 sfx, u8 studios, u32 flags, u32 aramSize); +void sndQuit(void); + +bool sndIsInstalled(void); +bool sndIsIdle(void); +SND_PLAYBACKINFO* sndGetPlayBackInfo(void); + +void sndSetMaxVoices(u8 music, u8 sfx); + void sndVolume(u8 volume, u16 time, u8 volGroup); void sndMasterVolume(u8 volume, u16 time, u8 music, u8 fx); void sndOutputMode(SND_OUTPUTMODE mode); -void sndSilence(); +void sndSilence(void); -#define SND_AUX_NUMPARAMETERS 4 +#define SND_PAUSEVOL_NORMAL 127 + +void sndPauseVolume(u8 mute_vol, u16 time, u8 volGroup); + +#define SND_MIDICTRL_MODULATION 0x01 +#define SND_MIDICTRL_VOLUME 0x07 +#define SND_MIDICTRL_PANNING 0x0A +#define SND_MIDICTRL_PEDAL 0x40 +#define SND_MIDICTRL_PORTAMENTO 0x41 +#define SND_MIDICTRL_REVERB 0x5B +#define SND_MIDICTRL_CHORUS 0x5D + +#define SND_MIDICTRL_PITCHBEND 0x80 +#define SND_MIDICTRL_SPANNING 0x83 +#define SND_MIDICTRL_DOPPLER 0x84 + +#define SND_SEQVOL_CONTINUE 0 +#define SND_SEQVOL_STOP 1 +#define SND_SEQVOL_PAUSE 2 +#define SND_SEQVOL_MUTE 3 +#define SND_SEQVOL_MODEMASK 0xF + +#define SND_ID_ERROR 0xFFFFFFFF // ID is invalid + +#define SND_MAX_SEQINSTANCES 8 +#define SND_SEQ_ERROR_ID 0xFFFFFFFF +#define SND_SEQ_CROSSFADE_ID 0x80000000 + +#define SND_PAUSEVOL_NORMAL 127 +#define SND_SEQVOL_CONTINUE 0 +#define SND_SEQVOL_STOP 1 +#define SND_SEQVOL_PAUSE 2 +#define SND_SEQVOL_MUTE 3 + +#define sndSeqPlay(sgid, sid, arrfile, para) \ + sndSeqPlayEx(sgid, sid, arrfile, para, SND_STUDIO_DEFAULT) +SND_SEQID sndSeqPlayEx(SND_GROUPID sgid, SND_SONGID sid, void* arrfile, SND_PLAYPARA* para, + u8 studio); + +void sndSeqStop(SND_SEQID seqId); +void sndSeqPause(SND_SEQID seqId); +void sndSeqContinue(SND_SEQID seqId); +void sndSeqMute(SND_SEQID seqId, u32 mask1, u32 mask2); +void sndSeqSpeed(SND_SEQID seqId, u16 speed); +bool sndSeqLoop(SND_SEQID seqId, bool on); +bool sndSeqLoopEx(SND_SEQID seqId, u8 track, bool on); +u16 sndSeqGetLoopCnt(SND_SEQID seqId); +u16 sndSeqGetLoopCntEx(SND_SEQID seqId, u8 track); +bool sndSeqGetValid(SND_SEQID seqId); +u8 sndSeqGetMidiCtrl(SND_SEQID seqId, u8 channel, u8 ctrl); +u16 sndSeqGetMidiCtrl14(SND_SEQID seqId, u8 channel, u8 ctrl); +bool sndSeqSetMidiCtrl(SND_SEQID seqId, u8 channel, u8 ctrl, u8 value); +bool sndSeqSetMidiCtrl14(SND_SEQID seqId, u8 channel, u8 ctrl, u16 value); + +void sndSeqVolume(u8 volume, u16 time, SND_SEQID seqId, u8 mode); +u8 sndSeqGetVolGroup(SND_SEQID seqId); +bool sndSeqAssignVolGroup2Track(SND_SEQID seqId, u8 track, u8 vGroup); +void sndSeqCrossFade(SND_CROSSFADE* ci, SND_SEQID* new_seqId); +bool sndSeqCrossFadeDone(SND_SEQID* new_seqId); + +typedef struct SND_PARAMETER { + u8 ctrl; + union _paraData { + u8 value7; + u16 value14; + } paraData; +} SND_PARAMETER; + +typedef struct SND_PARAMETER_INFO { + u8 numPara; // How many MIDI controller values (ID,value - value may be 8-bit or 16-bit!) + SND_PARAMETER* paraArray; // Parameter data... +} SND_PARAMETER_INFO; + +#define SND_FX_DEFVOL 0xFF +#define SND_FX_DEFPAN 0xFF + +#define sndFXStart(fid, vol, pan) sndFXStartEx(fid, vol, pan, SND_STUDIO_DEFAULT) +SND_VOICEID sndFXStartEx(SND_FXID fid, u8 vol, u8 pan, u8 studio); +SND_VOICEID sndFXStartPara(SND_FXID fid, u8 vol, u8 pan, u8 studio, u8 numPara, ...); +SND_VOICEID sndFXStartParaInfo(SND_FXID fid, u8 vol, u8 pan, u8 studio, + SND_PARAMETER_INFO* paraInfo); +SND_VOICEID sndFXCheck(SND_VOICEID vid); +bool sndFXKeyOff(SND_VOICEID vid); +bool sndFXCtrl(SND_VOICEID vid, u8 ctrl, u8 value); +bool sndFXCtrl14(SND_VOICEID vid, u8 ctrl, u16 value); + +#define SND_MIDICTRL_MODULATION 0x01 +#define SND_MIDICTRL_VOLUME 0x07 +#define SND_MIDICTRL_PANNING 0x0A +#define SND_MIDICTRL_PEDAL 0x40 +#define SND_MIDICTRL_PORTAMENTO 0x41 +#define SND_MIDICTRL_REVERB 0x5B +#define SND_MIDICTRL_CHORUS 0x5D + +#define SND_MIDICTRL_PITCHBEND 0x80 +#define SND_MIDICTRL_SPANNING 0x83 +#define SND_MIDICTRL_DOPPLER 0x84 + +#define sndFXPitchBend(vid, pb) sndFXCtrl14(vid, SND_MIDICTRL_PITCHBEND, pb) +#define sndFXModulation(vid, modu) sndFXCtrl14(vid, SND_MIDICTRL_MODULATION, modu) +#define sndFXDoppler(vid, doppler) sndFXCtrl14(vid, SND_MIDICTRL_DOPPLER, doppler) + +#define sndFXReverb(vid, reverb) sndFXCtrl(vid, SND_MIDICTRL_REVERB, reverb) +#define sndFXChorus(vid, chorus) sndFXCtrl(vid, SND_MIDICTRL_CHORUS, chorus) +#define sndFXPedal(vid, pedal) sndFXCtrl(vid, SND_MIDICTRL_PEDAL, pedal) +#define sndFXVolume(vid, vol) sndFXCtrl(vid, SND_MIDICTRL_VOLUME, vol) +#define sndFXPanning(vid, pan) sndFXCtrl(vid, SND_MIDICTRL_PANNING, pan) +#define sndFXSurroundPanning(vid, span) sndFXCtrl(vid, SND_MIDICTRL_SPANNING, span) + +bool sndFXAssignVolGroup2FXId(SND_FXID fid, u8 vGroup); + +// -------------------------------------------------------- + +s32 sndReadFlag(u8 num); +s32 sndWriteFlag(u8 num, s32 value); + +bool sndSendMessage(SND_VOICEID vid, s32 mesg); +void sndSetReceiveMessageCallback(void (*callback)(SND_VOICEID vid, s32 mesg)); + +// -------------------------------------------------------- + +// Flags +#define SND_STREAM_DEFAULT 0x00000000 // Default stream buffer (PCM16) +#define SND_STREAM_ADPCM 0x00000001 // ADPCM stream buffer +#define SND_STREAM_INACTIVE 0x00010000 // Allocate stream, but do not start it yet +#define SND_STREAM_MANUALARAMUPD 0x00020000 // Application will provide manual ARAM buffer updates + +#define SND_STREAM_ADPCM_BLKBYTES 8 // Bytes per ADPCM block +#define SND_STREAM_ADPCM_BLKSIZE 14 // Samples per ADPCM block + +// ADPCM info structure +typedef struct SND_ADPCMSTREAM_INFO { + s16 coefTab[8][2]; // Table of coef. pairs +} SND_ADPCMSTREAM_INFO; + +#define sndStreamAlloc(prio, buffer, size, frq, vol, pan, span, fxvol, updateFunction, user) \ + sndStreamAllocEx(prio, buffer, size, frq, vol, pan, span, fxvol, 0, SND_STUDIO_DEFAULT, \ + SND_STREAM_DEFAULT, updateFunction, user, NULL) +SND_STREAMID sndStreamAllocEx(u8 prio, void* buffer, u32 samples, u32 frq, u8 vol, u8 pan, u8 span, + u8 auxa, u8 auxb, u8 studio, u32 flags, + u32 (*updateFunction)(void* buffer1, u32 len1, void* buffer2, + u32 len2, u32 user), + u32 user, SND_ADPCMSTREAM_INFO* adpcmInfo); +SND_STREAMID sndStreamAllocStereo(u8 prio, void* lBuffer, void* rBuffer, u32 samples, u32 frq, + u8 vol, u8 pan, u8 span, u8 auxa, u8 auxb, u8 studio, u32 flags, + u32 (*updateFunction)(void* buffer1, u32 len1, void* buffer2, + u32 len2, u32 user), + u32 lUser, u32 rUser, SND_ADPCMSTREAM_INFO* adpcmInfoL, + SND_ADPCMSTREAM_INFO* adpcmInfoR); +u32 sndStreamAllocLength(u32 num, u32 flags); +void sndStreamFree(SND_STREAMID stid); +void sndStreamMixParameter(SND_STREAMID stid, u8 vol, u8 pan, u8 span, u8 fxvol); +void sndStreamMixParameterEx(SND_STREAMID stid, u8 vol, u8 pan, u8 span, u8 auxa, u8 auxb); +void sndStreamADPCMParameter(SND_STREAMID stid, SND_ADPCMSTREAM_INFO* adpcmInfo); +void sndStreamFrq(SND_STREAMID stid, u32 frq); +bool sndStreamActivate(SND_STREAMID stid); +void sndStreamDeactivate(SND_STREAMID stid); +void sndStreamARAMUpdate(SND_STREAMID stid, u32 off1, u32 len1, u32 off2, u32 len2); +u32 sndStreamCallbackFrq(u32 msTime); + +// -------------------------------------------------------- + +#define SND_VIRTUALSAMPLE_DEFAULT 0x00000000 + +bool sndVirtualSampleAllocateBuffers(u8 numInstances, u32 numSamples, u32 flags); +void sndVirtualSampleFreeBuffers(void); + +typedef u16 SND_VSID; // Virtual sample ID +typedef u16 SND_INSTID; // Virtual sample instance ID + +typedef struct SND_VIRTUALSAMPLE_INFO { + SND_VSID smpID; // ID of sample to be streamed + SND_INSTID instID; // ID of this instance of the stream + + union vsData { + struct vsUpdate { // Buffer update info + u32 off1; + u32 len1; + u32 off2; + u32 len2; + } update; + } data; +} SND_VIRTUALSAMPLE_INFO; + +#define SND_VIRTUALSAMPLE_REASON_INIT 0 // Virtual sample just started playback +#define SND_VIRTUALSAMPLE_REASON_UPDATE 1 // Virtual sample is within stream buffer and needs data +#define SND_VIRTUALSAMPLE_REASON_STOP 2 // Virtual sample just has been stopped +#define SND_VIRTUALSAMPLE_REASON_ARAMDMADONE \ + 3 // Last ARAM update initiated for this virtual sample has finished + +void sndVirtualSampleSetCallback(u32 (*callback)(u8 reason, const SND_VIRTUALSAMPLE_INFO* info)); + +void sndVirtualSampleARAMUpdate(SND_INSTID instID, void* base, u32 off1, u32 len1, u32 off2, + u32 len2); + +void sndVirtualSampleEndPlayback(SND_INSTID instID, bool sampleEndedNormally); + +#define SND_AUX_BLOCKSIZE 160 // Size of block passed to the AUX FX hanler (in samples) #define SND_AUX_REASON_BUFFERUPDATE 0 #define SND_AUX_REASON_PARAMETERUPDATE 1 -typedef enum { - SND_STUDIO_TYPE_STD = 0, - SND_STUDIO_TYPE_RESERVED0 = 1, - SND_STUDIO_TYPE_RESERVED1 = 2, - SND_STUDIO_TYPE_RESERVED2 = 3, -} SND_STUDIO_TYPE; +#define SND_MIDI_NONE 0xFF + +#define SND_AUX_NUMPARAMETERS 4 typedef struct SND_AUX_INFO { union SND_AUX_DATA { @@ -284,6 +421,73 @@ typedef struct SND_AUX_INFO { } data; } SND_AUX_INFO; +void sndSetAuxProcessingCallbacks(u8 studio, + void (*auxA)(u8 reason, SND_AUX_INFO* info, void* user), + void* userA, u8 midiA, SND_SEQID seqIDA, + void (*auxB)(u8 reason, SND_AUX_INFO* info, void* user), + void* userB, u8 midiB, SND_SEQID seqIDB); + +#define SND_AUXA_PARAMETERS 0 +#define SND_AUXB_PARAMETERS 1 + +void sndUpdateAuxParameter(u8 studio, u16 para[SND_AUX_NUMPARAMETERS], u8 auxBus); + +typedef enum { + SND_STUDIO_TYPE_STD = 0, + SND_STUDIO_TYPE_DPL2, + SND_STUDIO_TYPE_RESERVED1, + SND_STUDIO_TYPE_RESERVED2 +} SND_STUDIO_TYPE; + +#define sndActivateStudio(studio, isMaster) \ + sndActivateStudioEx(studio, isMaster, SND_STUDIO_TYPE_STD) +void sndActivateStudioEx(u8 studio, bool isMaster, SND_STUDIO_TYPE type); +void sndChangeStudioMasterMix(u8 studio, bool isMaster); +void sndDeactivateStudio(u8 studio); +void sndSetITDDefault(u8 studio, bool musicITD, bool sfxITD); + +// Standard Quality Reverb AUX FX + +typedef struct _SND_REVSTD_DELAYLINE { + s32 inPoint; + s32 outPoint; + s32 length; + f32* inputs; + f32 lastOutput; +} _SND_REVSTD_DELAYLINE; + +typedef struct _SND_REVSTD_WORK { + _SND_REVSTD_DELAYLINE AP[6]; + _SND_REVSTD_DELAYLINE C[6]; + f32 allPassCoeff; + f32 combCoef[6]; + f32 lpLastout[3]; + f32 level; + f32 damping; + s32 preDelayTime; + f32* preDelayLine[3]; + f32* preDelayPtr[3]; +} _SND_REVSTD_WORK; + +typedef struct SND_AUX_REVERBSTD { + _SND_REVSTD_WORK rv; + bool8 tempDisableFX; + + f32 coloration; + f32 mix; + f32 time; + f32 damping; + f32 preDelay; +} SND_AUX_REVERBSTD; + +typedef void (*SND_AUX_CALLBACK)(u8 reason, SND_AUX_INFO* info, void* user); +void sndAuxCallbackReverbSTD(u8 reason, SND_AUX_INFO* info, void* user); +bool sndAuxCallbackPrepareReverbSTD(SND_AUX_REVERBSTD* rev); +bool sndAuxCallbackShutdownReverbSTD(SND_AUX_REVERBSTD* rev); +bool sndAuxCallbackUpdateSettingsReverbSTD(SND_AUX_REVERBSTD* rev); + +// High Quality Reverb AUX FX +// typedef struct _SND_REVHI_DELAYLINE { s32 inPoint; s32 outPoint; @@ -321,7 +525,10 @@ typedef struct SND_AUX_REVERBHI { void sndAuxCallbackReverbHI(u8 reason, SND_AUX_INFO* info, void* user); bool sndAuxCallbackPrepareReverbHI(SND_AUX_REVERBHI* rev); bool sndAuxCallbackShutdownReverbHI(SND_AUX_REVERBHI* rev); +bool sndAuxCallbackUpdateSettingsReverbHI(SND_AUX_REVERBHI* rev); +// Delay AUX FX +// typedef struct SND_AUX_DELAY { u32 currentSize[3]; u32 currentPos[3]; @@ -332,66 +539,20 @@ typedef struct SND_AUX_DELAY { s32* right; s32* sur; + // - - - - - - - - - - - + u32 delay[3]; // Delay buffer length in ms per channel u32 feedback[3]; // Feedback volume in % per channel u32 output[3]; // Output volume in % per channel } SND_AUX_DELAY; -typedef void (*SND_AUX_CALLBACK)(u8 reason, SND_AUX_INFO* info, void* user); - void sndAuxCallbackDelay(u8 reason, SND_AUX_INFO* info, void* user); +bool sndAuxCallbackPrepareDelay(SND_AUX_DELAY* delay); +bool sndAuxCallbackShutdownDelay(SND_AUX_DELAY* delay); bool sndAuxCallbackUpdateSettingsDelay(SND_AUX_DELAY* delay); -bool sndAuxCallbackPrepareDelay(SND_AUX_DELAY* rev); -bool sndAuxCallbackShutdownDelay(SND_AUX_DELAY* rev); -bool sndAuxCallbackUpdateSettingsReverbHI(SND_AUX_REVERBHI* rev); -typedef struct _SND_REVSTD_DELAYLINE { - s32 inPoint; - s32 outPoint; - s32 length; - f32* inputs; - f32 lastOutput; -} _SND_REVSTD_DELAYLINE; +// Chorus AUX FX -typedef struct _SND_REVSTD_WORK { - _SND_REVSTD_DELAYLINE AP[6]; - _SND_REVSTD_DELAYLINE C[6]; - f32 allPassCoeff; - f32 combCoef[6]; - f32 lpLastout[3]; - f32 level; - f32 damping; - s32 preDelayTime; - f32* preDelayLine[3]; - f32* preDelayPtr[3]; -} _SND_REVSTD_WORK; - -typedef struct SND_AUX_REVERBSTD { - _SND_REVSTD_WORK rv; - bool8 tempDisableFX; - - f32 coloration; - f32 mix; - f32 time; - f32 damping; - f32 preDelay; -} SND_AUX_REVERBSTD; - -void sndAuxCallbackReverbSTD(u8 reason, SND_AUX_INFO* info, void* user); -bool sndAuxCallbackPrepareReverbSTD(SND_AUX_REVERBSTD* rev); -bool sndAuxCallbackShutdownReverbSTD(SND_AUX_REVERBSTD* rev); -bool sndAuxCallbackUpdateSettingsReverbSTD(SND_AUX_REVERBSTD* rev); - -#define sndFXStart(fid, vol, pan) sndFXStartEx(fid, vol, pan, SND_STUDIO_DEFAULT) -SND_VOICEID sndFXStartEx(SND_FXID fid, u8 vol, u8 pan, u8 studio); -SND_VOICEID sndFXStartPara(SND_FXID fid, u8 vol, u8 pan, u8 studio, u8 numPara, ...); -SND_VOICEID sndFXStartParaInfo(SND_FXID fid, u8 vol, u8 pan, u8 studio, - SND_PARAMETER_INFO* paraInfo); -SND_VOICEID sndFXCheck(SND_VOICEID vid); -bool sndFXKeyOff(SND_VOICEID vid); -bool sndFXCtrl(SND_VOICEID vid, u8 ctrl, u8 value); -bool sndFXCtrl14(SND_VOICEID vid, u8 ctrl, u16 value); -#define _SND_CHORUS_NUM_BLOCKS 3 typedef struct _SND_CHORUS_SRCINFO { s32* dest; s32* smpBase; @@ -404,6 +565,8 @@ typedef struct _SND_CHORUS_SRCINFO { u32 target; } _SND_CHORUS_SRCINFO; +#define _SND_CHORUS_NUM_BLOCKS 3 + typedef struct _SND_CHORUS_WORK { s32* lastLeft[_SND_CHORUS_NUM_BLOCKS]; s32* lastRight[_SND_CHORUS_NUM_BLOCKS]; @@ -425,9 +588,10 @@ typedef struct _SND_CHORUS_WORK { typedef struct SND_AUX_CHORUS { _SND_CHORUS_WORK work; - u32 baseDelay; - u32 variation; - u32 period; + + u32 baseDelay; // Base delay of chorus effect in ms + u32 variation; // Variation of base delay in ms + u32 period; // Period of variational oscilation in ms } SND_AUX_CHORUS; void sndAuxCallbackChorus(u8 reason, SND_AUX_INFO* info, void* user); @@ -435,36 +599,218 @@ bool sndAuxCallbackPrepareChorus(SND_AUX_CHORUS* ch); bool sndAuxCallbackShutdownChorus(SND_AUX_CHORUS* ch); bool sndAuxCallbackUpdateSettingsChorus(SND_AUX_CHORUS* ch); -#define SND_CROSSFADE_STOP 0x0 // Stop old song after fadedown -#define SND_CROSSFADE_PAUSE 0x1 // Pause old song after fadedown -#define SND_CROSSFADE_CONTINUE 0x2 // Continue previously paused song as new one -#define SND_CROSSFADE_START 0x0 // Start new song (no continue) -#define SND_CROSSFADE_SYNC 0x4 // Crossfade should start syncronized by sync-controller (104) -#define SND_CROSSFADE_PAUSENEW 0x8 // Pause new song before even starting it -#define SND_CROSSFADE_TRACKMUTE 0x10 // Use trackmute informtion -#define SND_CROSSFADE_SPEED 0x20 // Use speed informtion -#define SND_CROSSFADE_MUTE 0x40 // Old song continues playing & gets muted after fade down -#define SND_CROSSFADE_MUTENEW 0x80 // Mute new song after starting it +// Studio linkage +typedef struct SND_STUDIO_INPUT { + u8 vol; + u8 volA; + u8 volB; + u8 srcStudio; +} SND_STUDIO_INPUT; -#define SND_CROSSFADE_DEFAULT 0 +bool sndAddStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc); +bool sndRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc); -typedef struct SND_CROSSFADE { - SND_SEQID seqId1; - u16 time1; +// 3D API - SND_SEQID seqId2; - u16 time2; - void* arr2; - SND_GROUPID gid2; - SND_SONGID sid2; - u8 vol2; - u8 studio2; +typedef struct SND_FVECTOR { + f32 x; + f32 y; + f32 z; +} SND_FVECTOR; - u32 trackMute2[2]; - u16 speed2; +typedef struct SND_FMATRIX { + f32 m[3][3]; + f32 t[3]; +} SND_FMATRIX; - u8 flags; -} SND_CROSSFADE; +typedef struct SND_ROOM { + struct SND_ROOM* next; + struct SND_ROOM* prev; + + u32 flags; + SND_FVECTOR pos; // World "position" of room + f32 distance; // Average distance to listeners (squared) + + u8 studio; + + void (*activateReverb)(u8 studio, void* para); // Callbacks to activate/deactivate "reverb" (AuxA) + void (*deActivateReverb)(u8 studio); // (NULL -> none) + void* user; // Pointer to user data (e.g. "reverb" parameters) + + u32 curMVol; // Current master mix volume (7.16) +} SND_ROOM; + +typedef struct SND_DOOR { + struct SND_DOOR* next; + struct SND_DOOR* prev; + + SND_FVECTOR pos; // Position of door + + f32 open; // State (0=closed, 1=open) + f32 dampen; // Dampening when closed (0=none, 1=full) + u8 fxVol; // FX mix volume of this door (0-127) + + u8 destStudio; // When active: Studio the input is linked to + + SND_ROOM* a; // Rooms to be linked + SND_ROOM* b; + + u32 flags; // Flags + + s16 filterCoef[4]; // Coefs of the 4 tab FIR filter (0x7FFF = 1.0) + SND_STUDIO_INPUT input; // Input info (when active) +} SND_DOOR; + +#define SND_DOOR_A2B 0x00000000 // Door leads from A to B +#define SND_DOOR_B2A 0x00000001 // Door leads from B to A + +#define SND_DOOR_DEFAULT SND_DOOR_A2B + +typedef struct SND_LISTENER { + struct SND_LISTENER* next; + struct SND_LISTENER* prev; + SND_ROOM* room; + + u32 flags; + SND_FVECTOR pos; + f32 volPosOff; // (reserved for future use) + SND_FVECTOR dir; // Speed in units/second + SND_FVECTOR heading; + SND_FVECTOR right; + SND_FVECTOR up; + SND_FMATRIX mat; + f32 surroundDisFront; + f32 surroundDisBack; + f32 soundSpeed; + f32 vol; +} SND_LISTENER; + +#define SND_LISTENER_DEFAULT 0x00000000 // No special features are activated +#define SND_LISTENER_DOPPLERFX \ + 0x00000001 // Listener is supposed to be moving fast enough to display Dopller effects + +typedef struct SND_EMITTER { + struct SND_EMITTER* next; + struct SND_EMITTER* prev; + SND_ROOM* room; + + SND_PARAMETER_INFO* paraInfo; + + u32 flags; + SND_FVECTOR pos; + SND_FVECTOR dir; // Speed in units/second + f32 maxDis; + f32 maxVol; + f32 minVol; + f32 volPush; // -1.0f = 1/square -> 0.0 = linear -> 1.0 = square + SND_VOICEID vid; + u32 group; // Group ID (by default FXID | 0x80000000) used to do volume priorities for continous + // emitters + SND_FXID fxid; + + u8 studio; + + u8 maxVoices; // Max. voices of the assigned FX + + u16 VolLevelCnt; // Used during continous emitter allocation process + f32 fade; // Used to fade-in of continous emitters + +} SND_EMITTER; + +#define SND_EMITTER_DEFAULTKEY 0xFF +#define SND_EMITTER_DEFAULTVOL 0xFF + +#define SND_EMITTER_DEFAULT 0x00000000 // No special features are activated +#define SND_EMITTER_CONTINOUS \ + 0x00000001 // Parameters should be updated over time (they will be set just once if not set) +#define SND_EMITTER_CONTINUOUS \ + 0x00000001 // Parameters should be updated over time (they will be set just once if not set) +#define SND_EMITTER_RESTARTABLE \ + 0x00000002 // If the used voice is reallocated, the sound should be restarted as soon as possible +#define SND_EMITTER_PAUSABLE \ + 0x00000004 // The sound may be stopped if it is no longer audible (and restarted if the above flag + // is set as soon as it's audibel again) +#define SND_EMITTER_DOPPLERFX \ + 0x00000008 // Emitter is supposed to be moving fast enough to display Doppler effects +#define SND_EMITTER_ITD \ + 0x00000010 // Enable ITD per default. The macro controlling the voice may still overwrite this + // setting +#define SND_EMITTER_HARDSTART \ + 0x00000020 // By default continous emitters are quickly faded in at startup to avoid pop sounds at + // restart. This disables this behavior +#define SND_EMITTER_NOSILENTSTART \ + 0x00000040 // Do not start emitter if the volume would be zero (it will be removed from the active + // list in this case) + +// +// Setup / Change logical rooms +// +void sndSetup3DStudios(u8 first, u8 num); + +bool sndAddRoom(SND_ROOM* room, SND_FVECTOR* pos, void (*activateReverb)(u8 studio, void* para), + void (*deActivateReverb)(u8 studio)); +bool sndRemoveRoom(SND_ROOM* room); +bool sndUpdateRoom(SND_ROOM* room, SND_FVECTOR* pos); + +bool sndAddDoor(SND_DOOR* door, SND_ROOM* a, SND_ROOM* b, SND_FVECTOR* pos, f32 dampen, f32 open, + u8 fxVol, s16 filterCoef[4], u32 flags); +bool sndRemoveDoor(SND_DOOR* door); + +// +// Functions to add emitters to logical rooms +// +SND_VOICEID sndAddEmitter(SND_EMITTER* em, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, f32 comp, + u32 flags, SND_FXID fxid, u8 maxVol, u8 minVol, SND_ROOM* room); +SND_VOICEID sndAddEmitterEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, + f32 comp, u32 flags, SND_FXID fxid, u16 groupid, u8 maxVol, u8 minVol, + SND_ROOM* room); +SND_VOICEID sndAddEmitterPara(SND_EMITTER* em, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, + f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, u8 minVol, + SND_ROOM* room, SND_PARAMETER_INFO* para); +SND_VOICEID sndAddEmitterParaEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u16 groupid, + u8 maxVol, u8 minVol, SND_ROOM* room, SND_PARAMETER_INFO* para); + +// +// Listener related functions +// +bool sndAddListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, SND_FVECTOR* heading, + SND_FVECTOR* up, f32 front_sur, f32 back_sur, f32 soundSpeed, u32 flags, u8 vol, + SND_ROOM* room); +bool sndAddListenerEx(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, SND_FVECTOR* heading, + SND_FVECTOR* up, f32 front_sur, f32 back_sur, f32 soundSpeed, + f32 volPosOffset, u32 flags, u8 vol, SND_ROOM* room); +bool sndUpdateListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, SND_FVECTOR* heading, + SND_FVECTOR* up, u8 vol, SND_ROOM* room); +bool sndRemoveListener(SND_LISTENER* li); +// +// Functions to add emitters directly to a studio +// +SND_VOICEID sndAddEmitter2Studio(SND_EMITTER* em, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, + f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, u8 minVol, + u8 studio); +SND_VOICEID sndAddEmitter2StudioEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u16 groupid, + u8 maxVol, u8 minVol, u8 studio); +SND_VOICEID sndAddEmitter2StudioPara(SND_EMITTER* em, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, + u8 minVol, u8 studio, SND_PARAMETER_INFO* para); +SND_VOICEID sndAddEmitter2StudioParaEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u16 groupid, + u8 maxVol, u8 minVol, u8 studio, SND_PARAMETER_INFO* para); +// +// Maintain emitters +// +bool sndUpdateEmitter(SND_EMITTER* em, SND_FVECTOR* pos, SND_FVECTOR* dir, u8 maxVol, + SND_ROOM* room); + +bool sndRemoveEmitter(SND_EMITTER* em); + +// +// Misc. 3D functions +// +bool sndCheckEmitter(SND_EMITTER* em); +SND_VOICEID sndEmitterVoiceID(SND_EMITTER* em); typedef struct SND_3DINFO { u8 vol; @@ -476,74 +822,10 @@ typedef struct SND_3DINFO { void sndGet3DParameters(SND_3DINFO* info, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, f32 comp, u8 maxVol, u8 minVol, SND_ROOM* room); -typedef struct SND_PROFILE_DATA { - unsigned long loadStores; - unsigned long missCycles; - unsigned long cycles; - unsigned long instructions; - unsigned long lastLoadStores; - unsigned long lastMissCycles; - unsigned long lastCycles; - unsigned long lastInstructions; - unsigned long peekLoadStores; - unsigned long peekMissCycles; - unsigned long peekCycles; - unsigned long peekInstructions; - unsigned long _loadStores; - unsigned long _missCycles; - unsigned long _cycles; - unsigned long _instructions; - float avgLoadStores; - float avgMissCycles; - float avgCycles; - float avgInstructions; - float sumLoadStores; - float sumMissCycles; - float sumCycles; - float sumInstructions; - unsigned long cnt; - unsigned long paused; -} SND_PROFILE_DATA; +// ------------------------- Debug Functions ----------------------- -typedef struct SND_PROFILE_INFO { - SND_PROFILE_DATA dspCtrl; - SND_PROFILE_DATA auxProcessing; - SND_PROFILE_DATA sequencer; - SND_PROFILE_DATA synthesizer; - SND_PROFILE_DATA emitters; - SND_PROFILE_DATA streaming; - unsigned char numMusicVoices; - unsigned char numSFXVoices; -} SND_PROFILE_INFO; - -typedef void (*SND_PROF_USERCALLBACK)(struct SND_PROFILE_INFO*); -extern SND_PROF_USERCALLBACK sndProfUserCallback; - -#define SND_MIDICTRL_MODULATION 0x01 -#define SND_MIDICTRL_VOLUME 0x07 -#define SND_MIDICTRL_PANNING 0x0A -#define SND_MIDICTRL_PEDAL 0x40 -#define SND_MIDICTRL_PORTAMENTO 0x41 -#define SND_MIDICTRL_REVERB 0x5B -#define SND_MIDICTRL_CHORUS 0x5D - -#define SND_MIDICTRL_PITCHBEND 0x80 -#define SND_MIDICTRL_SPANNING 0x83 -#define SND_MIDICTRL_DOPPLER 0x84 - -#define SND_SEQVOL_CONTINUE 0 -#define SND_SEQVOL_STOP 1 -#define SND_SEQVOL_PAUSE 2 -#define SND_SEQVOL_MUTE 3 -#define SND_SEQVOL_MODEMASK 0xF - -#define SND_ID_ERROR 0xFFFFFFFF // ID is invalid - -#define SND_MAX_SEQINSTANCES 8 -#define SND_SEQ_ERROR_ID 0xFFFFFFFF -#define SND_SEQ_CROSSFADE_ID 0x80000000 - -#define SND_PAUSEVOL_NORMAL 127 +u8 sndDbgGetActiveVoices(void); +void* sndConvert32BitSDIRTo64BitSDIR(void* sdir_int); #ifdef __cplusplus } diff --git a/include/musyx/platform.h b/include/musyx/platform.h index 9c327709..42b35559 100644 --- a/include/musyx/platform.h +++ b/include/musyx/platform.h @@ -19,4 +19,13 @@ #endif #endif -#endif \ No newline at end of file +#if MUSY_TARGET == MUSY_TARGET_PC +#ifndef MUSY_CACHED_TO_UNCACHED_ADDR +#define MUSY_CACHED_TO_UNCACHED_ADDR(addr) addr +#endif +#elif MUSY_TARGET == MUSY_TARGET_DOLPHIN +#ifndef MUSY_CACHED_TO_UNCACHED_ADDR +#define MUSY_CACHED_TO_UNCACHED_ADDR(addr) OSCachedToUncached(addr) +#endif +#endif +#endif diff --git a/include/musyx/s3d.h b/include/musyx/s3d.h index ef9dde67..81030bcc 100644 --- a/include/musyx/s3d.h +++ b/include/musyx/s3d.h @@ -13,6 +13,7 @@ void s3dKillAllEmitter(); void s3dInit(u32); /* extern */ void s3dKillEmitterByFXID(FX_TAB* fxTab, u32 num); void s3dExit(); +void s3dHandle(); #ifdef __cplusplus } diff --git a/include/musyx/sal.h b/include/musyx/sal.h index e065b087..af17263c 100644 --- a/include/musyx/sal.h +++ b/include/musyx/sal.h @@ -41,21 +41,32 @@ typedef struct SAL_PANINFO { f32 rpan_fm; // offset 0x2C, size 0x4 } SAL_PANINFO; -u32 salInitAi(SND_SOME_CALLBACK, u32, u32*); -u32 salInitDsp(u32); -u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2); -u32 salStartAi(); +bool salInitAi(SND_SOME_CALLBACK, u32, u32*); +bool salInitDsp(u32); +bool salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2); +bool salExitDsp(); +bool salExitDspCtrl(); +bool salExitAi(); +bool salStartAi(); +void* salAiGetDest(); + void salInitHRTFBuffer(); void salActivateVoice(DSPvoice* dsp_vptr, u8 studio); void salDeactivateVoice(DSPvoice* dsp_vptr); void salActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type); void salDeactivateStudio(u8 studio); +bool salAddStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc); +bool salRemoveStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc); void salActivateVoice(DSPvoice* dsp_vptr, u8 studio); void salCalcVolume(u8 voltab_index, SAL_VOLINFO* vi, f32 vol, u32 pan, u32 span, f32 auxa, f32 auxb, u32 itd, u32 dpl2); void salReconnectVoice(DSPvoice* dsp_vptr, u8 studio); void* salMalloc(u32 len); void salFree(void* addr); +void salBuildCommandList(signed short* dest, unsigned long nsDelay); +void salStartDsp(s16* cmdList); +void salCtrlDsp(s16* dest); +void salHandleAuxProcessing(); #define SAL_MAX_STUDIONUM 8 extern u8 salMaxStudioNum; diff --git a/include/musyx/seq.h b/include/musyx/seq.h index ef1aa65a..f955d7e5 100644 --- a/include/musyx/seq.h +++ b/include/musyx/seq.h @@ -213,12 +213,6 @@ u32 seqStartPlay(PAGE* norm, PAGE* drum, MIDISETUP* midiSetup, u32* song, SND_PL u32 seqGetPrivateId(u32 seqId); void seqSpeed(u32 seqId, u16 speed); void seqVolume(u8 volume, u16 time, u32 seqId, u8 mode); -void sndSeqStop(s32 unk); -void sndSeqSpeed(u32 seqId, u16 speed); -void sndSeqContinue(s32 unk); -void sndSeqMute(s32 unk1, s32 unk2, s32 unk3); -void sndSeqVolume(u8 volume, u16 time, u32 seqId, u8 mode); -u32 sndSeqPlayEx(u16 sgid, u16 sid, void* arrfile, SND_PLAYPARA* para, u8 studio); void seqStop(u32 seqId); u16 seqGetMIDIPriority(u8 set, u8 channel); void seqCrossFade(SND_CROSSFADE* ci, u32* new_seqId, bool8 irq_call); @@ -228,6 +222,7 @@ void seqContinue(SND_SEQID seqId); void seqMute(SND_SEQID seqId, u32 mask1, u32 mask2); void seqKillInstancesByGroupID(SND_GROUPID sgid); void seqKillAllInstances(); +void seqHandle(u32 deltaTime); u8 inpTranslateExCtrl(u8 ctrl); void inpSetGlobalMIDIDirtyFlag(u8 chan, u8 midiSet, s32 flag); diff --git a/include/musyx/snd.h b/include/musyx/snd.h index b068a723..100b97ee 100644 --- a/include/musyx/snd.h +++ b/include/musyx/snd.h @@ -16,10 +16,6 @@ void* sndBSearch(void* key, void* base, s32 num, s32 len, SND_COMPARE cmp); void sndConvertMs(u32* time); void sndConvertTicks(u32* out, SYNTH_VOICE* svoice); u32 sndConvert2Ms(u32 time); -u32 sndStreamAllocLength(u32 num, u32 flags); -void sndStreamFree(u32 stid); -u32 sndStreamActivate(u32 stid); -void sndStreamDeactivate(u32 stid); u32 sndGetPitch(u8 key, u32 sInfo); s32 sndPitchUpOne(u16 note); diff --git a/include/musyx/stream.h b/include/musyx/stream.h index c2a5681c..c3bb8f39 100644 --- a/include/musyx/stream.h +++ b/include/musyx/stream.h @@ -7,7 +7,7 @@ extern "C" { #endif -typedef s32 (*SND_STREAM_UPDATE_CALLBACK)(void* buffer1, u32 len1, void* buffer2, u32 len2, +typedef u32 (*SND_STREAM_UPDATE_CALLBACK)(void* buffer1, u32 len1, void* buffer2, u32 len2, u32 user); typedef struct SNDADPCMinfo { // total size: 0x28 @@ -68,6 +68,7 @@ void streamOutputModeChanged(); void streamInit(); /* extern */ void streamKill(SND_VOICEID voice); void streamCorrectLoops(); +void streamHandle(); #ifdef __cplusplus } diff --git a/include/musyx/synth.h b/include/musyx/synth.h index d4ef4138..e4953aab 100644 --- a/include/musyx/synth.h +++ b/include/musyx/synth.h @@ -304,6 +304,7 @@ void synthInitPortamento(SYNTH_VOICE* svoice); void synthStartSynthJobHandling(SYNTH_VOICE* svoice); void synthForceLowPrecisionUpdate(SYNTH_VOICE* svoice); void synthKeyStateUpdate(SYNTH_VOICE* svoice); +void synthHandle(u32 deltaTime); bool synthFXSetCtrl(SND_VOICEID vid, u8 ctrl, u8 value); bool synthFXSetCtrl14(SND_VOICEID vid, u8 ctrl, u16 value); bool synthSendKeyOff(SND_VOICEID vid); @@ -322,8 +323,8 @@ u8 synthFXGetMaxVoices(u16 fid); void synthPauseVolume(u8 volume, u16 time, u8 vGroup); void synthKillAllVoices(bool8 musiconly); void synthKeyStateUpdate(SYNTH_VOICE* svoice); -u32 synthAddStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc); -u32 synthRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc); +bool synthAddStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc); +bool synthRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc); u32 synthGetTicksPerSecond(SYNTH_VOICE* svoice); #ifdef __cplusplus diff --git a/include/musyx/synthdata.h b/include/musyx/synthdata.h index d350fa2e..8f372121 100644 --- a/include/musyx/synthdata.h +++ b/include/musyx/synthdata.h @@ -60,6 +60,21 @@ typedef struct SDIR_DATA { u32 extraData; // offset 0x1C, size 0x4 } SDIR_DATA; +/*! A direct copy of the above structure to allow us to load in legacy data + * this must be done via sndConvert32BitSDIRto64BitSDIR via client code, + * this is explicit on the part of the programmer. + * MusyX data built with the new tools will not require this step. + */ +typedef struct SDIR_DATA_INTER { + // total size: 0x20 + u16 id; // offset 0x0, size 0x2 + u16 ref_cnt; // offset 0x2, size 0x2 + u32 offset; // offset 0x4, size 0x4 + u32 addr; // offset 0x8, size 0x4 + SAMPLE_HEADER header; // offset 0xC, size 0x10 + u32 extraData; // offset 0x1C, size 0x4 +} SDIR_DATA_INTER; + typedef struct SDIR_TAB { // total size: 0xC SDIR_DATA* data; // offset 0x0, size 0x4 @@ -183,21 +198,21 @@ void dataInitStack(unsigned long aramBase, unsigned long aramSize); #else void dataInitStack(); /* extern */ #endif -u32 dataInsertSDir(SDIR_DATA* sdir, void* smp_data); -u32 dataRemoveSDir(SDIR_DATA* sdir); -u32 dataInsertMacro(u16 mid, void* macroaddr); -u32 dataRemoveMacro(u16 mid); -u32 dataInsertCurve(u16 cid, void* curvedata); -u32 dataRemoveCurve(u16 sid); +bool dataInsertSDir(SDIR_DATA* sdir, void* smp_data); +bool dataRemoveSDir(SDIR_DATA* sdir); +bool dataInsertMacro(u16 mid, void* macroaddr); +bool dataRemoveMacro(u16 mid); +bool dataInsertCurve(u16 cid, void* curvedata); +bool dataRemoveCurve(u16 sid); s32 dataGetSample(u16 sid, SAMPLE_INFO* newsmp); void* dataGetCurve(u16 cid); -u32 dataAddSampleReference(u16 sid); -u32 dataRemoveSampleReference(u16 sid); -u32 dataInsertKeymap(u16 cid, void* keymapdata); -u32 dataRemoveKeymap(u16 sid); -u32 dataInsertLayer(u16 cid, void* layerdata, u16 size); -u32 dataRemoveLayer(u16 sid); -u32 dataInsertFX(u16 gid, FX_TAB* fx, u16 fxNum); +bool dataAddSampleReference(u16 sid); +bool dataRemoveSampleReference(u16 sid); +bool dataInsertKeymap(u16 cid, void* keymapdata); +bool dataRemoveKeymap(u16 sid); +bool dataInsertLayer(u16 cid, void* layerdata, u16 size); +bool dataRemoveLayer(u16 sid); +bool dataInsertFX(u16 gid, FX_TAB* fx, u16 fxNum); bool dataRemoveFX(u16 gid); FX_TAB* dataGetFX(u16 fid); void* dataGetLayer(u16 cid, u16* n); diff --git a/include/musyx/voice.h b/include/musyx/voice.h index ce195c1a..32ffee3f 100644 --- a/include/musyx/voice.h +++ b/include/musyx/voice.h @@ -141,21 +141,6 @@ typedef struct VSampleInfo { u8 inLoopBuffer; // offset 0x8, size 0x1 } VSampleInfo; -typedef struct SND_VIRTUALSAMPLE_INFO { - // total size: 0x14 - u16 smpID; // offset 0x0, size 0x2 - u16 instID; // offset 0x2, size 0x2 - union vsData { - struct vsUpdate { - // total size: 0x10 - u32 off1; // offset 0x0, size 0x4 - u32 len1; // offset 0x4, size 0x4 - u32 off2; // offset 0x8, size 0x4 - u32 len2; // offset 0xC, size 0x4 - } update; - } data; -} SND_VIRTUALSAMPLE_INFO; - typedef struct VS_BUFFER { // total size: 0x24 u8 state; // offset 0x0, size 0x1 @@ -176,7 +161,7 @@ typedef struct _VS { u8 voices[64]; // offset 0x908, size 0x40 u16 nextInstID; // offset 0x948, size 0x2 u32 (*callback)(u8, - SND_VIRTUALSAMPLE_INFO*); // offset 0x94C, size 0x4 + const SND_VIRTUALSAMPLE_INFO*); // offset 0x94C, size 0x4 } VS; extern VS vs; @@ -221,6 +206,7 @@ extern u8 voiceListRoot; void vsInit(); /* extern */ u32 vsSampleStartNotify(u8 voice); void vsSampleEndNotify(u32 pubID); +void vsSampleUpdates(); void voiceSetPriority(SYNTH_VOICE* svoice, u8 prio); u32 voiceIsLastStarted(SYNTH_VOICE* svoice); diff --git a/src/musyx/runtime/CheapReverb/creverb.c b/src/musyx/runtime/CheapReverb/creverb.c index ec101df7..937a4115 100644 --- a/src/musyx/runtime/CheapReverb/creverb.c +++ b/src/musyx/runtime/CheapReverb/creverb.c @@ -415,7 +415,7 @@ lbl_803B599C: #endif } #else -static void HandleReverb(long* sptr, struct _SND_REVSTD_WORK* rv) { +static void HandleReverb(s32* sptr, struct _SND_REVSTD_WORK* rv) { // TODO: Reimplement this in C } #endif diff --git a/src/musyx/runtime/Delay/delay_fx.c b/src/musyx/runtime/Delay/delay_fx.c index a196ff49..51de2509 100644 --- a/src/musyx/runtime/Delay/delay_fx.c +++ b/src/musyx/runtime/Delay/delay_fx.c @@ -15,17 +15,17 @@ #include "musyx/sal.h" void sndAuxCallbackDelay(u8 reason, SND_AUX_INFO* info, void* user) { - long l; // r30 - long r; // r29 - long s; // r28 - long* lBuf; // r27 - long* rBuf; // r26 - long* sBuf; // r25 - unsigned long i; // r24 + s32 l; // r30 + s32 r; // r29 + s32 s; // r28 + s32* lBuf; // r27 + s32* rBuf; // r26 + s32* sBuf; // r25 + u32 i; // r24 SND_AUX_DELAY* c; // r31 - long* left; // r23 - long* right; // r22 - long* sur; // r21 + s32* left; // r23 + s32* right; // r22 + s32* sur; // r21 switch (reason) { case SND_AUX_REASON_BUFFERUPDATE: diff --git a/src/musyx/runtime/dolphin/dsp_import.c b/src/musyx/runtime/dsp_import.c similarity index 99% rename from src/musyx/runtime/dolphin/dsp_import.c rename to src/musyx/runtime/dsp_import.c index 4b5573a6..56a40086 100644 --- a/src/musyx/runtime/dolphin/dsp_import.c +++ b/src/musyx/runtime/dsp_import.c @@ -1,8 +1,5 @@ #include "musyx/dsp_import.h" - -#ifdef __cplusplus -extern "C" { -#endif +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN char dspSlave[0x19E0] ATTRIBUTE_ALIGN(32) = { 0x00, 0x00, 0x00, 0x00, 0x02, 0x9F, 0x0C, 0x10, 0x02, 0x9F, 0x0C, 0x1F, 0x02, 0x9F, 0x0C, 0x3B, @@ -423,6 +420,4 @@ char dspSlave[0x19E0] ATTRIBUTE_ALIGN(32) = { u16 dspSlaveLength = sizeof(dspSlave); -#ifdef __cplusplus -} -#endif +#endif \ No newline at end of file diff --git a/src/musyx/runtime/dolphin/hardware.c b/src/musyx/runtime/hardware.c similarity index 84% rename from src/musyx/runtime/dolphin/hardware.c rename to src/musyx/runtime/hardware.c index 80f0bee3..c732c984 100644 --- a/src/musyx/runtime/dolphin/hardware.c +++ b/src/musyx/runtime/hardware.c @@ -1,19 +1,21 @@ -#include "musyx/assert.h" #include "musyx/hardware.h" +#include "musyx/assert.h" +#include "musyx/s3d.h" +#include "musyx/sal.h" +#include "musyx/seq.h" #include "musyx/stream.h" #include "musyx/synth.h" -#include "musyx/sal.h" - -extern void DCStoreRange(void* addr, u32 nBytes); static volatile const u16 itdOffTab[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, - 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, - 16, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, - 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, + 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, + 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, + 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, + 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, + 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, }; -//SND_PROFILE_INFO prof; +// SND_PROFILE_INFO prof; u8 salFrame; u8 salAuxFrame; @@ -140,7 +142,8 @@ void hwSetMesgCallback(SND_MESSAGE_CALLBACK callback) { salMessageCallback = cal void hwSetPriority(u32 v, u32 prio) { dspVoice[v].prio = prio; } -void hwInitSamplePlayback(u32 v, u16 smpID, void* newsmp, u32 set_defadsr, u32 prio, u32 callbackUserValue, u32 setSRC, u8 itdMode) { +void hwInitSamplePlayback(u32 v, u16 smpID, void* newsmp, u32 set_defadsr, u32 prio, + u32 callbackUserValue, u32 setSRC, u8 itdMode) { unsigned char i; // r30 unsigned long bf; // r29 bf = 0; @@ -249,14 +252,15 @@ void hwStart(u32 v, u8 studio) { void hwKeyOff(u32 v) { dspVoice[v].changed[salTimeOffset] |= 0x40; } -void hwSetPitch(unsigned long v, unsigned short speed) { - struct DSPvoice* dsp_vptr = &dspVoice[v]; +void hwSetPitch(u32 v, u16 speed) { + DSPvoice* dsp_vptr = &dspVoice[v]; if (speed >= 0x4000) { speed = 0x3fff; } - if (dsp_vptr->lastUpdate.pitch != 0xff && dsp_vptr->pitch[dsp_vptr->lastUpdate.pitch] == speed * 16) { + if (dsp_vptr->lastUpdate.pitch != 0xff && + dsp_vptr->pitch[dsp_vptr->lastUpdate.pitch] == speed * 16) { return; } @@ -272,9 +276,9 @@ void hwSetSRCType(u32 v, u8 salSRCType) { dsp_vptr->changed[0] |= 0x100; } -void hwSetPolyPhaseFilter(unsigned long v, unsigned char salCoefSel) { +void hwSetPolyPhaseFilter(u32 v, u8 salCoefSel) { static u16 dspCoefSel[3] = {0, 1, 2}; - struct DSPvoice* dsp_vptr = &dspVoice[v]; + DSPvoice* dsp_vptr = &dspVoice[v]; dsp_vptr->srcCoefSelect = dspCoefSel[salCoefSel]; dsp_vptr->changed[0] |= 0x80; } @@ -297,11 +301,11 @@ void hwSetITDMode(u32 v, u8 mode) { #define hwGetITDMode(dsp_vptr) (dsp_vptr->flags & 0x80000000) -void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long pan, unsigned long span, float auxa, float auxb) { +void hwSetVolume(u32 v, u8 table, float vol, u32 pan, u32 span, float auxa, float auxb) { SAL_VOLINFO vi; // r1+0x24 - unsigned short il; // r30 - unsigned short ir; // r29 - unsigned short is; // r28 + u16 il; // r30 + u16 ir; // r29 + u16 is; // r28 DSPvoice* dsp_vptr = &dspVoice[v]; // r31 if (vol >= 1.f) { vol = 1.f; @@ -316,13 +320,14 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long } salCalcVolume(table, &vi, vol, pan, span, auxa, auxb, (dsp_vptr->flags & 0x80000000) != 0, - dspStudio[dsp_vptr->studio].type == SND_STUDIO_TYPE_RESERVED0); + dspStudio[dsp_vptr->studio].type == SND_STUDIO_TYPE_DPL2); il = 32767.f * vi.volL; ir = 32767.f * vi.volR; is = 32767.f * vi.volS; - if (dsp_vptr->lastUpdate.vol == 0xff || dsp_vptr->volL != il || dsp_vptr->volR != ir || dsp_vptr->volS != is) { + if (dsp_vptr->lastUpdate.vol == 0xff || dsp_vptr->volL != il || dsp_vptr->volR != ir || + dsp_vptr->volS != is) { dsp_vptr->volL = il; dsp_vptr->volR = ir; dsp_vptr->volS = is; @@ -334,7 +339,8 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long ir = 32767.f * vi.volAuxAR; is = 32767.f * vi.volAuxAS; - if (dsp_vptr->lastUpdate.volA == 0xff || dsp_vptr->volLa != il || dsp_vptr->volRa != ir || dsp_vptr->volSa != is) { + if (dsp_vptr->lastUpdate.volA == 0xff || dsp_vptr->volLa != il || dsp_vptr->volRa != ir || + dsp_vptr->volSa != is) { dsp_vptr->volLa = il; dsp_vptr->volRa = ir; dsp_vptr->volSa = is; @@ -346,7 +352,8 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long ir = 32767.f * vi.volAuxBR; is = 32767.f * vi.volAuxBS; - if (dsp_vptr->lastUpdate.volB == 0xff || dsp_vptr->volLb != il || dsp_vptr->volRb != ir || dsp_vptr->volSb != is) { + if (dsp_vptr->lastUpdate.volB == 0xff || dsp_vptr->volLb != il || dsp_vptr->volRb != ir || + dsp_vptr->volSb != is) { dsp_vptr->volLb = il; dsp_vptr->volRb = ir; dsp_vptr->volSb = is; @@ -361,14 +368,17 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long void hwOff(s32 vid) { salDeactivateVoice(&dspVoice[vid]); } -void hwSetAUXProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA, SND_AUX_CALLBACK auxB, void* userB) { +void hwSetAUXProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA, + SND_AUX_CALLBACK auxB, void* userB) { dspStudio[studio].auxAHandler = auxA; dspStudio[studio].auxAUser = userA; dspStudio[studio].auxBHandler = auxB; dspStudio[studio].auxBUser = userB; } -void hwActivateStudio(unsigned char studio, unsigned long isMaster, SND_STUDIO_TYPE type) { salActivateStudio(studio, isMaster, type); } +void hwActivateStudio(u8 studio, bool isMaster, SND_STUDIO_TYPE type) { + salActivateStudio(studio, isMaster, type); +} void hwDeactivateStudio(u8 studio) { salDeactivateStudio(studio); } @@ -376,9 +386,13 @@ void hwChangeStudioMix(u8 studio, u32 isMaster) { dspStudio[studio].isMaster = i bool hwIsStudioActive(u8 studio) { return dspStudio[studio].state == 1; } -bool hwAddInput(u8 studio, SND_STUDIO_INPUT* in_desc) { return salAddStudioInput(&dspStudio[studio], in_desc); } +bool hwAddInput(u8 studio, SND_STUDIO_INPUT* in_desc) { + return salAddStudioInput(&dspStudio[studio], in_desc); +} -bool hwRemoveInput(u8 studio, SND_STUDIO_INPUT* in_desc) { return salRemoveStudioInput(&dspStudio[studio], in_desc); } +bool hwRemoveInput(u8 studio, SND_STUDIO_INPUT* in_desc) { + return salRemoveStudioInput(&dspStudio[studio], in_desc); +} void hwChangeStudio(u32 v, u8 studio) { salReconnectVoice(&dspVoice[v], studio); } @@ -411,17 +425,19 @@ u32 hwGetPos(u32 v) { return pos; } -void hwFlushStream(void* base, unsigned long offset, unsigned long bytes, unsigned char hwStreamHandle, void (*callback)(unsigned long), - unsigned long user) { - u32 aram; // r28 - u32 mram; // r29 - u32 len; +void hwFlushStream(void* base, u32 offset, u32 bytes, u8 hwStreamHandle, void (*callback)(size_t), + u32 user) { + size_t aram; // r28 + size_t mram; // r29 + size_t len; aram = aramGetStreamBufferAddress(hwStreamHandle, &len); bytes += (offset & 31); offset &= ~31; bytes = (bytes + 31) & ~31; mram = (u32)base + offset; +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCStoreRange((void*)mram, bytes); +#endif aramUploadData((void*)mram, aram + offset, bytes, 1, callback, user); } @@ -430,7 +446,9 @@ u8 hwInitStream(u32 len) { return aramAllocateStreamBuffer(len); } void hwExitStream(u8 id) { aramFreeStreamBuffer(id); } -void* hwGetStreamPlayBuffer(u8 hwStreamHandle) { return (void*)aramGetStreamBufferAddress(hwStreamHandle, NULL); } +void* hwGetStreamPlayBuffer(u8 hwStreamHandle) { + return (void*)aramGetStreamBufferAddress(hwStreamHandle, NULL); +} void* hwTransAddr(void* samples) { return samples; } @@ -438,7 +456,7 @@ u32 hwFrq2Pitch(u32 frq) { return (frq * 4096.f) / synthInfo.mixFrq; } void hwInitSampleMem(u32 baseAddr, u32 length) { #line 940 - MUSY_ASSERT(baseAddr==0x00000000); + MUSY_ASSERT(baseAddr == 0x00000000); aramInit(length); } @@ -458,13 +476,17 @@ static u32 convert_length(u32 len, u8 type) { } void hwSaveSample(void* header, void* data) { +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN u32 len = ((u32*)*((u32*)header))[1] & 0xFFFFFF; u8 type = ((u32*)*((u32*)header))[1] >> 0x18; len = convert_length(len, type); *((u32*)data) = (u32)aramStoreData((void*)*((u32*)data), len); +#endif } -void hwSetSaveSampleCallback(ARAMUploadCallback callback, unsigned long chunckSize) { aramSetUploadCallback(callback, chunckSize); } +void hwSetSaveSampleCallback(ARAMUploadCallback callback, unsigned long chunckSize) { + aramSetUploadCallback(callback, chunckSize); +} void hwRemoveSample(void* header, void* data) { #if MUSY_VERSION <= MUSY_VERSION_CHECK(1, 5, 3) diff --git a/src/musyx/runtime/dolphin/hw_aramdma.c b/src/musyx/runtime/hw_aramdma.c similarity index 74% rename from src/musyx/runtime/dolphin/hw_aramdma.c rename to src/musyx/runtime/hw_aramdma.c index 6cc7eda7..b411c12d 100644 --- a/src/musyx/runtime/dolphin/hw_aramdma.c +++ b/src/musyx/runtime/hw_aramdma.c @@ -1,13 +1,24 @@ +#include "musyx/assert.h" +#include "musyx/musyx.h" +#include "musyx/platform.h" + +typedef struct STREAM_BUFFER { + // total size: 0x10 + struct STREAM_BUFFER* next; // offset 0x0, size 0x4 + unsigned long aram; // offset 0x4, size 0x4 + unsigned long length; // offset 0x8, size 0x4 + unsigned long allocLength; // offset 0xC, size 0x4 +} STREAM_BUFFER; + +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN #include #include #include -#include "musyx/assert.h" - typedef struct ARAMTransferJob { // total size: 0x28 ARQRequest arq; // offset 0x0, size 0x20 - void (*callback)(unsigned long); // offset 0x20, size 0x4 + void (*callback)(u32); // offset 0x20, size 0x4 unsigned long user; // offset 0x24, size 0x4 } ARAMTransferJob; @@ -18,19 +29,11 @@ typedef struct ARAMTransferQueue { vu8 valid; // offset 0x281, size 0x1 } ARAMTransferQueue; -typedef struct STREAM_BUFFER { - // total size: 0x10 - struct STREAM_BUFFER* next; // offset 0x0, size 0x4 - unsigned long aram; // offset 0x4, size 0x4 - unsigned long length; // offset 0x8, size 0x4 - unsigned long allocLength; // offset 0xC, size 0x4 -} STREAM_BUFFER; - -static unsigned long aramTop; // size: 0x4 -static unsigned long aramWrite; // size: 0x4 -static unsigned long aramStream; // size: 0x4 -static void* (*aramUploadCallback)(unsigned long, unsigned long); // size: 0x4 -static unsigned long aramUploadChunkSize; // size: 0x4 +static u32 aramTop; // size: 0x4 +static u32 aramWrite; // size: 0x4 +static u32 aramStream; // size: 0x4 +static void* (*aramUploadCallback)(u32, u32); // size: 0x4 +static u32 aramUploadChunkSize; // size: 0x4 static ARAMTransferQueue aramQueueLo; static ARAMTransferQueue aramQueueHi; @@ -337,3 +340,83 @@ void aramFreeStreamBuffer(unsigned char id) { fSb->next = aramFreeStreamBuffers; aramFreeStreamBuffers = fSb; } + +#elif MUSY_TARGET == MUSY_TARGET_PC +// typedef struct ARAMTransferJob { +// // total size: 0x28 +// ARQRequest arq; // offset 0x0, size 0x20 +// void (*callback)(unsigned long); // offset 0x20, size 0x4 +// unsigned long user; // offset 0x24, size 0x4 +// } ARAMTransferJob; +// +// typedef struct ARAMTransferQueue { +// // total size: 0x284 +// ARAMTransferJob queue[16]; // offset 0x0, size 0x280 +// vu8 write; // offset 0x280, size 0x1 +// vu8 valid; // offset 0x281, size 0x1 +// } ARAMTransferQueue; +// +// typedef struct STREAM_BUFFER { +// // total size: 0x10 +// struct STREAM_BUFFER* next; // offset 0x0, size 0x4 +// unsigned long aram; // offset 0x4, size 0x4 +// unsigned long length; // offset 0x8, size 0x4 +// unsigned long allocLength; // offset 0xC, size 0x4 +// } STREAM_BUFFER; +// +// static unsigned long aramTop; // size: 0x4 +// static unsigned long aramWrite; // size: 0x4 +// static unsigned long aramStream; // size: 0x4 +// static void* (*aramUploadCallback)(unsigned long, unsigned long); // size: 0x4 +// static unsigned long aramUploadChunkSize; // size: 0x4 +// +// static ARAMTransferQueue aramQueueLo; +// static ARAMTransferQueue aramQueueHi; + +// static STREAM_BUFFER aramStreamBuffers[64]; +// static STREAM_BUFFER* aramUsedStreamBuffers; +// static STREAM_BUFFER* aramFreeStreamBuffers; +// static STREAM_BUFFER* aramIdleStreamBuffers; + +static void InitStreamBuffers(); + +static void aramQueueInit() {} + +static void aramQueueCallback(unsigned long ptr) {} + +void aramUploadData(void* mram, unsigned long aram, unsigned long len, unsigned long highPrio, + void (*callback)(unsigned long), unsigned long user) {} + +void aramSyncTransferQueue() {} + +void aramInit(unsigned long length) {} + +void aramExit() {} + +unsigned long aramGetZeroBuffer() { return 0; } + +void aramSetUploadCallback(void* (*callback)(unsigned long, unsigned long), + unsigned long chunckSize) {} + +void* aramStoreData(void* src, unsigned long len) {} + +void aramRemoveData(void* aram, unsigned long len) {} + +static void InitStreamBuffers() {} + +unsigned char aramAllocateStreamBuffer(u32 len) { return 0; } + +size_t aramGetStreamBufferAddress(u8 id, size_t* len) { + MUSY_ASSERT_MSG(id != 0xFF, "Stream buffer ID is invalid"); +} + +void aramFreeStreamBuffer(unsigned char id) { + STREAM_BUFFER* fSb; // r30 + STREAM_BUFFER* sb; // r31 + STREAM_BUFFER* lastSb; // r29 + STREAM_BUFFER* nextSb; // r27 + unsigned long minAddr; // r28 + + MUSY_ASSERT_MSG(id != 0xFF, "Stream buffer ID is invalid"); +} +#endif \ No newline at end of file diff --git a/src/musyx/runtime/dolphin/hw_dolphin.c b/src/musyx/runtime/hw_dolphin.c similarity index 96% rename from src/musyx/runtime/dolphin/hw_dolphin.c rename to src/musyx/runtime/hw_dolphin.c index 3ce7e12c..313d1626 100644 --- a/src/musyx/runtime/dolphin/hw_dolphin.c +++ b/src/musyx/runtime/hw_dolphin.c @@ -1,3 +1,6 @@ +#include "musyx/platform.h" + +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN #include "dolphin/dsp.h" #include "musyx/assert.h" #include "musyx/dsp_import.h" @@ -125,7 +128,7 @@ u32 salExitDsp() { return TRUE; } -void salStartDsp(u16* cmdList) { +void salStartDsp(s16* cmdList) { salDspIsDone = FALSE; PPCSync(); /* clang-format off */ @@ -140,7 +143,7 @@ void salStartDsp(u16* cmdList) { ; } -void salCtrlDsp(u16* dest) { +void salCtrlDsp(s16* dest) { salBuildCommandList(dest, salGetStartDelay()); salStartDsp(dspCmdList); } @@ -169,3 +172,4 @@ void hwDisableIrq() { void hwIRQEnterCritical() { OSDisableInterrupts(); } void hwIRQLeaveCritical() { OSEnableInterrupts(); } +#endif \ No newline at end of file diff --git a/src/musyx/runtime/dolphin/hw_dspctrl.c b/src/musyx/runtime/hw_dspctrl.c similarity index 91% rename from src/musyx/runtime/dolphin/hw_dspctrl.c rename to src/musyx/runtime/hw_dspctrl.c index 65c91f9c..d7b375c6 100644 --- a/src/musyx/runtime/dolphin/hw_dspctrl.c +++ b/src/musyx/runtime/hw_dspctrl.c @@ -20,6 +20,8 @@ #include "musyx/hardware.h" #include "musyx/sal.h" +#include + #ifdef _DEBUG static u32 dbgActiveVoicesMax = 0; #endif @@ -34,7 +36,7 @@ u16* dspCmdLastLoad = NULL; u16* dspCmdLastBase = NULL; -u16* dspCmdList = NULL; +s16* dspCmdList = NULL; u16 dspCmdLastSize = 0; @@ -50,7 +52,7 @@ u32 dspHRTFOn = FALSE; s16* dspHrtfHistoryBuffer = NULL; -long* dspSurround = NULL; +s32* dspSurround = NULL; s16* dspITDBuffer = NULL; @@ -58,10 +60,10 @@ DSPvoice* dspVoice = NULL; SND_MESSAGE_CALLBACK salMessageCallback = NULL; -u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { - u32 i; // r31 - u32 j; // r27 - u32 itdPtr; // r28 +bool salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { + u32 i; // r31 + u32 j; // r27 + size_t itdPtr; // r28 salNumVoices = numVoices; salMaxStudioNum = numStudios; @@ -70,15 +72,19 @@ u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { dspARAMZeroBuffer = aramGetZeroBuffer(); if ((dspCmdList = salMalloc(1024 * sizeof(u16))) != NULL) { MUSY_DEBUG("Allocated dspCmdList.\n\n"); - if ((dspSurround = salMalloc(160 * sizeof(long))) != NULL) { + if ((dspSurround = salMalloc(160 * sizeof(s32))) != NULL) { MUSY_DEBUG("Allocated surround buffer.\n\n"); - memset(dspSurround, 0, 160 * sizeof(long)); + memset(dspSurround, 0, 160 * sizeof(s32)); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRange(dspSurround, 160 * sizeof(long)); +#endif if ((dspVoice = salMalloc(salNumVoices * sizeof(DSPvoice))) != NULL) { MUSY_DEBUG("Allocated HW voice array.\n\n"); if ((dspITDBuffer = salMalloc(salNumVoices * 64)) != NULL) { MUSY_DEBUG("Allocated ITD buffers for voice array.\n\n"); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCInvalidateRange(dspITDBuffer, salNumVoices * 64); +#endif itdPtr = (u32)dspITDBuffer; for (i = 0; i < salNumVoices; ++i) { MUSY_DEBUG("Initializing voice %d...\n", i); @@ -101,8 +107,9 @@ u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { dspVoice[i].itdBuffer = (void*)itdPtr; itdPtr += 0x40; dspVoice[i].virtualSampleID = 0xFFFFFFFF; +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCStoreRangeNoSync(dspVoice[i].pb, sizeof(_PB)); - +#endif for (j = 0; j < 5; ++j) { dspVoice[i].changed[j] = 0; } @@ -122,7 +129,9 @@ u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { } memset(dspStudio[i].main[0], 0, 0x3c00); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspStudio[i].main[0], 0x3c00); +#endif dspStudio[i].main[1] = dspStudio[i].main[0] + 0x1e0; dspStudio[i].auxA[0] = dspStudio[i].main[1] + 0x1e0; dspStudio[i].auxA[1] = dspStudio[i].auxA[0] + 0x1e0; @@ -137,11 +146,13 @@ u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { dspStudio[i].hostDPopSum.sA = 0; dspStudio[i].hostDPopSum.lB = dspStudio[i].hostDPopSum.rB = dspStudio[i].hostDPopSum.sB = 0; +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspStudio[i].spb, sizeof(_SPB)); +#endif } MUSY_DEBUG("All studios are initialized.\n\n"); salActivateStudio( - 0, 1, defaultStudioDPL2 != FALSE ? SND_STUDIO_TYPE_RESERVED0 : SND_STUDIO_TYPE_STD); + 0, 1, defaultStudioDPL2 != FALSE ? SND_STUDIO_TYPE_DPL2 : SND_STUDIO_TYPE_STD); MUSY_DEBUG("Default studio is active.\n\n"); if ((dspHrtfHistoryBuffer = salMalloc(0x100)) == NULL) { return FALSE; @@ -159,10 +170,12 @@ u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { void salInitHRTFBuffer() { memset(dspHrtfHistoryBuffer, 0, 0x100); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspHrtfHistoryBuffer, 0x100); +#endif } -u32 salExitDspCtrl() { +bool salExitDspCtrl() { u8 i; // r31 salFree(dspHrtfHistoryBuffer); @@ -185,7 +198,9 @@ u32 salExitDspCtrl() { void salActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type) { memset(dspStudio[studio].main[0], 0, 0x3c00); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspStudio[studio].main[0], 0x3c00); +#endif memset(dspStudio[studio].spb, 0, sizeof(_SPB)); dspStudio[studio].hostDPopSum.l = dspStudio[studio].hostDPopSum.r = dspStudio[studio].hostDPopSum.s = 0; @@ -193,12 +208,17 @@ void salActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type) { dspStudio[studio].hostDPopSum.sA = 0; dspStudio[studio].hostDPopSum.lB = dspStudio[studio].hostDPopSum.rB = dspStudio[studio].hostDPopSum.sB = 0; - +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspStudio[studio].spb, sizeof(_SPB)); +#endif memset(dspStudio[studio].auxA[0], 0, 0x780); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspStudio[studio].auxA[0], 0x780); +#endif memset(dspStudio[studio].auxB[0], 0, 0x780); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(dspStudio[studio].auxB[0], 0x780); +#endif dspStudio[studio].voiceRoot = NULL; dspStudio[studio].alienVoiceRoot = NULL; dspStudio[studio].state = 1; @@ -222,7 +242,7 @@ static const u16 dspMixerCycles[32] = { void salDeactivateStudio(u8 studio) { dspStudio[studio].state = 0; } static u32 salCheckVolErrorAndResetDelta(u16* dsp_vol, u16* dsp_delta, u16* last_vol, u16 targetVol, - u16* resetFlags, u16 resetMask) { + u16* resetFlags, u16 resetMask) { s16 d; // r31 s16 x; // r30 @@ -287,7 +307,7 @@ static void sal_update_hostplayinfo(DSPvoice* dsp_vptr) { } } -static void AddDpop(long* sum, s16 delta) { +static void AddDpop(s32* sum, s16 delta) { *sum += (int)delta; *sum = (*sum > 0x7fffff) ? 0x7fffff : (*sum < -0x7fffff ? -0x7fffff : *sum); } @@ -369,7 +389,7 @@ static void SortVoices(DSPvoice** voices, long l, long r) { void salBuildCommandList(signed short* dest, unsigned long nsDelay) { static const u16 pbOffsets[9] = {10, 12, 24, 13, 16, 26, 18, 20, 22}; - static DSPvoice * voices[64]; + static DSPvoice* voices[64]; } u32 salSynthSendMessage(DSPvoice* dsp_vptr, u32 mesg) { @@ -440,7 +460,7 @@ void salReconnectVoice(DSPvoice* dsp_vptr, u8 studio) { dsp_vptr->studio = studio; } -u32 salAddStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc) { +bool salAddStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc) { if (stp->numInputs < 7) { stp->in[stp->numInputs].studio = desc->srcStudio; stp->in[stp->numInputs].vol = ((u16)desc->vol << 8) | ((u16)desc->vol << 1); @@ -454,7 +474,7 @@ u32 salAddStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc) { return 0; } -unsigned long salRemoveStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc) { +bool salRemoveStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc) { long i; // r31 for (i = 0; i < stp->numInputs; ++i) { @@ -472,7 +492,7 @@ unsigned long salRemoveStudioInput(DSPstudioinfo* stp, SND_STUDIO_INPUT* desc) { void salHandleAuxProcessing() { u8 st; // r29 - long* work; // r30 + s32* work; // r30 DSPstudioinfo* sp; // r31 SND_AUX_INFO info; // r1+0x8 sp = &dspStudio[0]; @@ -488,7 +508,9 @@ void salHandleAuxProcessing() { info.data.bufferUpdate.right = work + 0xa0; info.data.bufferUpdate.surround = work + 0x140; sp->auxAHandler(0, &info, sp->auxAUser); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(work, 0x780); +#endif } if (sp->type == 0 && sp->auxBHandler != 0) { @@ -497,7 +519,9 @@ void salHandleAuxProcessing() { info.data.bufferUpdate.right = work + 0xa0; info.data.bufferUpdate.surround = work + 0x140; sp->auxBHandler(0, &info, sp->auxBUser); +#if MUSY_TARGET == MUSY_TARGET_DOLPHIN DCFlushRangeNoSync(work, 0x780); +#endif } } } diff --git a/src/musyx/runtime/hw_pc.c b/src/musyx/runtime/hw_pc.c new file mode 100644 index 00000000..921850b3 --- /dev/null +++ b/src/musyx/runtime/hw_pc.c @@ -0,0 +1,138 @@ +#include "musyx/platform.h" + +#if MUSY_TARGET == MUSY_TARGET_PC +#include +#include "musyx/assert.h" +#include "musyx/hardware.h" +#include "musyx/sal.h" +#include + +static volatile u32 oldState = 0; +static volatile u16 hwIrqLevel = 0; +static volatile u32 salDspInitIsDone = 0; +static volatile u64 salLastTick = 0; +static volatile u32 salLogicActive = 0; +static volatile u32 salLogicIsWaiting = 0; +static volatile u32 salDspIsDone = 0; +void* salAIBufferBase = NULL; +static u8 salAIBufferIndex = 0; +static SND_SOME_CALLBACK userCallback = NULL; + +#define DMA_BUFFER_LEN 0x280 +pthread_mutex_t globalMutex; +pthread_mutex_t globalInterrupt; + +u32 salGetStartDelay(); +static void callUserCallback() { + if (salLogicActive) { + return; + } + salLogicActive = 1; + // OSEnableInterrupts(); + userCallback(); + // OSDisableInterrupts(); + salLogicActive = 0; +} + +void salCallback() { + salAIBufferIndex = (salAIBufferIndex + 1) % 4; + // AIInitDMA(OSCachedToPhysical(salAIBufferBase) + (salAIBufferIndex * DMA_BUFFER_LEN), + // DMA_BUFFER_LEN); + salLastTick = 0; // OSGetTick(); + if (salDspIsDone) { + callUserCallback(); + } else { + salLogicIsWaiting = 1; + } +} + +void dspInitCallback() { + salDspIsDone = TRUE; + salDspInitIsDone = TRUE; +} + +void dspResumeCallback() { + salDspIsDone = TRUE; + if (salLogicIsWaiting) { + salLogicIsWaiting = FALSE; + callUserCallback(); + } +} + +bool salInitAi(SND_SOME_CALLBACK callback, u32 unk, u32* outFreq) { + if ((salAIBufferBase = salMalloc(DMA_BUFFER_LEN * 4)) != NULL) { + memset(salAIBufferBase, 0, DMA_BUFFER_LEN * 4); + // DCFlushRange(salAIBufferBase, DMA_BUFFER_LEN * 4); + salAIBufferIndex = TRUE; + salLogicIsWaiting = FALSE; + salDspIsDone = TRUE; + salLogicActive = FALSE; + userCallback = callback; + // AIRegisterDMACallback(salCallback); + // AIInitDMA(OSCachedToPhysical(salAIBufferBase) + (salAIBufferIndex * 0x280), 0x280); + synthInfo.numSamples = 0x20; + *outFreq = 32000; + MUSY_DEBUG("MusyX AI interface initialized.\n"); + return TRUE; + } + + return FALSE; +} + +bool salStartAi() { } //AIStartDMA(); } + +bool salExitAi() { + salFree(salAIBufferBase); + return TRUE; +} + +void* salAiGetDest() { + u8 index; // r31 + index = (salAIBufferIndex + 2) % 4; + return NULL; +} + +bool salInitDsp(u32) { return TRUE; } + +bool salExitDsp() {} + +void salStartDsp(s16* cmdList) {} + +void salCtrlDsp(s16* dest) { + salBuildCommandList(dest, salGetStartDelay()); + salStartDsp(dspCmdList); +} + +u32 salGetStartDelay() { return 0; } + +void hwInitIrq() { + // oldState = OSDisableInterrupts(); + hwIrqLevel = 1; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ROBUST); + pthread_mutex_init(&globalMutex, &attr); +} + +void hwExitIrq() {} + +void hwEnableIrq() { + if (--hwIrqLevel == 0) { + // OSRestoreInterrupts(oldState); + } +} + +void hwDisableIrq() { + if ((hwIrqLevel++) == 0) { + // oldState = OSDisableInterrupts(); + } +} + +void hwIRQEnterCritical() { + pthread_mutex_lock(&globalMutex); +} + +void hwIRQLeaveCritical() { + pthread_mutex_unlock(&globalMutex); +} +#endif diff --git a/src/musyx/runtime/dolphin/profile.c b/src/musyx/runtime/profile.c similarity index 100% rename from src/musyx/runtime/dolphin/profile.c rename to src/musyx/runtime/profile.c diff --git a/src/musyx/runtime/s_data.c b/src/musyx/runtime/s_data.c index f4b60a1f..815d4562 100644 --- a/src/musyx/runtime/s_data.c +++ b/src/musyx/runtime/s_data.c @@ -179,12 +179,12 @@ static void InsertFXTab(unsigned short gid, FX_DATA* fd) { dataInsertFX(gid, fd- static void RemoveFXTab(unsigned short gid) { dataRemoveFX(gid); } -void sndSetSampleDataUploadCallback(void* (*callback)(unsigned long, unsigned long), - unsigned long chunckSize) { +void sndSetSampleDataUploadCallback(void* (*callback)(u32, u32), + u32 chunckSize) { hwSetSaveSampleCallback(callback, chunckSize); } -u32 sndPushGroup(void* prj_data, u16 gid, void* samples, void* sdir, void* pool) { +bool sndPushGroup(void* prj_data, u16 gid, void* samples, void* sdir, void* pool) { GROUP_DATA* g; // r31 MUSY_ASSERT_MSG(prj_data != NULL, "Project data pointer is NULL"); MUSY_ASSERT_MSG(sdir != NULL, "Sample directory pointer is NULL"); @@ -207,7 +207,7 @@ u32 sndPushGroup(void* prj_data, u16 gid, void* samples, void* sdir, void* pool) } hwSyncSampleMem(); ++sp; - return 1; + return TRUE; } g = (GROUP_DATA*)((u8*)prj_data + g->nextOff); @@ -215,7 +215,7 @@ u32 sndPushGroup(void* prj_data, u16 gid, void* samples, void* sdir, void* pool) } MUSY_DEBUG("Group ID=%d could not be pushed.\n", gid); - return 0; + return FALSE; } /* @@ -230,11 +230,11 @@ u32 sndPushGroup(void* prj_data, u16 gid, void* samples, void* sdir, void* pool) */ -unsigned long sndPopGroup() { - struct GROUP_DATA* g; - struct SDIR_DATA* sdir; +bool sndPopGroup() { + GROUP_DATA* g; + SDIR_DATA* sdir; void* prj; - struct FX_DATA* fd; + FX_DATA* fd; MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); MUSY_ASSERT_MSG(sp != 0, "Soundstack is empty."); @@ -296,9 +296,9 @@ u32 seqPlaySong(u16 sgid, u16 sid, void* arrfile, SND_PLAYPARA* para, u8 irq_cal if (gs[i].gAddr->type == 0) { g = gs[i].gAddr; prj = gs[i].prjAddr; - norm = (PAGE*)((u32)prj + g->data.song.normpageOff); - drum = (PAGE*)((u32)prj + g->data.song.drumpageOff); - midiSetup = (MIDISETUP*)((u32)prj + g->data.song.midiSetupOff); + norm = (PAGE*)((size_t)prj + g->data.song.normpageOff); + drum = (PAGE*)((size_t)prj + g->data.song.drumpageOff); + midiSetup = (MIDISETUP*)((size_t)prj + g->data.song.midiSetupOff); while (midiSetup->songId != 0xFFFF) { if (midiSetup->songId == sid) { if (irq_call != 0) { diff --git a/src/musyx/runtime/seq.c b/src/musyx/runtime/seq.c index e74b6c9f..6a2728ab 100644 --- a/src/musyx/runtime/seq.c +++ b/src/musyx/runtime/seq.c @@ -430,7 +430,7 @@ u32 seqStartPlay(PAGE* norm, PAGE* drum, MIDISETUP* midiSetup, u32* song, SND_PL nseq->section[i].bpm = bpm; synthSetBpm(bpm >> 10, seqId, i); - if (arr->mTrack != NULL) { + if (arr->mTrack != 0) { nseq->section[i].mTrack.base = ARR_GET(arr, arr->mTrack); nseq->section[i].mTrack.addr = nseq->section[i].mTrack.base; } else { @@ -657,7 +657,6 @@ void seqSpeed(u32 seqId, u16 speed) { u32 i; // r30 seqId = seqGetPrivateId(seqId); -#line 1018 MUSY_ASSERT_MSG(seqId != SND_SEQ_ERROR_ID, "Sequencer ID is not valid."); if ((seqId & SND_SEQ_CROSSFADE_ID) == 0) { @@ -675,7 +674,6 @@ void seqContinue(u32 seqId) { struct SEQ_INSTANCE* si; // r31 seqId = seqGetPrivateId(seqId); -#line 1043 MUSY_ASSERT_MSG(seqId != SND_SEQ_ERROR_ID, "Sequencer ID is not valid."); if ((seqId & SND_SEQ_CROSSFADE_ID) == 0) { @@ -758,7 +756,6 @@ void seqVolume(u8 volume, u16 time, u32 seqId, u8 mode) { seqInstance[seqId].syncCrossInfo.vol2 = volume; break; default: -#line 1153 MUSY_FATAL("Illegal sequencere fade mode detected."); break; } @@ -771,7 +768,6 @@ void seqCrossFade(SND_CROSSFADE* ci, u32* new_seqId, bool8 irq_call) { u16 time; // r27 seqId = seqGetPrivateId(ci->seqId1); -#line 1170 MUSY_ASSERT_MSG(seqId != SND_SEQ_ERROR_ID, "Sequencer ID is not valid."); if ((ci->flags & SND_CROSSFADE_SYNC) != 0) { @@ -1087,7 +1083,7 @@ static SEQ_EVENT* GetGlobalEvent(SEQ_SECTION* section) { return ev; } -static SEQ_EVENT* HandleEvent(SEQ_EVENT* event, u8 secIndex, u32* loopFlag) { +static SEQ_EVENT* HandleEvent(SEQ_EVENT* event, u8 secIndex, bool* loopFlag) { CPAT* pa; // r26 NOTE_DATA* pe; // r24 s32 velocity; // r28 diff --git a/src/musyx/runtime/seq_api.c b/src/musyx/runtime/seq_api.c index ba31eff9..3242aa29 100644 --- a/src/musyx/runtime/seq_api.c +++ b/src/musyx/runtime/seq_api.c @@ -16,9 +16,9 @@ */ +#include "musyx/assert.h" #include "musyx/hardware.h" #include "musyx/seq.h" -#include "musyx/assert.h" /* @@ -29,7 +29,7 @@ */ -void sndSeqCrossFade(struct SND_CROSSFADE* ci, unsigned long* new_seqId) { +void sndSeqCrossFade(struct SND_CROSSFADE* ci, u32* new_seqId) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); MUSY_ASSERT_MSG(ci != NULL, "Crossfade information pointer is NULL."); @@ -49,7 +49,7 @@ void sndSeqCrossFade(struct SND_CROSSFADE* ci, unsigned long* new_seqId) { */ -u32 sndSeqCrossFadeDone(u32* new_seqId) { +bool sndSeqCrossFadeDone(SND_SEQID* new_seqId) { if (*new_seqId != -1) { return (*new_seqId & 0x80000000) == 0; } @@ -57,7 +57,7 @@ u32 sndSeqCrossFadeDone(u32* new_seqId) { return TRUE; } -u16 sndSeqGetLoopCnt(u32 seqId) { +u16 sndSeqGetLoopCnt(SND_SEQID seqId) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); seqId = seqGetPrivateId(seqId); @@ -99,7 +99,7 @@ u16 sndSeqGetLoopCntEx(u32 seqId, u8 track) { */ -unsigned long sndSeqGetValid(unsigned long seqId) { +bool sndSeqGetValid(SND_SEQID seqId) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); return seqGetPrivateId(seqId) != -1; @@ -109,10 +109,10 @@ unsigned long sndSeqGetValid(unsigned long seqId) { */ -void sndSeqPause(s32 unk) { +void sndSeqPause(SND_SEQID seqId) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); - seqPause(unk); + seqPause(seqId); hwEnableIrq(); } @@ -121,10 +121,10 @@ void sndSeqPause(s32 unk) { */ -void sndSeqStop(s32 unk) { +void sndSeqStop(SND_SEQID seqid) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); - seqStop(unk); + seqStop(seqid); hwEnableIrq(); } @@ -133,7 +133,7 @@ void sndSeqStop(s32 unk) { */ -unsigned long sndSeqLoop(unsigned long seqId, bool on) { +bool sndSeqLoop(SND_SEQID seqId, bool on) { unsigned long i; // r30 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); @@ -162,8 +162,8 @@ unsigned long sndSeqLoop(unsigned long seqId, bool on) { */ -unsigned long sndSeqLoopEx(unsigned long seqId, unsigned char track, bool on) { - unsigned long i; // r29 +bool sndSeqLoopEx(SND_SEQID seqId, u8 track, bool on) { + u32 i; // r29 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); if ((seqId = seqGetPrivateId(seqId)) != -1) { @@ -209,10 +209,10 @@ void sndSeqSpeed(u32 seqId, u16 speed) { */ -void sndSeqContinue(s32 unk) { +void sndSeqContinue(SND_SEQID seqId) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); - seqContinue(unk); + seqContinue(seqId); hwEnableIrq(); } @@ -221,10 +221,10 @@ void sndSeqContinue(s32 unk) { */ -void sndSeqMute(s32 unk1, s32 unk2, s32 unk3) { +void sndSeqMute(SND_SEQID seqId, u32 mask1, u32 mask2) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); - seqMute(unk1, unk2, unk3); + seqMute(seqId, mask1, mask2); hwEnableIrq(); } @@ -232,8 +232,7 @@ void sndSeqMute(s32 unk1, s32 unk2, s32 unk3) { */ -void sndSeqVolume(unsigned char volume, unsigned short time, unsigned long seqId, - unsigned char mode) { +void sndSeqVolume(u8 volume, u16 time, u32 seqId, u8 mode) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); seqVolume(volume, time, seqId, mode); @@ -245,7 +244,7 @@ void sndSeqVolume(unsigned char volume, unsigned short time, unsigned long seqId */ -unsigned char sndSeqGetVolGroup(unsigned long seqId) { +u8 sndSeqGetVolGroup(SND_SEQID seqId) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); if ((seqId = seqGetPrivateId(seqId)) != -1) { return seqInstance[seqId].defVGroup; @@ -259,8 +258,7 @@ unsigned char sndSeqGetVolGroup(unsigned long seqId) { */ -unsigned long sndSeqAssignVolGroup2Track(unsigned long seqId, unsigned char track, - unsigned char vGroup) { +bool sndSeqAssignVolGroup2Track(SND_SEQID seqId, u8 track, u8 vGroup) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); if ((seqId = seqGetPrivateId(seqId)) != -1) { @@ -280,8 +278,8 @@ unsigned long sndSeqAssignVolGroup2Track(unsigned long seqId, unsigned char trac */ -unsigned char sndSeqGetMidiCtrl(unsigned long seqId, unsigned char channel, unsigned char ctrl) { - unsigned char value; // r31 +u8 sndSeqGetMidiCtrl(SND_SEQID seqId, u8 channel, u8 ctrl) { + u8 value; // r31 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); value = 0; @@ -299,8 +297,8 @@ unsigned char sndSeqGetMidiCtrl(unsigned long seqId, unsigned char channel, unsi */ -unsigned short sndSeqGetMidiCtrl14(unsigned long seqId, unsigned char channel, unsigned char ctrl) { - unsigned short value; // r31 +u16 sndSeqGetMidiCtrl14(SND_SEQID seqId, u8 channel, u8 ctrl) { + u16 value; // r31 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); value = 0; @@ -317,8 +315,7 @@ unsigned short sndSeqGetMidiCtrl14(unsigned long seqId, unsigned char channel, u /* */ -unsigned long sndSeqSetMidiCtrl(unsigned long seqId, unsigned char channel, unsigned char ctrl, - unsigned char value) { +bool sndSeqSetMidiCtrl(SND_SEQID seqId, u8 channel, u8 ctrl, u8 value) { unsigned long ret = FALSE; // r30 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); @@ -339,9 +336,8 @@ unsigned long sndSeqSetMidiCtrl(unsigned long seqId, unsigned char channel, unsi */ -unsigned long sndSeqSetMidiCtrl14(unsigned long seqId, unsigned char channel, unsigned char ctrl, - unsigned short value) { - unsigned long ret = FALSE; // r30 +bool sndSeqSetMidiCtrl14(SND_SEQID seqId, u8 channel, u8 ctrl, u16 value) { + bool ret = FALSE; // r30 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); if ((seqId = seqGetPrivateId(seqId)) != -1) { diff --git a/src/musyx/runtime/snd3d.c b/src/musyx/runtime/snd3d.c index de99cdfd..534780d8 100644 --- a/src/musyx/runtime/snd3d.c +++ b/src/musyx/runtime/snd3d.c @@ -601,9 +601,9 @@ static SND_VOICEID AddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVEC return -1; } -unsigned long sndAddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, - f32 comp, unsigned long flags, unsigned short fxid, - unsigned char maxVol, unsigned char minVol, SND_ROOM* room) { +SND_VOICEID sndAddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, + f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, u8 minVol, + SND_ROOM* room) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, fxid | 0x80000000, maxVol, minVol, room, NULL, 0); @@ -612,10 +612,9 @@ unsigned long sndAddEmitter(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTO return -1; } -unsigned long sndAddEmitterEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, - unsigned short fxid, unsigned short groupid, unsigned char maxVol, - unsigned char minVol, struct SND_ROOM* room) { +SND_VOICEID sndAddEmitterEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, f32 maxDis, + f32 comp, u32 flags, SND_FXID fxid, unsigned short groupid, u8 maxVol, + u8 minVol, SND_ROOM* room) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, groupid, maxVol, minVol, room, NULL, 0); @@ -624,10 +623,9 @@ unsigned long sndAddEmitterEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* return -1; } -unsigned long sndAddEmitterPara(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, unsigned long flags, - unsigned short fxid, unsigned char maxVol, unsigned char minVol, - struct SND_ROOM* room, struct SND_PARAMETER_INFO* para) { +SND_VOICEID sndAddEmitterPara(SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, u8 minVol, + SND_ROOM* room, struct SND_PARAMETER_INFO* para) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, fxid | 0x80000000, maxVol, minVol, room, para, 0); @@ -635,11 +633,9 @@ unsigned long sndAddEmitterPara(struct SND_EMITTER* em_buffer, struct SND_FVECTO return -1; } -unsigned long sndAddEmitterParaEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, - unsigned long flags, unsigned short fxid, unsigned short groupid, - unsigned char maxVol, unsigned char minVol, struct SND_ROOM* room, - struct SND_PARAMETER_INFO* para) { +SND_VOICEID sndAddEmitterParaEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, SND_GROUPID groupid, + u8 maxVol, u8 minVol, SND_ROOM* room, SND_PARAMETER_INFO* para) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, groupid, maxVol, minVol, room, para, 0); @@ -648,10 +644,9 @@ unsigned long sndAddEmitterParaEx(struct SND_EMITTER* em_buffer, struct SND_FVEC return -1; } -unsigned long sndAddEmitter2Studio(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, - unsigned long flags, unsigned short fxid, unsigned char maxVol, - unsigned char minVol, unsigned char studio) { +SND_VOICEID sndAddEmitter2Studio(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, + u8 minVol, u8 studio) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, fxid | 0x80000000, maxVol, minVol, NULL, NULL, studio); @@ -659,11 +654,9 @@ unsigned long sndAddEmitter2Studio(struct SND_EMITTER* em_buffer, struct SND_FVE return -1; } -unsigned long sndAddEmitter2StudioEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, - unsigned long flags, unsigned short fxid, - unsigned short groupid, unsigned char maxVol, - unsigned char minVol, unsigned char studio) { +SND_VOICEID sndAddEmitter2StudioEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u16 groupid, + u8 maxVol, u8 minVol, u8 studio) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, groupid, maxVol, minVol, NULL, NULL, studio); @@ -671,11 +664,9 @@ unsigned long sndAddEmitter2StudioEx(struct SND_EMITTER* em_buffer, struct SND_F return -1; } -unsigned long sndAddEmitter2StudioPara(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, - unsigned long flags, unsigned short fxid, - unsigned char maxVol, unsigned char minVol, - unsigned char studio, struct SND_PARAMETER_INFO* para) { +SND_VOICEID sndAddEmitter2StudioPara(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u8 maxVol, + u8 minVol, u8 studio, SND_PARAMETER_INFO* para) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, fxid | 0x80000000, maxVol, minVol, NULL, para, studio); @@ -683,12 +674,9 @@ unsigned long sndAddEmitter2StudioPara(struct SND_EMITTER* em_buffer, struct SND return -1; } -unsigned long sndAddEmitter2StudioParaEx(struct SND_EMITTER* em_buffer, struct SND_FVECTOR* pos, - struct SND_FVECTOR* dir, f32 maxDis, f32 comp, - unsigned long flags, unsigned short fxid, - unsigned short groupid, unsigned char maxVol, - unsigned char minVol, unsigned char studio, - struct SND_PARAMETER_INFO* para) { +SND_VOICEID sndAddEmitter2StudioParaEx(SND_EMITTER* em_buffer, SND_FVECTOR* pos, SND_FVECTOR* dir, + f32 maxDis, f32 comp, u32 flags, SND_FXID fxid, u16 groupid, + u8 maxVol, u8 minVol, u8 studio, SND_PARAMETER_INFO* para) { if (sndActive) { return AddEmitter(em_buffer, pos, dir, maxDis, comp, flags, fxid, groupid, maxVol, minVol, NULL, para, studio); @@ -696,7 +684,7 @@ unsigned long sndAddEmitter2StudioParaEx(struct SND_EMITTER* em_buffer, struct S return -1; } -unsigned long sndRemoveEmitter(SND_EMITTER* em) { +bool sndRemoveEmitter(SND_EMITTER* em) { if (sndActive) { hwDisableIrq(); if (em->flags & 0x10000) { @@ -711,7 +699,7 @@ unsigned long sndRemoveEmitter(SND_EMITTER* em) { } SND_VOICEID sndEmitterVoiceID(SND_EMITTER* em) { - unsigned long ret; // r31 + SND_VOICEID ret; // r31 ret = 0xffffffff; if (sndActive != FALSE) { @@ -770,8 +758,8 @@ static void MakeListenerMatrix(SND_LISTENER* li) { salInvertMatrix(&li->mat, &mat); } -unsigned long sndUpdateListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, - SND_FVECTOR* heading, SND_FVECTOR* up, u8 vol, SND_ROOM* room) { +bool sndUpdateListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, SND_FVECTOR* heading, + SND_FVECTOR* up, u8 vol, SND_ROOM* room) { if (sndActive) { hwDisableIrq(); li->pos = *pos; @@ -800,10 +788,9 @@ unsigned long sndUpdateListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* return FALSE; } -unsigned long sndAddListenerEx(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, - SND_FVECTOR* heading, SND_FVECTOR* up, f32 front_sur, f32 back_sur, - f32 soundSpeed, f32 volPosOffset, unsigned long flags, - unsigned char vol, SND_ROOM* room) { +bool sndAddListenerEx(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, SND_FVECTOR* heading, + SND_FVECTOR* up, f32 front_sur, f32 back_sur, f32 soundSpeed, + f32 volPosOffset, u32 flags, u8 vol, SND_ROOM* room) { if (sndActive) { hwDisableIrq(); @@ -835,15 +822,14 @@ unsigned long sndAddListenerEx(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* return FALSE; } -unsigned long sndAddListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, - SND_FVECTOR* heading, SND_FVECTOR* up, f32 front_sur, f32 back_sur, - f32 soundSpeed, unsigned long flags, unsigned char vol, - SND_ROOM* room) { +bool sndAddListener(SND_LISTENER* li, SND_FVECTOR* pos, SND_FVECTOR* dir, SND_FVECTOR* heading, + SND_FVECTOR* up, f32 front_sur, f32 back_sur, f32 soundSpeed, u32 flags, u8 vol, + SND_ROOM* room) { return sndAddListenerEx(li, pos, dir, heading, up, front_sur, back_sur, soundSpeed, 0.f, flags, vol, room); } -unsigned long sndRemoveListener(SND_LISTENER* li) { +bool sndRemoveListener(SND_LISTENER* li) { if (sndActive) { hwDisableIrq(); diff --git a/src/musyx/runtime/snd_init.c b/src/musyx/runtime/snd_init.c index 8f053bdb..b09bcdff 100644 --- a/src/musyx/runtime/snd_init.c +++ b/src/musyx/runtime/snd_init.c @@ -18,11 +18,11 @@ */ #include "musyx/assert.h" +#include "musyx/hardware.h" #include "musyx/s3d.h" #include "musyx/seq.h" #include "musyx/stream.h" #include "musyx/synth.h" -#include "musyx/hardware.h" #include "musyx/synthdata.h" // #define _DEBUG @@ -41,8 +41,7 @@ static s32 DoInit(u32 mixFrq, u32 aramSize, u32 numVoices, u32 flags) { bool ret; - MUSY_DEBUG("\nMusyX software initialization...\nBuild Date: %s %s\n\n", "Dec 17 2003", - "20:32:41"); + MUSY_DEBUG("\nMusyX software initialization...\nBuild Date: %s %s\n\n", __DATE__, __TIME__); ret = FALSE; #if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 3) diff --git a/src/musyx/runtime/snd_service.c b/src/musyx/runtime/snd_service.c index 0fa18175..4c312a81 100644 --- a/src/musyx/runtime/snd_service.c +++ b/src/musyx/runtime/snd_service.c @@ -109,7 +109,7 @@ void* sndBSearch(void* key, void* base, s32 num, s32 len, SND_COMPARE cmp) { r = num; do { // This is kind of gross.... - if ((c = cmp(key, (ptr = (void*)((u32)base + len * ((m = (l + r) >> 1) - 1))))) == 0) { + if ((c = cmp(key, (ptr = (void*)((size_t)base + len * ((m = (l + r) >> 1) - 1))))) == 0) { return ptr; } diff --git a/src/musyx/runtime/snd_synthapi.c b/src/musyx/runtime/snd_synthapi.c index 6ffabc2c..60cbb206 100644 --- a/src/musyx/runtime/snd_synthapi.c +++ b/src/musyx/runtime/snd_synthapi.c @@ -202,7 +202,7 @@ SND_VOICEID sndFXStartParaInfo(SND_FXID fid, u8 vol, u8 pan, u8 studio, */ SND_VOICEID sndFXCheck(SND_VOICEID vid) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); return vidGetInternalId(vid) != -1 ? vid : -1; } @@ -213,9 +213,9 @@ SND_VOICEID sndFXCheck(SND_VOICEID vid) { */ -bool sndReadFlag(unsigned char num) { +s32 sndReadFlag(unsigned char num) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); return synthGlobalVariable[num & 0xf]; } @@ -225,9 +225,9 @@ bool sndReadFlag(unsigned char num) { */ -long sndWriteFlag(unsigned char num, long value) { - long old; // r30 - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +s32 sndWriteFlag(u8 num, s32 value) { + s32 old; // r30 + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); num &= 0xf; @@ -244,9 +244,9 @@ long sndWriteFlag(unsigned char num, long value) { */ -u32 sndSendMessage(u32 vid, s32 mesg) { - u32 ret; // r31 - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +bool sndSendMessage(SND_VOICEID vid, s32 mesg) { + bool ret; // r31 + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); ret = macPostMessage(vid, mesg); @@ -258,8 +258,8 @@ u32 sndSendMessage(u32 vid, s32 mesg) { */ -void sndSetReceiveMessageCallback(void (*callback)(unsigned long, long)) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +void sndSetReceiveMessageCallback(void (*callback)(u32, s32)) { + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); synthMessageCallback = callback; } @@ -269,7 +269,7 @@ void sndSetReceiveMessageCallback(void (*callback)(unsigned long, long)) { */ void sndSilence() { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); seqKillAllInstances(); @@ -283,11 +283,11 @@ void sndSilence() { */ -u32 sndIsIdle() { +bool sndIsIdle() { u32 i; // r31 u8 flag; // r30 - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); flag = 0; @@ -308,11 +308,11 @@ u32 sndIsIdle() { */ -u32 sndFXAssignVolGroup2FXId(SND_FXID fid, u8 vGroup) { +bool sndFXAssignVolGroup2FXId(SND_FXID fid, u8 vGroup) { FX_TAB* fx; // r30 u32 ret; // r29 - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); ret = 0; @@ -350,7 +350,7 @@ u32 sndFXAssignVolGroup2FXId(SND_FXID fid, u8 vGroup) { */ void sndPauseVolume(u8 volume, u16 time, u8 vGroup) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); synthPauseVolume(volume, time, vGroup); @@ -363,7 +363,7 @@ void sndPauseVolume(u8 volume, u16 time, u8 vGroup) { */ void sndVolume(u8 volume, u16 time, u8 volgroup) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); synthVolume(volume, time, volgroup, 0, -1); @@ -375,7 +375,7 @@ void sndVolume(u8 volume, u16 time, u8 volgroup) { */ void sndMasterVolume(u8 volume, u16 time, u8 music, u8 fx) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); if (music != 0) synthVolume(volume, time, 0x15, 0, -1); @@ -392,7 +392,7 @@ void sndMasterVolume(u8 volume, u16 time, u8 music, u8 fx) { void sndOutputMode(SND_OUTPUTMODE output) { u32 i; u32 oldFlags; - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); oldFlags = synthFlags; switch (output) { @@ -418,9 +418,7 @@ void sndOutputMode(SND_OUTPUTMODE output) { break; default: -#line 426 MUSY_ASSERT_MSG(FALSE, "Unsupported outputmode selected."); -#line 418 break; } @@ -449,7 +447,7 @@ void sndSetAuxProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA, u8 midiA, SND_SEQID seqIDA, SND_AUX_CALLBACK auxB, void* userB, u8 midiB, SND_SEQID seqIDB) { // clang-format on - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); if (auxA != NULL) { @@ -503,7 +501,7 @@ void sndUpdateAuxParameter(unsigned char studio, unsigned short* para, unsigned struct SND_AUX_INFO info; // r1+0x14 unsigned long i; // r30 - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); for (i = 0; i < 4; ++i) { info.data.parameterUpdate.para[i] = para[i]; @@ -524,7 +522,7 @@ void sndUpdateAuxParameter(unsigned char studio, unsigned short* para, unsigned */ -void sndSetITDDefault(unsigned char studio, unsigned long musicITD, unsigned long sfxITD) { +void sndSetITDDefault(u8 studio, bool musicITD, bool sfxITD) { synthITDDefault[studio].music = musicITD; synthITDDefault[studio].sfx = sfxITD; } @@ -534,7 +532,7 @@ void sndSetITDDefault(unsigned char studio, unsigned long musicITD, unsigned lon */ void synthActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); synthAuxACallback[studio] = NULL; synthAuxBCallback[studio] = NULL; @@ -551,8 +549,8 @@ void synthActivateStudio(u8 studio, u32 isMaster, SND_STUDIO_TYPE type) { */ -void sndActivateStudioEx(u8 studio, u32 isMaster, SND_STUDIO_TYPE type) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +void sndActivateStudioEx(u8 studio, bool isMaster, SND_STUDIO_TYPE type) { + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); MUSY_ASSERT_MSG(studio < synthInfo.studioNum, "Illegal studio index."); if (studio != 0) { hwDisableIrq(); @@ -573,7 +571,7 @@ void sndActivateStudioEx(u8 studio, u32 isMaster, SND_STUDIO_TYPE type) { */ void synthDeactivateStudio(u8 studio) { u32 i; - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); for (i = 0; i < synthInfo.voiceNum; ++i) { @@ -605,7 +603,7 @@ void synthDeactivateStudio(u8 studio) { */ void sndDeactivateStudio(u8 studio) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); MUSY_ASSERT_MSG(studio < synthInfo.studioNum, "Illegal studio index."); if (studio != 0) { hwDisableIrq(); @@ -624,14 +622,14 @@ void sndDeactivateStudio(u8 studio) { */ void synthChangeStudioMasterMix(u8 studio, u32 isMaster) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwChangeStudioMix(studio, isMaster); } // -void sndChangeStudioMasterMix(unsigned char studio, unsigned long isMaster) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +void sndChangeStudioMasterMix(u8 studio, bool isMaster) { + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); if (studio != 0) { hwDisableIrq(); synthChangeStudioMasterMix(studio, isMaster); @@ -648,18 +646,18 @@ void sndChangeStudioMasterMix(unsigned char studio, unsigned long isMaster) { */ -u32 synthAddStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { +bool synthAddStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); return hwAddInput(studio, in_desc); } // -u32 sndAddStudioInput(u8 studio, struct SND_STUDIO_INPUT* in_desc) { +bool sndAddStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { u32 ret; - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); ret = synthAddStudioInput(studio, in_desc); hwEnableIrq(); @@ -669,17 +667,17 @@ u32 sndAddStudioInput(u8 studio, struct SND_STUDIO_INPUT* in_desc) { /* */ -u32 synthRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +bool synthRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); return hwRemoveInput(studio, in_desc); } /* */ -u32 sndRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { - u32 ret; - MUSY_ASSERT_MSG(sndActive != NULL, "Sound system is not initialized."); +bool sndRemoveStudioInput(u8 studio, SND_STUDIO_INPUT* in_desc) { + bool ret; + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); hwDisableIrq(); ret = synthRemoveStudioInput(studio, in_desc); hwEnableIrq(); diff --git a/src/musyx/runtime/stream.c b/src/musyx/runtime/stream.c index d2d84bb0..cbbcb534 100644 --- a/src/musyx/runtime/stream.c +++ b/src/musyx/runtime/stream.c @@ -2,11 +2,11 @@ #include "musyx/assert.h" #include "musyx/hardware.h" +#include "musyx/snd.h" #include "musyx/stream.h" #include "musyx/synth.h" #include "musyx/synthdata.h" #include "musyx/voice.h" -#include "musyx/snd.h" #if !defined(_DEBUG) && MUSY_TARGET == MUSY_TARGET_DOLPHIN #include "dolphin/os.h" @@ -129,8 +129,8 @@ void streamHandle() { } break; case 1: { cpos = (si->last / 14) * 8; - if ((len = si->updateFunction((void*)((u32)si->buffer + cpos), off - si->last, NULL, 0, - si->user)) != 0 && + if ((len = si->updateFunction((void*)((size_t)si->buffer + cpos), off - si->last, NULL, + 0, si->user)) != 0 && si->state == 2) { off = (si->last + len) % si->size; @@ -167,7 +167,7 @@ void streamHandle() { break; case 1: cpos = ((si->last / 14) * 8); - if ((len = si->updateFunction((void*)((u32)si->buffer + cpos), si->size - si->last, + if ((len = si->updateFunction((void*)((size_t)si->buffer + cpos), si->size - si->last, NULL, 0, si->user)) && si->state == 2) { off = (si->last + len) % si->size; @@ -211,7 +211,7 @@ void streamHandle() { break; case 1: { cpos = (si->last / 14) * 8; - if ((len = si->updateFunction((void*)((u32)si->buffer + cpos), si->size - si->last, + if ((len = si->updateFunction((void*)((size_t)si->buffer + cpos), si->size - si->last, si->buffer, off, si->user)) && si->state == 2) { off = (si->last + len) % si->size; @@ -334,20 +334,16 @@ void sndStreamARAMUpdate(u32 stid, u32 off1, u32 len1, u32 off2, u32 len2) { #if MUSY_VERSION >= MUSY_VERSION_CHECK(1, 5, 4) if (streamInfo[i].type == 1) { - -#if MUSY_TARGET == MUSY_TARGET_DOLPHIN - streamInfo[i].lastPSFromBuffer = (*(u32*)OSCachedToUncached(streamInfo[i].buffer)) >> 24; -#elif MUSY_TARGET == MUSY_TARGET_PC - streamInfo[i].lastPSFromBuffer = (*(u32*)streamInfo[i].buffer) >> 24; -#endif - + streamInfo[i].lastPSFromBuffer = + (*(u32*)MUSY_CACHED_TO_UNCACHED_ADDR(streamInfo[i].buffer)) >> 24; if (streamInfo[i].voice != -1) { hwSetStreamLoopPS(streamInfo[i].voice, streamInfo[i].lastPSFromBuffer); } } #else if (streamInfo[i].type == 1) { - hwSetStreamLoopPS(streamInfo[i].voice, *(u32*)OSCachedToUncached(streamInfo[i].buffer) >> 24); + hwSetStreamLoopPS(streamInfo[i].voice, + *(u32*)MUSY_CACHED_TO_UNCACHED_ADDR(streamInfo[i].buffer) >> 24); } #endif } else { @@ -398,9 +394,11 @@ void streamOutputModeChanged() { } #endif -u32 sndStreamAllocEx(u8 prio, void* buffer, u32 samples, u32 frq, u8 vol, u8 pan, u8 span, u8 auxa, - u8 auxb, u8 studio, u32 flags, SND_STREAM_UPDATE_CALLBACK updateFunction, - u32 user, SND_ADPCMSTREAM_INFO* adpcmInfo) { +SND_STREAMID sndStreamAllocEx(u8 prio, void* buffer, u32 samples, u32 frq, u8 vol, u8 pan, u8 span, + u8 auxa, u8 auxb, u8 studio, u32 flags, + u32 (*updateFunction)(void* buffer1, u32 len1, void* buffer2, + u32 len2, u32 user), + u32 user, SND_ADPCMSTREAM_INFO* adpcmInfo) { u32 stid; // r29 u32 i; // r31 u32 bytes; // r25 @@ -643,7 +641,7 @@ void sndStreamFree(u32 stid) { hwEnableIrq(); } -u32 sndStreamActivate(u32 stid) { +bool sndStreamActivate(SND_STREAMID stid) { u32 i; // r31 u32 ret; // r28 ret = 0; diff --git a/src/musyx/runtime/synth.c b/src/musyx/runtime/synth.c index 9f734d21..a3bed2f7 100644 --- a/src/musyx/runtime/synth.c +++ b/src/musyx/runtime/synth.c @@ -1091,9 +1091,9 @@ static bool synthFXVolume(u32 vid, u8 vol) { return ret; } -u32 synthSendKeyOff(u32 voiceid) { +bool synthSendKeyOff(u32 voiceid) { u32 i; // r30 - u32 ret; // r29 + bool ret; // r29 ret = FALSE; @@ -1206,7 +1206,7 @@ void synthVolume(u8 volume, u16 time, u8 vGroup, u8 seqMode, u32 seqId) { } } -u32 synthIsFadeOutActive(u8 vGroup) { +bool synthIsFadeOutActive(u8 vGroup) { if (synthMasterFader[vGroup].type != 4 && (synthMasterFaderActiveFlags & (1 << vGroup)) != 0 && synthMasterFader[vGroup].start > synthMasterFader[vGroup].target) { return TRUE; diff --git a/src/musyx/runtime/synth_adsr.c b/src/musyx/runtime/synth_adsr.c index 6e3753ae..2e8b1cbd 100644 --- a/src/musyx/runtime/synth_adsr.c +++ b/src/musyx/runtime/synth_adsr.c @@ -11,7 +11,7 @@ static u32 adsrGetIndex(ADSR_VARS* adsr) { return i < 0 ? 0 : i; } -u32 adsrConvertTimeCents(long tc) { return 1000.f * powf(2.f, 1.2715658e-08f * tc); } +u32 adsrConvertTimeCents(s32 tc) { return 1000.f * powf(2.f, 1.2715658e-08f * tc); } u32 salChangeADSRState(ADSR_VARS* adsr) { u32 VoiceDone; // r30 @@ -140,7 +140,7 @@ u32 adsrStartRelease(ADSR_VARS* adsr, u32 rtime) { return 0; } -u32 adsrRelease(ADSR_VARS* adsr) { +bool adsrRelease(ADSR_VARS* adsr) { switch (adsr->mode) { case 0: case 1: diff --git a/src/musyx/runtime/synth_vsamples.c b/src/musyx/runtime/synth_vsamples.c index bd6e2841..217a6fd9 100644 --- a/src/musyx/runtime/synth_vsamples.c +++ b/src/musyx/runtime/synth_vsamples.c @@ -56,9 +56,9 @@ void vsFreeBuffer(u8 bufferIndex) { } u32 vsSampleStartNotify(unsigned char voice) { - u8 sb; // r29 - u8 i; // r28 - u32 addr; // r27 + u8 sb; // r29 + u8 i; // r28 + size_t addr; // r27 for (i = 0; i < vs.numBuffers; ++i) { if (vs.streamBuffer[i].state != 0 && vs.streamBuffer[i].voice == voice) { @@ -87,7 +87,7 @@ u32 vsSampleStartNotify(unsigned char voice) { return 0xFFFFFFFF; } -void vsSampleEndNotify(unsigned long pubID) { +void vsSampleEndNotify(u32 pubID) { u8 sb; u8 voice; @@ -221,10 +221,9 @@ void vsSampleUpdates() { } } -unsigned long sndVirtualSampleAllocateBuffers(unsigned char numInstances, - unsigned long numSamples) { - long i; // r31 - unsigned long len; // r28 +bool sndVirtualSampleAllocateBuffers(u8 numInstances, u32 numSamples, u32 flags) { + s32 i; // r31 + u32 len; // r28 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); MUSY_ASSERT_MSG(numInstances <= 64, "Parameter exceeded maximum number of instances allowable"); @@ -255,7 +254,7 @@ unsigned long sndVirtualSampleAllocateBuffers(unsigned char numInstances, return 0; } -s32 sndVirtualSampleFreeBuffers() { +void sndVirtualSampleFreeBuffers() { u8 i; // r31 MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); @@ -266,13 +265,12 @@ s32 sndVirtualSampleFreeBuffers() { vs.numBuffers = 0; } -void sndVirtualSampleSetCallback(unsigned long (*callback)(unsigned char, - struct SND_VIRTUALSAMPLE_INFO*)) { +void sndVirtualSampleSetCallback(u32 (*callback)(u8 reason, const SND_VIRTUALSAMPLE_INFO* info)) { MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); vs.callback = callback; } -void vsARAMDMACallback(unsigned long user) { +void vsARAMDMACallback(size_t user) { if (vs.callback == NULL) { return; } @@ -280,8 +278,8 @@ void vsARAMDMACallback(unsigned long user) { vs.callback(3, &((VS_BUFFER*)user)->info); } -void sndVirtualSampleARAMUpdate(unsigned short instID, void* base, unsigned long off1, - unsigned long len1, unsigned long off2, unsigned long len2) { +void sndVirtualSampleARAMUpdate(SND_INSTID instID, void* base, u32 off1, u32 len1, u32 off2, + u32 len2) { u8 i; MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); @@ -322,7 +320,7 @@ void sndVirtualSampleARAMUpdate(unsigned short instID, void* base, unsigned long hwEnableIrq(); } -void sndVirtualSampleEndPlayback(unsigned short instID) { +void sndVirtualSampleEndPlayback(SND_INSTID instID, bool sampleEndedNormally) { u8 i; // r30 VS_BUFFER* stream; // r31 u32 cpos; // r28 diff --git a/src/musyx/runtime/synthdata.c b/src/musyx/runtime/synthdata.c index aaf3fc76..aa3bcb6d 100644 --- a/src/musyx/runtime/synthdata.c +++ b/src/musyx/runtime/synthdata.c @@ -1,6 +1,6 @@ +#include "musyx/synthdata.h" #include "musyx/assert.h" #include "musyx/hardware.h" -#include "musyx/synthdata.h" #include "musyx/snd.h" static SDIR_TAB dataSmpSDirs[128]; @@ -347,7 +347,7 @@ done: "Sample ID to be inserted could not be found in any sample directory.\n"); if (sdir->ref_cnt == 0) { - sdir->addr = (void*)(sdir->offset + (s32)dataSmpSDirs[i].base); + sdir->addr = (void*)((size_t)sdir->offset + (s32)dataSmpSDirs[i].base); header = &sdir->header; hwSaveSample(&header, &sdir->addr); } @@ -532,7 +532,7 @@ MSTEP* dataGetMacro(u16 mid) { static s32 smpcmp(void* p1, void* p2) { return ((SDIR_DATA*)p1)->id - ((SDIR_DATA*)p2)->id; } -long dataGetSample(u16 sid, SAMPLE_INFO* newsmp) { +s32 dataGetSample(u16 sid, SAMPLE_INFO* newsmp) { static SDIR_DATA key; static SDIR_DATA* result; static SAMPLE_HEADER* sheader; @@ -554,7 +554,7 @@ long dataGetSample(u16 sid, SAMPLE_INFO* newsmp) { newsmp->compType = sheader->length >> 24; if (result->extraData) { - newsmp->extraData = (void*)((u32) & (dataSmpSDirs[i].data)->id + result->extraData); + newsmp->extraData = (void*)((size_t) & (dataSmpSDirs[i].data)->id + result->extraData); } return 0; } @@ -605,7 +605,9 @@ void* dataGetLayer(u16 cid, u16* n) { return NULL; } -static s32 fxcmp(void* p1, void* p2) { return ((FX_TAB*)p1)->id - ((FX_TAB*)p2)->id; } +static s32 fxcmp(void* p1, void* p2) { + return ((FX_TAB*)p1)->id - ((FX_TAB*)p2)->id; +} struct FX_TAB* dataGetFX(u16 fid) { static FX_TAB key; @@ -640,3 +642,35 @@ void dataInit(u32 smpBase, u32 smpLength) { } void dataExit() { hwExitSampleMem(); } + +#if MUSY_TARGET == MUSY_PLATFORM_PC +void* sndConvert32BitSDIRTo64BitSDIR(void* sdir_int) { + SDIR_DATA_INTER* sdir_inter = sdir_int; + SDIR_DATA* sdir = NULL; + s32 i = 0; + SDIR_DATA* s; + SDIR_DATA_INTER* s2 = NULL; + u16 n = 0; + + for (s2 = sdir_inter; s2->id != 0xffff; ++s2) { + ++n; + } + + ++n; + + sdir = malloc(n * sizeof(SDIR_DATA)); + + for (i = 0; i < n; ++i) { + sdir[i].id = sdir_inter[i].id; + sdir[i].ref_cnt = sdir_inter[i].ref_cnt; + sdir[i].offset = sdir_inter[i].offset; + sdir[i].addr = (void*)(size_t)sdir_inter[i].addr; + sdir[i].header = sdir_inter[i].header; + sdir[i].extraData = sdir_inter[i].extraData; + } + + free(sdir_int); + + return sdir; +} +#endif diff --git a/src/musyx/runtime/synthmacros.c b/src/musyx/runtime/synthmacros.c index b5d724d9..8e9be60e 100644 --- a/src/musyx/runtime/synthmacros.c +++ b/src/musyx/runtime/synthmacros.c @@ -1064,7 +1064,7 @@ static void mcmdIfVarCompare(SYNTH_VOICE* svoice, MSTEP* cstep, u8 cmp) { svoice->curAddr = svoice->addr + (u16)(cstep->para[1] >> 0x10); } } -u32 macPostMessage(u32 vid, s32 mesg) { +bool macPostMessage(u32 vid, s32 mesg) { SYNTH_VOICE* sv; // r31 if ((vid = vidGetInternalId(vid)) != -1 && (sv = &synthVoice[vid & 0xFF])->mesgNum < 4) { ++sv->mesgNum; diff --git a/src/musyx/runtime/synthvoice.c b/src/musyx/runtime/synthvoice.c index c42de959..1781b881 100644 --- a/src/musyx/runtime/synthvoice.c +++ b/src/musyx/runtime/synthvoice.c @@ -117,7 +117,7 @@ void vidRemoveVoiceReferences(SYNTH_VOICE* svoice) { } } -unsigned long vidMakeRoot(struct SYNTH_VOICE* svoice) { +u32 vidMakeRoot(SYNTH_VOICE* svoice) { svoice->vidMasterList = svoice->vidList; return svoice->vidList->vid; } @@ -551,7 +551,7 @@ void voiceKill(u32 vi) { hwBreak(vi); } -long voiceKillSound(u32 voiceid) { +s32 voiceKillSound(u32 voiceid) { s32 ret = -1; // r29 u32 next_voiceid; // r28 u32 i; // r30