1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     snd_Bcwav.h
4   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law. They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10   $Rev: 25790 $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 #ifndef NN_SND_BCWAV_H_
16 #define NN_SND_BCWAV_H_
17 
18 #include <nn/snd/CTR/Common/snd_Adpcm.h>
19 
20 /* Please see man pages for details
21 
22 */
23 
24 #ifdef __cplusplus
25 
26 namespace nn { namespace snd { namespace CTR {
27 
28 /* Please see man pages for details
29 
30  */
31 class Bcwav {
32 private:
Bcwav()33     Bcwav() {}
~Bcwav()34     ~Bcwav() {}
35 
36 public:
37     // --- Basic types ---
38     struct Reference
39     {
40         u16 typeId;     // Non-public to users
41         u16 padding;
42         u32 offset;
43     };
44 
45     struct ReferenceWithSize : public Reference
46     {
47         u32 size;
48     };
49 
50     template< typename ITEM_TYPE >
51     struct Table
52     {
53         u32 count;
54         ITEM_TYPE item[1];
55     };
56 
57     // --- File data structure ---
58     struct FileHeader
59     {
60         u32 signature;          // Always 'CWAV'
61         u16 byteOrderMark;
62         u16 headerSize;
63         u32 version;
64         u32 fileSize;
65         u16 dataBlocks;
66         u16 reserved;
67     };
68 
69     struct BlockInfo
70     {
71         ReferenceWithSize infoBlockReference;
72         ReferenceWithSize dataBlockReference;
73     };
74 
75     struct FileInfo
76     {
77         FileHeader header;
78         BlockInfo  blockInfo;
79     };
80 
81     // --- Block data structure ---
82     struct BlockHeader
83     {
84         u32 kind;       // 'INFO' or 'DATA'
85         u32 size;
86     };
87 
88     /* Please see man pages for details
89 
90      */
91     struct WaveInfo
92     {
93         u8  encoding;           //
94         u8  isLoop;             //
95         u16 padding;
96         u32 sampleRate;         //
97         u32 loopStartFrame;     //
98         u32 loopEndFrame;       //
99     };
100 
101     struct InfoBlockBody
102     {
103         WaveInfo waveInfo;
104         u32 reserved;
105         Table<Reference> channelInfoReferenceTable;
106     };
107 
108     struct ChannelInfo
109     {
110         Reference toSamples;    // Origin is data block body (after BlockHeader)
111         Reference toAdpcmInfo;
112         u32 reserved;
113     };
114 
115     /* Please see man pages for details
116 
117      */
118     struct DspAdpcmInfo
119     {
120         AdpcmParam     param;          //
121         AdpcmContext   context;        //
122         AdpcmContext   loopContext;    //
123     };
124 
125     /* Please see man pages for details
126 
127 
128      */
129     struct ImaAdpcmContext
130     {
131         s16 data;
132         u8  tableIndex;
133         u8  padding;
134     };
135 
136     /* Please see man pages for details
137 
138 
139      */
140     struct ImaAdpcmInfo
141     {
142         ImaAdpcmContext   context;        //
143         ImaAdpcmContext   loopContext;    //
144     };
145 
146     struct InfoBlock
147     {
148         BlockHeader header;
149         InfoBlockBody body;
150     };
151 
152     /* Please see man pages for details
153 
154      */
155     typedef enum
156     {
157         ENCODING_PCM8      = 0,    //
158         ENCODING_PCM16     = 1,    //
159         ENCODING_DSP_ADPCM = 2,    //
160         ENCODING_IMA_ADPCM = 3,    //
161         ENCODING_NUM       = 4
162     } Encoding;
163 
164     /* Please see man pages for details
165 
166      */
167     typedef enum
168     {
169         CHANNEL_INDEX_L = 0,       //
170         CHANNEL_INDEX_R = 1        //
171     } ChannelIndex;
172 
173     /* Please see man pages for details
174 
175 
176      */
177     /* Please see man pages for details
178 
179 
180 
181      */
182     static const WaveInfo& GetWaveInfo(const void* bcwav);
183 
184     /* Please see man pages for details
185 
186 
187 
188      */
189     static int GetChannelCount(const void* bcwav);
190 
191     /* Please see man pages for details
192 
193 
194 
195 
196      */
197     static const void* GetWave(const void* bcwav, int channelNo);
198 
199     /* Please see man pages for details
200 
201 
202 
203 
204      */
205     static const DspAdpcmInfo* GetDspAdpcmInfo(const void* bcwav, int channelNo);
206 
207     /* Please see man pages for details
208 
209 
210 
211 
212 
213      */
214     static const ImaAdpcmContext* GetImaAdpcmContext(const void* bcwav, int channelNo);
215 
216     /* Please see man pages for details
217 
218 
219 
220 
221 
222      */
223     static const ImaAdpcmContext* GetImaAdpcmLoopContext(const void* bcwav, int channelNo);
224 
225     /* Please see man pages for details
226 
227 
228 
229 
230      */
231     static u32 FrameToByte(u8 encoding, u32 frame);
232 
233     /* Please see man pages for details
234 
235 
236 
237 
238      */
239     static const void* AddOffsetToPtr(const void* ptr, int offset);
240 
241     /* Please see man pages for details
242 
243 
244 
245      */
246     static bool IsBcwav(const void* bcwav);
247 
248     /*
249 
250 */
251 };
252 
253 }}} // namespace nn::snd::CTR
254 
255 #endif // __cplusplus
256 
257 typedef enum
258 {
259     NN_SND_BCWAV_ENCODING_PCM8      = 0,    //
260     NN_SND_BCWAV_ENCODING_PCM16     = 1,    //
261     NN_SND_BCWAV_ENCODING_DSP_ADPCM = 2,    //
262     NN_SND_BCWAV_ENCODING_IMA_ADPCM = 3,    //
263     NN_SND_BCWAV_ENCODING_NUM       = 4
264 } nnsndBcwavEncoding;
265 
266 typedef enum
267 {
268     NN_SND_BCWAV_CHANNEL_INDEX_L = 0,       //
269     NN_SND_BCWAV_CHANNEL_INDEX_R = 1        //
270 } nnsndBcwavChannelIndex;
271 
272 #endif /* NN_SND_BCWAV_H_ */
273 
274