1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_CurveAdshr.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_SND_CURVE_ADSHR_H_
19 #define NW_SND_CURVE_ADSHR_H_
20 
21 #include <nn/types.h>
22 
23 namespace nw {
24 namespace snd {
25 namespace internal {
26 
27 /* ========================================================================
28         class definition
29    ======================================================================== */
30 
31 class CurveAdshr
32 {
33     /* ------------------------------------------------------------------------
34             typename difinition
35        ------------------------------------------------------------------------ */
36 public:
37     enum Status
38     {
39         STATUS_ATTACK = 0,
40         STATUS_HOLD,
41         STATUS_DECAY,
42         STATUS_SUSTAIN,
43         STATUS_RELEASE
44     };
45 
46     /* ------------------------------------------------------------------------
47             constant declaration
48        ------------------------------------------------------------------------ */
49 private:
50     static const float VOLUME_INIT; // -90.4;
51     static const int ATTACK_INIT    = 127;
52     static const int HOLD_INIT      = 0;
53     static const int DECAY_INIT     = 127;
54     static const int SUSTAIN_INIT   = 127;
55     static const int RELEASE_INIT   = 127;
56 
57     static const int DECIBEL_SQUARE_TABLE_SIZE  = 128;
58     static const int CALC_DECIBEL_SCALE_MAX     = 127;
59     static const s16 DecibelSquareTable[ DECIBEL_SQUARE_TABLE_SIZE ];
60 
61     /* ------------------------------------------------------------------------
62             class member
63        ------------------------------------------------------------------------ */
64 public:
65     CurveAdshr();
66     void Initialize( float initDecibel = VOLUME_INIT );
67     void Reset( float initDecibel = VOLUME_INIT );
68 
69     void Update( int msec );
70     f32  GetValue() const;
71 
72     // Accesser
GetStatus()73     Status GetStatus() const { return m_Status; }
SetStatus(Status status)74     void SetStatus( Status status ) { m_Status = status; }
75 
76     void SetAttack( int attack );
77     void SetHold( int hold );
78     void SetDecay( int decay );
79     void SetSustain( int sustain );
80     void SetRelease( int release );
81 
82 private:
83     static f32 CalcRelease( int release );
84     static s16 CalcDecibelSquare( int scale );
85 
86     Status m_Status;
87     f32 m_Value;
88     f32 m_Decay;
89     f32 m_Release;
90     f32 m_Attack;
91     u16 m_Hold;
92     u16 m_HoldCounter;
93     u8  m_Sustain;
94     u8  padding[3];
95 };
96 
97 
98 } // namespace nw::snd::internal
99 } // namespace nw::snd
100 } // namespace nw
101 
102 
103 #endif /* NW_SND_CURVE_ADSHR_H_ */
104 
105