/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_Bank.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 25221 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include // NoteOnInfo #include #include #include // GetWaveFile namespace nw { namespace snd { namespace internal { namespace driver { /* ======================================================================== public functions ======================================================================== */ /*---------------------------------------------------------------------------* Name: Bank Description: コンストラクタ Arguments: bankData - バンクデータへの参照 Returns: None. *---------------------------------------------------------------------------*/ Bank::Bank() { } /*---------------------------------------------------------------------------* Name: ~Bank Description: デストラクタ Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ Bank::~Bank() { } Channel* Bank::NoteOn( const void* bankFile, const NoteOnInfo& noteOnInfo, const SoundArchive& archive, const SoundArchivePlayer& player ) const { if ( bankFile == NULL ) { return NULL; } // VelocityRegionInfo の取得 VelocityRegionInfo regionInfo; { BankFileReader reader( bankFile ); if ( ! reader.ReadVelocityRegionInfo( ®ionInfo, noteOnInfo.prgNo, noteOnInfo.key, noteOnInfo.velocity ) ) { return NULL; } } // regnioInfo に応じた波形を取得する const void* waveFile = Util::GetWaveFile( regionInfo.waveArchiveId, regionInfo.waveIndex, archive, player ); if ( waveFile == NULL ) { return NULL; } // 波形の詳細を取得、Channel 確保 WaveInfo waveInfo; { WaveFileReader reader( waveFile ); if ( ! reader.ReadWaveInfo( &waveInfo ) ) { return NULL; } } Channel* pChannel = Channel::AllocChannel( ut::Min( static_cast( waveInfo.channelCount ), 2 ), noteOnInfo.priority, noteOnInfo.channelCallback, noteOnInfo.channelCallbackData ); if ( pChannel == NULL ) { return NULL; } // 初期パラメータ設定 pChannel->SetKey( noteOnInfo.key, regionInfo.originalKey ); register int velocity = noteOnInfo.velocity; velocity *= velocity; velocity *= regionInfo.volume; float initVolume = static_cast( velocity ); initVolume /= (127.0f * 127.0f * 127.0f); pChannel->SetInitVolume( initVolume ); pChannel->SetTune( regionInfo.pitch ); pChannel->SetAttack( regionInfo.adshrCurve.attack ); pChannel->SetHold( regionInfo.adshrCurve.hold ); pChannel->SetDecay( regionInfo.adshrCurve.decay ); pChannel->SetSustain( regionInfo.adshrCurve.sustain ); pChannel->SetRelease( regionInfo.adshrCurve.release ); float initPan = static_cast( noteOnInfo.initPan + regionInfo.pan - 64 ) / 63.0f; pChannel->SetInitPan( initPan ); // pChannel->SetInitSurroundPan( 0.0f ); pChannel->SetKeyGroupId( regionInfo.keyGroup ); pChannel->SetIsIgnoreNoteOff( regionInfo.isIgnoreNoteOff ); pChannel->SetInterpolationType( regionInfo.interpolationType ); pChannel->Start( waveInfo, noteOnInfo.length, 0 ); return pChannel; } } // namespace nw::snd::internal::driver } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw