1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_AnimSoundFile.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_SND_ANIM_SOUND_FILE_H_ 19 #define NW_SND_ANIM_SOUND_FILE_H_ 20 21 #include <nn/types.h> 22 #include <nw/snd/snd_Util.h> 23 #include <nw/snd/snd_ElementType.h> 24 25 namespace nw { 26 namespace snd { 27 28 class SoundArchive; 29 30 namespace internal { 31 32 /* 33 アニメーションサウンドファイル (.bcasd) の構造 34 35 bcasd 36 | 37 +-- FileHeader 38 +-- DataBlock 39 | 40 +-- BinaryBlockHeader 41 +-- DataBlockBody 42 | 43 +-- u32 frameSize 44 +-- Reference toAnimEventTable 45 | 46 +--- ( &DataBlockBody + toAnimEventTable.offset ) --+ 47 | 48 +------------------------------------------------------------------+ 49 | 50 +--> AnimEventTable 51 | 52 +-- u32 count 53 +-- AnimEvent item[count] 54 | 55 +-- FrameInfo 56 | | 57 | +-- s32 startFrame 58 | +-- s32 endFrame 59 | +-- u8 frameFlag 60 | +-- s8 loopOffset 61 | +-- u8 loopInterval 62 | +-- u8 reserved 63 | 64 +-- Reference toEventInfo 65 | 66 +-- ( &item[...] + toEventInfo.offset ) --+ 67 | 68 +------------------------------------------------------------+ 69 | 70 +--> EventInfo 71 | 72 +-- u32 optionFlag 73 +-- u32 placeForSoundId 74 +-- Reference toSoundLabel 75 | | 76 | +-- ( &EventInfo + toSoundLabel.offset ) --+ 77 | | 78 | +---------------------------------------------+ 79 | | 80 | +--> const char* soundLabel 81 | 82 +-- u8 volume 83 +-- u8 playDirection 84 +-- u8 sequenceVariableNo 85 +-- u8 reserved1 86 +-- f32 pitch 87 +-- u32 reserved2 88 +-- u32 userParam 89 */ 90 91 92 struct AnimSoundFile 93 { 94 // 前方宣言 95 struct DataBlock; 96 struct AnimEvent; 97 struct AnimEventFrameInfo; 98 99 struct FileHeader : public Util::SoundFileHeader 100 { 101 const DataBlock* GetDataBlock() const; 102 }; 103 104 // フレーム情報。開始・終了位置やループについての情報を保持。 105 struct FrameInfo 106 { 107 // フレーム処理のオプションフラグ 108 enum FrameFlag 109 { 110 FRAME_FLAG_TRIGGER_EVENT = 0x01, // トリガタイプのイベント 111 FRAME_FLAG_END_FRAME_INF = 0x02, // 終了フレームが無限大 112 FRAME_FLAG_START_FRAME_INF = 0x04 // 開始フレームが負無限大 113 }; 114 115 // データ 116 nw::ut::ResS32 startFrame; // イベント開始フレーム 117 nw::ut::ResS32 endFrame; // イベント終了フレーム (* の場合は 0xffffffff) 118 nw::ut::ResU8 frameFlag; // 参照: AnimSoundImpl::FrameFlag 119 nw::ut::ResS8 loopOffset; // 再生ループ数 120 nw::ut::ResU8 loopInterval; // loopCount 以降で再生するループ間隔 121 u8 reserved; 122 }; 123 124 // イベント情報。どのサウンドを、どのようなピッチで鳴らすかなどの情報を保持。 125 struct EventInfo 126 { 127 // オプションフラグタイプ 128 enum OptionFlag 129 { 130 OPTION_FLAG_IS_NOT_STOP_SOUND_WHEN_ANIMATION_FINISH = (1<<0), 131 OPTION_FLAG_IS_ENABLE_SEQUENCE_VARIABLE = (1<<1) 132 }; 133 134 // 再生方向 135 enum PlayDirection 136 { 137 PLAY_DIRECTION_BOTH = 0, // 両方向 138 PLAY_DIRECTION_FORWARD = 1, // 順方向 139 PLAY_DIRECTION_BACKWARD = 2 // 逆方向 140 }; 141 142 // データ 143 nw::ut::ResU32 optionFlag; // 参照: OptionFlag 144 nw::ut::ResU32 placeForSoundId; // バイナリには SoundArchive::INVALID_ID 145 // (0xffffffff) が書かれるが、WriteSoundId にて 146 // 有効な値が書かれる。プレースホルダ。 147 Util::Reference toSoundLabel; 148 149 nw::ut::ResU8 volume; 150 nw::ut::ResU8 playDirection; // 参照: PlayDirection 151 nw::ut::ResU8 sequenceVariableNo; // 0-15:ローカル変数、16-31:グローバル変数 152 u8 reserved1; 153 154 nw::ut::ResF32 pitch; 155 nw::ut::ResU32 reserved2; 156 nw::ut::ResU32 userParam; 157 158 // アクセサ GetSoundLabelAnimSoundFile::EventInfo159 const char* GetSoundLabel() const 160 { 161 NW_ASSERT( toSoundLabel.typeId == 162 nw::snd::internal::ElementType_General_String ); 163 return reinterpret_cast<const char*>( 164 ut::AddOffsetToPtr( this, toSoundLabel.offset ) ); 165 } IsNotStopSoundWhenAnimationFinishAnimSoundFile::EventInfo166 bool IsNotStopSoundWhenAnimationFinish() const 167 { 168 if ( optionFlag & OPTION_FLAG_IS_NOT_STOP_SOUND_WHEN_ANIMATION_FINISH ) 169 { 170 return true; 171 } 172 else 173 { 174 return false; 175 } 176 } GetSequenceVariableAnimSoundFile::EventInfo177 bool GetSequenceVariable( u8* out ) const 178 { 179 if ( optionFlag & OPTION_FLAG_IS_ENABLE_SEQUENCE_VARIABLE ) 180 { 181 *out = sequenceVariableNo; 182 return true; 183 } 184 else 185 { 186 return false; 187 } 188 } 189 }; 190 191 // フレーム情報と、イベント情報 (への参照) をまとめたコンテナ 192 struct AnimEvent 193 { 194 FrameInfo frameInfo; // TODO: 将来的には Reference にしておいたほうが無難そう 195 Util::Reference toEventInfo; 196 GetEventInfoAnimSoundFile::AnimEvent197 const EventInfo* GetEventInfo() const 198 { 199 // シグニチャチェック 200 NW_ASSERT( toEventInfo.typeId == 201 nw::snd::internal::ElementType_AnimSoundFile_EventInfo ); 202 return reinterpret_cast<const EventInfo*>( 203 ut::AddOffsetToPtr( this, toEventInfo.offset ) ); 204 } 205 }; 206 207 typedef Util::Table<AnimEvent> AnimEventTable; 208 209 // DATA ブロックのボディ (ブロックヘッダーを抜いた部分) 210 struct DataBlockBody 211 { 212 nw::ut::ResU32 frameSize; // 総フレーム数 213 Util::Reference toAnimEventTable; // AnimEventTable へのオフセット 214 GetAnimEventTableAnimSoundFile::DataBlockBody215 const AnimEventTable* GetAnimEventTable() const 216 { 217 NW_ASSERT( toAnimEventTable.typeId == 218 nw::snd::internal::ElementType_Table_EmbeddingTable ); 219 return reinterpret_cast<const AnimEventTable*>( 220 ut::AddOffsetToPtr( this, toAnimEventTable.offset ) ); 221 } 222 }; 223 224 struct DataBlock 225 { 226 ut::BinaryBlockHeader header; 227 DataBlockBody body; 228 }; 229 }; 230 231 232 // void WriteSoundId( void* animSoundData, const SoundArchive& arc ); 233 234 235 } // namespace nw::snd::internal 236 } // namespace nw::snd 237 } // namespace nw 238 239 240 #endif /* NW_SND_ANIM_SOUND_FILE_H_ */ 241 242