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