1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_ChannelManager.cpp
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: 19566 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "precompiled.h"
17 
18 #include <nw/snd/snd_ChannelManager.h>
19 
20 namespace nw {
21 namespace snd {
22 namespace internal {
23 namespace driver {
24 
25 /* ========================================================================
26         ChannelManager class
27    ======================================================================== */
28 
GetInstance()29 ChannelManager& ChannelManager::GetInstance()
30 {
31     static ChannelManager instance;
32     return instance;
33 }
34 
ChannelManager()35 ChannelManager::ChannelManager()
36 : m_IsInitialized( false ),
37   m_ChannelCount( 0 )
38 {
39 }
40 
GetRequiredMemSize(int channelCount)41 size_t ChannelManager::GetRequiredMemSize( int channelCount )
42 {
43     return sizeof( Channel ) * ( channelCount + 1 );
44 }
45 
Initialize(void * mem,unsigned long memSize)46 void ChannelManager::Initialize( void* mem, unsigned long memSize )
47 {
48     if ( m_IsInitialized ) return;
49 
50     m_ChannelCount = m_Pool.Create( mem, memSize );
51     m_pMem = mem;
52     m_MemSize = memSize;
53 
54     m_IsInitialized = true;
55 }
56 
Finalize()57 void ChannelManager::Finalize()
58 {
59     if ( !m_IsInitialized ) return;
60 
61     // リスト中の全ボイスを停止
62     for ( ChannelList::Iterator itr = m_ChannelList.GetBeginIter();
63           itr != m_ChannelList.GetEndIter();
64         )
65     {
66         ChannelList::Iterator curItr = itr++;
67         curItr->Stop();
68     }
69 
70     NW_ASSERT( m_ChannelList.IsEmpty() );
71 
72     m_Pool.Destroy( m_pMem, m_MemSize );
73 
74     m_IsInitialized = false;
75 }
76 
Alloc()77 Channel* ChannelManager::Alloc()
78 {
79     Channel* channel = m_Pool.Alloc();
80     m_ChannelList.PushBack( channel );
81     return channel;
82 }
Free(Channel * channel)83 void ChannelManager::Free( Channel* channel )
84 {
85     m_ChannelList.Erase( channel );
86     m_Pool.Free( channel );
87 }
88 
UpdateAllChannel()89 void ChannelManager::UpdateAllChannel()
90 {
91     for ( ChannelList::Iterator itr = m_ChannelList.GetBeginIter();
92           itr != m_ChannelList.GetEndIter();
93         )
94     {
95         ChannelList::Iterator curItr = itr++;
96         curItr->Update( true );
97     }
98 }
99 
100 } // namespace nw::snd::internal::driver
101 } // namespace nw::snd::internal
102 } // namespace nw::snd
103 } // namespace nw
104 
105