1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     snd_FxReverb.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: $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 #ifndef NN_SND_FX_REVERB_H_
17 #define NN_SND_FX_REVERB_H_
18 
19 #ifdef __cplusplus
20 
21 namespace nn  { namespace snd { namespace CTR {
22 
23 //---------------------------------------------------------------------------
24 //
25 //
26 //
27 //
28 //
29 //
30 //
31 //
32 //
33 //
34 //
35 //---------------------------------------------------------------------------
36 class FxReverb
37 {
38 public:
39     //---------------------------------------------------------------------------
40     //
41     //
42     //
43     //
44     //
45     //
46     //
47     //
48     //
49     //
50     //
51     //
52     //
53     //
54     //
55     //
56     //
57     //
58     //
59     //
60     //
61     //
62     //
63     //
64     //
65     //
66     //
67     //
68     //---------------------------------------------------------------------------
69     struct FilterSize
70     {
71         u32  m_Comb0;    //
72         u32  m_Comb1;    //
73         u32  m_AllPass;  //
74 
75         //---------------------------------------------------------------------------
76         //
77         //
78         //
79         //---------------------------------------------------------------------------
FilterSizeFilterSize80         FilterSize()
81         : m_Comb0( 19 * NN_SND_SAMPLES_PER_FRAME ),
82           m_Comb1( 23 * NN_SND_SAMPLES_PER_FRAME ),
83           m_AllPass( 13 * NN_SND_SAMPLES_PER_FRAME )
84         {}
85     };
86 
87     //---------------------------------------------------------------------------
88     //
89     //
90     //
91     //
92     //
93     //
94     //
95     //
96     //
97     //
98     //
99     //
100     //
101     //
102     //
103     //
104     //
105     //
106     //
107     //
108     //
109     //
110     //
111     //
112     //
113     //
114     //
115     //
116     //
117     //
118     //
119     //
120     //
121     //
122     //
123     //
124     //
125     //
126     //
127     //
128     //
129     //
130     //
131     //
132     //
133     //
134     //
135     //
136     //
137     //
138     //
139     //
140     //
141     //
142     //
143     //
144     //
145     //
146     //
147     //
148     //
149     //
150     //
151     //
152     //
153     //
154     //
155     //
156     //
157     //
158     //---------------------------------------------------------------------------
159     struct Param
160     {
161         u32 m_EarlyReflectionTime;  //
162         u32 m_FusedTime;            //
163         u32 m_PreDelayTime;         //
164         f32 m_Coloration;           //
165         f32 m_Damping;              //
166 
167         //
168         FilterSize* m_pFilterSize;
169 
170         f32 m_EarlyGain;            //
171         f32 m_FusedGain;            //
172 
173         //---------------------------------------------------------------------------
174         //
175         //
176         //
177         //---------------------------------------------------------------------------
ParamParam178         Param()
179         : m_EarlyReflectionTime( 60 ),  // msec
180           m_FusedTime( 4000 ),          // msec
181           m_PreDelayTime( 100 ),        // msec
182           m_Coloration( 0.5f ),
183           m_Damping( 0.4f ),
184           m_pFilterSize( &s_DefaultFilterSize ),
185           m_EarlyGain( 0.6f ),
186           m_FusedGain( 0.4f )
187         {}
188     };
189 
190     //----------------------------------------
191     //
192     //
193     //---------------------------------------------------------------------------
194     //
195     //
196     //
197     //---------------------------------------------------------------------------
198     FxReverb();
199 
200     //---------------------------------------------------------------------------
201     //
202     //
203     //
204     //---------------------------------------------------------------------------
205     virtual ~FxReverb();
206     //
207 
208     //----------------------------------------------------------------
209     //
210     //----------------------------------------------------------------
211     //
212     //---------------------------------------------------------------------------
213     //
214     //
215     //
216     //
217     //
218     //
219     //
220     //
221     //
222     //
223     //
224     //
225     //
226     //
227     //
228     //
229     //
230     //
231     //
232     //
233     //
234     //
235     //
236     //
237     //
238     //
239     //
240     //
241     //
242     //
243     //
244     //
245     //
246     //
247     //
248     //
249     //
250     //
251     //---------------------------------------------------------------------------
252     bool SetParam( const Param& param );
253 
254     //---------------------------------------------------------------------------
255     //
256     //
257     //
258     //
259     //
260     //
261     //
262     //---------------------------------------------------------------------------
GetParam()263     const Param& GetParam() const
264     {
265         return m_Param;
266     }
267     //
268 
269     //----------------------------------------
270     //
271     //
272 
273     //---------------------------------------------------------------------------
274     //
275     //
276     //
277     //
278     //
279     //
280     //
281     //
282     //
283     //
284     //---------------------------------------------------------------------------
285     size_t GetRequiredMemSize();
286 
287     //---------------------------------------------------------------------------
288     //
289     //
290     //
291     //
292     //
293     //
294     //
295     //
296     //
297     //
298     //
299     //
300     //
301     //
302     //
303     //
304     //
305     //
306     //
307     //---------------------------------------------------------------------------
308     bool AssignWorkBuffer( uptr buffer, size_t size );
309 
310     //---------------------------------------------------------------------------
311     //
312     //
313     //
314     //
315     //
316     //
317     //
318     //
319     //
320     //
321     //---------------------------------------------------------------------------
322     void ReleaseWorkBuffer();
323     //
324 
325     /* Please see man pages for details */
326     bool Initialize();
327 
328     /* Please see man pages for details */
329     void Finalize();
330 
331     /* Please see man pages for details */
332     void UpdateBuffer( uptr data );
333 
334 private:
335     struct WorkBuffer
336     {
337         s32*  m_EarlyReflection[4]; // For initial reflection
338         s32*  m_PreDelay[4];        // For pre-delay
339         s32*  m_CombFilter[4][2];   // For comb filter (2 level)
340         s32*  m_AllPassFilter[4];   // For all-pass filter (1 level)
341         s32   m_Lpf[4];             // For LPF
342     };
343 
344     static FilterSize s_DefaultFilterSize;
345 
346     void AllocBuffer();
347     void FreeBuffer();
348 
349     void InitializeParam();
350 
351     Param           m_Param;
352     uptr            m_pBuffer;
353     size_t          m_BufferSize;
354     FilterSize      m_FilterSize;
355     WorkBuffer      m_WorkBuffer;
356 
357     s32  m_EarlyLength;
358     s32  m_EarlyPos;
359 
360     s32  m_PreDelayLength;
361     s32  m_PreDelayPos;
362 
363     s32  m_CombFilterLength[2];
364     s32  m_CombFilterPos[2];
365     s32  m_CombFilterCoef[2];
366 
367     s32  m_AllPassFilterLength;
368     s32  m_AllPassFilterPos;
369     s32  m_AllPassFilterCoef;
370 
371     s32  m_LastLpfOut[4];
372 
373 
374     // Changed so that the following arguments are calculated by the InitializeParam function
375     s32 m_EarlyGain;
376     s32 m_FusedGain;
377     s32 m_LpfCoef1;
378     s32 m_LpfCoef2;
379 
380     u32 m_EarlyReflectionTimeAtInitialize;
381     u32 m_PreDelayTimeAtInitialize;
382     FilterSize m_FilterSizeAtInitialize;
383 
384     bool m_IsActive;
385 
386     NN_PADDING3;
387 };
388 
389 }}} // namespace nn::snd::CTR
390 
391 #endif // __cplusplus
392 
393 #endif /* NN_SND_FX_REVERB_H_ */
394 
395