1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_VoiceManager.h
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 #ifndef NW_SND_VOICE_MANAGER_H_
19 #define NW_SND_VOICE_MANAGER_H_
20 
21 #include <nw/snd/snd_Voice.h>
22 #include <nw/ut/ut_LinkList.h>
23 
24 namespace nw {
25 namespace snd {
26 namespace internal {
27 namespace driver {
28 
29 /* ========================================================================
30         class definition
31    ======================================================================== */
32 
33 class VoiceManager
34 {
35     friend class Voice;
36 
37 public:
38     typedef ut::LinkList< Voice, offsetof(Voice,m_LinkNode)> VoiceList;
39 
40 public:
41     static VoiceManager& GetInstance();
42 
43     size_t GetRequiredMemSize( int voiceCount );
44     void Initialize( void* mem, size_t memSize );
45     void Finalize();
46 
47     // ------------------------------------------------------------------------
48     // ボイス管理
49     Voice* AllocVoice(
50         int voiceChannelCount,
51         int priority,
52         Voice::VoiceCallback callback,
53         void* callbackData
54     );
55     void FreeVoice( Voice* voice );
56 
57     void StopAllVoices();
58 
59     void UpdateAllVoices();
60     void UpdateAllVoicesSync( u32 syncFlag );
61 
62     int GetVoiceCount() const;
63     unsigned long GetActiveCount() const;
64     unsigned long GetFreeCount() const;
65     const VoiceList& GetVoiceList() const;
66 
67 private:
68     VoiceManager();
69 
70     void ChangeVoicePriority( Voice* voice );
71     int DropLowestPriorityVoice( int priority );
72     void UpdateEachVoicePriority(
73         const VoiceList::Iterator& beginItr,
74         const VoiceList::Iterator& endItr
75     );
76 
77     void AppendVoiceList( Voice* voice );
78     void RemoveVoiceList( Voice* voice );
79 
80     bool m_Initialized;
81     VoiceList m_PrioVoiceList; // lower priority order
82     VoiceList m_FreeVoiceList;
83 };
84 
85 } // namespace nw::snd::internal::driver
86 } // namespace nw::snd::internal
87 } // namespace nw::snd
88 } // namespace nw
89 
90 
91 #endif /* NW_SND_VOICE_MANAGER_H_ */
92 
93