1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_WaveSoundFile.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: 15989 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_SND_WAVE_SOUND_FILE_H_
17 #define NW_SND_WAVE_SOUND_FILE_H_
18 
19 #include <nw/ut/ut_BinaryFileFormat.h>
20 #include <nw/snd/snd_Util.h>
21 #include <nw/snd/snd_Global.h>
22 #include <nw/snd/snd_CurveAdshr.h>
23 
24 namespace nw {
25 namespace snd {
26 namespace internal {
27 
28 /*
29     ウェーブサウンドファイル (.bcwsd) の構造
30 
31     「ウェーブサウンド」ファイルと呼んでいるが、実際には、
32     「ウェーブサウンドセット」1つ分を格納するファイルとなっている。
33 
34     bcwsd
35      |
36      +-- FileHeader
37      +-- InfoBlock
38           |
39           +-- ut::BinaryBlockHeader
40           +-- InfoBlockBody
41                |
42                +-- Table<ref to WaveSoundData>
43                     |
44                     +-- u32 count
45                     +-- ref to WaveSoundData[0] --+ ← このインデックスが、ウェー
46                     +-- ref to WaveSoundData[1]   |    ブサウンドセット内でのイン
47                     +-- ...                       |    デックスに相当する。
48      +--------------------------------------------+
49      |
50      +-> WaveSoundData
51           |
52           +-- ref to WaveSoundInfo
53           |    |
54           |    +--> RawWaveSoundInfo
55           |          |
56           |          +-- optionParameter (パン、ピッチ、センド量、ADSR)
57           |
58           +-- ref to TrackInfoTable  <-- 各トラックの楽譜情報が入る
59           |    |
60           |    +--> Table<ref to TrackInfo>
61           |          |
62           |          +-- u32 count
63           |          +-- ref to TrackInfo[0] --+
64           |          +-- ref to TrackInfo[1]   |
65           |          +-- ...                   |
66           |    +-------------------------------+
67           |    |
68           |    +--> TrackInfo
69           |          |
70           |          +-- ref to Table<ref to NoteEvent>
71           |               |
72           |               +--> Table<ref to NoteEvent>
73           |                     |
74           |                     +-- u32 count
75           |                     +-- ref to NoteEvent[0] --+
76           |                     +-- ref to NoteEvent[1]   |
77           |                     +-- ...                   |
78           |   +-------------------------------------------+
79           |   |
80           |   +--> NoteEvent
81           |         |
82           |         +-- position
83           |         +-- length
84           |         +-- noteIndex    <-- NoteInfoTable のノートのインデックス
85           |         +-- reserved
86           |
87           +-- ref to NoteInfoTable   <-- トラックで使われる全ノートの
88                |                               情報が入る
89                +--> Table<ref to NoteInfo>
90                      |
91                      +-- u32 count
92                      +-- ref to NoteInfo[0] --+
93                      +-- ref to NoteInfo[1]   |
94                      +-- ...                     |
95               +----------------------------------+
96               |
97               +--> NoteInfo
98                     |
99                     +-- waveArchiveId
100                     +-- waveIndex
101                     +-- optionParameter
102                          |
103                          +-- originalKey
104                          +-- volume
105                          +-- pan
106                          +-- (surroundPan)
107                          +-- pitch
108                          +-- sendValue
109                          +-- adshrCurve
110 
111 */
112 
113 struct WaveSoundFile
114 {
115     //
116     // ヘッダー
117     //
118     struct InfoBlock;
119     struct FileHeader : public Util::SoundFileHeader
120     {
121         // アクセサ
122         const InfoBlock* GetInfoBlock() const;
123     };
124 
125     //
126     // INFO ブロック
127     //
128 
129     struct WaveSoundData;
130 
131     struct InfoBlockBody
132     {
133         // データ
134         Util::Reference toWaveIdTable;
135         Util::Reference toWaveSoundDataReferenceTable;
136 
137         // アクセサ
138         // (テーブル取得)
139         const Util::WaveIdTable& GetWaveIdTable() const;
140         const Util::ReferenceTable& GetWaveSoundDataReferenceTable() const;
141 
142         // (テーブルアイテム数取得)
GetWaveIdCountWaveSoundFile::InfoBlockBody143         NW_INLINE u32 GetWaveIdCount() const
144         {
145             return GetWaveIdTable().GetCount();
146         }
GetWaveSoundCountWaveSoundFile::InfoBlockBody147         NW_INLINE u32 GetWaveSoundCount() const
148         {
149             return GetWaveSoundDataReferenceTable().count;
150         }
151 
152         // (テーブルアイテム取得)
GetWaveIdWaveSoundFile::InfoBlockBody153         NW_INLINE const Util::WaveId& GetWaveId( u32 index ) const
154         {
155             return GetWaveIdTable().GetWaveId( index );
156         }
157         const WaveSoundData& GetWaveSoundData( u32 index ) const;
158     };
159 
160     struct InfoBlock
161     {
162         ut::BinaryBlockHeader   header;
163         InfoBlockBody           body;
164     };
165 
166 
167     struct WaveSoundInfo;
168     struct TrackInfo;
169     struct NoteInfo;
170 
171     // ウェーブサウンド 1 つ分のデータ
172     struct WaveSoundData
173     {
174         // データ
175         Util::Reference toWaveSoundInfo;
176         Util::Reference toTrackInfoReferenceTable;
177         Util::Reference toNoteInfoReferenceTable;
178 
179         // アクセサ
180         const WaveSoundInfo& GetWaveSoundInfo() const;
181 
182         // (テーブル取得)
183         const Util::ReferenceTable& GetTrackInfoReferenceTable() const;
184         const Util::ReferenceTable& GetNoteInfoReferenceTable() const;
185 
186         // (テーブルアイテム数取得)
GetTrackCountWaveSoundFile::WaveSoundData187         NW_INLINE u32 GetTrackCount() const
188         {
189             return GetTrackInfoReferenceTable().count;
190         }
GetNoteCountWaveSoundFile::WaveSoundData191         NW_INLINE u32 GetNoteCount() const
192         {
193             return GetNoteInfoReferenceTable().count;
194         }
195 
196         // (テーブルアイテム取得)
197         const TrackInfo& GetTrackInfo( u32 index ) const;
198         const NoteInfo& GetNoteInfo( u32 index ) const;
199     };
200 
201     struct WaveSoundInfo
202     {
203         // データ
204         Util::BitFlag optionParameter;
205 
206         // アクセサ
207         u8 GetPan() const;
208         s8 GetSurroundPan() const;
209         f32 GetPitch() const;
210         void GetSendValue( u8* mainSend, u8* fxSend, u8 fxSendCount ) const;
211         const AdshrCurve& GetAdshrCurve() const;
212     };
213 
214     struct NoteEvent;
215 
216     struct TrackInfo
217     {
218         // データ
219         Util::Reference toNoteEventReferenceTable;
220 
221         // アクセサ
222         // (テーブル取得)
223         const Util::ReferenceTable& GetNoteEventReferenceTable() const;
224 
225         // (テーブルアイテム数取得)
GetNoteEventCountWaveSoundFile::TrackInfo226         NW_INLINE u32 GetNoteEventCount() const
227         {
228             return GetNoteEventReferenceTable().count;
229         }
230 
231         // (テーブルアイテム取得)
232         const NoteEvent& GetNoteEvent( u32 index ) const;
233     };
234 
235     struct NoteEvent
236     {
237         ut::ResF32  position;
238         ut::ResF32  length;
239         ut::ResU32  noteIndex;
240         ut::ResU32  reserved;
241     };
242 
243     struct NoteInfo
244     {
245         // データ
246         ut::ResU32  waveIdTableIndex;
247         Util::BitFlag optionParameter;
248 
249         // アクセサ
250         u8 GetOriginalKey() const;
251         u8 GetVolume() const;
252         u8 GetPan() const;
253         u8 GetSurroundPan() const;
254         f32 GetPitch() const;
255         void GetSendValue( u8* mainSend, u8* fxSend[], u8 fxSendCount ) const;
256         const AdshrCurve& GetAdshrCurve() const;
257     };
258 };
259 
260 } // namespace nw::snd::internal
261 } // namespace nw::snd
262 } // namespace nw
263 
264 #endif /* NW_SND_WAVE_SOUND_FILE_H_ */
265 
266