/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_ChannelManager.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: 19566 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include namespace nw { namespace snd { namespace internal { namespace driver { /* ======================================================================== ChannelManager class ======================================================================== */ ChannelManager& ChannelManager::GetInstance() { static ChannelManager instance; return instance; } ChannelManager::ChannelManager() : m_IsInitialized( false ), m_ChannelCount( 0 ) { } size_t ChannelManager::GetRequiredMemSize( int channelCount ) { return sizeof( Channel ) * ( channelCount + 1 ); } void ChannelManager::Initialize( void* mem, unsigned long memSize ) { if ( m_IsInitialized ) return; m_ChannelCount = m_Pool.Create( mem, memSize ); m_pMem = mem; m_MemSize = memSize; m_IsInitialized = true; } void ChannelManager::Finalize() { if ( !m_IsInitialized ) return; // リスト中の全ボイスを停止 for ( ChannelList::Iterator itr = m_ChannelList.GetBeginIter(); itr != m_ChannelList.GetEndIter(); ) { ChannelList::Iterator curItr = itr++; curItr->Stop(); } NW_ASSERT( m_ChannelList.IsEmpty() ); m_Pool.Destroy( m_pMem, m_MemSize ); m_IsInitialized = false; } Channel* ChannelManager::Alloc() { Channel* channel = m_Pool.Alloc(); m_ChannelList.PushBack( channel ); return channel; } void ChannelManager::Free( Channel* channel ) { m_ChannelList.Erase( channel ); m_Pool.Free( channel ); } void ChannelManager::UpdateAllChannel() { for ( ChannelList::Iterator itr = m_ChannelList.GetBeginIter(); itr != m_ChannelList.GetEndIter(); ) { ChannelList::Iterator curItr = itr++; curItr->Update( true ); } } } // namespace nw::snd::internal::driver } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw