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