1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_SoundActor.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: $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/snd/snd_SoundActor.h>
19
20 namespace nw {
21 namespace snd {
22
23 /*---------------------------------------------------------------------------*
24 Name: SoundActor
25
26 Description: コンストラクタ
27
28 Arguments: soundArchivePlayer - サウンドアーカイブプレイヤー
29
30 Returns: None.
31 *---------------------------------------------------------------------------*/
SoundActor()32 SoundActor::SoundActor()
33 : m_pSoundArchivePlayer( NULL ),
34 m_IsInitialized( false ),
35 m_IsFinalized( true )
36 {
37 // 何もしない
38 }
SoundActor(SoundArchivePlayer & soundArchivePlayer)39 SoundActor::SoundActor( SoundArchivePlayer& soundArchivePlayer )
40 : m_pSoundArchivePlayer( NULL ),
41 m_IsInitialized( false ),
42 m_IsFinalized( true )
43 {
44 Initialize( soundArchivePlayer );
45 }
46
47 /*---------------------------------------------------------------------------*
48 Name: ~SoundActor
49
50 Description: デストラクタ
51
52 Arguments: None.
53
54 Returns: None.
55 *---------------------------------------------------------------------------*/
~SoundActor()56 SoundActor::~SoundActor()
57 {
58 Finalize();
59 }
60
Initialize(SoundArchivePlayer & soundArchivePlayer)61 void SoundActor::Initialize( SoundArchivePlayer& soundArchivePlayer )
62 {
63 if ( m_IsInitialized ) return;
64
65 m_pSoundArchivePlayer = &soundArchivePlayer;
66
67 for ( int i = 0; i < ACTOR_PLAYER_COUNT; i++ )
68 {
69 const int playableSoundCount = ( i == 0 ) ? INT_MAX : 1;
70 m_ActorPlayer[i].SetPlayableSoundCount( playableSoundCount );
71 }
72
73 m_IsInitialized = true;
74 m_IsFinalized = false;
75 }
Finalize()76 void SoundActor::Finalize()
77 {
78 if ( m_IsFinalized ) return;
79
80 for ( int i = 0; i < ACTOR_PLAYER_COUNT; i++ )
81 {
82 m_ActorPlayer[i].StopAllSound( 0 );
83 m_ActorPlayer[i].DetachSoundActorAll( this );
84 m_ActorPlayer[i].~ExternalSoundPlayer();
85 }
86
87 m_IsFinalized = true;
88 m_IsInitialized = false;
89 m_pSoundArchivePlayer = NULL;
90 m_ActorParam.Reset();
91 }
92
93 /*---------------------------------------------------------------------------*
94 Name: StopAllSound
95
96 Description: 全てのサウンドを停止する
97
98 Arguments: fadeFrames - フェードアウトフレーム数
99
100 Returns: None.
101 *---------------------------------------------------------------------------*/
StopAllSound(int fadeFrames)102 void SoundActor::StopAllSound( int fadeFrames )
103 {
104 for ( int i = 0; i < ACTOR_PLAYER_COUNT; i++ )
105 {
106 m_ActorPlayer[ i ].StopAllSound( fadeFrames );
107 }
108 }
109
110 /*---------------------------------------------------------------------------*
111 Name: PauseAllSound
112
113 Description: 全てのサウンドを一時停止または再開する
114
115 Arguments: flag - 一時停止か再開か
116 fadeFrames - フェードフレーム数
117
118 Returns: None.
119 *---------------------------------------------------------------------------*/
PauseAllSound(bool flag,int fadeFrames)120 void SoundActor::PauseAllSound( bool flag, int fadeFrames )
121 {
122 for ( int i = 0; i < ACTOR_PLAYER_COUNT; i++ )
123 {
124 m_ActorPlayer[ i ].PauseAllSound( flag, fadeFrames );
125 }
126 }
127
128 /*---------------------------------------------------------------------------*
129 Name: GetPlayingSoundCount
130
131 Description: 現在再生中のサウンド数を取得する
132
133 Arguments: actorPlayerId - アクタープレイヤーID
134
135 Returns: なし
136 *---------------------------------------------------------------------------*/
GetPlayingSoundCount(int actorPlayerId) const137 int SoundActor::GetPlayingSoundCount( int actorPlayerId ) const
138 {
139 NW_MINMAXLT_ASSERT( actorPlayerId, 0, ACTOR_PLAYER_COUNT );
140
141 return m_ActorPlayer[ actorPlayerId ].GetPlayingSoundCount();
142 }
143
144 /*---------------------------------------------------------------------------*
145 Name: SetPlayableSoundCount
146
147 Description: サウンドの最大同時再生数を設定する
148
149 Arguments: actorPlayerId - アクタープレイヤーID
150 count - サウンドの最大同時再生数
151
152 Returns: None.
153 *---------------------------------------------------------------------------*/
SetPlayableSoundCount(int actorPlayerId,int count)154 void SoundActor::SetPlayableSoundCount( int actorPlayerId, int count )
155 {
156 NW_MINMAXLT_ASSERT( actorPlayerId, 0, ACTOR_PLAYER_COUNT );
157
158 m_ActorPlayer[ actorPlayerId ].SetPlayableSoundCount( count );
159 }
160
161 /*---------------------------------------------------------------------------*
162 Name: SetPlayableSoundCount
163
164 Description: サウンドの最大同時再生数を取得する
165
166 Arguments: actorPlayerId - アクタープレイヤーID
167
168 Returns: サウンドの最大同時再生数を返す
169 *---------------------------------------------------------------------------*/
GetPlayableSoundCount(int actorPlayerId) const170 int SoundActor::GetPlayableSoundCount( int actorPlayerId ) const
171 {
172 NW_MINMAXLT_ASSERT( actorPlayerId, 0, ACTOR_PLAYER_COUNT );
173
174 return m_ActorPlayer[ actorPlayerId ].GetPlayableSoundCount();
175 }
176
177 /*---------------------------------------------------------------------------*
178 Name: SetupSound [virtual]
179
180 Description: 再生の実装関数
181
182 Arguments: handle - サウンドハンドル
183 soundId - サウンドID
184 startInfo - サウンド再生パラメータ
185 setupArg - セットアップ引数
186
187 Returns: 結果コード
188 *---------------------------------------------------------------------------*/
SetupSound(SoundHandle * handle,u32 soundId,const SoundStartable::StartInfo * startInfo,void * setupArg)189 SoundStartable::StartResult SoundActor::SetupSound(
190 SoundHandle* handle,
191 u32 soundId,
192 const SoundStartable::StartInfo* startInfo,
193 void* setupArg
194 )
195 {
196 NW_NULL_ASSERT( setupArg );
197 if ( m_IsInitialized == false )
198 {
199 return SoundStartable::StartResult::START_ERR_ACTOR_NOT_INITIALIZED;
200 }
201
202 const SetupInfo* setupInfo = reinterpret_cast<SetupInfo*>(setupArg);
203
204 return m_pSoundArchivePlayer->detail_SetupSoundImpl(
205 handle,
206 soundId,
207 NULL,
208 this,
209 setupInfo->holdFlag,
210 startInfo
211 );
212 }
213
214 // AmbientInfoが公開された際には上の関数に統合される予定
215 // AmbientInfoはStartInfoのメンバで渡される予定
detail_SetupSoundWithAmbientInfo(SoundHandle * handle,u32 soundId,const SoundStartable::StartInfo * startInfo,internal::BasicSound::AmbientInfo * ambientInfo,void * setupArg)216 SoundStartable::StartResult SoundActor::detail_SetupSoundWithAmbientInfo(
217 SoundHandle* handle,
218 u32 soundId,
219 const SoundStartable::StartInfo* startInfo,
220 internal::BasicSound::AmbientInfo* ambientInfo,
221 void* setupArg
222 )
223 {
224 NW_NULL_ASSERT( setupArg );
225 if ( m_IsInitialized == false )
226 {
227 return SoundStartable::StartResult::START_ERR_ACTOR_NOT_INITIALIZED;
228 }
229
230 const SetupInfo* setupInfo = reinterpret_cast<SetupInfo*>(setupArg);
231
232 return m_pSoundArchivePlayer->detail_SetupSoundImpl(
233 handle,
234 soundId,
235 ambientInfo,
236 this,
237 setupInfo->holdFlag,
238 startInfo
239 );
240 }
241
242 /*---------------------------------------------------------------------------*
243 Name: detail_SetupSound [override]
244
245 Description: SoundStartableインターフェイスの実装
246
247 Arguments: handle - サウンドハンドル
248 soundId - サウンドID
249 holdFlag - ホールドサウンドフラグ
250 startInfo - サウンド再生パラメータ
251
252 Returns: 結果コード
253 *---------------------------------------------------------------------------*/
detail_SetupSound(SoundHandle * handle,u32 soundId,bool holdFlag,const SoundStartable::StartInfo * startInfo)254 SoundStartable::StartResult SoundActor::detail_SetupSound(
255 SoundHandle* handle,
256 u32 soundId,
257 bool holdFlag,
258 const SoundStartable::StartInfo* startInfo
259 )
260 {
261 SetupInfo setupInfo;
262 setupInfo.holdFlag = holdFlag;
263
264 return SetupSound(
265 handle,
266 soundId,
267 startInfo,
268 &setupInfo
269 );
270 }
271
272 /*---------------------------------------------------------------------------*
273 Name: detail_GetItemId [override]
274
275 Description: ラベル文字列からサウンドIDへの変換
276
277 Arguments: label - ラベル文字列
278
279 Returns: サウンドIDを返す
280 *---------------------------------------------------------------------------*/
detail_GetItemId(const char * pString)281 SoundArchive::ItemId SoundActor::detail_GetItemId( const char* pString )
282 {
283 if ( m_IsInitialized == false )
284 {
285 return SoundArchive::INVALID_ID;
286 }
287 return m_pSoundArchivePlayer->detail_GetItemId( pString );
288 }
289
290 } // namespace nw::snd
291 } // namespace nw
292
293