1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_ChannelManager.cpp
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #include "precompiled.h"
19 
20 #include <nw/snd/snd_ChannelManager.h>
21 
22 namespace nw {
23 namespace snd {
24 namespace internal {
25 namespace driver {
26 
27 /* ========================================================================
28         ChannelManager class
29    ======================================================================== */
30 
GetInstance()31 ChannelManager& ChannelManager::GetInstance()
32 {
33     static ChannelManager instance;
34     return instance;
35 }
36 
ChannelManager()37 ChannelManager::ChannelManager()
38 : m_IsInitialized( false ),
39   m_ChannelCount( 0 )
40 {
41 }
42 
GetRequiredMemSize(int channelCount)43 size_t ChannelManager::GetRequiredMemSize( int channelCount )
44 {
45     return sizeof( Channel ) * ( channelCount + 1 );
46 }
47 
Initialize(void * mem,unsigned long memSize)48 void ChannelManager::Initialize( void* mem, unsigned long memSize )
49 {
50     if ( m_IsInitialized ) return;
51 
52     m_ChannelCount = m_Pool.Create( mem, memSize );
53     m_pMem = mem;
54     m_MemSize = memSize;
55 
56     m_IsInitialized = true;
57 }
58 
Finalize()59 void ChannelManager::Finalize()
60 {
61     if ( !m_IsInitialized ) return;
62 
63     // リスト中の全ボイスを停止
64     for ( ChannelList::Iterator itr = m_ChannelList.GetBeginIter();
65           itr != m_ChannelList.GetEndIter();
66         )
67     {
68         ChannelList::Iterator curItr = itr++;
69         curItr->Stop();
70     }
71 
72     NW_ASSERT( m_ChannelList.IsEmpty() );
73 
74     m_Pool.Destroy( m_pMem, m_MemSize );
75 
76     m_IsInitialized = false;
77 }
78 
Alloc()79 Channel* ChannelManager::Alloc()
80 {
81     Channel* channel = m_Pool.Alloc();
82     m_ChannelList.PushBack( channel );
83     return channel;
84 }
Free(Channel * channel)85 void ChannelManager::Free( Channel* channel )
86 {
87     m_ChannelList.Erase( channel );
88     m_Pool.Free( channel );
89 }
90 
UpdateAllChannel()91 void ChannelManager::UpdateAllChannel()
92 {
93     for ( ChannelList::Iterator itr = m_ChannelList.GetBeginIter();
94           itr != m_ChannelList.GetEndIter();
95         )
96     {
97         ChannelList::Iterator curItr = itr++;
98         curItr->Update( true );
99     }
100 }
101 
102 } // namespace nw::snd::internal::driver
103 } // namespace nw::snd::internal
104 } // namespace nw::snd
105 } // namespace nw
106 
107