/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_StreamSoundFileReader.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: 19484 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include // EncodeMethod namespace nw { namespace snd { namespace internal { namespace { const u32 SIGNATURE_FILE = NW_UT_MAKE_SIGWORD( 'C', 'S', 'T', 'M' ); const u32 SIGNATURE_INFO_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'O' ); const u32 SIGNATURE_SEEK_BLOCK = NW_UT_MAKE_SIGWORD( 'S', 'E', 'E', 'K' ); const u32 SIGNATURE_DATA_BLOCK = NW_UT_MAKE_SIGWORD( 'D', 'A', 'T', 'A' ); const int SUPPORTED_FILE_VERSION = 0x02000000; const int CURRENT_FILE_VERSION = 0x02000000; } // anonymous namespace StreamSoundFileReader::StreamSoundFileReader() : m_pHeader( NULL ), m_pInfoBlockBody( NULL ) { } void StreamSoundFileReader::Initialize( const void* streamSoundFile ) { NW_NULL_ASSERT( streamSoundFile ); if ( ! IsValidFileHeader( streamSoundFile ) ) return; m_pHeader = reinterpret_cast( streamSoundFile ); const StreamSoundFile::InfoBlock* infoBlock = m_pHeader->GetInfoBlock(); NW_ASSERT( infoBlock->header.kind == SIGNATURE_INFO_BLOCK ); m_pInfoBlockBody = &infoBlock->body; NW_ASSERT( m_pInfoBlockBody->GetStreamSoundInfo()->oneBlockBytes % 32 == 0 ); } void StreamSoundFileReader::Finalize() { m_pHeader = NULL; m_pInfoBlockBody = NULL; } bool StreamSoundFileReader::ReadStreamSoundInfo( StreamSoundFile::StreamSoundInfo* strmInfo ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); const StreamSoundFile::StreamSoundInfo* info = m_pInfoBlockBody->GetStreamSoundInfo(); NW_ALIGN32_ASSERT( info->oneBlockBytes ); NW_ALIGN32_ASSERT( info->lastBlockPaddedBytes ); // struct copy *strmInfo = *info; return true; } bool StreamSoundFileReader::ReadStreamTrackInfo( TrackInfo* pTrackInfo, int trackIndex ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); NW_NULL_ASSERT( pTrackInfo ); const StreamSoundFile::TrackInfoTable* table = m_pInfoBlockBody->GetTrackInfoTable(); if ( trackIndex >= static_cast( table->GetTrackCount() ) ) { return false; } const StreamSoundFile::TrackInfo* src = table->GetTrackInfo( trackIndex ); pTrackInfo->volume = src->volume; pTrackInfo->pan = src->pan; pTrackInfo->channelCount = static_cast( src->GetTrackChannelCount() ); // TODO: バイナリデータも 1 バイトでいいかも (NW4C-0.1.0) u32 count = ut::Min( static_cast( pTrackInfo->channelCount ), WAVE_CHANNEL_MAX ); for ( u32 i = 0; i < count; i++ ) { pTrackInfo->globalChannelIndex[ i ] = src->GetGlobalChannelIndex( i ); } return true; } bool StreamSoundFileReader::ReadDspAdpcmChannelInfo( DspAdpcmParam* pParam, DspAdpcmLoopParam* pLoopParam, int channelIndex ) const { NW_NULL_ASSERT( m_pInfoBlockBody ); NW_NULL_ASSERT( pParam ); NW_NULL_ASSERT( pLoopParam ); const StreamSoundFile::DspAdpcmChannelInfo* src = m_pInfoBlockBody-> GetChannelInfoTable()-> GetChannelInfo( channelIndex )-> GetDspAdpcmChannelInfo(); if ( src == NULL ) return false; *pParam = src->param; *pLoopParam = src->loopParam; return true; } bool StreamSoundFileReader::IsValidFileHeader( const void* streamSoundFile ) const { NW_NULL_ASSERT( streamSoundFile ); const ut::BinaryFileHeader& header = *reinterpret_cast( streamSoundFile ); // シグニチャ確認 NW_ASSERTMSG( header.signature == SIGNATURE_FILE, "invalid file signature. stream data is not available." ); if ( header.signature != SIGNATURE_FILE ) return false; // バージョン確認 NW_ASSERTMSG( header.version >= SUPPORTED_FILE_VERSION, "stream 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, "stream 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; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw