/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_WaveFile.h 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: 13145 $ *---------------------------------------------------------------------------*/ #ifndef NW_SND_WAVE_FILE_ #define NW_SND_WAVE_FILE_ #include #include #include // Util::Table #include // ut::BinaryFileHeader など #include // ResU32 など namespace nw { namespace snd { namespace internal { /* 波形ファイル (.bcwav) の構造 bcwav | +-- FileHeader +-- InfoBlock | | | +-- BinaryBlockHeader | +-- InfoBlockBody | | | +-- u8 encoding | +-- u8 isLoop | +-- u32 sampleRate | +-- u32 loopStart | +-- u32 loopEnd | +-- u32 reserved | +-- Table< reference to ChannelInfo > | | | +-- s32 count | +-- reference to ChannelInfo[0] ----------------+ | +-- reference to ChannelInfo[1] | | +-- ... (2ch までしかサポートしていない?!) | | | | +---------------------------------------------------------+ | | | +-> ChannelInfo | | | +-- reference to Samples (DataBlockBody を起点とするサンプルへのオフセット) | +-- reference to AdpcmInfo --+ | | | +---------------------------------+ | | | +-> AdpcmInfo | | | +-- DspAdpcmParam (snd_Global.h) | | | | | +-- u16 coef[16] | | +-- u16 predScale | | +-- u16 yn1 | | +-- u16 yn2 | | | +-- DspAdpcmLoopParam (snd_Global.h) | | | +-- u16 loopPredScale | +-- u16 loopYn1 | +-- u16 loopYn2 | +-- DataBlock | +-- BinaryBlockHeader +-- DataBlockBody (サンプルデータ) */ struct WaveFile { enum EncodeMethod { PCM8 = 0, PCM16, // バイトオーダーはプラットフォームに依存 DSP_ADPCM, IMA_ADPCM }; // // 前方宣言 // struct InfoBlock; struct ChannelInfo; struct DspAdpcmInfo; struct DataBlock; struct FileHeader : public Util::SoundFileHeader { const InfoBlock* GetInfoBlock() const; const DataBlock* GetDataBlock() const; }; struct InfoBlockBody { u8 encoding; // EncodeMethod が入る u8 isLoop; // 0: ループなし, 1: ループあり u16 padding; nw::ut::ResU32 sampleRate; // サンプリングレート nw::ut::ResU32 loopStartFrame; // ループ開始 (ループなしなら 0) nw::ut::ResU32 loopEndFrame; // ループ終端 (ループなしなら 0) nw::ut::ResU32 reserved; Util::ReferenceTable channelInfoReferenceTable; inline s32 GetChannelCount() const { return channelInfoReferenceTable.count; } const ChannelInfo& GetChannelInfo( s32 channelIndex ) const; }; struct InfoBlock { ut::BinaryBlockHeader header; InfoBlockBody body; }; struct ChannelInfo { Util::Reference referToSamples; // 起点は DATA ブロックボディ Util::Reference referToAdpcmInfo; nw::ut::ResU32 reserved; const void* GetSamplesAddress( const void* dataBlockBodyAddress ) const; const DspAdpcmInfo& GetDspAdpcmInfo() const; }; struct DspAdpcmInfo { DspAdpcmParam adpcmParam; DspAdpcmLoopParam adpcmLoopParam; }; struct DataBlock { ut::BinaryBlockHeader header; union { s8 pcm8[1]; s16 pcm16[1]; u8 byte[1]; }; }; }; // struct WaveFile } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw #endif /* NW_SND_WAVE_FILE_ */