/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_BankFileReader.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 = 0x01000100; bool IsValidFileHeader( const void* bankFile ) { const ut::BinaryFileHeader* header = reinterpret_cast( bankFile ); // シグニチャ確認 NW_ASSERTMSG( header->signature == BankFileReader::SIGNATURE_FILE, "invalid file signature. bank file is not available." ); if ( header->signature != BankFileReader::SIGNATURE_FILE ) return false; // バージョン確認 NW_ASSERTMSG( header->version >= SUPPORTED_FILE_VERSION, "bank 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, "bank 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 BankFileReader::BankFileReader( const void* bankFile ) : m_pHeader( NULL ), m_pInfoBlockBody( NULL ) { NW_NULL_ASSERT( bankFile ); if ( ! IsValidFileHeader( bankFile ) ) return; m_pHeader = reinterpret_cast( bankFile ); const BankFile::InfoBlock* infoBlock = m_pHeader->GetInfoBlock(); NW_NULL_ASSERT( infoBlock ); NW_ASSERT( infoBlock->header.kind == SIGNATURE_INFO_BLOCK ); m_pInfoBlockBody = &infoBlock->body; } bool BankFileReader::ReadVelocityRegionInfo( VelocityRegionInfo* info, int programNo, int key, int velocity ) const { // イレギュラーな programNo を指定された場合 if ( programNo < 0 || programNo >= m_pInfoBlockBody->GetInstrumentCount() ) { return false; } // ベロシティリージョンを取得 const BankFile::Instrument* instrument = m_pInfoBlockBody->GetInstrument( programNo ); if ( instrument == NULL ) { return false; } const BankFile::KeyRegion* keyRegion = instrument->GetKeyRegion( key ); if ( keyRegion == NULL ) { return false; } const BankFile::VelocityRegion* velocityRegion = keyRegion->GetVelocityRegion( velocity ); if ( velocityRegion == NULL ) { return false; } // 波形アーカイブ ID / 波形アーカイブ内インデックスを取得 NW_ASSERT( velocityRegion->waveIdTableIndex < m_pInfoBlockBody->GetWaveIdCount() ); const Util::WaveId* pWaveId = m_pInfoBlockBody->GetWaveId( velocityRegion->waveIdTableIndex ); if ( pWaveId == NULL ) { return false; } if ( pWaveId->waveIndex == 0xffffffff ) // 当該リージョンに波形ファイルが割り当たっていない { NW_WARNING( false, "This region [programNo(%d) key(%d) velocity(%d)] is not assigned wave file.", programNo, key, velocity ); return false; } // info への書き込み info->waveArchiveId = pWaveId->waveArchiveId; info->waveIndex = pWaveId->waveIndex; const BankFile::RegionParameter* regionParameter = velocityRegion->GetRegionParameter(); if ( regionParameter == NULL ) { info->originalKey = velocityRegion->GetOriginalKey(); info->volume = velocityRegion->GetVolume(); info->pan = velocityRegion->GetPan(); #ifdef NW_PLATFORM_RVL info->surroundPan = velocityRegion->GetSurroundPan(); #endif /* NW_PLATFORM_RVL */ info->pitch = velocityRegion->GetPitch(); info->isIgnoreNoteOff = velocityRegion->IsIgnoreNoteOff(); info->keyGroup = velocityRegion->GetKeyGroup(); info->interpolationType = velocityRegion->GetInterpolationType(); info->adshrCurve = velocityRegion->GetAdshrCurve(); } else { info->originalKey = regionParameter->originalKey; info->volume = regionParameter->volume; info->pan = regionParameter->pan; #ifdef NW_PLATFORM_RVL info->surroundPan = regionParameter->surroundPan; #endif /* NW_PLATFORM_RVL */ info->pitch = regionParameter->pitch; info->isIgnoreNoteOff = regionParameter->isIgnoreNoteOff; info->keyGroup = regionParameter->keyGroup; info->interpolationType = regionParameter->interpolationType; info->adshrCurve = regionParameter->adshrCurve; } return true; } const Util::WaveIdTable& BankFileReader::GetWaveIdTable() const { return m_pInfoBlockBody->GetWaveIdTable(); } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw