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