/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_MemorySoundArchive.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision:$ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include namespace nw { namespace snd { /*---------------------------------------------------------------------------* Name: MemorySoundArchive Description: コンストラクタ Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ MemorySoundArchive::MemorySoundArchive() : m_pData( NULL ) { } /*---------------------------------------------------------------------------* Name: ~MemorySoundArchive Description: デストラクタ Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ MemorySoundArchive::~MemorySoundArchive() { } /*---------------------------------------------------------------------------* Name: Initialize Description: サウンドアーカイブを初期化する Arguments: soundArchiveData - サウンドアーカイブデータ Returns: 成功したかどうか *---------------------------------------------------------------------------*/ bool MemorySoundArchive::Initialize( const void* soundArchiveData ) { NW_NULL_ASSERT( soundArchiveData ); NW_ALIGN4_ASSERT( soundArchiveData ); m_FileReader.Initialize( soundArchiveData ); SoundArchive::Initialize( &m_FileReader ); const unsigned long infoBlockOffset = m_FileReader.GetInfoBlockOffset(); const unsigned long infoBlockSize = m_FileReader.GetInfoBlockSize(); m_FileReader.SetInfoBlock( ut::AddOffsetToPtr( soundArchiveData, infoBlockOffset ) ); const unsigned long stringBlockOffset = m_FileReader.GetStringBlockOffset(); const unsigned long stringBlockSize = m_FileReader.GetStringBlockSize(); // 文字列ブロックへのリファレンスは必ず含まれるが、 // ブロック自体が含まれない場合、stringBlockOffset/stringBlockSize の両方共、 // 0xffffffff が入っている。 if ( stringBlockOffset == 0xffffffff || stringBlockSize == 0xffffffff ) { // なにもしない } else { m_FileReader.SetStringBlock( ut::AddOffsetToPtr( soundArchiveData, stringBlockOffset )); } m_pData = soundArchiveData; return true; } /*---------------------------------------------------------------------------* Name: Finalize Description: サウンドアーカイブを閉じる Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ void MemorySoundArchive::Finalize() { m_pData = NULL; m_FileReader.Finalize(); SoundArchive::Finalize(); } const void* MemorySoundArchive::detail_GetFileAddress( FileId fileId ) const { #if 0 // ファイル位置情報取得 FilePos filePos; if ( ! detail_ReadFilePos( fileId, 0, &filePos ) ) { return NULL; } // グループ情報取得 GroupInfo groupInfo; if ( ! detail_ReadGroupInfo( filePos.groupId, &groupInfo ) ) { return NULL; } GroupItemInfo itemInfo; if ( ! detail_ReadGroupItemInfo( filePos.groupId, filePos.index, &itemInfo ) ) { return NULL; } if ( groupInfo.extFilePath != NULL ) { // 外部参照グループ return NULL; } const u32 itemOffset = groupInfo.offset + itemInfo.offset; return ut::AddOffsetToPtr( m_pData, itemOffset ); #else FileInfo fileInfo; if ( ! detail_ReadFileInfo( fileId, &fileInfo ) ) { return NULL; } // 外部参照ファイルは対応しない (?) return ut::AddOffsetToPtr( m_pData, fileInfo.offsetFromFileBlockHead + m_FileReader.GetFileBlockOffset() ); #endif } io::FileStream* MemorySoundArchive::OpenStream( void* buffer, int size, u32 begin, u32 length ) { if ( m_pData == NULL ) return NULL; if ( size < sizeof( MemoryFileStream ) ) return NULL; MemoryFileStream* stream = new( buffer ) MemoryFileStream( ut::AddOffsetToPtr( m_pData, begin ), length ); return stream; } io::FileStream* MemorySoundArchive::OpenExtStream( void* buffer, int size, const char* extFilePath, // const wchar_t* extFilePath, u32 begin, u32 length ) const { (void)buffer; (void)size; (void)extFilePath; (void)begin; (void)length; NW_WARNING( false, "Cannot OpenExtStream for MemorySoundArchive\n"); return NULL; } size_t MemorySoundArchive::detail_GetRequiredStreamBufferSize() const { return sizeof( MemoryFileStream ); } MemorySoundArchive::MemoryFileStream::MemoryFileStream( const void* buffer, u32 size ) : m_pBuffer( buffer ), m_Size( size ), m_Position( 0 ) { } void MemorySoundArchive::MemoryFileStream::Close() { m_pBuffer = NULL; m_Size = 0; m_Position = 0; } s32 MemorySoundArchive::MemoryFileStream::Read( void* buf, u32 length ) { u32 readLen = ut::Min( length, m_Size - m_Position ); std::memcpy( buf, ut::AddOffsetToPtr( m_pBuffer, m_Position ), readLen ); return static_cast(readLen); } void MemorySoundArchive::MemoryFileStream::Seek( s32 offset, u32 origin ) { switch( origin ) { case io::FILE_STREAM_SEEK_BEGIN: m_Position = static_cast(offset); break; case io::FILE_STREAM_SEEK_CURRENT: m_Position += offset; break; case io::FILE_STREAM_SEEK_END: m_Position = m_Size - offset; break; default: NW_ASSERTMSG( false, "Unsupported Seek origin" ); return; } } } // namespace nw::snd } // namespace nw