Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1#ifndef NW4HBM_SND_UTIL_H
2#define NW4HBM_SND_UTIL_H
3
4#include <revolution/types.h>
5
6#include "../db/assert.h"
7#include "snd_types.h"
8
9namespace nw4hbm {
10 namespace snd {
11 namespace detail {
12 class Util {
13 public:
14 static const int SEMITONE_MAX = 12;
15 static const int MICROTONE_MAX = 256;
16
17 static const int VOLUME_MIN = static_cast<int>(10 * VOLUME_MIN_DB); // -90.4db
18 static const int VOLUME_MAX = static_cast<int>(10 * VOLUME_MAX_DB); // +6.0db
19
20 public:
25
33
34 template <typename T0, typename T1 = void, typename T2 = void, typename T3 = void>
35 struct DataRef {
36 /* 0x00 */ u8 refType;
37 /* 0x01 */ u8 dataType;
38 /* 0x02 */ u16 reserved;
39 /* 0x04 */ u32 value;
40 };
41
42 template <typename T0, typename T1, typename T2, typename T3>
43 static inline const T0* GetDataRefAddress0(const DataRef<T0, T1, T2, T3>& ref,
44 const void* base) {
45 NW4HBM_ASSERT(111, ref.dataType == 0);
46 return static_cast<const T0*>(
47 GetDataRefAddressImpl(static_cast<RefType>(ref.refType), ref.value, base));
48 }
49
50 template <typename T0, typename T1, typename T2, typename T3>
51 static inline const T1* GetDataRefAddress1(const DataRef<T0, T1, T2, T3>& ref,
52 const void* base) {
53 NW4HBM_ASSERT(112, ref.dataType == 1);
54 return static_cast<const T1*>(
55 GetDataRefAddressImpl(static_cast<RefType>(ref.refType), ref.value, base));
56 }
57
58 template <typename T0, typename T1, typename T2, typename T3>
59 static inline const T2* GetDataRefAddress2(const DataRef<T0, T1, T2, T3>& ref,
60 const void* base) {
61 NW4HBM_ASSERT(113, ref.dataType == 2);
62 return static_cast<const T2*>(
63 GetDataRefAddressImpl(static_cast<RefType>(ref.refType), ref.value, base));
64 }
65
66 template <typename T0, typename T1, typename T2, typename T3>
67 static inline const T3* GetDataRefAddress3(const DataRef<T0, T1, T2, T3>& ref,
68 const void* base) {
69 NW4HBM_ASSERT(114, ref.dataType == 3);
70 return static_cast<const T3*>(
71 GetDataRefAddressImpl(static_cast<RefType>(ref.refType), ref.value, base));
72 }
73
74 template <typename T>
75 struct Table {
76 /* 0x00 */ u32 count;
77 /* 0x04 */ T items[1];
78 };
79
80 static inline u16 ReadBigEndian(u16 x) { return x; }
81 static inline u32 ReadBigEndian(u32 x) { return x; }
82
83 static f32 CalcPitchRatio(int pitch);
85 static f32 CalcPanRatio(f32 pan);
86 static f32 CalcSurroundPanRatio(f32 surroundPan);
87 static int CalcLpfFreq(f32 scale);
88
89 static u16 CalcRandom();
90
91 private:
92 static const void* GetDataRefAddressImpl(RefType type, u32 value, const void* base);
93
94 private:
95 // Chromatic scale (tbl[idx] / tbl[idx-1] == ~1.06)
96 static const f32 NoteTable[SEMITONE_MAX];
97 // Each note contains 256 microtones
99
100 // Table index is the millibel / hundredth-of-a-decibel
101 // dB(idx) = VOLUME_MIN_DB + (idx / 10)
102 // tbl[idx] = 10 ** (dB(idx) / 20)
103 static const int VOLUME_TABLE_SIZE = VOLUME_RANGE_MB + 1;
105
106 // 1/256 step
107 static const int PAN_TABLE_MIN = 0;
108 static const int PAN_TABLE_MAX = 256;
109 static const int PAN_TABLE_CENTER = PAN_TABLE_MAX / 2;
110 static const int PAN_TABLE_SIZE = PAN_TABLE_MAX + 1;
111 // tbl[idx] = sqrt(1 - (idx / PAN_TABLE_MAX))
113 };
114 } // namespace detail
115 } // namespace snd
116} // namespace nw4hbm
117
118#endif
static u8 base[0x2A]
Definition WPADEncrypt.c:10
Definition Util.h:12
static f32 CalcPanRatio(f32 pan)
static const T3 * GetDataRefAddress3(const DataRef< T0, T1, T2, T3 > &ref, const void *base)
Definition Util.h:67
static const int PAN_TABLE_SIZE
Definition Util.h:110
static const int PAN_TABLE_CENTER
Definition Util.h:109
static const T2 * GetDataRefAddress2(const DataRef< T0, T1, T2, T3 > &ref, const void *base)
Definition Util.h:59
DataType
Definition Util.h:26
@ DATATYPE_INVALID
Definition Util.h:31
@ DATATYPE_T3
Definition Util.h:30
@ DATATYPE_T0
Definition Util.h:27
@ DATATYPE_T1
Definition Util.h:28
@ DATATYPE_T2
Definition Util.h:29
static f32 CalcPitchRatio(int pitch)
static u16 ReadBigEndian(u16 x)
Definition Util.h:80
static const f32 NoteTable[SEMITONE_MAX]
Definition Util.h:96
static int CalcLpfFreq(f32 scale)
static const f32 Decibel2RatioTable[VOLUME_TABLE_SIZE]
Definition Util.h:104
static u32 ReadBigEndian(u32 x)
Definition Util.h:81
static const void * GetDataRefAddressImpl(RefType type, u32 value, const void *base)
static const int VOLUME_MIN
Definition Util.h:17
static const int VOLUME_MAX
Definition Util.h:18
static const int SEMITONE_MAX
Definition Util.h:14
static f32 CalcSurroundPanRatio(f32 surroundPan)
static const int VOLUME_TABLE_SIZE
Definition Util.h:103
static const T1 * GetDataRefAddress1(const DataRef< T0, T1, T2, T3 > &ref, const void *base)
Definition Util.h:51
static const int MICROTONE_MAX
Definition Util.h:15
RefType
Definition Util.h:21
@ REFTYPE_OFFSET
Definition Util.h:23
@ REFTYPE_ADDRESS
Definition Util.h:22
static const int PAN_TABLE_MAX
Definition Util.h:108
static const f32 PitchTable[MICROTONE_MAX]
Definition Util.h:98
static const f32 Pan2RatioTable[PAN_TABLE_SIZE]
Definition Util.h:112
static f32 CalcVolumeRatio(f32 db)
static const int PAN_TABLE_MIN
Definition Util.h:107
static const T0 * GetDataRefAddress0(const DataRef< T0, T1, T2, T3 > &ref, const void *base)
Definition Util.h:43
double x double x
Definition e_atan2.c:58
unsigned long u32
Definition types.h:12
float f32
Definition types.h:25
unsigned short int u16
Definition types.h:10
unsigned char u8
Definition types.h:8
static const f32 VOLUME_MIN_DB
Definition snd_types.h:56
static const int VOLUME_RANGE_MB
Definition snd_types.h:59
static const f32 VOLUME_MAX_DB
Definition snd_types.h:57
Definition HBMAnmController.h:6
u32 value
Definition Util.h:39
u8 refType
Definition Util.h:36
u8 dataType
Definition Util.h:37
u16 reserved
Definition Util.h:38
T items[1]
Definition Util.h:77
u32 count
Definition Util.h:76