/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_WaveSoundFileReader.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: 32399 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include namespace nw { namespace snd { namespace internal { namespace { const u32 SIGNATURE_INFO_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'O' ); const u32 SUPPORTED_FILE_VERSION = 0x01000000; // ライブラリがサポートする最低バージョン const u32 CURRENT_FILE_VERSION = 0x01000000; // ライブラリがサポートする最新バージョン bool IsValidFileHeader( const void* waveSoundFile ) { const ut::BinaryFileHeader& header = *reinterpret_cast( waveSoundFile ); // シグニチャ確認 NW_ASSERTMSG( header.signature == WaveSoundFileReader::SIGNATURE_FILE, "invalid file signature." ); if ( header.signature != WaveSoundFileReader::SIGNATURE_FILE ) { return false; } // バージョン確認 NW_ASSERTMSG( header.version >= SUPPORTED_FILE_VERSION, "wavesound 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, "wavesound 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 WaveSoundFileReader::WaveSoundFileReader( const void* waveSoundFile ) : m_pHeader( NULL ), m_pInfoBlockBody( NULL ) { NW_NULL_ASSERT( waveSoundFile ); if ( ! IsValidFileHeader( waveSoundFile ) ) return; m_pHeader = reinterpret_cast( waveSoundFile ); // INFO ブロックチェック const WaveSoundFile::InfoBlock* infoBlock = m_pHeader->GetInfoBlock(); NW_NULL_ASSERT( infoBlock ); if ( infoBlock == NULL ) return; // シグニチャチェック NW_ASSERTMSG( infoBlock->header.kind == SIGNATURE_INFO_BLOCK, "invalid block signature." ); m_pInfoBlockBody = &infoBlock->body; } u32 WaveSoundFileReader::GetWaveSoundCount() const { NW_NULL_ASSERT( m_pInfoBlockBody ); return m_pInfoBlockBody->GetWaveSoundCount(); } u32 WaveSoundFileReader::GetNoteInfoCount( u32 index ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); NW_ASSERT( index < GetWaveSoundCount() ); const WaveSoundFile::WaveSoundData& wsdData = m_pInfoBlockBody->GetWaveSoundData( index ); return wsdData.GetNoteCount(); } u32 WaveSoundFileReader::GetTrackInfoCount( u32 index ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); NW_ASSERT( index < GetWaveSoundCount() ); const WaveSoundFile::WaveSoundData& wsdData = m_pInfoBlockBody->GetWaveSoundData( index ); return wsdData.GetTrackCount(); } bool WaveSoundFileReader::ReadWaveSoundInfo( WaveSoundInfo* dst, u32 index ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); NW_NULL_ASSERT( dst ); const WaveSoundFile::WaveSoundInfo& src = m_pInfoBlockBody->GetWaveSoundData( index ).GetWaveSoundInfo(); dst->pitch = src.GetPitch(); dst->pan = src.GetPan(); dst->surroundPan = src.GetSurroundPan(); src.GetSendValue( &dst->mainSend, dst->fxSend, AUX_BUS_NUM ); dst->adshr = src.GetAdshrCurve(); return true; } bool WaveSoundFileReader::ReadNoteInfo( WaveSoundNoteInfo* dst, u32 index, u32 noteIndex ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); NW_NULL_ASSERT( dst ); const WaveSoundFile::NoteInfo& src = m_pInfoBlockBody->GetWaveSoundData( index ).GetNoteInfo( noteIndex ); const Util::WaveId* pWaveId = m_pInfoBlockBody->GetWaveIdTable().GetWaveId( src.waveIdTableIndex ); if ( pWaveId == NULL ) { return false; } dst->waveArchiveId = pWaveId->waveArchiveId; dst->waveIndex = pWaveId->waveIndex; dst->pitch = src.GetPitch(); dst->adshr = src.GetAdshrCurve(); dst->originalKey = src.GetOriginalKey(); dst->pan = src.GetPan(); dst->surroundPan = src.GetSurroundPan(); dst->volume = src.GetVolume(); return true; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw