/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_CurveLfo.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include namespace nw { namespace snd { namespace internal { /* ======================================================================== public function ======================================================================== */ /*---------------------------------------------------------------------------* Name: LfoParam::Init Description: LFOパラメータ構造体を初期化します Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ void CurveLfoParam::Initialize() { depth = 0.0f; range = 1; speed = 6.25f; delay = 0; } /*---------------------------------------------------------------------------* Name: Reset Description: LFOをリセットします Arguments: なし Returns: なし *---------------------------------------------------------------------------*/ void CurveLfo::Reset() { m_Counter = 0.0f; m_DelayCounter = 0; } /*---------------------------------------------------------------------------* Name: Update Description: LFOを更新します Arguments: msec - 更新時間[msec] Returns: なし *---------------------------------------------------------------------------*/ void CurveLfo::Update( int msec ) { if ( m_DelayCounter < m_Param.delay ) { if ( m_DelayCounter + msec <= m_Param.delay ) { m_DelayCounter += msec; return; } else { msec -= m_Param.delay - m_DelayCounter; m_DelayCounter = m_Param.delay; } } m_Counter += m_Param.speed * msec / 1000.0f; m_Counter -= static_cast( m_Counter ); } /*---------------------------------------------------------------------------* Name: GetValue Description: 現在のLFO値を取得します Arguments: なし Returns: 現在のLFO値 *---------------------------------------------------------------------------*/ f32 CurveLfo::GetValue() const { if ( m_Param.depth == 0.0f ) return 0.0f; if ( m_DelayCounter < m_Param.delay ) return 0.0f; f32 value = GetSinIdx( static_cast( m_Counter * TABLE_SIZE * 4 ) ) / 127.0f; value *= m_Param.depth; value *= m_Param.range ; return value; } s8 CurveLfo::GetSinIdx( int index ) { // LFO用サイン波テーブル static const s8 sinTable[ TABLE_SIZE + 1 ] = { 0, 6, 12, 19, 25, 31, 37, 43, 49, 54, 60, 65, 71, 76, 81, 85, 90, 94, 98, 102, 106, 109, 112, 115, 117, 120, 122, 123, 125, 126, 126, 127, 127 }; NW_MINMAXLT_ASSERT( index, 0, PERIOD ); if ( index < TABLE_SIZE ) { return sinTable[ index ]; } if ( index < TABLE_SIZE * 2 ) { return sinTable[ TABLE_SIZE - ( index - TABLE_SIZE ) ]; } if ( index < TABLE_SIZE * 3 ) { return static_cast( - sinTable[ index - TABLE_SIZE * 2 ] ); } return static_cast( - sinTable[ TABLE_SIZE - ( index - TABLE_SIZE * 3 ) ] ); } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw