summaryrefslogtreecommitdiff
path: root/include/nw4r/snd/snd_EnvGenerator.h
blob: 3d34abc91c2f0e1ff98df9d3293ff4cb186b808f (plain)
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
#ifndef NW4R_SND_ENV_GENERATOR_H
#define NW4R_SND_ENV_GENERATOR_H

/*******************************************************************************
 * headers
 */

#include "common.h"

/*******************************************************************************
 * classes and functions
 */

namespace nw4r { namespace snd { namespace detail
{
	// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x28b11
	class EnvGenerator
	{
	// enums
	public:
		// [R89JEL]:/bin/RVL/Debug/mainD.elf:.debug::0x28a77
		enum Status
		{
			STATUS_ATTACK,
			STATUS_HOLD,
			STATUS_DECAY,
			STATUS_SUSTAIN,
			STATUS_RELEASE,
		};

	// methods
	public:
		// cdtors
		EnvGenerator();

		// methods
		void Init(f32 initDecibel);
		void Update(int msec);
		void Reset(f32 initDecibel);

		Status GetStatus() const { return mStatus; }
		f32 GetValue() const;

		void SetStatus(Status status) { mStatus = status; }
		void SetAttack(int attack);
		void SetHold(int hold);
		void SetDecay(int decay);
		void SetSustain(int sustain);
		void SetRelease(int release);

	private:
		f32 CalcRelease(int release);
		s16 CalcDecibelSquare(int scale);

	// static members
	public:
		static int const CALC_DECIBEL_SCALE_MAX;

		static int const DECIBEL_SQUARE_TABLE_SIZE = 128;

		static int const RELEASE_INIT = 127;
		static int const SUSTAIN_INIT = 127;
		static int const DECAY_INIT = 127;
		static int const HOLD_INIT = 0;
		static int const ATTACK_INIT = 127;
		static f32 const volatile VOLUME_INIT;

	private:
		static s16 const DecibelSquareTable[DECIBEL_SQUARE_TABLE_SIZE];

	// members
	private:
		Status	mStatus;		// size 0x04, offset 0x00
		f32		mValue;			// size 0x04, offset 0x04
		f32		mDecay;			// size 0x04, offset 0x08
		f32		mRelease;		// size 0x04, offset 0x0c
		f32		mAttack;		// size 0x04, offset 0x10
		u8		mSustain;		// size 0x01, offset 0x14
		/* 1 byte padding */
		u16		mHold;			// size 0x02, offset 0x16
		u16		mHoldCounter;	// size 0x02, offset 0x18
		/* 2 bytes padding */
	}; // size 0x1c
}}} // namespace nw4r::snd::detail

#endif // NW4R_SND_ENV_GENERATOR_H