/*---------------------------------------------------------------------------* Project: NintendoWare File: LabelStringApp.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include "LabelStringApp.h" #ifdef NW_PLATFORM_CTRWIN #include #endif namespace { const s32 SOUND_THREAD_PRIORITY = 4; const s32 LOAD_THREAD_PRIORITY = 3; const s32 SOUND_HEAP_SIZE = 1 * 1024 * 1024; const char SOUND_ARC_PATH[] = NW_SND_DEMO_PATH_PREFIX "simple.bcsar"; const char DEMO_TITLE[] = "LabelString"; } void LabelStringApp::OnInitialize() { InitializeSoundSystem(); // サウンドデータのロード if ( ! m_DataManager.LoadData( "SEQ_MARIOKART", &m_Heap ) ) { NW_ASSERTMSG( false, "LoadData(SEQ_MARIOKART) failed." ); } if ( ! m_DataManager.LoadData( "SE_YOSHI", &m_Heap ) ) { NW_ASSERTMSG( false, "LoadData(SE_YOSHI) failed." ); } } void LabelStringApp::InitializeSoundSystem() { // サウンドシステムの初期化 { nw::snd::SoundSystem::SoundSystemParam param; size_t workMemSize = nw::snd::SoundSystem::GetRequiredMemSize( param ); m_pMemoryForSoundSystem = MemAlloc( workMemSize ); nw::snd::SoundSystem::Initialize( param, reinterpret_cast( m_pMemoryForSoundSystem ), workMemSize ); } // サウンドアーカイブの初期化 if ( ! m_Archive.Open( SOUND_ARC_PATH ) ) { NW_ASSERTMSG( 0, "cannot open bcsar(%s)\n", SOUND_ARC_PATH ); } // INFO ブロックのロード { u32 infoBlockSize = m_Archive.GetHeaderSize(); m_pMemoryForInfoBlock = MemAlloc( infoBlockSize ); if ( ! m_Archive.LoadHeader( m_pMemoryForInfoBlock, infoBlockSize ) ) { NW_ASSERTMSG( 0, "cannot load infoBlock(%s)", SOUND_ARC_PATH ); } } // STRING ブロックのロード { u32 stringBlockSize = m_Archive.GetLabelStringDataSize(); m_pMemoryForStringBlock = MemAlloc( stringBlockSize ); if ( ! m_Archive.LoadLabelStringData( m_pMemoryForStringBlock, stringBlockSize ) ) { NW_ASSERTMSG( 0, "cannot load stringBlock(%s)", SOUND_ARC_PATH ); } } // サウンドデータマネージャーの初期化 { u32 setupSize = m_DataManager.GetRequiredMemSize( &m_Archive ); m_pMemoryForSoundDataManager = MemAlloc( setupSize ); m_DataManager.Initialize( &m_Archive, m_pMemoryForSoundDataManager, setupSize ); } // サウンドアーカイブプレイヤーの初期化 { u32 setupSize = m_ArchivePlayer.GetRequiredMemSize( &m_Archive ); m_pMemoryForSoundArchivePlayer = MemAlloc( setupSize, 32 ); u32 setupStrmBufferSize = m_ArchivePlayer.GetRequiredStreamBufferSize( &m_Archive ); m_pMemoryForStreamBuffer = MemAlloc( setupStrmBufferSize, 32 ); bool result = m_ArchivePlayer.Initialize( &m_Archive, &m_DataManager, m_pMemoryForSoundArchivePlayer, setupSize, m_pMemoryForStreamBuffer, setupStrmBufferSize ); NW_ASSERT( result ); } // サウンドヒープの構築 { m_pMemoryForSoundHeap = MemAlloc( SOUND_HEAP_SIZE ); bool result = m_Heap.Create( m_pMemoryForSoundHeap, SOUND_HEAP_SIZE ); NW_ASSERT( result ); } } void LabelStringApp::OnFinalize() { nw::snd::SoundSystem::Finalize(); MemFree( m_pMemoryForSoundSystem ); MemFree( m_pMemoryForInfoBlock ); MemFree( m_pMemoryForSoundDataManager ); MemFree( m_pMemoryForSoundArchivePlayer ); MemFree( m_pMemoryForSoundHeap ); MemFree( m_pMemoryForStreamBuffer ); } void LabelStringApp::OnDrawUpLCD( nw::font::TextWriter& writer ) { writer.Printf(" DEMO nw::snd %s\n\n", DEMO_TITLE); writer.Print(" -- usage --\n\n"); writer.Print(" [A] Play Sequence Sound\n"); writer.Print(" [X] Play Wave Sound\n"); writer.Print(" [Y] Play Stream Sound\n"); writer.Print(" [B] Stop Sound\n\n"); } void LabelStringApp::OnDrawDownLCD( nw::font::TextWriter& writer ) { #ifdef NW_PLATFORM_CTRWIN (void)writer; #else #if 0 writer.Printf("ChannelStatus\n\n"); char str[37]; str[0] = '\0'; for ( int i = 0; i < 36; i++ ) { nw::os::SNPrintf( str, 36, "%s%d", str, nw::snd::internal::HardwareChannelManager::IsChannelPlay( i ) ); if ( i % 8 == 7 ) nw::os::SNPrintf( str, 36, "%s ", str ); } writer.Printf("%s\n", str); #else (void)writer; #endif #endif } void LabelStringApp::OnUpdatePad( nw::demo::Pad& pad ) { if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_A ) ) { m_Handle.Stop( 0 ); bool result = m_ArchivePlayer.StartSound( &m_Handle, "SEQ_MARIOKART" ).IsSuccess(); NN_LOG("[SEQ] SEQ_MARIOKART ... (%d)\n", result); } if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_X ) ) { m_Handle.Stop( 0 ); bool result = m_ArchivePlayer.StartSound( &m_Handle, "SE_YOSHI" ).IsSuccess(); NN_LOG("[WSD] SE_YOSHI ... (%d)\n", result); } if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_Y ) ) { m_Handle.Stop( 0 ); bool result = m_ArchivePlayer.StartSound( &m_Handle, "STRM_MARIOKART" ).IsSuccess(); NN_LOG("[STRM] STRM_MARIOKART ... (%d)\n", result ); } if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_B ) ) { m_Handle.Stop( 3 ); } } void LabelStringApp::OnUpdate() { m_ArchivePlayer.Update(); }