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