/*---------------------------------------------------------------------------* Project: NintendoWare File: SoundActorApp.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 "SoundActorApp.h" #include "simple.csid" 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[] = "SoundActor"; const f32 ACTOR_PAN_MIN = -1.0f; const f32 ACTOR_PAN_MAX = 1.0f; const f32 ACTOR_PAN_DEFAULT = 0.0f; const f32 ACTOR_VOLUME_MIN = 0.1f; const f32 ACTOR_VOLUME_MAX = 2.0f; const f32 ACTOR_VOLUME_DEFAULT = 1.0f; const f32 CONTROL_PAD_STEP = 0.05f; } void SoundActorApp::OnInitialize() { InitializeSoundSystem(); // サウンドデータのロード if ( ! m_DataManager.LoadData( SE_SIN440, &m_Heap ) ) { NW_ASSERTMSG( false, "LoadData(SE_SIN440) failed." ); } if ( ! m_DataManager.LoadData( SE_YOSHI, &m_Heap ) ) { NW_ASSERTMSG( false, "LoadData(SE_YOSHI) failed." ); } // サウンドアクターの初期化 m_ActorPan = ACTOR_PAN_DEFAULT; m_ActorVolume = ACTOR_VOLUME_DEFAULT; m_Actor.Initialize( m_ArchivePlayer ); m_Actor.SetPlayableSoundCount( 0, 1 ); } void SoundActorApp::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 ); } } // サウンドデータマネージャーの初期化 { 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 SoundActorApp::OnFinalize() { m_Actor.Finalize(); nw::snd::SoundSystem::Finalize(); MemFree( m_pMemoryForSoundSystem ); MemFree( m_pMemoryForInfoBlock ); MemFree( m_pMemoryForSoundDataManager ); MemFree( m_pMemoryForSoundArchivePlayer ); MemFree( m_pMemoryForSoundHeap ); MemFree( m_pMemoryForStreamBuffer ); } void SoundActorApp::OnDrawUpLCD( nw::font::TextWriter& writer ) { writer.Printf(" DEMO nw::snd %s\n\n", DEMO_TITLE); writer.Print (" -- usage --\n\n"); writer.Print (" [A] Play Sound\n"); writer.Print (" [B] Stop Sound\n"); writer.Print (" [LEFT/RIGHT] Modify Actor Pan\n"); writer.Print (" [UP/DOWN] Modify Actor Volume\n\n\n"); writer.Print (" -- status --\n\n"); writer.Printf(" pan % 2.2f\n", m_ActorPan ); writer.Printf(" volume % 2.2f\n", m_ActorVolume ); } void SoundActorApp::OnDrawDownLCD( nw::font::TextWriter& writer ) { (void)writer; } void SoundActorApp::OnUpdatePad( nw::demo::Pad& pad ) { // A, B で再生停止 if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_A ) ) { // m_Handle.Stop( 0 ); bool result = m_Actor.StartSound( &m_Handle, SE_YOSHI ).IsSuccess(); NN_LOG("SE_YOSHI ... (%d)\n", result); } if ( pad.IsButtonDown( nw::demo::Pad::BUTTON_B ) ) { m_Actor.StopAllSound( 3 ); } // 左右で、位置変更 if ( pad.IsButtonPress( nw::demo::Pad::BUTTON_LEFT ) ) { m_ActorPan = m_ActorPan <= ACTOR_PAN_MIN ? ACTOR_PAN_MIN : m_ActorPan - CONTROL_PAD_STEP; m_Actor.HoldSound( &m_HandleForHoldSound, SE_SIN440 ); } if ( pad.IsButtonPress( nw::demo::Pad::BUTTON_RIGHT ) ) { m_ActorPan = m_ActorPan >= ACTOR_PAN_MAX ? ACTOR_PAN_MAX : m_ActorPan + CONTROL_PAD_STEP; m_Actor.HoldSound( &m_HandleForHoldSound, SE_SIN440 ); } // 上下で、サイズ変更 if ( pad.IsButtonPress( nw::demo::Pad::BUTTON_UP ) ) { m_ActorVolume = m_ActorVolume >= ACTOR_VOLUME_MAX ? ACTOR_VOLUME_MAX : m_ActorVolume + CONTROL_PAD_STEP; m_Actor.HoldSound( &m_HandleForHoldSound, SE_SIN440 ); } if ( pad.IsButtonPress( nw::demo::Pad::BUTTON_DOWN ) ) { m_ActorVolume = m_ActorVolume <= ACTOR_VOLUME_MIN ? ACTOR_VOLUME_MIN : m_ActorVolume - CONTROL_PAD_STEP; m_Actor.HoldSound( &m_HandleForHoldSound, SE_SIN440 ); } } void SoundActorApp::OnUpdate() { m_ArchivePlayer.Update(); // アクターの更新 { m_Actor.SetVolume( m_ActorVolume ); m_Actor.SetPan( m_ActorPan ); } }