1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: playerHeapApp.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 "playerHeapApp.h"
19 #include "playerHeap.csid"
20
21 namespace
22 {
23 /*
24
25 定数
26
27 */
28 const s32 SOUND_THREAD_PRIORITY = 4;
29 const s32 LOAD_THREAD_PRIORITY = 3;
30 const s32 SOUND_HEAP_SIZE = 1 * 1024 * 1024;
31 const char SOUND_ARC_PATH[] = NW_SND_DEMO_PATH_PREFIX "playerHeap.bcsar";
32 const char DEMO_TITLE[] = "playerHeap";
33
34 } // anonymous namespace
35
36
37
38 /*
39
40 PlayerHeapApp クラス定義
41
42 */
PlayerHeapApp()43 PlayerHeapApp::PlayerHeapApp()
44 {
45 }
46
OnInitialize()47 void PlayerHeapApp::OnInitialize()
48 {
49 InitializeSoundSystem();
50
51 // バンクと波形アーカイブのみロード
52 // (シーケンスデータはプレイヤーヒープにロードされる)
53 if ( ! m_DataManager.LoadData( BANK_YOSHI, &m_Heap ) )
54 {
55 NW_ASSERTMSG( false, "LoadData(BANK_YOSHI) failed.");
56 }
57 }
58
InitializeSoundSystem()59 void PlayerHeapApp::InitializeSoundSystem()
60 {
61 // サウンドシステムの初期化
62 {
63 nw::snd::SoundSystem::SoundSystemParam param;
64 size_t workMemSize = nw::snd::SoundSystem::GetRequiredMemSize( param );
65 m_pMemoryForSoundSystem = MemAlloc( workMemSize );
66
67 nw::snd::SoundSystem::Initialize(
68 param,
69 reinterpret_cast<uptr>( m_pMemoryForSoundSystem ),
70 workMemSize );
71 }
72
73 // サウンドアーカイブ
74 if ( ! m_Archive.Open( SOUND_ARC_PATH ) )
75 {
76 NW_ASSERTMSG( 0, "cannot open bcsar(%s)\n", SOUND_ARC_PATH );
77 }
78
79 // INFO ブロックのロード
80 {
81 u32 infoBlockSize = m_Archive.GetHeaderSize();
82 m_pMemoryForInfoBlock = MemAlloc( infoBlockSize );
83 if ( ! m_Archive.LoadHeader( m_pMemoryForInfoBlock, infoBlockSize ) )
84 {
85 NW_ASSERTMSG( 0, "cannot load infoBlock(%s)", SOUND_ARC_PATH );
86 }
87 }
88
89 // STRING ブロックのロード
90 {
91 u32 stringBlockSize = m_Archive.GetLabelStringDataSize();
92 m_pMemoryForStringBlock = MemAlloc( stringBlockSize );
93 if ( ! m_Archive.LoadLabelStringData( m_pMemoryForStringBlock, stringBlockSize ) )
94 {
95 NW_ASSERTMSG( 0, "cannot load stringBlock(%s)", SOUND_ARC_PATH );
96 }
97 }
98
99 // サウンドデータマネージャーの初期化
100 {
101 u32 setupSize = m_DataManager.GetRequiredMemSize( &m_Archive );
102 m_pMemoryForSoundDataManager = MemAlloc( setupSize );
103 m_DataManager.Initialize( &m_Archive, m_pMemoryForSoundDataManager, setupSize );
104 }
105
106 // サウンドアーカイブプレイヤーの初期化
107 {
108 u32 setupSize = m_ArchivePlayer.GetRequiredMemSize( &m_Archive );
109 m_pMemoryForSoundArchivePlayer = MemAlloc( setupSize, 32 );
110 u32 setupStrmBufferSize =
111 m_ArchivePlayer.GetRequiredStreamBufferSize( &m_Archive );
112 m_pMemoryForStreamBuffer = MemAlloc( setupStrmBufferSize, 32 );
113 bool result = m_ArchivePlayer.Initialize(
114 &m_Archive,
115 &m_DataManager,
116 nw::ut::RoundUp( m_pMemoryForSoundArchivePlayer, 32 ), setupSize,
117 m_pMemoryForStreamBuffer, setupStrmBufferSize );
118 NW_ASSERT( result );
119 }
120
121 // サウンドヒープの構築
122 {
123 m_pMemoryForSoundHeap = MemAlloc( SOUND_HEAP_SIZE );
124 bool result = m_Heap.Create( m_pMemoryForSoundHeap, SOUND_HEAP_SIZE );
125 NW_ASSERT( result );
126 }
127 }
128
OnFinalize()129 void PlayerHeapApp::OnFinalize()
130 {
131 nw::snd::SoundSystem::Finalize();
132
133 MemFree( m_pMemoryForSoundSystem );
134 MemFree( m_pMemoryForInfoBlock );
135 MemFree( m_pMemoryForStringBlock );
136 MemFree( m_pMemoryForSoundDataManager );
137 MemFree( m_pMemoryForSoundArchivePlayer );
138 MemFree( m_pMemoryForSoundHeap );
139 MemFree( m_pMemoryForStreamBuffer );
140 }
141
OnDrawUpLCD(nw::font::TextWriter & writer)142 void PlayerHeapApp::OnDrawUpLCD( nw::font::TextWriter& writer )
143 {
144 writer.Printf(" DEMO nw::snd %s\n\n", DEMO_TITLE);
145
146 writer.Print(" -- usage --\n\n");
147 writer.Print(" [A] Play SE_1\n");
148 writer.Print(" [X] Play SE_2\n");
149 writer.Print(" [B] Stop Sound\n\n");
150 }
151
OnDrawDownLCD(nw::font::TextWriter &)152 void PlayerHeapApp::OnDrawDownLCD( nw::font::TextWriter& )
153 {
154 // なにも書かない
155 }
156
OnUpdatePad(nw::demo::Pad & pad)157 void PlayerHeapApp::OnUpdatePad( nw::demo::Pad& pad )
158 {
159 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_A ) )
160 {
161 bool result = m_ArchivePlayer.StartSound( &m_Handle, SEQ_YOSHI ).IsSuccess();
162 NN_LOG("SEQ_YOSHI ... (%d)\n", result);
163 }
164
165 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_X ) )
166 {
167 bool result = m_ArchivePlayer.StartSound( &m_Handle, SEQ_WIHAHO ).IsSuccess();
168 NN_LOG("SEQ_WIHAHO ... (%d)\n", result);
169 }
170
171 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_B ) )
172 {
173 m_Handle.Stop( 3 );
174 }
175 }
176
OnUpdate()177 void PlayerHeapApp::OnUpdate()
178 {
179 m_ArchivePlayer.Update();
180 }
181