1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: externalFileApp.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 "externalFileApp.h"
21 #include "externalFile.csid"
22
23 namespace
24 {
25 /*
26
27 定数
28
29 */
30 const s32 SOUND_THREAD_PRIORITY = 4;
31 const s32 LOAD_THREAD_PRIORITY = 3;
32 const s32 SOUND_HEAP_SIZE = 1 * 1024 * 1024;
33 const char DEMO_TITLE[] = "externalFile";
34 const char SOUND_ARC_PATH[] = NW_SND_DEMO_PATH_PREFIX "externalFile.bcsar";
35 const char EXTERNAL_FILE_PATH[] = NW_SND_DEMO_PATH_PREFIX "WARC_TEST.bcwar";
36
37 } // anonymous namespace
38
39
40
41 /*
42
43 ExternalFileApp クラス定義
44
45 */
ExternalFileApp()46 ExternalFileApp::ExternalFileApp()
47 {
48 }
49
OnInitialize()50 void ExternalFileApp::OnInitialize()
51 {
52 InitializeSoundSystem();
53 InitializeDemo();
54 }
55
InitializeSoundSystem()56 void ExternalFileApp::InitializeSoundSystem()
57 {
58 // サウンドシステムの初期化
59 {
60 nw::snd::SoundSystem::SoundSystemParam param;
61 size_t workMemSize = nw::snd::SoundSystem::GetRequiredMemSize( param );
62 m_pMemoryForSoundSystem = MemAlloc( workMemSize );
63
64 nw::snd::SoundSystem::Initialize(
65 param,
66 reinterpret_cast<uptr>( m_pMemoryForSoundSystem ),
67 workMemSize );
68 }
69
70 // サウンドアーカイブ
71 if ( ! m_Archive.Open( SOUND_ARC_PATH ) )
72 {
73 NW_ASSERTMSG( 0, "cannot open bcsar(%s)\n", SOUND_ARC_PATH );
74 }
75
76 // INFO ブロックのロード
77 {
78 u32 infoBlockSize = m_Archive.GetHeaderSize();
79 m_pMemoryForInfoBlock = MemAlloc( infoBlockSize );
80 if ( ! m_Archive.LoadHeader( m_pMemoryForInfoBlock, infoBlockSize ) )
81 {
82 NW_ASSERTMSG( 0, "cannot load infoBlock(%s)", SOUND_ARC_PATH );
83 }
84 }
85
86 // STRING ブロックのロード
87 {
88 u32 stringBlockSize = m_Archive.GetLabelStringDataSize();
89 m_pMemoryForStringBlock = MemAlloc( stringBlockSize );
90 if ( ! m_Archive.LoadLabelStringData( m_pMemoryForStringBlock, stringBlockSize ) )
91 {
92 NW_ASSERTMSG( 0, "cannot load stringBlock(%s)", SOUND_ARC_PATH );
93 }
94 }
95
96 // サウンドデータマネージャーの初期化
97 {
98 u32 setupSize = m_DataManager.GetRequiredMemSize( &m_Archive );
99 m_pMemoryForSoundDataManager = MemAlloc( setupSize );
100 m_DataManager.Initialize( &m_Archive, m_pMemoryForSoundDataManager, setupSize );
101 }
102
103 // サウンドアーカイブプレイヤーの初期化
104 {
105 u32 setupSize = m_ArchivePlayer.GetRequiredMemSize( &m_Archive );
106 m_pMemoryForSoundArchivePlayer = MemAlloc( setupSize, 32 );
107 u32 setupStrmBufferSize =
108 m_ArchivePlayer.GetRequiredStreamBufferSize( &m_Archive );
109 m_pMemoryForStreamBuffer = MemAlloc( setupStrmBufferSize, 32 );
110 bool result = m_ArchivePlayer.Initialize(
111 &m_Archive,
112 &m_DataManager,
113 m_pMemoryForSoundArchivePlayer, setupSize,
114 m_pMemoryForStreamBuffer, setupStrmBufferSize );
115 NW_ASSERT( result );
116 }
117
118 // サウンドヒープの構築
119 {
120 m_pMemoryForSoundHeap = MemAlloc( SOUND_HEAP_SIZE );
121 bool result = m_Heap.Create( m_pMemoryForSoundHeap, SOUND_HEAP_SIZE );
122 NW_ASSERT( result );
123 }
124 }
125
OnFinalize()126 void ExternalFileApp::OnFinalize()
127 {
128 nw::snd::SoundSystem::Finalize();
129
130 MemFree( m_pMemoryForSoundSystem );
131 MemFree( m_pMemoryForInfoBlock );
132 MemFree( m_pMemoryForStringBlock );
133 MemFree( m_pMemoryForSoundDataManager );
134 MemFree( m_pMemoryForSoundArchivePlayer );
135 MemFree( m_pMemoryForSoundHeap );
136 MemFree( m_pMemoryForStreamBuffer );
137 MemFree( m_pMemoryForExternalFile );
138 }
139
OnDrawUpLCD(nw::font::TextWriter & writer)140 void ExternalFileApp::OnDrawUpLCD( nw::font::TextWriter& writer )
141 {
142 writer.Printf(" DEMO nw::snd %s\n\n", DEMO_TITLE );
143
144 writer.Print(" -- usage --\n\n");
145 writer.Print(" [A] Play SE_1\n");
146 writer.Print(" [X] Play SE_2\n");
147 writer.Print(" [B] Stop Sound\n\n");
148 }
149
OnDrawDownLCD(nw::font::TextWriter &)150 void ExternalFileApp::OnDrawDownLCD( nw::font::TextWriter& )
151 {
152 // なにも書かない
153 }
154
OnUpdatePad(nw::demo::Pad & pad)155 void ExternalFileApp::OnUpdatePad( nw::demo::Pad& pad )
156 {
157 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_A ) )
158 {
159 m_Handle.Stop(0);
160 bool result = m_ArchivePlayer.StartSound( &m_Handle, WSD_YOSHI ).IsSuccess();
161 NN_LOG("WSD_YOSHI ... (%d)\n", result);
162 }
163
164 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_X ) )
165 {
166 m_Handle.Stop(0);
167 bool result = m_ArchivePlayer.StartSound( &m_Handle, WSD_WIHAHO ).IsSuccess();
168 NN_LOG("WSD_WIHAHO ... (%d)\n", result);
169 }
170
171 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_B ) )
172 {
173 m_Handle.Stop( 3 );
174 }
175 }
176
InitializeDemo()177 void ExternalFileApp::InitializeDemo()
178 {
179 // ウェーブサウンドデータのみ、サウンドヒープにロード
180 if ( ! m_DataManager.LoadData( WSD_YOSHI, &m_Heap, nw::snd::SoundDataManager::LOAD_WSD ) )
181 {
182 NW_ASSERTMSG( false, "LoadData(WSD_YOSHI) failed.\n");
183 }
184
185 // 波形アーカイブファイルをメモリにロード
186 {
187 nn::fs::FileReader reader( EXTERNAL_FILE_PATH );
188 m_LengthForExternalFile = (s32)reader.GetSize();
189 m_pMemoryForExternalFile = MemAlloc( m_LengthForExternalFile, 32 );
190 (void)reader.Read( m_pMemoryForExternalFile, m_LengthForExternalFile );
191 reader.Finalize();
192 }
193
194 // ロードした波形アーカイブファイルを SoundDataManager に登録
195 {
196 u32 fileId = m_Archive.GetItemFileId( WARC_TEST );
197 m_DataManager.SetFileAddress( fileId, m_pMemoryForExternalFile );
198 }
199
200 // SoundDataManager の登録を解除し、波形アーカイブファイルをメモリから解放
201 // {
202 // m_DataManager.InvalidateSoundData(
203 // m_pMemoryForExternalFile, m_LengthForExternalFile );
204 // MemFree( m_pMemoryForExternalFile );
205 // }
206 }
207
OnUpdate()208 void ExternalFileApp::OnUpdate()
209 {
210 m_ArchivePlayer.Update();
211 }
212