diff --git a/include/PR/abi.h b/include/PR/abi.h index 07ff777f..2631214f 100644 --- a/include/PR/abi.h +++ b/include/PR/abi.h @@ -1,16 +1,16 @@ #ifndef _ABI_H_ -#define _ABI_H_ +#define _ABI_H_ /************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * * These coded instructions, statements, and computer programs contain * * unpublished proprietary information of Silicon Graphics, Inc., and * * are protected by Federal copyright law. They may not be disclosed * * to third parties or copied or duplicated in any form, in whole or * * in part, without the prior written consent of Silicon Graphics, Inc. * - * * + * * **************************************************************************/ /************************************************************************** @@ -24,47 +24,69 @@ /* * Header file for the Audio Binary Interface. * This is included in the Media Binary Interface file - * mbi.h. + * mbi.h. * * This file follows the framework used for graphics. - * + * */ /* Audio commands: */ -#define A_SPNOOP 0 -#define A_ADPCM 1 -#define A_CLEARBUFF 2 -#define A_ENVMIXER 3 -#define A_LOADBUFF 4 -#define A_RESAMPLE 5 -#define A_SAVEBUFF 6 -#define A_SEGMENT 7 -#define A_SETBUFF 8 -#define A_SETVOL 9 +#define A_SPNOOP 0 +#define A_ADPCM 1 +#define A_CLEARBUFF 2 +#define A_RESAMPLE 5 +#define A_SETBUFF 8 #define A_DMEMMOVE 10 #define A_LOADADPCM 11 -#define A_MIXER 12 +#define A_MIXER 12 #define A_INTERLEAVE 13 -#define A_POLEF 14 #define A_SETLOOP 15 +#ifndef VERSION_SH + +#define A_ENVMIXER 3 +#define A_LOADBUFF 4 +#define A_RESAMPLE 5 +#define A_SAVEBUFF 6 +#define A_SEGMENT 7 +#define A_SETVOL 9 +#define A_POLEF 14 + +#else + +#define A_ADDMIXER 4 +#define A_RESAMPLE_ZOH 6 +#define A_INTERL 17 +#define A_ENVSETUP1 18 +#define A_ENVMIXER 19 +#define A_LOADBUFF 20 +#define A_SAVEBUFF 21 +#define A_ENVSETUP2 22 +#define A_UNK_23 23 +#define A_HILOGAIN 24 +#define A_UNK_25 25 +#define A_DUPLICATE 26 +#define A_FILTER 27 + +#endif + #define ACMD_SIZE 32 /* * Audio flags */ -#define A_INIT 0x01 -#define A_CONTINUE 0x00 +#define A_INIT 0x01 +#define A_CONTINUE 0x00 #define A_LOOP 0x02 #define A_OUT 0x02 -#define A_LEFT 0x02 -#define A_RIGHT 0x00 -#define A_VOL 0x04 -#define A_RATE 0x00 -#define A_AUX 0x08 -#define A_NOAUX 0x00 -#define A_MAIN 0x00 -#define A_MIX 0x10 +#define A_LEFT 0x02 +#define A_RIGHT 0x00 +#define A_VOL 0x04 +#define A_RATE 0x00 +#define A_AUX 0x08 +#define A_NOAUX 0x00 +#define A_MAIN 0x00 +#define A_MIX 0x10 /* * BEGIN C-specific section: (typedef's) @@ -76,173 +98,173 @@ */ typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int addr; } Aadpcm; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int addr; } Apolef; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; } Aenvelope; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int dmem:16; - unsigned int pad2:16; - unsigned int count:16; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int dmem:16; + unsigned int pad2:16; + unsigned int count:16; } Aclearbuff; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int pad2:16; - unsigned int inL:16; - unsigned int inR:16; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int pad2:16; + unsigned int inL:16; + unsigned int inR:16; } Ainterleave; typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int addr; } Aloadbuff; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; } Aenvmixer; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int dmemi:16; - unsigned int dmemo:16; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int dmemi:16; + unsigned int dmemo:16; } Amixer; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int dmem2:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int dmem2:16; + unsigned int addr; } Apan; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pitch:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pitch:16; + unsigned int addr; } Aresample; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; } Areverb; typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int addr; } Asavebuff; typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int pad2:2; - unsigned int number:4; - unsigned int base:24; + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int pad2:2; + unsigned int number:4; + unsigned int base:24; } Asegment; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int dmemin:16; - unsigned int dmemout:16; - unsigned int count:16; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int dmemin:16; + unsigned int dmemout:16; + unsigned int count:16; } Asetbuff; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int vol:16; - unsigned int voltgt:16; - unsigned int volrate:16; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int vol:16; + unsigned int voltgt:16; + unsigned int volrate:16; } Asetvol; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int dmemin:16; - unsigned int dmemout:16; - unsigned int count:16; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int dmemin:16; + unsigned int dmemout:16; + unsigned int count:16; } Admemmove; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int count:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int count:16; + unsigned int addr; } Aloadadpcm; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int pad2:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int pad2:16; + unsigned int addr; } Asetloop; - + /* * Generic Acmd Packet */ typedef struct { - unsigned int w0; - unsigned int w1; + uintptr_t w0; + uintptr_t w1; } Awords; typedef union { - Awords words; - Aadpcm adpcm; - Apolef polef; - Aclearbuff clearbuff; - Aenvelope envelope; - Ainterleave interleave; - Aloadbuff loadbuff; - Aenvmixer envmixer; - Aresample resample; - Areverb reverb; - Asavebuff savebuff; - Asegment segment; - Asetbuff setbuff; - Asetvol setvol; - Admemmove dmemmove; - Aloadadpcm loadadpcm; - Amixer mixer; - Asetloop setloop; - long long int force_union_align; /* dummy, force alignment */ + Awords words; +#if IS_BIG_ENDIAN && !IS_64_BIT + Aadpcm adpcm; + Apolef polef; + Aclearbuff clearbuff; + Aenvelope envelope; + Ainterleave interleave; + Aloadbuff loadbuff; + Aenvmixer envmixer; + Aresample resample; + Areverb reverb; + Asavebuff savebuff; + Asegment segment; + Asetbuff setbuff; + Asetvol setvol; + Admemmove dmemmove; + Aloadadpcm loadadpcm; + Amixer mixer; + Asetloop setloop; +#endif + long long int force_union_align; /* dummy, force alignment */ } Acmd; /* * ADPCM State */ -#define ADPCMVSIZE 8 -#define ADPCMFSIZE 16 -typedef short ADPCM_STATE[ADPCMFSIZE]; +typedef short ADPCM_STATE[16]; /* * Pole filter state @@ -258,7 +280,7 @@ typedef short RESAMPLE_STATE[16]; * Resampler constants */ #define UNITY_PITCH 0x8000 -#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ +#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ /* * Enveloper/Mixer state @@ -269,144 +291,551 @@ typedef short ENVMIX_STATE[40]; * Macros to assemble the audio command list */ -#define aADPCMdec(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (unsigned int)(s); \ +/* + * Info about parameters: + * + * A "count" in the following macros is always measured in bytes. + * + * All volumes/gains are in Q1.15 signed fixed point numbers: + * 0x8000 is the minimum volume (-100%), negating the audio curve. + * 0x0000 is silent. + * 0x7fff is maximum volume (99.997%). + * + * All DRAM addresses refer to segmented addresses. A segment table shall + * first be set up by calling aSegment for each segment. When a DRAM + * address is later used as parameter, the 8 high bits will be an index + * to the segment table and the lower 24 bits are added to the base address + * stored in the segment table for this entry. The result is the physical address. + * + * Transfers to/from DRAM are executed using DMA and hence follow these restrictions: + * All DRAM addresses should be aligned by 8 bytes, or they will be + * rounded down to the nearest multiple of 8 bytes. + * All DRAM lengths should be aligned by 8 bytes, or they will be + * rounded up to the nearest multiple of 8 bytes. + */ + +/* + * Decompresses ADPCM data. + * Possible flags: A_INIT and A_LOOP. + * + * First set up internal data in DMEM: + * aLoadADPCM(cmd++, nEntries * 16, physicalAddressOfBook) + * aSetLoop(cmd++, physicalAddressOfLoopState) (if A_LOOP is set) + * + * Then before this command, call: + * aSetBuffer(cmd++, 0, in, out, count) + * + * Note: count will be rounded up to the nearest multiple of 32 bytes. + * + * ADPCM decompression works on a block of 16 (uncompressed) samples. + * The previous 2 samples and 9 bytes of input are decompressed to + * 16 new samples using the code book previously loaded. + * + * Before the algorithm starts, the previous 16 samples are loaded according to flag: + * A_INIT: all zeros + * A_LOOP: the address set by aSetLoop + * no flags: the DRAM address in the s parameter + * These 16 samples are immediately copied to the destination address. + * + * The result of "count" bytes will be written after these 16 initial samples. + * The last 16 samples written to the destination will also be written to + * the state address in DRAM. + */ +#define aADPCMdec(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aPoleFilter(pkt, f, g, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ +#define aADPCM_23(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_UNK_23, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aClearBuffer(pkt, d, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \ - _a->words.w1 = (unsigned int)(c); \ +/* + * Not used in SM64. + */ +#define aPoleFilter(pkt, f, g, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(g, 0, 16)); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aEnvMixer(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ENVMIXER, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (unsigned int)(s); \ +/* + * Clears DMEM data, where d is address and c is count, by writing zeros. + * + * Note: c is rounded up to the nearest multiple of 16 bytes. + */ +#define aClearBuffer(pkt, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \ + _a->words.w1 = (uintptr_t)(c); \ } -#define aInterleave(pkt, l, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8); \ - _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ +/* + * Mixes an envelope with mono sound into 2 or 4 channels. + * Possible flags: A_INIT, A_AUX (indicates that 4 channels should be used). + * + * Before this command, call: + * aSetBuffer(cmd++, 0, inBuf, dryLeft, count) + * aSetBuffer(cmd++, A_AUX, dryRight, wetLeft, wetRight) + * + * The first time (A_INIT is set), volume also needs to be set: + * aSetVolume(cmd++, A_VOL | A_LEFT, initialVolumeLeft, 0, 0) + * aSetVolume(cmd++, A_VOL | A_RIGHT, initialVolumeRight, 0, 0) + * aSetVolume32(cmd++, A_RATE | A_LEFT, targetVolumeLeft, rampLeft) + * aSetVolume32(cmd++, A_RATE | A_RIGHT, targetVolumeRight, rampRight) + * aSetVolume(cmd++, A_AUX, dryVolume, 0, wetVolume) + * + * This command will now mix samples in inBuf into the destination buffers (dry and wet), + * but with the volume increased (or decreased) from initial volumes to target volumes, + * with the specified ramp rate. Once the target volume is reached, the volume stays + * at that level. Before the samples are finally mixed (added) into the destination + * buffers (dry and wet), the volume is changed according to dryVolume and wetVolume. + * + * Note: count will be rounded up to the nearest multiple of 16 bytes. + * Note: the wet channels are used for reverb. + * + */ +#define aEnvMixer(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ENVMIXER, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aLoadBuffer(pkt, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ - _a->words.w1 = (unsigned int)(s); \ +/* + * Interleaves two mono channels into stereo. + * + * First call: + * aSetBuffer(cmd++, 0, 0, output, count) + * + * The count refers to the size of each input. Hence 2 * count bytes will be written out. + * A left sample will be placed before the right sample. + * + * Note: count will be rounded up to the nearest multiple of 16 bytes. + */ +#define aInterleave(pkt, l, r) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8); \ + _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ } -#define aMix(pkt, f, g, i, o) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = _SHIFTL(i,16, 16) | _SHIFTL(o, 0, 16); \ +/* + * Loads a buffer from DRAM to DMEM. + * + * First call: + * aSetBuffer(cmd++, 0, in, 0, count) + * + * The in parameter to aSetBuffer is the destination in DMEM and the + * s parameter to this command is the source in DRAM. + */ +#define aLoadBuffer(pkt, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aPan(pkt, f, d, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(d, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ +/* + * Mixes audio. + * Possible flags: no flags used, although parameter present. + * + * First call: + * aSetBuffer(cmd++, 0, 0, 0, count) + * + * Input and output addresses are taken from the i and o parameters. + * The volume with which the input is changed is taken from the g parameter. + * After the volume of the input samples have been changed, the result + * is added to the output. + * + * Note: count will be rounded up to the nearest multiple of 32 bytes. + */ +#define aMix(pkt, f, g, i, o) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(g, 0, 16)); \ + _a->words.w1 = _SHIFTL(i,16, 16) | _SHIFTL(o, 0, 16); \ } -#define aResample(pkt, f, p, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) |\ - _SHIFTL(p, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ +// Not present in the audio microcode. +#define aPan(pkt, f, d, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(d, 0, 16)); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aSaveBuffer(pkt, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8); \ - _a->words.w1 = (unsigned int)(s); \ +/* + * Resamples audio. + * Possible flags: A_INIT, A_OUT? (not used in SM64). + * + * First call: + * aSetBuffer(cmd++, 0, in, out, count) + * + * This command resamples the audio using the given frequency ratio (pitch) + * using a filter that uses a window of 4 source samples. This can be used + * either for just resampling audio to be able to be played back at a different + * sample rate, or to change the pitch if the result is played back at + * the same sample rate as the input. + * + * The frequency ratio is given in UQ1.15 fixed point format. + * For no change in frequency, use pitch 0x8000. + * For 1 octave up or downsampling to (roughly) half number of samples, use pitch 0xffff. + * For 1 octave down or upsampling to double as many samples, use pitch 0x4000. + * + * Note: count represents the number of output sample bytes and is rounded up to + * the nearest multiple of 16 bytes. + * + * The state consists of the four following source samples when the algorithm stopped as + * well as a fractional position, and is initialized to all zeros if A_INIT is given. + * Otherwise it is loaded from DRAM at address s. + * + * The algorithm starts by writing the four source samples from the state (or zero) + * to just before the input address given. It then creates one output sample by examining + * the four next source samples and then moving the source position zero or more + * samples forward. The first output sample (when A_INIT is given) is always 0. + * + * When "count" bytes have been written, the following four source samples + * are written to the state in DRAM as well as a fractional position. + */ +#define aResample(pkt, f, p, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) |\ + _SHIFTL(p, 0, 16)); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aSegment(pkt, s, b) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ - _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ +/* + * Stores a buffer in DMEM to DRAM. + * + * First call: + * aSetBuffer(cmd++, 0, 0, out, count) + * + * The out parameter to aSetBuffer is the source in DMEM and the + * s parameter to this command is the destination in DRAM. + */ +#define aSaveBuffer(pkt, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8); \ + _a->words.w1 = (uintptr_t)(s); \ } -#define aSetBuffer(pkt, f, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(i, 0, 16)); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +/* + * Sets up an entry in the segment table. + * + * The s parameter is a segment index, 0 to 15. + * The b parameter is the base offset. + */ +#define aSegment(pkt, s, b) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ + _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ } -#define aSetVolume(pkt, f, v, t, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ - _SHIFTL(v, 0, 16)); \ - _a->words.w1 = _SHIFTL(t, 16, 16) | _SHIFTL(r, 0, 16); \ +/* + * Sets internal DMEM buffer addresses used for later commands. + * See each command for how to use aSetBuffer. + */ +#define aSetBuffer(pkt, f, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(i, 0, 16)); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ } -#define aSetVolume32(pkt, f, v, tr) aSetVolume(pkt, f, v, (int16_t)((tr) >> 16), (int16_t)(tr)) +#define aInterl(pkt, f, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_INTERL, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(i, 0, 16)); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +} +/* + * Sets internal volume parameters. + * See aEnvMixer for more info. + */ +#define aSetVolume(pkt, f, v, t, r) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ + _SHIFTL(v, 0, 16)); \ + _a->words.w1 = _SHIFTL(t, 16, 16) | _SHIFTL(r, 0, 16); \ +} + +/* + * Sets the address to ADPCM loop state. + * + * The a parameter is a DRAM address. + * See aADPCMdec for more info. + */ #define aSetLoop(pkt, a) \ { \ Acmd *_a = (Acmd *)pkt; \ _a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \ - _a->words.w1 = (unsigned int)(a); \ -} - -#define aDMEMMove(pkt, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ + _a->words.w1 = (uintptr_t)(a); \ } -#define aLoadADPCM(pkt, c, d) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ - _a->words.w1 = (unsigned int) d; \ +/* + * Copies memory in DMEM. + * + * Copies c bytes from address i to address o. + * + * Note: count is rounded up to the nearest multiple of 16 bytes. + * + * Note: This acts as memcpy where 16 bytes are moved at a time, therefore + * if input and output overlap, output address should be less than input address. + */ +#define aDMEMMove(pkt, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ } +/* + * Loads ADPCM book from DRAM into DMEM. + * + * This command loads ADPCM table entries from DRAM to DMEM. + * + * The count parameter c should be a multiple of 16 bytes. + * The d parameter is a DRAM address. + */ +#define aLoadADPCM(pkt, c, d) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ + _a->words.w1 = (uintptr_t) (d); \ +} + +// This is a version of aSetVolume which takes a single 32-bit parameter +// instead of two 16-bit ones. According to AziAudio, it is used to set +// ramping values when neither bit 4 nor bit 8 is set in the flags parameter. +// It does not appear in the official abi.h header. +/* + * Sets internal volume parameters. + * See aEnvMixer for more info. + */ +#define aSetVolume32(pkt, f, v, tr) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ + _SHIFTL(v, 0, 16)); \ + _a->words.w1 = (uintptr_t)(tr); \ +} + +#ifdef VERSION_SH +#undef aLoadBuffer +#undef aSaveBuffer +#undef aMix +#undef aEnvMixer +#undef aInterleave + +/* + * Mix two tracks by simple clamped addition. + * + * s: DMEM source track 1 + * d: DMEM source track 2 and destination + * c: number of bytes to write (rounded down to 16 byte alignment) + */ +#define aAddMixer(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ADDMIXER, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(0x7fff, 0, 16)); \ + _a->words.w1 = (_SHIFTL(s, 16, 16) | _SHIFTL(d, 0, 16)); \ +} + +/* + * Loads a buffer from DRAM to DMEM. + * + * s: DRAM source + * d: DMEM destination + * c: number of bytes to copy (rounded down to 16 byte alignment) + */ +#define aLoadBuffer(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(d, 0, 16); \ + _a->words.w1 = (uintptr_t)(s); \ +} + +/* + * Stores a buffer from DMEM to DRAM. + * + * s: DMEM source + * d: DRAM destination + * c: number of bytes to copy (rounded down to 16 byte alignment) + */ +#define aSaveBuffer(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(s, 0, 16); \ + _a->words.w1 = (uintptr_t)(d); \ +} + +/* + * Duplicates 128 bytes of data a number of times. + * + * 128 bytes are read from source DMEM address s. + * Then c identical copies of these bytes are written to DMEM address d. + */ +#define aDuplicate(pkt, s, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_DUPLICATE, 24, 8) | \ + _SHIFTL(c, 16, 8) | _SHIFTL(s, 0, 16)); \ + _a->words.w1 = (_SHIFTL(d, 16, 16) | _SHIFTL(0x80, 0, 16)); \ +} + +/* + * Fast resample. + * + * Before this command, call: + * aSetBuffer(cmd++, 0, in, out, count) + * + * This works like the other resample command but just takes the "nearest" sample, + * instead of a function of the four nearest samples. + */ +#define aResampleZoh(pkt, pitch, start_fract) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE_ZOH, 24, 8) | \ + _SHIFTL(pitch, 0, 16)); \ + _a->words.w1 = _SHIFTL(start_fract, 0, 16); \ +} + +/* + * Mixes audio. + * + * Input and output addresses are taken from the i and o parameters. + * The volume with which the input is changed is taken from the g parameter. + * After the volume of the input samples have been changed, the result + * is added to the output. + * + * Note: count is first rounded down to the nearest multiple of 16 bytes + * and then rounded up to the nearest multiple of 32 bytes. + */ +#define aMix(pkt, g, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(g, 0, 16)); \ + _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ +} + +#define aEnvSetup1(pkt, a, b, c, d) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ENVSETUP1, 24, 8) | \ + _SHIFTL(a, 16, 8) | _SHIFTL(b, 0, 16)); \ + _a->words.w1 = _SHIFTL(c, 16, 16) | _SHIFTL(d, 0, 16); \ +} + +#define aEnvSetup2(pkt, volLeft, volRight) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ENVSETUP2, 24, 8); \ + _a->words.w1 = _SHIFTL(volLeft, 16, 16) | \ + _SHIFTL(volRight, 0, 16); \ +} + +#define aEnvMixer(pkt, inBuf, nSamples, bit1, bit2, bit3, dryLeft, dryRight, wetLeft, wetRight) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ENVMIXER, 24, 8) | \ + _SHIFTL((inBuf) >> 4, 16, 8) | \ + _SHIFTL(nSamples, 8, 8)) | \ + _SHIFTL(bit1, 2, 1) | _SHIFTL(bit2, 1, 1) | \ + _SHIFTL(bit3, 0, 1); \ + _a->words.w1 = _SHIFTL((dryLeft) >> 4, 24, 8) | \ + _SHIFTL((dryRight) >> 4, 16, 8) | \ + _SHIFTL((wetLeft) >> 4, 8, 8) | \ + _SHIFTL((wetRight) >> 4, 0, 8); \ +} + +#define aInterleave(pkt, o, l, r, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8) | \ + _SHIFTL((c) >> 4, 16, 8) | _SHIFTL(o, 0, 16); \ + _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ +} + +// countOrBuf meaning depends on flag +#define aFilter(pkt, f, countOrBuf, addr) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_FILTER, 24, 8) | _SHIFTL((f), 16, 8) | \ + _SHIFTL((countOrBuf), 0, 16); \ + _a->words.w1 = (uintptr_t)(addr); \ +} + +#define aHilogain(pkt, id, buflen, i) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_HILOGAIN, 24, 8) | \ + _SHIFTL((id), 16, 8) | _SHIFTL((buflen), 0, 16); \ + _a->words.w1 = _SHIFTL((i), 16, 16); \ +} + +#define aUnknown25(pkt, f, g, i, o) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_UNK_25, 24, 8) | \ + _SHIFTL((f), 16, 8) | _SHIFTL((g), 0, 16)); \ + _a->words.w1 = _SHIFTL((i), 16, 16) | _SHIFTL((o), 0, 16); \ +} + +#endif + #endif /* _LANGUAGE_C */ #endif /* !_ABI_H_ */ - - - diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index b5d63609..3fffe9c0 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -1,281 +1,12 @@ -/*==================================================================== - * libaudio.h - * - * Copyright 1993, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ +#ifndef _ULTRA64_LIBAUDIO_H_ +#define _ULTRA64_LIBAUDIO_H_ -/************************************************************************** - * - * $Revision: 1.173 $ - * $Date: 1997/12/01 12:42:21 $ - * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/libaudio.h,v $ - * - **************************************************************************/ +#include "abi.h" -#ifndef __LIB_AUDIO__ -#define __LIB_AUDIO__ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include - -/*********************************************************************** - * misc defines - ***********************************************************************/ -#ifndef _EMULATOR -# ifdef AUD_PROFILE - -#define PROFILE_AUD(num, cnt, max, min) \ -{ \ - u32 currCnt = osGetCount(); \ - currCnt -= lastCnt[cnt_index]; \ - cnt_index--; \ - cnt += currCnt; \ - num++; \ - \ - if ( currCnt > max ) max = currCnt; \ - if ( currCnt < min ) min = currCnt; \ -} - -# endif /* AUD_PROFILE */ -#endif /* EMULATOR */ - -#ifndef NULL -#define NULL 0 -#endif - -#define AL_FX_BUFFER_SIZE 8192 -#define AL_FRAME_INIT -1 -#define AL_USEC_PER_FRAME 16000 -#define AL_MAX_PRIORITY 127 -#define AL_GAIN_CHANGE_TIME 1000 - -typedef s32 ALMicroTime; -typedef u8 ALPan; - -#define AL_PAN_CENTER 64 -#define AL_PAN_LEFT 0 -#define AL_PAN_RIGHT 127 -#define AL_VOL_FULL 127 -#define AL_KEY_MIN 0 -#define AL_KEY_MAX 127 -#define AL_DEFAULT_FXMIX 0 -#define AL_SUSTAIN 63 - -/*********************************************************************** - * Error handling - ***********************************************************************/ - -#ifdef _DEBUG -#define ALFailIf(condition, error) \ - if (condition) { \ - __osError(error, 0); \ - return; } - -#else -#define ALFailIf(condition, error) \ - if (condition) { \ - return; } -#endif - -#ifdef _DEBUG -#define ALFlagFailIf(condition, flag, error) \ - if (condition) { \ - if(flag) __osError(error, 0); \ - return; } - -#else -#define ALFlagFailIf(condition, flag, error) \ - if (condition) { \ - return; } -#endif - -/*********************************************************************** - * Audio Library global routines - ***********************************************************************/ -typedef struct ALLink_s { - struct ALLink_s *next; - struct ALLink_s *prev; -} ALLink; - -void alUnlink(ALLink *element); -void alLink(ALLink *element, ALLink *after); - -typedef s32 (*ALDMAproc)(s32 addr, s32 len, void *state); -typedef ALDMAproc (*ALDMANew)(void *state); - -void alCopy(void *src, void *dest, s32 len); - -typedef struct { - u8 *base; - u8 *cur; - s32 len; - s32 count; -} ALHeap; - -#define AL_HEAP_DEBUG 1 -#define AL_HEAP_MAGIC 0x20736a73 -#define AL_HEAP_INIT 0 - -void alHeapInit(ALHeap *hp, u8 *base, s32 len); -void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); -s32 alHeapCheck(ALHeap *hp); - -#ifdef _DEBUG -#define alHeapAlloc(hp, elem ,size) alHeapDBAlloc((u8 *) __FILE__,__LINE__,(hp),(elem),(size)) -#else -#define alHeapAlloc(hp, elem ,size) alHeapDBAlloc(0, 0,(hp),(elem),(size)) -#endif - -/*********************************************************************** - * FX Stuff - ***********************************************************************/ -#define AL_FX_NONE 0 -#define AL_FX_SMALLROOM 1 -#define AL_FX_BIGROOM 2 -#define AL_FX_CHORUS 3 -#define AL_FX_FLANGE 4 -#define AL_FX_ECHO 5 -#define AL_FX_CUSTOM 6 - -typedef u8 ALFxId; -typedef void *ALFxRef; - -/*********************************************************************** - * data structures for sound banks - ***********************************************************************/ - -#define AL_BANK_VERSION 0x4231 /* 'B1' */ - -/* Possible wavetable types */ -enum {AL_ADPCM_WAVE = 0, - AL_RAW16_WAVE}; - -typedef struct { - s32 order; - s32 npredictors; - s16 book[1]; /* Actually variable size. Must be 8-byte aligned */ -} ALADPCMBook; - -typedef struct { - u32 start; - u32 end; - u32 count; - ADPCM_STATE state; -} ALADPCMloop; - -typedef struct { - u32 start; - u32 end; - u32 count; -} ALRawLoop; - -typedef struct { - ALMicroTime attackTime; - ALMicroTime decayTime; - ALMicroTime releaseTime; - u8 attackVolume; - u8 decayVolume; -} ALEnvelope; - -typedef struct { - u8 velocityMin; - u8 velocityMax; - u8 keyMin; - u8 keyMax; - u8 keyBase; - s8 detune; -} ALKeyMap; - -typedef struct { - ALADPCMloop *loop; - ALADPCMBook *book; -} ALADPCMWaveInfo; - -typedef struct { - ALRawLoop *loop; -} ALRAWWaveInfo; - -typedef struct ALWaveTable_s { - u8 *base; /* ptr to start of wave data */ - s32 len; /* length of data in bytes */ - u8 type; /* compression type */ - u8 flags; /* offset/address flags */ - union { - ALADPCMWaveInfo adpcmWave; - ALRAWWaveInfo rawWave; - } waveInfo; -} ALWaveTable; - -typedef struct ALSound_s { - ALEnvelope *envelope; - ALKeyMap *keyMap; - ALWaveTable *wavetable; /* offset to wavetable struct */ - ALPan samplePan; - u8 sampleVolume; - u8 flags; -} ALSound; - -typedef struct { - u8 volume; /* overall volume for this instrument */ - ALPan pan; /* 0 = hard left, 127 = hard right */ - u8 priority; /* voice priority for this instrument */ - u8 flags; - u8 tremType; /* the type of tremelo osc. to use */ - u8 tremRate; /* the rate of the tremelo osc. */ - u8 tremDepth; /* the depth of the tremelo osc */ - u8 tremDelay; /* the delay for the tremelo osc */ - u8 vibType; /* the type of tremelo osc. to use */ - u8 vibRate; /* the rate of the tremelo osc. */ - u8 vibDepth; /* the depth of the tremelo osc */ - u8 vibDelay; /* the delay for the tremelo osc */ - s16 bendRange; /* pitch bend range in cents */ - s16 soundCount; /* number of sounds in this array */ - ALSound *soundArray[1]; -} ALInstrument; - -typedef struct ALBank_s { - s16 instCount; /* number of programs in this bank */ - u8 flags; - u8 pad; - s32 sampleRate; /* e.g. 44100, 22050, etc... */ - ALInstrument *percussion; /* default percussion for GM */ - ALInstrument *instArray[1]; /* ARRAY of instruments */ -} ALBank; - -typedef struct { /* Note: sizeof won't be correct */ - s16 revision; /* format revision of this file */ - s16 bankCount; /* number of banks */ - ALBank *bankArray[1]; /* ARRAY of bank offsets */ -} ALBankFile; - -void alBnkfNew(ALBankFile *f, u8 *table); - -/*********************************************************************** - * Sequence Files - ***********************************************************************/ -#define AL_SEQBANK_VERSION 'S1' - -typedef struct { - u8 *offset; - s32 len; +typedef struct +{ + u8 *offset; + s32 len; #ifdef VERSION_SH s8 magic[2]; // tbl: 0x0204, otherwise: 0x0203 @@ -298,675 +29,20 @@ typedef struct { #endif } ALSeqData; -typedef struct { /* Note: sizeof won't be correct */ - s16 revision; /* format revision of this file */ - s16 seqCount; /* number of sequences */ +typedef struct +{ +#ifndef VERSION_SH + s16 revision; +#endif + s16 seqCount; #ifdef VERSION_SH s16 unk2; u8 *data; s32 pad[2]; #endif - ALSeqData seqArray[1]; /* ARRAY of sequence info */ + ALSeqData seqArray[1]; } ALSeqFile; -void alSeqFileNew(ALSeqFile *f, u8 *base); +void alSeqFileNew(ALSeqFile *f, u8 *base); -/*********************************************************************** - * Synthesis driver stuff - ***********************************************************************/ -typedef ALMicroTime (*ALVoiceHandler)(void *); - -typedef struct { - s32 maxVVoices; /* obsolete */ - s32 maxPVoices; - s32 maxUpdates; - s32 maxFXbusses; - void *dmaproc; - ALHeap *heap; - s32 outputRate; /* output sample rate */ - ALFxId fxType; - s32 *params; -} ALSynConfig; - -typedef struct ALPlayer_s { - struct ALPlayer_s *next; - void *clientData; /* storage for client callback */ - ALVoiceHandler handler; /* voice handler for player */ - ALMicroTime callTime; /* usec requested callback */ - s32 samplesLeft; /* usec remaining to callback */ -} ALPlayer; - -typedef struct ALVoice_s { - ALLink node; - struct PVoice_s *pvoice; - ALWaveTable *table; - void *clientPrivate; - s16 state; - s16 priority; - s16 fxBus; - s16 unityPitch; -} ALVoice; - -typedef struct ALVoiceConfig_s { - s16 priority; /* voice priority */ - s16 fxBus; /* bus assignment */ - u8 unityPitch; /* unity pitch flag */ -} ALVoiceConfig; - -typedef struct { - ALPlayer *head; /* client list head */ - ALLink pFreeList; /* list of free physical voices */ - ALLink pAllocList; /* list of allocated physical voices */ - ALLink pLameList; /* list of voices ready to be freed */ - s32 paramSamples; - s32 curSamples; /* samples from start of game */ - ALDMANew dma; - ALHeap *heap; - - struct ALParam_s *paramList; - - struct ALMainBus_s *mainBus; - struct ALAuxBus_s *auxBus; /* ptr to array of aux bus structs */ - struct ALFilter_s *outputFilter; /* last filter in the filter chain */ - - s32 numPVoices; - s32 maxAuxBusses; - s32 outputRate; /* output sample rate */ - s32 maxOutSamples; /* Maximum samples rsp can generate - at one time at output rate */ -} ALSynth; - -void alSynNew(ALSynth *s, ALSynConfig *config); -void alSynDelete(ALSynth *s); - -void alSynAddPlayer(ALSynth *s, ALPlayer *client); -void alSynRemovePlayer(ALSynth *s, ALPlayer *client); - -s32 alSynAllocVoice(ALSynth *s, ALVoice *v, ALVoiceConfig *vc); -void alSynFreeVoice(ALSynth *s, ALVoice *voice); - -void alSynStartVoice(ALSynth *s, ALVoice *voice, ALWaveTable *w); -void alSynStartVoiceParams(ALSynth *s, ALVoice *voice, ALWaveTable *w, - f32 pitch, s16 vol, ALPan pan, u8 fxmix, - ALMicroTime t); -void alSynStopVoice(ALSynth *s, ALVoice *voice); - -void alSynSetVol(ALSynth *s, ALVoice *v, s16 vol, ALMicroTime delta); -void alSynSetPitch(ALSynth *s, ALVoice *voice, f32 ratio); -void alSynSetPan(ALSynth *s, ALVoice *voice, ALPan pan); -void alSynSetFXMix(ALSynth *s, ALVoice *voice, u8 fxmix); -void alSynSetPriority(ALSynth *s, ALVoice *voice, s16 priority); -s16 alSynGetPriority(ALSynth *s, ALVoice *voice); - -ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp); -ALFxRef alSynGetFXRef(ALSynth *s, s16 bus, s16 index); -void alSynFreeFX(ALSynth *s, ALFxRef *fx); -void alSynSetFXParam(ALSynth *s, ALFxRef fx, s16 paramID, void *param); - -/*********************************************************************** - * Audio Library (AL) stuff - ***********************************************************************/ -typedef struct { - ALSynth drvr; -} ALGlobals; - -extern ALGlobals *alGlobals; - -void alInit(ALGlobals *glob, ALSynConfig *c); -void alClose(ALGlobals *glob); - -Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen); - -/*********************************************************************** - * Sequence Player stuff - ***********************************************************************/ - -/* - * Play states - */ -#define AL_STOPPED 0 -#define AL_PLAYING 1 -#define AL_STOPPING 2 - -#define AL_DEFAULT_PRIORITY 5 -#define AL_DEFAULT_VOICE 0 -#define AL_MAX_CHANNELS 16 - -/* - * Audio Library event type definitions - */ -enum ALMsg { - AL_SEQ_REF_EVT, /* Reference to a pending event in the sequence. */ - AL_SEQ_MIDI_EVT, - AL_SEQP_MIDI_EVT, - AL_TEMPO_EVT, - AL_SEQ_END_EVT, - AL_NOTE_END_EVT, - AL_SEQP_ENV_EVT, - AL_SEQP_META_EVT, - AL_SEQP_PROG_EVT, - AL_SEQP_API_EVT, - AL_SEQP_VOL_EVT, - AL_SEQP_LOOP_EVT, - AL_SEQP_PRIORITY_EVT, - AL_SEQP_SEQ_EVT, - AL_SEQP_BANK_EVT, - AL_SEQP_PLAY_EVT, - AL_SEQP_STOP_EVT, - AL_SEQP_STOPPING_EVT, - AL_TRACK_END, - AL_CSP_LOOPSTART, - AL_CSP_LOOPEND, - AL_CSP_NOTEOFF_EVT, - AL_TREM_OSC_EVT, - AL_VIB_OSC_EVT -}; - -/* - * Midi event definitions - */ -#define AL_EVTQ_END 0x7fffffff - -enum AL_MIDIstatus { - /* For distinguishing channel number from status */ - AL_MIDI_ChannelMask = 0x0F, - AL_MIDI_StatusMask = 0xF0, - - /* Channel voice messages */ - AL_MIDI_ChannelVoice = 0x80, - AL_MIDI_NoteOff = 0x80, - AL_MIDI_NoteOn = 0x90, - AL_MIDI_PolyKeyPressure = 0xA0, - AL_MIDI_ControlChange = 0xB0, - AL_MIDI_ChannelModeSelect = 0xB0, - AL_MIDI_ProgramChange = 0xC0, - AL_MIDI_ChannelPressure = 0xD0, - AL_MIDI_PitchBendChange = 0xE0, - - /* System messages */ - AL_MIDI_SysEx = 0xF0, /* System Exclusive */ - - /* System common */ - AL_MIDI_SystemCommon = 0xF1, - AL_MIDI_TimeCodeQuarterFrame = 0xF1, - AL_MIDI_SongPositionPointer = 0xF2, - AL_MIDI_SongSelect = 0xF3, - AL_MIDI_Undefined1 = 0xF4, - AL_MIDI_Undefined2 = 0xF5, - AL_MIDI_TuneRequest = 0xF6, - AL_MIDI_EOX = 0xF7, /* End of System Exclusive */ - - /* System real time */ - AL_MIDI_SystemRealTime = 0xF8, - AL_MIDI_TimingClock = 0xF8, - AL_MIDI_Undefined3 = 0xF9, - AL_MIDI_Start = 0xFA, - AL_MIDI_Continue = 0xFB, - AL_MIDI_Stop = 0xFC, - AL_MIDI_Undefined4 = 0xFD, - AL_MIDI_ActiveSensing = 0xFE, - AL_MIDI_SystemReset = 0xFF, - AL_MIDI_Meta = 0xFF /* MIDI Files only */ -}; - -enum AL_MIDIctrl { - AL_MIDI_VOLUME_CTRL = 0x07, - AL_MIDI_PAN_CTRL = 0x0A, - AL_MIDI_PRIORITY_CTRL = 0x10, /* use general purpose controller for priority */ - AL_MIDI_FX_CTRL_0 = 0x14, - AL_MIDI_FX_CTRL_1 = 0x15, - AL_MIDI_FX_CTRL_2 = 0x16, - AL_MIDI_FX_CTRL_3 = 0x17, - AL_MIDI_FX_CTRL_4 = 0x18, - AL_MIDI_FX_CTRL_5 = 0x19, - AL_MIDI_FX_CTRL_6 = 0x1A, - AL_MIDI_FX_CTRL_7 = 0x1B, - AL_MIDI_FX_CTRL_8 = 0x1C, - AL_MIDI_FX_CTRL_9 = 0x1D, - AL_MIDI_SUSTAIN_CTRL = 0x40, - AL_MIDI_FX1_CTRL = 0x5B, - AL_MIDI_FX3_CTRL = 0x5D -}; - -enum AL_MIDImeta { - AL_MIDI_META_TEMPO = 0x51, - AL_MIDI_META_EOT = 0x2f -}; - - -#define AL_CMIDI_BLOCK_CODE 0xFE -#define AL_CMIDI_LOOPSTART_CODE 0x2E -#define AL_CMIDI_LOOPEND_CODE 0x2D -#define AL_CMIDI_CNTRL_LOOPSTART 102 -#define AL_CMIDI_CNTRL_LOOPEND 103 -#define AL_CMIDI_CNTRL_LOOPCOUNT_SM 104 -#define AL_CMIDI_CNTRL_LOOPCOUNT_BIG 105 - -typedef struct { - u8 *curPtr; /* ptr to the next event */ - s32 lastTicks; /* sequence clock ticks (used by alSeqSetLoc) */ - s32 curTicks; /* sequence clock ticks of next event (used by loop end test) */ - s16 lastStatus; /* the last status msg */ -} ALSeqMarker; - -typedef struct { - s32 ticks; /* MIDI, Tempo and End events must start with ticks */ - u8 status; - u8 byte1; - u8 byte2; - u32 duration; -} ALMIDIEvent; - -typedef struct { - s32 ticks; - u8 status; - u8 type; - u8 len; - u8 byte1; - u8 byte2; - u8 byte3; -} ALTempoEvent; - -typedef struct { - s32 ticks; - u8 status; - u8 type; - u8 len; -} ALEndEvent; - -typedef struct { - struct ALVoice_s *voice; -} ALNoteEvent; - -typedef struct { - struct ALVoice_s *voice; - ALMicroTime delta; - u8 vol; -} ALVolumeEvent; - -typedef struct { - s16 vol; -} ALSeqpVolEvent; - -typedef struct { - ALSeqMarker *start; - ALSeqMarker *end; - s32 count; -} ALSeqpLoopEvent; - -typedef struct { - u8 chan; - u8 priority; -} ALSeqpPriorityEvent; - -typedef struct { - void *seq; /* pointer to a seq (could be an ALSeq or an ALCSeq). */ -} ALSeqpSeqEvent; - -typedef struct { - ALBank *bank; -} ALSeqpBankEvent; - -typedef struct { - struct ALVoiceState_s *vs; - void *oscState; - u8 chan; -} ALOscEvent; - -typedef struct { - s16 type; - union { - ALMIDIEvent midi; - ALTempoEvent tempo; - ALEndEvent end; - ALNoteEvent note; - ALVolumeEvent vol; - ALSeqpLoopEvent loop; - ALSeqpVolEvent spvol; - ALSeqpPriorityEvent sppriority; - ALSeqpSeqEvent spseq; - ALSeqpBankEvent spbank; - ALOscEvent osc; - } msg; -} ALEvent; - -typedef struct { - ALLink node; - ALMicroTime delta; - ALEvent evt; -} ALEventListItem; - -typedef struct { - ALLink freeList; - ALLink allocList; - s32 eventCount; -} ALEventQueue; - -void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, - s32 itemCount); -ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt); -void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, - ALMicroTime delta); -void alEvtqFlush(ALEventQueue *evtq); -void alEvtqFlushType(ALEventQueue *evtq, s16 type); - - -#define AL_PHASE_ATTACK 0 -#define AL_PHASE_NOTEON 0 -#define AL_PHASE_DECAY 1 -#define AL_PHASE_SUSTAIN 2 -#define AL_PHASE_RELEASE 3 -#define AL_PHASE_SUSTREL 4 - -typedef struct ALVoiceState_s { - struct ALVoiceState_s *next;/* MUST be first */ - ALVoice voice; - ALSound *sound; - ALMicroTime envEndTime; /* time of envelope segment end */ - f32 pitch; /* currect pitch ratio */ - f32 vibrato; /* current value of the vibrato */ - u8 envGain; /* current envelope gain */ - u8 channel; /* channel assignment */ - u8 key; /* note on key number */ - u8 velocity; /* note on velocity */ - u8 envPhase; /* what envelope phase */ - u8 phase; - u8 tremelo; /* current value of the tremelo */ - u8 flags; /* bit 0 tremelo flag - bit 1 vibrato flag */ -} ALVoiceState; - -typedef struct { - ALInstrument *instrument; /* instrument assigned to this chan */ - s16 bendRange; /* pitch bend range in cents */ - ALFxId fxId; /* type of fx assigned to this chan */ - ALPan pan; /* overall pan for this chan */ - u8 priority; /* priority for this chan */ - u8 vol; /* current volume for this chan */ - u8 fxmix; /* current fx mix for this chan */ - u8 sustain; /* current sustain pedal state */ - f32 pitchBend; /* current pitch bend val in cents */ -} ALChanState; - -typedef struct ALSeq_s { - u8 *base; /* ptr to start of sequence file */ - u8 *trackStart; /* ptr to first MIDI event */ - u8 *curPtr; /* ptr to next event to read */ - s32 lastTicks; /* MIDI ticks for last event */ - s32 len; /* length of sequence in bytes */ - f32 qnpt; /* qrter notes / tick (1/division) */ - s16 division; /* ticks per quarter note */ - s16 lastStatus; /* for running status */ -} ALSeq; - -typedef struct { - u32 trackOffset[16]; - u32 division; -} ALCMidiHdr; - -typedef struct ALCSeq_s { - ALCMidiHdr *base; /* ptr to start of sequence file */ - u32 validTracks; /* set of flags, showing valid tracks */ - f32 qnpt; /* qrter notes / tick (1/division) */ - u32 lastTicks; /* keep track of ticks incase app wants */ - u32 lastDeltaTicks; /* number of delta ticks of last event */ - u32 deltaFlag; /* flag: set if delta's not subtracted */ - u8 *curLoc[16]; /* ptr to current track location, */ - /* may point to next event, or may point */ - /* to a backup code */ - u8 *curBUPtr[16]; /* ptr to next event if in backup mode */ - u8 curBULen[16]; /* if > 0, then in backup mode */ - u8 lastStatus[16]; /* for running status */ - u32 evtDeltaTicks[16]; /* delta time to next event */ -} ALCSeq; - -typedef struct { - u32 validTracks; - s32 lastTicks; - u32 lastDeltaTicks; - u8 *curLoc[16]; - u8 *curBUPtr[16]; - u8 curBULen[16]; - u8 lastStatus[16]; - u32 evtDeltaTicks[16]; -} ALCSeqMarker; - -#define NO_SOUND_ERR_MASK 0x01 -#define NOTE_OFF_ERR_MASK 0x02 -#define NO_VOICE_ERR_MASK 0x04 - -typedef struct { - s32 maxVoices; /* max number of voices to alloc */ - s32 maxEvents; /* max internal events to support */ - u8 maxChannels; /* max MIDI channels to support (16)*/ - u8 debugFlags; /* control which error get reported */ - ALHeap *heap; /* ptr to initialized heap */ - void *initOsc; - void *updateOsc; - void *stopOsc; -} ALSeqpConfig; - -typedef ALMicroTime (*ALOscInit)(void **oscState,f32 *initVal, u8 oscType, - u8 oscRate, u8 oscDepth, u8 oscDelay); -typedef ALMicroTime (*ALOscUpdate)(void *oscState, f32 *updateVal); -typedef void (*ALOscStop)(void *oscState); - -typedef struct { - ALPlayer node; /* note: must be first in structure */ - ALSynth *drvr; /* reference to the client driver */ - ALSeq *target; /* current sequence */ - ALMicroTime curTime; - ALBank *bank; /* current ALBank */ - s32 uspt; /* microseconds per tick */ - s32 nextDelta; /* microseconds to next callback */ - s32 state; - u16 chanMask; /* active channels */ - s16 vol; /* overall sequence volume */ - u8 maxChannels; /* number of MIDI channels */ - u8 debugFlags; /* control which error get reported */ - ALEvent nextEvent; - ALEventQueue evtq; - ALMicroTime frameTime; - ALChanState *chanState; /* 16 channels for MIDI */ - ALVoiceState *vAllocHead; /* list head for allocated voices */ - ALVoiceState *vAllocTail; /* list tail for allocated voices */ - ALVoiceState *vFreeList; /* list of free voice state structs */ - ALOscInit initOsc; - ALOscUpdate updateOsc; - ALOscStop stopOsc; - ALSeqMarker *loopStart; - ALSeqMarker *loopEnd; - s32 loopCount; /* -1 = loop forever, 0 = no loop */ -} ALSeqPlayer; - -typedef struct { - ALPlayer node; /* note: must be first in structure */ - ALSynth *drvr; /* reference to the client driver */ - ALCSeq *target; /* current sequence */ - ALMicroTime curTime; - ALBank *bank; /* current ALBank */ - s32 uspt; /* microseconds per tick */ - s32 nextDelta; /* microseconds to next callback */ - s32 state; - u16 chanMask; /* active channels */ - s16 vol; /* overall sequence volume */ - u8 maxChannels; /* number of MIDI channels */ - u8 debugFlags; /* control which error get reported */ - ALEvent nextEvent; - ALEventQueue evtq; - ALMicroTime frameTime; - ALChanState *chanState; /* 16 channels for MIDI */ - ALVoiceState *vAllocHead; /* list head for allocated voices */ - ALVoiceState *vAllocTail; /* list tail for allocated voices */ - ALVoiceState *vFreeList; /* list of free voice state structs */ - ALOscInit initOsc; - ALOscUpdate updateOsc; - ALOscStop stopOsc; -} ALCSPlayer; - -/* - * Sequence data representation routines - */ -void alSeqNew(ALSeq *seq, u8 *ptr, s32 len); -void alSeqNextEvent(ALSeq *seq, ALEvent *event); -s32 alSeqGetTicks(ALSeq *seq); -f32 alSeqTicksToSec(ALSeq *seq, s32 ticks, u32 tempo); -u32 alSeqSecToTicks(ALSeq *seq, f32 sec, u32 tempo); -void alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks); -void alSeqSetLoc(ALSeq *seq, ALSeqMarker *marker); -void alSeqGetLoc(ALSeq *seq, ALSeqMarker *marker); -/* - * Compact Sequence data representation routines - */ -void alCSeqNew(ALCSeq *seq, u8 *ptr); -void alCSeqNextEvent(ALCSeq *seq,ALEvent *evt); -s32 alCSeqGetTicks(ALCSeq *seq); -f32 alCSeqTicksToSec(ALCSeq *seq, s32 ticks, u32 tempo); -u32 alCSeqSecToTicks(ALCSeq *seq, f32 sec, u32 tempo); -void alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks); -void alCSeqSetLoc(ALCSeq *seq, ALCSeqMarker *marker); -void alCSeqGetLoc(ALCSeq *seq, ALCSeqMarker *marker); - -/* - * Sequence Player routines - */ -f32 alCents2Ratio(s32 cents); - -void alSeqpNew(ALSeqPlayer *seqp, ALSeqpConfig *config); -void alSeqpDelete(ALSeqPlayer *seqp); -void alSeqpSetSeq(ALSeqPlayer *seqp, ALSeq *seq); -ALSeq *alSeqpGetSeq(ALSeqPlayer *seqp); -void alSeqpPlay(ALSeqPlayer *seqp); -void alSeqpStop(ALSeqPlayer *seqp); -s32 alSeqpGetState(ALSeqPlayer *seqp); -void alSeqpSetBank(ALSeqPlayer *seqp, ALBank *b); -void alSeqpSetTempo(ALSeqPlayer *seqp, s32 tempo); -s32 alSeqpGetTempo(ALSeqPlayer *seqp); -s16 alSeqpGetVol(ALSeqPlayer *seqp); /* Master volume control */ -void alSeqpSetVol(ALSeqPlayer *seqp, s16 vol); -void alSeqpLoop(ALSeqPlayer *seqp, ALSeqMarker *start, ALSeqMarker *end, s32 count); - -void alSeqpSetChlProgram(ALSeqPlayer *seqp, u8 chan, u8 prog); -s32 alSeqpGetChlProgram(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlFXMix(ALSeqPlayer *seqp, u8 chan, u8 fxmix); -u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlVol(ALSeqPlayer *seqp, u8 chan, u8 vol); -u8 alSeqpGetChlVol(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlPan(ALSeqPlayer *seqp, u8 chan, ALPan pan); -ALPan alSeqpGetChlPan(ALSeqPlayer *seqp, u8 chan); -void alSeqpSetChlPriority(ALSeqPlayer *seqp, u8 chan, u8 priority); -u8 alSeqpGetChlPriority(ALSeqPlayer *seqp, u8 chan); -void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byte2); - - -/* Maintain backwards compatibility with old routine names. */ -#define alSeqpSetProgram alSeqpSetChlProgram -#define alSeqpGetProgram alSeqpGetChlProgram -#define alSeqpSetFXMix alSeqpSetChlFXMix -#define alSeqpGetFXMix alSeqpGetChlFXMix -#define alSeqpSetPan alSeqpSetChlPan -#define alSeqpGetPan alSeqpGetChlPan -#define alSeqpSetChannelPriority alSeqpSetChlPriority -#define alSeqpGetChannelPriority alSeqpGetChlPriority - - - -/* - * Compressed Sequence Player routines - */ -void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *config); -void alCSPDelete(ALCSPlayer *seqp); -void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq); -ALCSeq *alCSPGetSeq(ALCSPlayer *seqp); -void alCSPPlay(ALCSPlayer *seqp); -void alCSPStop(ALCSPlayer *seqp); -s32 alCSPGetState(ALCSPlayer *seqp); -void alCSPSetBank(ALCSPlayer *seqp, ALBank *b); -void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo); -s32 alCSPGetTempo(ALCSPlayer *seqp); -s16 alCSPGetVol(ALCSPlayer *seqp); -void alCSPSetVol(ALCSPlayer *seqp, s16 vol); - -void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog); -s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix); -u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan); -ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol); -u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority); -u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan); -void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, - u8 byte1, u8 byte2); - - -/* Maintain backwards compatibility with old routine names. */ -#define alCSPSetProgram alCSPSetChlProgram -#define alCSPGetProgram alCSPGetChlProgram -#define alCSPSetFXMix alCSPSetChlFXMix -#define alCSPGetFXMix alCSPGetChlFXMix -#define alCSPSetPan alCSPSetChlPan -#define alCSPGetPan alCSPGetChlPan -#define alCSPSetChannelPriority alCSPSetChlPriority -#define alCSPGetChannelPriority alCSPGetChlPriority - - - -/*********************************************************************** - * Sound Player stuff - ***********************************************************************/ - -typedef struct { - s32 maxSounds; - s32 maxEvents; - ALHeap *heap; -} ALSndpConfig; - -typedef struct { - ALPlayer node; /* note: must be first in structure */ - ALEventQueue evtq; - ALEvent nextEvent; - ALSynth *drvr; /* reference to the client driver */ - s32 target; - void *sndState; - s32 maxSounds; - ALMicroTime frameTime; - ALMicroTime nextDelta; /* microseconds to next callback */ - ALMicroTime curTime; -} ALSndPlayer; - -typedef s16 ALSndId; - -void alSndpNew(ALSndPlayer *sndp, ALSndpConfig *c); -void alSndpDelete(ALSndPlayer *sndp); - -ALSndId alSndpAllocate(ALSndPlayer *sndp, ALSound *sound); -void alSndpDeallocate(ALSndPlayer *sndp, ALSndId id); - -void alSndpSetSound(ALSndPlayer *sndp, ALSndId id); -ALSndId alSndpGetSound(ALSndPlayer *sndp); - -void alSndpPlay(ALSndPlayer *sndp); -void alSndpPlayAt(ALSndPlayer *sndp, ALMicroTime delta); -void alSndpStop(ALSndPlayer *sndp); - -void alSndpSetVol(ALSndPlayer *sndp, s16 vol); -void alSndpSetPitch(ALSndPlayer *sndp, f32 pitch); -void alSndpSetPan(ALSndPlayer *sndp, ALPan pan); -void alSndpSetPriority(ALSndPlayer *sndp, ALSndId id, u8 priority); - -void alSndpSetFXMix(ALSndPlayer *sndp, u8 mix); -s32 alSndpGetState(ALSndPlayer *sndp); - -#ifndef _FINALROM -void alParseAbiCL(Acmd *cmdList, u32 nbytes); #endif -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !__LIB_AUDIO__ */ - - - diff --git a/lib/rsp.s b/lib/rsp.s index c00c2e56..969b7f68 100644 --- a/lib/rsp.s +++ b/lib/rsp.s @@ -41,9 +41,18 @@ glabel gspFast3D_fifoTextEnd /* Audio Bins */ +/* + * "What the heck is this?" + * Shindou is the only version to actually edit the audio microcode, so I had to do this sorry lol + */ + .balign 16 glabel aspMainTextStart +.if VERSION_SH == 1 + .incbin "rsp/audio.bin" +.else .incbin "lib/PR/audio/aspMain.bin" +.endif glabel aspMainTextEnd /* @@ -186,7 +195,11 @@ glabel gspFast3D_fifoDataEnd .balign 16 glabel aspMainDataStart +.if VERSION_SH == 1 + .incbin "rsp/audio_data.bin" +.else .incbin "lib/PR/audio/aspMain_data.bin" +.endif glabel aspMainDataEnd /* LESS COMMON MICROCODES */