1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
#ifndef NW4R_SND_AX_VOICE_H
#define NW4R_SND_AX_VOICE_H
/*******************************************************************************
* headers
*/
#include "common.h"
#include "nw4r/snd/snd_adpcm.h"
#include "nw4r/snd/snd_global.h" // SampleFormat
#include "nw4r/ut/ut_LinkList.h"
#include <rvl/AX/AX.h>
#include <rvl/AX/AXCL.h>
#include <rvl/AX/AXAlloc.h> // AXSetVoicePriority
#include <rvl/AX/AXVPB.h>
/*******************************************************************************
* classes and functions
*/
namespace nw4r { namespace snd { namespace detail
{
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2ae88
class AxVoiceParamBlock
{
// methods
public:
// cdtors
AxVoiceParamBlock();
// conversion operators
operator AXVPB *() { return mVpb; }
// methods
bool IsAvailable() const { return mVpb != nullptr; }
bool IsRun() const
{
return IsAvailable() && mVpb->pb.state == AX_VOICE_RUN;
}
u32 GetLoopAddress() const
{
if (!IsAvailable())
return 0;
return (mVpb->pb.addr.loopAddressHi << 16)
+ mVpb->pb.addr.loopAddressLo;
}
u32 GetEndAddress() const
{
if (!IsAvailable())
return 0;
return (mVpb->pb.addr.endAddressHi << 16)
+ mVpb->pb.addr.endAddressLo;
}
u32 GetCurrentAddress() const
{
if (!IsAvailable())
return 0;
return (mVpb->pb.addr.currentAddressHi << 16)
+ mVpb->pb.addr.currentAddressLo;
}
bool IsLpfEnable() const
{
return IsAvailable() && mVpb->pb.lpf.on == AX_PB_LPF_ON;
}
bool IsBiquadEnable() const
{
return IsAvailable() && mVpb->pb.biquad.on == AX_PB_BIQUAD_ON;
}
bool IsRmtIirEnable() const;
void SetVoiceAddr(AXPBADDR const &addr)
{
if (!IsAvailable())
return;
// AXSetVoiceAddr doesn't actually modify the object
AXSetVoiceAddr(mVpb, const_cast<AXPBADDR *>(&addr));
}
void SetVoicePriority(u32 priority)
{
if (!IsAvailable())
return;
AXSetVoicePriority(mVpb, priority);
}
void SetVoiceSrcType(u32 type);
void SetVoiceStateRun()
{
if (!IsAvailable())
return;
AXSetVoiceState(mVpb, AX_VOICE_RUN);
}
void SetVoiceStateStop()
{
if (!IsRun())
return;
AXSetVoiceState(mVpb, AX_VOICE_STOP);
}
void SetVoiceType(u16 type);
void SetVoiceMix(AXPBMIX const &mix, bool immediatelySync);
void SetVoiceVe(u16 volume, u16 initVolume);
void SetVoiceLoop(u16 loop);
void SetVoiceLoopAddr(u32 addr);
void SetVoiceEndAddr(u32 addr);
void SetVoiceAdpcm(AXPBADPCM const &adpcm);
void SetVoiceSrc(AXPBSRC const &src);
void SetVoiceSrcRatio(f32 ratio);
void SetVoiceAdpcmLoop(AXPBADPCMLOOP const &adpcmloop);
void SetVoiceLpf(AXPBLPF const &lpf);
void SetVoiceLpfCoefs(u16 a0, u16 b0);
void SetVoiceBiquad(AXPBBIQUAD const &biquad);
void SetVoiceBiquadCoefs(u16 b0, u16 b1, u16 b2, u16 a1, u16 a2);
void SetVoiceRmtIIR(__AXPBRMTIIR const &iir);
void SetVoiceRmtOn(u16 on);
void SetVoiceRmtMix(_AXPBRMTMIX const &iir);
void SetVoiceRmtIIRCoefs(u16 type, ...);
void Set(AXVPB *vpb);
void Clear();
void UpdateDelta();
void Sync();
// static members
public:
static u16 const DEFAULT_VOLUME = AX_MAX_VOLUME;
// members
private:
AXVPB *mVpb; // size 0x04, offset 0x00
u32 mSync; // size 0x04, offset 0x04
AXPBVE volatile mPrevVeSetting; // size 0x04, offset 0x08
bool mFirstVeUpdateFlag; // size 0x01, offset 0x0c
/* 1 byte padding */
u16 mVolume; // size 0x02, offset 0x0e
}; // size 0x10
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b45f
class AxVoice
{
// enums
public:
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b187
enum AxVoiceCallbackStatus
{
CALLBACK_STATUS_CANCEL,
CALLBACK_STATUS_DROP_DSP,
};
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b23a
enum VoiceType
{
VOICE_TYPE_NORMAL,
VOICE_TYPE_STREAM,
};
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b3dd
enum SrcType
{
SRC_NONE,
SRC_LINEAR,
SRC_4TAP_8K,
SRC_4TAP_12K,
SRC_4TAP_16K,
SRC_4TAP_AUTO,
};
// typedefs
public:
typedef ut::LinkList<AxVoice, 0x40> LinkList;
typedef void Callback(AxVoice *dropVoice, AxVoiceCallbackStatus status,
void *callbackData);
// nested types
public:
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2afaa
struct MixParam
{
u16 vL; // size 0x02, offset 0x00
u16 vR; // size 0x02, offset 0x02
u16 vS; // size 0x02, offset 0x04
u16 vAuxAL; // size 0x02, offset 0x06
u16 vAuxAR; // size 0x02, offset 0x08
u16 vAuxAS; // size 0x02, offset 0x0a
u16 vAuxBL; // size 0x02, offset 0x0c
u16 vAuxBR; // size 0x02, offset 0x0e
u16 vAuxBS; // size 0x02, offset 0x10
u16 vAuxCL; // size 0x02, offset 0x12
u16 vAuxCR; // size 0x02, offset 0x14
u16 vAuxCS; // size 0x02, offset 0x16
}; // size 0x18
// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x2b28a
struct RemoteMixParam
{
u16 vMain0; // size 0x02, offset 0x00
u16 vAux0; // size 0x02, offset 0x02
u16 vMain1; // size 0x02, offset 0x04
u16 vAux1; // size 0x02, offset 0x06
u16 vMain2; // size 0x02, offset 0x08
u16 vAux2; // size 0x02, offset 0x0a
u16 vMain3; // size 0x02, offset 0x0c
u16 vAux3; // size 0x02, offset 0x0e
}; // size 0x10
// methods
public:
// cdtors
AxVoice();
~AxVoice();
// methods
void Setup(void const *waveAddr, SampleFormat format, int sampleRate);
SampleFormat GetFormat() const { return mFormat; }
u32 GetCurrentPlayingSample() const;
u32 GetCurrentPlayingDspAddress() const;
u32 GetLoopEndDspAddress() const;
f32 GetDspRatio(f32 ratio) const
{
return ratio * mSampleRate / AX_SAMPLE_RATE;
}
void SetLoopStart(void const *baseAddress, u32 samples);
void SetLoopEnd(void const *baseAddress, u32 samples);
void SetLoopFlag(bool loopFlag);
void SetPriority(u32 priority);
void SetVoiceType(VoiceType type);
void EnableRemote(bool enable);
void ResetDelta();
void SetAddr(bool loopFlag, void const *waveAddr, u32 startOffset,
u32 loopStart, u32 loopEnd);
void SetSrcType(SrcType type, f32 pitch);
void SetAdpcm(AdpcmParam const *param);
void SetAdpcmLoop(AdpcmLoopParam const *param);
bool SetMix(MixParam const ¶m);
void SetRmtMix(const RemoteMixParam ¶m);
void SetSrc(f32 ratio, bool initialUpdate);
void SetVe(f32 volume, f32 initVolume);
void SetLpf(u16 freq);
void SetBiquad(u8 filterType, f32 value);
void SetRemoteFilter(u8 filter);
/* NOTE: covered misspelled as coverd */
bool IsDataAddressCoverd(void const *beginAddress,
void const *endAddress) const;
bool IsNeedNextUpdate(MixParam const ¶m) const;
bool IsPlayFinished() const;
void Run() { mVpb.SetVoiceStateRun(); }
bool IsRun() const { return mVpb.IsRun(); }
void Stop() { mVpb.SetVoiceStateStop(); }
void StopAtPoint(void const *baseAddress, u32 samples);
void Sync() { mVpb.Sync(); }
static u32 GetDspAddressBySample(void const *baseAddress, u32 samples,
SampleFormat format);
static u32 GetSampleByDspAddress(void const *baseAddress, u32 addr,
SampleFormat format);
static u16 GetAxFormatFromSampleFormat(SampleFormat sampleFormat);
static void CalcOffsetAdpcmParam(u16 *outPredScale, u16 *outYn1,
u16 *outYn2, u32 offset,
const void *dataAddr,
AdpcmParam const &adpcmParam);
private:
// callbacks
static void VoiceCallback(void *callbackData);
// static members
public:
static u16 const VOICE_GAIN_MAX;
// methods
private:
AxVoiceParamBlock mVpb; // size 0x10, offset 0x00
void const *mWaveData; // size 0x04, offset 0x10
SampleFormat mFormat; // size 0x04, offset 0x14
int mSampleRate; // size 0x04, offset 0x18
bool mFirstMixUpdateFlag; // size 0x01, offset 0x1c
bool mReserveForFreeFlag; // size 0x01, offset 0x1d
/* 2 bytes padding */
MixParam mMixPrev; // size 0x18, offset 0x20
Callback *mCallback; // size 0x04, offset 0x38
void *mCallbackData; // size 0x04, offset 0x3c
public:
ut::LinkListNode node; // size 0x08, offset 0x40
// friends
private:
friend class AxVoiceManager;
}; // size 0x48
}}} // namespace nw4r::snd::detail
#endif // NW4R_SND_AX_VOICE_H
|