/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_WaveArchiveFileReader.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: 28239 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include // #define NW_SND_DEBUG_PRINT_ENABLE namespace nw { namespace snd { namespace internal { namespace { const u32 SIGNATURE_INFO_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'O' ); const u32 SIGNATURE_FILE_BLOCK = NW_UT_MAKE_SIGWORD( 'F', 'I', 'L', 'E' ); const u32 SUPPORTED_FILE_VERSION = 0x01000000; // ライブラリがサポートする最低バージョン const u32 CURRENT_FILE_VERSION = 0x01000000; // ライブラリがサポートする最新バージョン bool IsValidFileHeader( const void* waveArchiveData ) { const ut::BinaryFileHeader& header = *reinterpret_cast( waveArchiveData ); // シグニチャ確認 NW_ASSERTMSG( header.signature == WaveArchiveFileReader::SIGNATURE_FILE, "invalid file signature." ); if ( header.signature != WaveArchiveFileReader::SIGNATURE_FILE ) { return false; } // バージョン確認 NW_ASSERTMSG( header.version >= SUPPORTED_FILE_VERSION, "wave archive file is not supported version.\n" "please reconvert file using new version tools.\n" "(SUPPORTED_FILE_VERSION:0x%08x >= your version:0x%08x)\n", SUPPORTED_FILE_VERSION, header.version ); if ( header.version < SUPPORTED_FILE_VERSION ) { return false; } NW_ASSERTMSG( header.version <= CURRENT_FILE_VERSION, "wave archive file is not supported version.\n" "please reconvert file using new version tools.\n" "(CURRENT_FILE_VERSION:0x%08x <= your version:0x%08x)\n", CURRENT_FILE_VERSION, header.version ); if ( header.version > CURRENT_FILE_VERSION ) { return false; } return true; } } // anonymous namespace const u32 WaveArchiveFileReader::SIGNATURE_WARC_TABLE = NW_UT_MAKE_SIGWORD( 'C', 'W', 'A', 'T' ); WaveArchiveFileReader::WaveArchiveFileReader( const void* pWaveArchiveFile, bool isIndividual ) : m_pHeader( NULL ), m_pInfoBlockBody( NULL ), m_pLoadTable( NULL ) { NW_NULL_ASSERT( pWaveArchiveFile ); if ( ! IsValidFileHeader( pWaveArchiveFile ) ) return; m_pHeader = reinterpret_cast( pWaveArchiveFile ); m_pInfoBlockBody = &m_pHeader->GetInfoBlock()->body; if ( isIndividual ) { m_pLoadTable = reinterpret_cast( ut::AddOffsetToPtr( const_cast( pWaveArchiveFile ), m_pHeader->GetFileBlockOffset() + sizeof( SIGNATURE_WARC_TABLE ) ) ); // INFO ブロックと FILE ブロックの間に、 // アライメントがはさまっているので、その分ムダになるが、 // 見通しのよさを優先する。 } } void WaveArchiveFileReader::InitializeFileTable() { NW_NULL_ASSERT( m_pInfoBlockBody ); // ロード管理用ファイルテーブルの初期化 for ( u32 i = 0; i < GetWaveFileCount(); i++ ) { m_pLoadTable->waveFile[ i ] = NULL; } } u32 WaveArchiveFileReader::GetWaveFileCount() const { NW_NULL_ASSERT( m_pInfoBlockBody ); return m_pInfoBlockBody->GetWaveFileCount(); } const void* WaveArchiveFileReader::GetWaveFile( u32 waveIndex ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); if ( waveIndex >= GetWaveFileCount() ) return NULL; if ( m_pLoadTable != NULL ) { return GetWaveFileForIndividual( waveIndex ); } return GetWaveFileForWhole( waveIndex ); } u32 WaveArchiveFileReader::GetWaveFileSize( u32 waveIndex ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); return m_pInfoBlockBody->GetSize( waveIndex ); } u32 WaveArchiveFileReader::GetWaveFileOffsetFromFileHead( u32 waveIndex ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); u32 result = + m_pHeader->GetFileBlockOffset() + offsetof( WaveArchiveFile::FileBlock, body ) + m_pInfoBlockBody->GetOffsetFromFileBlockBody( waveIndex ); return result; } const void* WaveArchiveFileReader::SetWaveFile( u32 waveIndex, const void* pWaveFile ) { if ( m_pLoadTable == NULL ) return NULL; if ( waveIndex >= GetWaveFileCount() ) return NULL; const void* preAddress = GetWaveFileForIndividual( waveIndex ); m_pLoadTable->waveFile[ waveIndex ] = pWaveFile; #ifdef NW_SND_DEBUG_PRINT_ENABLE // デバッグ for ( u32 i = 0; i < GetWaveFileCount(); i++ ) { NN_LOG(" [%3d] %p\n", i, m_pLoadTable->waveFile[i] ); } #endif /* NW_SND_DEBUG_PRINT_ENABLE */ return preAddress; } bool WaveArchiveFileReader::HasIndividualLoadTable() const { const u32* signature = reinterpret_cast( ut::AddOffsetToPtr( m_pHeader, m_pHeader->GetFileBlockOffset() ) ); if ( *signature == SIGNATURE_WARC_TABLE ) { return true; } return false; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw