1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: MemorySoundArchiveApp.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 "MemorySoundArchiveApp.h"
21 #include "simple.csid"
22
23 namespace
24 {
25
26 const s32 SOUND_THREAD_PRIORITY = 4;
27 const s32 LOAD_THREAD_PRIORITY = 3;
28 const s32 SOUND_HEAP_SIZE = 1 * 1024 * 1024;
29 const char SOUND_ARC_PATH[] = NW_SND_DEMO_PATH_PREFIX "simple.bcsar";
30 const char DEMO_TITLE[] = "MemorySoundArchive";
31
32 }
33
OnInitialize()34 void MemorySoundArchiveApp::OnInitialize()
35 {
36 InitializeSoundSystem();
37 }
38
InitializeSoundSystem()39 void MemorySoundArchiveApp::InitializeSoundSystem()
40 {
41 // サウンドシステムの初期化
42 {
43 nw::snd::SoundSystem::SoundSystemParam param;
44 size_t workMemSize = nw::snd::SoundSystem::GetRequiredMemSize( param );
45 m_pMemoryForSoundSystem = MemAlloc( workMemSize );
46
47 nw::snd::SoundSystem::Initialize(
48 param,
49 reinterpret_cast<uptr>( m_pMemoryForSoundSystem ),
50 workMemSize );
51 }
52
53 // メモリーサウンドアーカイブの初期化
54 {
55 nn::fs::FileReader reader( SOUND_ARC_PATH );
56 s32 size = (s32)reader.GetSize();
57 m_pMemoryForSoundArchive = MemAlloc( size, 32 );
58 s32 readSize = reader.Read( m_pMemoryForSoundArchive, size );
59 m_Archive.Initialize( m_pMemoryForSoundArchive );
60 reader.Finalize();
61 }
62
63 // サウンドデータマネージャーの初期化
64 {
65 u32 setupSize = m_DataManager.GetRequiredMemSize( &m_Archive );
66 m_pMemoryForSoundDataManager = MemAlloc( setupSize );
67 m_DataManager.Initialize( &m_Archive, m_pMemoryForSoundDataManager, setupSize );
68 }
69
70 // サウンドアーカイブプレイヤーの初期化
71 {
72 u32 setupSize = m_ArchivePlayer.GetRequiredMemSize( &m_Archive );
73 m_pMemoryForSoundArchivePlayer = MemAlloc( setupSize, 32 );
74 u32 setupStrmBufferSize =
75 m_ArchivePlayer.GetRequiredStreamBufferSize( &m_Archive );
76 m_pMemoryForStreamBuffer = MemAlloc( setupStrmBufferSize, 32 );
77 bool result = m_ArchivePlayer.Initialize(
78 &m_Archive,
79 &m_DataManager,
80 m_pMemoryForSoundArchivePlayer, setupSize,
81 m_pMemoryForStreamBuffer, setupStrmBufferSize );
82 NW_ASSERT( result );
83 }
84 }
85
OnFinalize()86 void MemorySoundArchiveApp::OnFinalize()
87 {
88 nw::snd::SoundSystem::Finalize();
89
90 MemFree( m_pMemoryForSoundSystem );
91 MemFree( m_pMemoryForSoundDataManager );
92 MemFree( m_pMemoryForSoundArchivePlayer );
93 MemFree( m_pMemoryForStreamBuffer );
94 MemFree( m_pMemoryForSoundArchive );
95 }
96
OnDrawUpLCD(nw::font::TextWriter & writer)97 void MemorySoundArchiveApp::OnDrawUpLCD( nw::font::TextWriter& writer )
98 {
99 writer.Printf(" DEMO nw::snd %s\n\n", DEMO_TITLE);
100
101 writer.Print(" -- usage --\n\n");
102 writer.Print(" [A] Play Sequence Sound\n");
103 writer.Print(" [X] Play Wave Sound\n");
104 writer.Print(" [B] Stop Sound\n\n");
105 }
106
OnDrawDownLCD(nw::font::TextWriter &)107 void MemorySoundArchiveApp::OnDrawDownLCD( nw::font::TextWriter& )
108 {
109 // なにも書かない
110 }
111
OnUpdatePad(nw::demo::Pad & pad)112 void MemorySoundArchiveApp::OnUpdatePad( nw::demo::Pad& pad )
113 {
114 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_A ) )
115 {
116 m_Handle.Stop( 0 );
117 bool result = m_ArchivePlayer.StartSound( &m_Handle, SEQ_MARIOKART ).IsSuccess();
118 NN_LOG("[SEQ] SEQ_MARIOKART ... (%d)\n", result);
119 }
120
121 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_X ) )
122 {
123 m_Handle.Stop( 0 );
124 bool result = m_ArchivePlayer.StartSound( &m_Handle, SE_YOSHI ).IsSuccess();
125 NN_LOG("[WSD] SE_YOSHI ... (%d)\n", result);
126 }
127
128 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_B ) )
129 {
130 m_Handle.Stop( 3 );
131 }
132 }
133
OnUpdate()134 void MemorySoundArchiveApp::OnUpdate()
135 {
136 m_ArchivePlayer.Update();
137 }
138