Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/audio/synthesis.h
7858 views
1
#ifndef AUDIO_SYNTHESIS_H
2
#define AUDIO_SYNTHESIS_H
3
4
#include "internal.h"
5
6
#ifdef VERSION_SH
7
#define DEFAULT_LEN_1CH 0x180
8
#define DEFAULT_LEN_2CH 0x300
9
#else
10
#define DEFAULT_LEN_1CH 0x140
11
#define DEFAULT_LEN_2CH 0x280
12
#endif
13
14
#if defined(VERSION_EU) || defined(VERSION_SH)
15
#define MAX_UPDATES_PER_FRAME 5
16
#else
17
#define MAX_UPDATES_PER_FRAME 4
18
#endif
19
20
struct ReverbRingBufferItem
21
{
22
s16 numSamplesAfterDownsampling;
23
s16 chunkLen; // never read
24
s16 *toDownsampleLeft;
25
s16 *toDownsampleRight; // data pointed to by left and right are adjacent in memory
26
s32 startPos; // start pos in ring buffer
27
s16 lengthA; // first length in ring buffer (from startPos, at most until end)
28
s16 lengthB; // second length in ring buffer (from pos 0)
29
}; // size = 0x14
30
31
struct SynthesisReverb
32
{
33
/*0x00, 0x00, 0x00*/ u8 resampleFlags;
34
/*0x01, 0x01, 0x01*/ u8 useReverb;
35
/*0x02, 0x02, 0x02*/ u8 framesLeftToIgnore;
36
/*0x03, 0x03, 0x03*/ u8 curFrame;
37
#if defined(VERSION_EU) || defined(VERSION_SH)
38
/* 0x04, 0x04*/ u8 downsampleRate;
39
#ifdef VERSION_SH
40
/* 0x05*/ s8 unk5;
41
#endif
42
/* 0x06, 0x06*/ u16 windowSize; // same as bufSizePerChannel
43
#endif
44
#ifdef VERSION_SH
45
/* 0x08*/ u16 unk08;
46
#endif
47
/*0x04, 0x08, 0x0A*/ u16 reverbGain;
48
/*0x06, 0x0A, 0x0C*/ u16 resampleRate;
49
#ifdef VERSION_SH
50
/* 0x0E*/ u16 panRight;
51
/* 0x10*/ u16 panLeft;
52
#endif
53
/*0x08, 0x0C, 0x14*/ s32 nextRingBufferPos;
54
/*0x0C, 0x10, 0x18*/ s32 unkC; // never read
55
/*0x10, 0x14, 0x1C*/ s32 bufSizePerChannel;
56
struct
57
{
58
s16 *left;
59
s16 *right;
60
} ringBuffer;
61
/*0x1C, 0x20, 0x28*/ s16 *resampleStateLeft;
62
/*0x20, 0x24, 0x2C*/ s16 *resampleStateRight;
63
/*0x24, 0x28, 0x30*/ s16 *unk24; // never read
64
/*0x28, 0x2C, 0x34*/ s16 *unk28; // never read
65
/*0x2C, 0x30, 0x38*/ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME];
66
#if defined(VERSION_EU) || defined(VERSION_SH)
67
// Only used in sh:
68
/* 0x100*/ s16 *unk100;
69
/* 0x104*/ s16 *unk104;
70
/* 0x108*/ s16 *unk108;
71
/* 0x10C*/ s16 *unk10C;
72
#endif
73
}; // 0xCC <= size <= 0x100
74
#if defined(VERSION_EU) || defined(VERSION_SH)
75
extern struct SynthesisReverb gSynthesisReverbs[4];
76
extern s8 gNumSynthesisReverbs;
77
extern struct NoteSubEu *gNoteSubsEu;
78
extern f32 gLeftVolRampings[3][1024];
79
extern f32 gRightVolRampings[3][1024];
80
extern f32 *gCurrentLeftVolRamping; // Points to any of the three left buffers above
81
extern f32 *gCurrentRightVolRamping; // Points to any of the three right buffers above
82
#else
83
extern struct SynthesisReverb gSynthesisReverb;
84
#endif
85
86
#ifdef VERSION_SH
87
extern s16 D_SH_803479B4;
88
#endif
89
90
u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen);
91
#if defined(VERSION_JP) || defined(VERSION_US)
92
void note_init_volume(struct Note *note);
93
void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverbVol);
94
void note_set_frequency(struct Note *note, f32 frequency);
95
void note_enable(struct Note *note);
96
void note_disable(struct Note *note);
97
#endif
98
99
#endif // AUDIO_SYNTHESIS_H
100
101