1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_SoundActor.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: $
16  *---------------------------------------------------------------------------*/
17 
18 #include "precompiled.h"
19 
20 #include <nw/snd/snd_SoundActor.h>
21 
22 namespace nw {
23 namespace snd {
24 
25 /*---------------------------------------------------------------------------*
26   Name:         SoundActor
27 
28   Description:  コンストラクタ
29 
30   Arguments:    soundArchivePlayer - サウンドアーカイブプレイヤー
31 
32   Returns:      None.
33   *---------------------------------------------------------------------------*/
SoundActor()34 SoundActor::SoundActor()
35 : m_pSoundArchivePlayer( NULL ),
36   m_IsInitialized( false ),
37   m_IsFinalized( true )
38 {
39     // 何もしない
40 }
SoundActor(SoundArchivePlayer & soundArchivePlayer)41 SoundActor::SoundActor( SoundArchivePlayer& soundArchivePlayer )
42 : m_pSoundArchivePlayer( NULL ),
43   m_IsInitialized( false ),
44   m_IsFinalized( true )
45 {
46     Initialize( soundArchivePlayer );
47 }
48 
49 /*---------------------------------------------------------------------------*
50   Name:         ~SoundActor
51 
52   Description:  デストラクタ
53 
54   Arguments:    None.
55 
56   Returns:      None.
57   *---------------------------------------------------------------------------*/
~SoundActor()58 SoundActor::~SoundActor()
59 {
60     Finalize();
61 }
62 
Initialize(SoundArchivePlayer & soundArchivePlayer)63 void SoundActor::Initialize( SoundArchivePlayer& soundArchivePlayer )
64 {
65     if ( m_IsInitialized ) return;
66 
67     m_pSoundArchivePlayer = &soundArchivePlayer;
68 
69     for ( int i = 0; i < ACTOR_PLAYER_COUNT; i++ )
70     {
71         const int playableSoundCount = ( i == 0 ) ? INT_MAX : 1;
72         m_ActorPlayer[i].SetPlayableSoundCount( playableSoundCount );
73     }
74 
75     m_IsInitialized = true;
76     m_IsFinalized = false;
77 }
Finalize()78 void SoundActor::Finalize()
79 {
80     if ( m_IsFinalized ) return;
81 
82     for ( int i = 0; i < ACTOR_PLAYER_COUNT; i++ )
83     {
84         m_ActorPlayer[i].Finalize( this );
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