1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_WaveFile.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 13145 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_SND_WAVE_FILE_ 17 #define NW_SND_WAVE_FILE_ 18 19 #include <nn/types.h> 20 21 #include <nw/snd/snd_Global.h> 22 #include <nw/snd/snd_Util.h> // Util::Table 23 #include <nw/ut/ut_BinaryFileFormat.h> // ut::BinaryFileHeader など 24 #include <nw/ut/ut_BinaryReader.h> // ResU32 など 25 26 namespace nw { 27 namespace snd { 28 namespace internal { 29 30 /* 31 波形ファイル (.bcwav) の構造 32 33 bcwav 34 | 35 +-- FileHeader 36 +-- InfoBlock 37 | | 38 | +-- BinaryBlockHeader 39 | +-- InfoBlockBody 40 | | 41 | +-- u8 encoding 42 | +-- u8 isLoop 43 | +-- u32 sampleRate 44 | +-- u32 loopStart 45 | +-- u32 loopEnd 46 | +-- u32 reserved 47 | +-- Table< reference to ChannelInfo > 48 | | 49 | +-- s32 count 50 | +-- reference to ChannelInfo[0] ----------------+ 51 | +-- reference to ChannelInfo[1] | 52 | +-- ... (2ch までしかサポートしていない?!) | 53 | | 54 | +---------------------------------------------------------+ 55 | | 56 | +-> ChannelInfo 57 | | 58 | +-- reference to Samples (DataBlockBody を起点とするサンプルへのオフセット) 59 | +-- reference to AdpcmInfo --+ 60 | | 61 | +---------------------------------+ 62 | | 63 | +-> AdpcmInfo 64 | | 65 | +-- DspAdpcmParam (snd_Global.h) 66 | | | 67 | | +-- u16 coef[16] 68 | | +-- u16 predScale 69 | | +-- u16 yn1 70 | | +-- u16 yn2 71 | | 72 | +-- DspAdpcmLoopParam (snd_Global.h) 73 | | 74 | +-- u16 loopPredScale 75 | +-- u16 loopYn1 76 | +-- u16 loopYn2 77 | 78 +-- DataBlock 79 | 80 +-- BinaryBlockHeader 81 +-- DataBlockBody (サンプルデータ) 82 */ 83 84 struct WaveFile 85 { 86 enum EncodeMethod 87 { 88 PCM8 = 0, 89 PCM16, // バイトオーダーはプラットフォームに依存 90 DSP_ADPCM, 91 IMA_ADPCM 92 }; 93 94 // 95 // 前方宣言 96 // 97 struct InfoBlock; 98 struct ChannelInfo; 99 struct DspAdpcmInfo; 100 struct DataBlock; 101 102 struct FileHeader : public Util::SoundFileHeader 103 { 104 const InfoBlock* GetInfoBlock() const; 105 const DataBlock* GetDataBlock() const; 106 }; 107 108 struct InfoBlockBody 109 { 110 u8 encoding; // EncodeMethod が入る 111 u8 isLoop; // 0: ループなし, 1: ループあり 112 u16 padding; 113 nw::ut::ResU32 sampleRate; // サンプリングレート 114 nw::ut::ResU32 loopStartFrame; // ループ開始 (ループなしなら 0) 115 nw::ut::ResU32 loopEndFrame; // ループ終端 (ループなしなら 0) 116 nw::ut::ResU32 reserved; 117 Util::ReferenceTable channelInfoReferenceTable; 118 GetChannelCountWaveFile::InfoBlockBody119 inline s32 GetChannelCount() const { return channelInfoReferenceTable.count; } 120 const ChannelInfo& GetChannelInfo( s32 channelIndex ) const; 121 }; 122 123 struct InfoBlock 124 { 125 ut::BinaryBlockHeader header; 126 InfoBlockBody body; 127 }; 128 129 struct ChannelInfo 130 { 131 Util::Reference referToSamples; // 起点は DATA ブロックボディ 132 Util::Reference referToAdpcmInfo; 133 nw::ut::ResU32 reserved; 134 135 const void* GetSamplesAddress( const void* dataBlockBodyAddress ) const; 136 const DspAdpcmInfo& GetDspAdpcmInfo() const; 137 }; 138 139 struct DspAdpcmInfo 140 { 141 DspAdpcmParam adpcmParam; 142 DspAdpcmLoopParam adpcmLoopParam; 143 }; 144 145 struct DataBlock 146 { 147 ut::BinaryBlockHeader header; 148 union 149 { 150 s8 pcm8[1]; 151 s16 pcm16[1]; 152 u8 byte[1]; 153 }; 154 }; 155 }; // struct WaveFile 156 157 } // namespace nw::snd::internal 158 } // namespace nw::snd 159 } // namespace nw 160 161 #endif /* NW_SND_WAVE_FILE_ */ 162