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