1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_SoundStartable.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_SoundStartable.h>
21 #include <nw/snd/snd_SoundHandle.h>
22
23 namespace nw {
24 namespace snd {
25
26 #if 0
27 const char* SoundStartable::detail_ConvertStartResultToString( SoundStartable::StartResult startResult )
28 {
29 static const int resultStringsSize = 15;
30 static const char* resultStrings[ resultStringsSize ] =
31 {
32 "START_SUCCESS",
33 "START_ERR_LOW_PRIORITY",
34 "START_ERR_INVALID_LABEL_STRING",
35 "START_ERR_INVALID_SOUNDID",
36 "START_ERR_NOT_DATA_LOADED",
37 "START_ERR_NOT_SEQ_LOADED",
38 "START_ERR_NOT_BANK_LOADED",
39 "START_ERR_NOT_WSD_LOADED",
40 "START_ERR_NOT_WARC_LOADED",
41 "START_ERR_NOT_ENOUGH_PLAYER_HEAP",
42 "START_ERR_CANNOT_OPEN_FILE",
43 "START_ERR_NOT_AVAILABLE",
44 "START_ERR_CANNOT_ALLOCATE_TRACK",
45 "START_ERR_NOT_ENOUGH_INSTANCE",
46 "START_ERR_INVALID_PARAMETER"
47 };
48
49 static const char resultStrings128[] = "START_ERR_USER";
50 static const char resultStrings255[] = "START_ERR_UNKNOWN";
51 static const char nullStrings[] = "";
52
53 if ( startResult < resultStringsSize )
54 {
55 return resultStrings[ startResult ];
56 }
57 else if ( startResult == START_ERR_USER )
58 {
59 return resultStrings128;
60 }
61 else if ( startResult == START_ERR_UNKNOWN )
62 {
63 return resultStrings255;
64 }
65 else
66 {
67 return nullStrings;
68 }
69 }
70 #endif
71
72 /*---------------------------------------------------------------------------*
73 Name: detail_StartSound
74
75 Description: 指定したサウンド番号のサウンドを再生する
76
77 Arguments: handle - サウンドハンドル
78 soundId - サウンドID
79 startInfo - 再生パラメータ
80
81 Returns: 結果コード
82 *---------------------------------------------------------------------------*/
StartSound(SoundHandle * handle,u32 soundId,const StartInfo * startInfo)83 SoundStartable::StartResult SoundStartable::StartSound(
84 SoundHandle* handle,
85 u32 soundId,
86 const StartInfo* startInfo
87 )
88 {
89 StartResult result = detail_SetupSound(
90 handle,
91 soundId,
92 false,
93 startInfo
94 );
95 if ( ! result.IsSuccess() ) return result;
96 handle->StartPrepared();
97 StartResult result2( StartResult::START_SUCCESS );
98 return result2;
99 }
100
101 /*---------------------------------------------------------------------------*
102 Name: detail_StartSound
103
104 Description: 指定したサウンド番号のサウンドを再生する
105
106 Arguments: handle - サウンドハンドル
107 soundName - サウンド名
108 startInfo - 再生パラメータ
109
110 Returns: 結果コード
111 *---------------------------------------------------------------------------*/
StartSound(SoundHandle * handle,const char * soundName,const StartInfo * startInfo)112 SoundStartable::StartResult SoundStartable::StartSound(
113 SoundHandle* handle,
114 const char* soundName,
115 const StartInfo* startInfo
116 )
117 {
118 u32 soundId = detail_GetItemId( soundName );
119 if ( soundId == SoundArchive::INVALID_ID )
120 {
121 StartResult result( StartResult::START_ERR_INVALID_LABEL_STRING );
122 return result;
123 }
124 return StartSound( handle, soundId, startInfo );
125 }
126
127 /*---------------------------------------------------------------------------*
128 Name: detail_HoldSound
129
130 Description: 指定したサウンド番号のサウンドを再生する
131
132 Arguments: handle - サウンドハンドル
133 soundNo - サウンド番号
134 startInfo - 再生パラメータ
135
136 Returns: 結果コード
137 *---------------------------------------------------------------------------*/
HoldSound(SoundHandle * handle,u32 soundId,const StartInfo * startInfo)138 SoundStartable::StartResult SoundStartable::HoldSound(
139 SoundHandle* handle,
140 u32 soundId,
141 const StartInfo* startInfo
142 )
143 {
144 if ( handle->IsAttachedSound() && ( handle->GetId() == soundId ) )
145 {
146 handle->detail_GetAttachedSound()->SetAutoStopCounter( 1 );
147 StartResult result( StartResult::START_SUCCESS );
148 return result;
149 }
150
151 StartResult result = detail_SetupSound(
152 handle,
153 soundId,
154 true,
155 startInfo
156 );
157 if ( ! result.IsSuccess() ) return result;
158 handle->StartPrepared();
159 handle->detail_GetAttachedSound()->SetAutoStopCounter( 1 );
160 StartResult result2( StartResult::START_SUCCESS );
161 return result2;
162 }
163
164 /*---------------------------------------------------------------------------*
165 Name: detail_HoldSound
166
167 Description: 指定したサウンド番号のサウンドを再生する
168
169 Arguments: handle - サウンドハンドル
170 soundLabel - サウンドラベル
171 startInfo - 再生パラメータ
172
173 Returns: 結果コード
174 *---------------------------------------------------------------------------*/
HoldSound(SoundHandle * handle,const char * soundLabel,const StartInfo * startInfo)175 SoundStartable::StartResult SoundStartable::HoldSound(
176 SoundHandle* handle,
177 const char* soundLabel,
178 const StartInfo* startInfo
179 )
180 {
181 u32 soundId = detail_GetItemId( soundLabel );
182 if ( soundId == SoundArchive::INVALID_ID )
183 {
184 StartResult result( StartResult::START_ERR_INVALID_LABEL_STRING );
185 return result;
186 }
187 return HoldSound( handle, soundId, startInfo );
188 }
189
190 /*---------------------------------------------------------------------------*
191 Name: detail_PrepareSound
192
193 Description: 指定したサウンド番号のサウンドを再生する
194
195 Arguments: handle - サウンドハンドル
196 soundNo - サウンド番号
197 startInfo - 再生パラメータ
198
199 Returns: 結果コード
200 *---------------------------------------------------------------------------*/
PrepareSound(SoundHandle * handle,u32 soundId,const StartInfo * startInfo)201 SoundStartable::StartResult SoundStartable::PrepareSound(
202 SoundHandle* handle,
203 u32 soundId,
204 const StartInfo* startInfo
205 )
206 {
207 return detail_SetupSound(
208 handle,
209 soundId,
210 false,
211 startInfo
212 );
213 }
214
215 /*---------------------------------------------------------------------------*
216 Name: detail_PrepareSound
217
218 Description: 指定したサウンド番号のサウンドを再生する
219
220 Arguments: handle - サウンドハンドル
221 soundLabel - サウンドラベル
222 startInfo - 再生パラメータ
223
224 Returns: 結果コード
225 *---------------------------------------------------------------------------*/
PrepareSound(SoundHandle * handle,const char * soundName,const StartInfo * startInfo)226 SoundStartable::StartResult SoundStartable::PrepareSound(
227 SoundHandle* handle,
228 const char* soundName,
229 const StartInfo* startInfo
230 )
231 {
232 u32 soundId = detail_GetItemId( soundName );
233 if ( soundId == SoundArchive::INVALID_ID )
234 {
235 StartResult result( StartResult::START_ERR_INVALID_LABEL_STRING );
236 return result;
237 }
238 return PrepareSound( handle, soundId, startInfo );
239 }
240
241 } // namespace nw::snd
242 } // namespace nw
243
244