/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_Sound3DEngine.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: $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include // nw::snd::SoundAmbientParam namespace nw { namespace snd { /*---------------------------------------------------------------------------* Name: Sound3DEngine Description: コンストラクタ Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ Sound3DEngine::Sound3DEngine() { } void Sound3DEngine::UpdateAmbientParam( const Sound3DManager* sound3DManager, const Sound3DParam* sound3DParam, u32 soundId, u32 updateFlag, SoundAmbientParam* ambientParam ) { NW_NULL_ASSERT( sound3DManager ); NW_NULL_ASSERT( sound3DParam ); NW_NULL_ASSERT( ambientParam ); (void)soundId; const Sound3DManager::ListenerList& listenerList = sound3DManager->GetListenerList(); // 更新する場合は、最低値で初期化 if ( updateFlag & UPDATE_VOLUME ) ambientParam->volume = 0.0f; if ( updateFlag & UPDATE_PRIORITY ) ambientParam->priority = - sound3DManager->GetMaxPriorityReduction(); // マルチリスナー場合、パン・ピッチ計算を行わない if ( listenerList.GetSize() > 1 ) { updateFlag &= ~UPDATE_PAN; updateFlag &= ~UPDATE_SPAN; updateFlag &= ~UPDATE_PITCH; } for( Sound3DManager::ListenerList::ConstIterator itr = listenerList.GetBeginIter() ; itr != listenerList.GetEndIter() ; itr++ ) { const Sound3DListener& listener = *itr; //------------------------------------------------------------------ // 音量/プライオリティ計算 if ( updateFlag & ( UPDATE_VOLUME | UPDATE_PRIORITY ) ) { f32 volume; int priority; Sound3DCalculator::CalcVolumeAndPriority( *sound3DManager, listener, *sound3DParam, &volume, &priority ); if ( updateFlag & UPDATE_VOLUME ) { ambientParam->volume = ut::Max( volume, ambientParam->volume ); } if ( updateFlag & UPDATE_PRIORITY ) { ambientParam->priority = ut::Max( priority, ambientParam->priority ); } } //------------------------------------------------------------------ // パン/サラウンドパン計算 if ( updateFlag & ( UPDATE_PAN | UPDATE_SPAN )) { f32 pan; f32 span; Sound3DCalculator::CalcPan( *sound3DManager, listener, *sound3DParam, m_CalcPanParam, &pan, &span ); if ( updateFlag & UPDATE_PAN ) ambientParam->pan = pan; if ( updateFlag & UPDATE_SPAN ) ambientParam->span = span; } //------------------------------------------------------------------ // ピッチ計算 if ( updateFlag & UPDATE_PITCH ) { float pitch; Sound3DCalculator::CalcPitch( *sound3DManager, listener, *sound3DParam, &pitch ); ambientParam->pitch = pitch; } //------------------------------------------------------------------ // Biquadフィルタ計算 if ( updateFlag & UPDATE_FILTER ) { float biquadFilterValue; Sound3DCalculator::CalcBiquadFilterValue( *sound3DManager, listener, *sound3DParam, &biquadFilterValue ); ambientParam->biquadFilterType = sound3DManager->GetBiquadFilterType(); ambientParam->biquadFilterValue = ut::Min( biquadFilterValue, ambientParam->biquadFilterValue ); } } } void Sound3DEngine::UpdateAmbientParam( const Sound3DManager* sound3DManager, const Sound3DParam* sound3DParam, u32 soundId, SoundAmbientParam* ambientParam ) { NW_NULL_ASSERT( sound3DManager ); NW_NULL_ASSERT( sound3DParam ); NW_NULL_ASSERT( ambientParam ); u32 updateFlag = 0; if ( sound3DParam->ctrlFlag & SoundArchive::Sound3DInfo::FLAG_CTRL_VOLUME ) { updateFlag |= UPDATE_VOLUME; } if ( sound3DParam->ctrlFlag & SoundArchive::Sound3DInfo::FLAG_CTRL_PRIORITY ) { updateFlag |= UPDATE_PRIORITY; } if ( sound3DParam->ctrlFlag & SoundArchive::Sound3DInfo::FLAG_CTRL_PAN ) { updateFlag |= UPDATE_PAN; } if ( sound3DParam->ctrlFlag & SoundArchive::Sound3DInfo::FLAG_CTRL_SPAN ) { updateFlag |= UPDATE_SPAN; } if ( sound3DParam->ctrlFlag & SoundArchive::Sound3DInfo::FLAG_CTRL_FILTER ) { updateFlag |= UPDATE_FILTER; } if ( sound3DParam->dopplerFactor > 0 ) { updateFlag |= UPDATE_PITCH; } UpdateAmbientParam( sound3DManager, sound3DParam, soundId, updateFlag, ambientParam ); } int Sound3DEngine::GetAmbientPriority( const Sound3DManager* sound3DManager, const Sound3DParam* sound3DParam, u32 soundId ) { NW_NULL_ASSERT( sound3DManager ); NW_NULL_ASSERT( sound3DParam ); u32 updateFlag = UPDATE_START_PRIORITY ; if ( sound3DParam->ctrlFlag & SoundArchive::Sound3DInfo::FLAG_CTRL_PRIORITY ) { updateFlag |= UPDATE_PRIORITY; } SoundAmbientParam ambientParam; UpdateAmbientParam( sound3DManager, sound3DParam, soundId, updateFlag, &ambientParam ); return ambientParam.priority; } } // namespace nw::snd } // namespace nw