Mario Kart 64
synthesis.h
Go to the documentation of this file.
1 #ifndef AUDIO_SYNTHESIS_H
2 #define AUDIO_SYNTHESIS_H
3 
4 #include "audio/internal.h"
5 #include "PR/abi.h"
6 
7 #define DEFAULT_LEN_1CH 0x180
8 #define DEFAULT_LEN_2CH 0x300
9 
10 #define DMEM_ADDR_TEMP 0x0
11 #define DMEM_ADDR_RESAMPLED 0x20
12 #define DMEM_ADDR_RESAMPLED2 0x1A0
13 #define DMEM_ADDR_UNCOMPRESSED_NOTE 0x180
14 #define DMEM_ADDR_NOTE_PAN_TEMP 0x200
15 #define DMEM_ADDR_STEREO_STRONG_TEMP_DRY 0x200
16 #define DMEM_ADDR_STEREO_STRONG_TEMP_WET 0x340
17 #define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x3f0
18 #define DMEM_ADDR_LEFT_CH 0x540
19 #define DMEM_ADDR_RIGHT_CH 0x6C0
20 #define DMEM_ADDR_WET_LEFT_CH 0x840
21 #define DMEM_ADDR_WET_RIGHT_CH 0x9C0
22 
23 /*
24 Its not clear what values these macros should have. Neither version seem to
25 line up for MK64. Maybe each game has unique values for these? I don't know
26 enough about the Audio engine stuff to speculate beyond that.
27 
28 Non-Shindou SM64
29 #define DMEM_ADDR_TEMP 0x0
30 #define DMEM_ADDR_RESAMPLED 0x20
31 #define DMEM_ADDR_RESAMPLED2 0x160
32 #define DMEM_ADDR_UNCOMPRESSED_NOTE 0x180
33 #define DMEM_ADDR_NOTE_PAN_TEMP 0x200
34 #define DMEM_ADDR_STEREO_STRONG_TEMP_DRY 0x200
35 #define DMEM_ADDR_STEREO_STRONG_TEMP_WET 0x340
36 #define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x3f0
37 #define DMEM_ADDR_LEFT_CH 0x4c0
38 #define DMEM_ADDR_RIGHT_CH 0x600
39 #define DMEM_ADDR_WET_LEFT_CH 0x740
40 #define DMEM_ADDR_WET_RIGHT_CH 0x880
41 
42 Shindou SM64
43 #define DMEM_ADDR_TEMP 0x450
44 #define DMEM_ADDR_RESAMPLED 0x470
45 #define DMEM_ADDR_RESAMPLED2 0x5f0
46 #define DMEM_ADDR_UNCOMPRESSED_NOTE 0x5f0
47 #define DMEM_ADDR_NOTE_PAN_TEMP 0x650
48 #define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x990
49 #define DMEM_ADDR_LEFT_CH 0x990
50 #define DMEM_ADDR_RIGHT_CH 0xb10
51 #define DMEM_ADDR_WET_LEFT_CH 0xc90
52 #define DMEM_ADDR_WET_RIGHT_CH 0xe10
53 */
54 
55 #define MAX_UPDATES_PER_FRAME 5
56 
59  /* 0x02 */ s16 chunkLen; // never read
60  /* 0x04 */ s16 *toDownsampleLeft;
61  /* 0x08 */ s16 *toDownsampleRight; // data pointed to by left and right are adjacent in memory
62  /* 0x0C */ s32 startPos; // start pos in ring buffer
63  /* 0x10 */ s16 lengthA; // first length in ring buffer (from startPos, at most until end)
64  /* 0x12 */ s16 lengthB; // second length in ring buffer (from pos 0)
65 }; // size = 0x14
66 
68  /* 0x00 */ u8 resampleFlags;
69  /* 0x01 */ u8 useReverb;
70  /* 0x02 */ u8 framesLeftToIgnore;
71  /* 0x03 */ u8 curFrame;
72  /* 0x04 */ u8 downsampleRate;
73  /* 0x05 */ // u8 compilerPadding;
74  /* 0x06 */ u16 windowSize; // same as bufSizePerChannel
75  /* 0x08 */ u16 reverbGain;
76  /* 0x0A */ u16 resampleRate;
77  /* 0x0C */ s32 nextRingBufferPos;
78  /* 0x10 */ s32 unkC; // never read
79  /* 0x14 */ s32 bufSizePerChannel;
80  struct {
81  /* 0x18 */ s16 *left;
82  /* 0x1C */ s16 *right;
84  /* 0x20 */ s16 *resampleStateLeft;
85  /* 0x24 */ s16 *resampleStateRight;
86  /* 0x28 */ s16 *unk24; // never read
87  /* 0x2C */ s16 *unk28; // never read
88  /* 0x30 */ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME];
89  /* 0xF8 */ s16 *unkF8;
90  /* 0xFC */ s16 *unkFC;
91  /* 0x100 */ s16 *unk100;
92  /* 0x104 */ s16 *unk104;
93 }; // size = 0x108
94 
95 #define ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1))
96 
97 void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex);
100 void func_800B6FB4(s32 updateIndexStart, s32 noteIndex);
101 void synthesis_load_note_subs_eu(s32 updateIndex);
102 Acmd *synthesis_execute(Acmd*, s32*, s16*, s32);
104 Acmd *synthesis_save_reverb_samples(Acmd*, s16, s16);
105 Acmd *synthesis_do_one_audio_update(s16*, s32, Acmd*, s32);
106 Acmd *synthesis_process_note(s32, struct NoteSubEu*, struct NoteSynthesisState*, s16*, s32, Acmd*, s32);
107 Acmd *load_wave_samples(Acmd *acmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad);
108 Acmd *final_resample(Acmd *acmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags);
109 Acmd *func_800B86A0(Acmd *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags);
110 Acmd *note_apply_headset_pan_effects(Acmd *acmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight);
111 
112 // These 2 are almost certainly misnamed and misplaced
113 extern u64 gGfxSPTaskOutputBuffer[];
115 
116 extern struct SynthesisReverb gSynthesisReverbs[4];
117 
118 /*
119 SO
120 gLeftVolRampings is almost certainly gAudioSessionPool (D_803AFBC8) in disguise, but since
121 synthesis' ro/data has already been broken out it'll be very hard to fix that.
122 
123 extern f32 gLeftVolRampings[3][1024];
124 extern f32 gRightVolRampings[3][1024];
125 extern f32 *gCurrentLeftVolRamping; // Points to any of the three left buffers above
126 extern f32 *gCurrentRightVolRamping; // Points to any of the three right buffers above
127 */
128 
129 #endif // AUDIO_SYNTHESIS_H
unsigned long long int u64
Definition: llconv.c:2
Definition: internal.h:410
Definition: internal.h:383
Definition: synthesis.h:57
s32 startPos
Definition: synthesis.h:62
s16 * toDownsampleLeft
Definition: synthesis.h:60
s16 lengthB
Definition: synthesis.h:64
s16 lengthA
Definition: synthesis.h:63
s16 * toDownsampleRight
Definition: synthesis.h:61
s16 numSamplesAfterDownsampling
Definition: synthesis.h:58
s16 chunkLen
Definition: synthesis.h:59
Definition: synthesis.h:67
s16 * unk28
Definition: synthesis.h:87
struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME]
Definition: synthesis.h:88
struct SynthesisReverb::@7 ringBuffer
u8 resampleFlags
Definition: synthesis.h:68
u16 reverbGain
Definition: synthesis.h:75
s32 unkC
Definition: synthesis.h:78
s16 * resampleStateLeft
Definition: synthesis.h:84
s16 * left
Definition: synthesis.h:81
s16 * unk24
Definition: synthesis.h:86
s32 bufSizePerChannel
Definition: synthesis.h:79
u8 useReverb
Definition: synthesis.h:69
s16 * right
Definition: synthesis.h:82
u8 framesLeftToIgnore
Definition: synthesis.h:70
u8 curFrame
Definition: synthesis.h:71
s16 * resampleStateRight
Definition: synthesis.h:85
s16 * unk100
Definition: synthesis.h:91
u16 resampleRate
Definition: synthesis.h:76
s16 * unkF8
Definition: synthesis.h:89
s16 * unkFC
Definition: synthesis.h:90
u8 downsampleRate
Definition: synthesis.h:72
u16 windowSize
Definition: synthesis.h:74
s32 nextRingBufferPos
Definition: synthesis.h:77
s16 * unk104
Definition: synthesis.h:92
Acmd * synthesis_do_one_audio_update(s16 *, s32, Acmd *, s32)
Definition: synthesis.c:254
Acmd * synthesis_process_note(s32, struct NoteSubEu *, struct NoteSynthesisState *, s16 *, s32, Acmd *, s32)
u32 gGfxSPTaskOutputBufferSize
Definition: gfx_output_buffer.c:6
u64 gGfxSPTaskOutputBuffer[]
Definition: gfx_output_buffer.c:4
struct SynthesisReverb gSynthesisReverbs[4]
Definition: synthesis.c:33
Acmd * final_resample(Acmd *acmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags)
Definition: synthesis.c:688
Acmd * synthesis_save_reverb_ring_buffer(Acmd *, u16, u16, s32, s32)
Definition: synthesis.c:119
Acmd * note_apply_headset_pan_effects(Acmd *acmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight)
Definition: synthesis.c:779
void func_800B6FB4(s32 updateIndexStart, s32 noteIndex)
Definition: synthesis.c:125
Acmd * load_wave_samples(Acmd *acmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad)
Definition: synthesis.c:672
Acmd * synthesis_load_reverb_ring_buffer(Acmd *, u16, u16, s32, s32)
Definition: synthesis.c:113
void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
Definition: synthesis.c:60
Acmd * synthesis_resample_and_mix_reverb(Acmd *, s32, s16, s16)
Definition: synthesis.c:198
void synthesis_load_note_subs_eu(s32 updateIndex)
Definition: synthesis.c:137
Acmd * synthesis_execute(Acmd *, s32 *, s16 *, s32)
Definition: synthesis.c:154
#define MAX_UPDATES_PER_FRAME
Definition: synthesis.h:55
Acmd * func_800B86A0(Acmd *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags)
Acmd * synthesis_save_reverb_samples(Acmd *, s16, s16)
Definition: synthesis.c:233
signed int s32
Definition: ultratypes.h:15
unsigned int u32
Definition: ultratypes.h:16
signed short int s16
Definition: ultratypes.h:13
unsigned short int u16
Definition: ultratypes.h:14
unsigned char u8
Definition: ultratypes.h:12