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