1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     snd_FxReverb.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:$
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     //
160     //
161     //
162     //
163     //---------------------------------------------------------------------------
164     struct Param
165     {
166         u32 m_EarlyReflectionTime;  //
167         u32 m_FusedTime;            //
168         u32 m_PreDelayTime;         //
169         f32 m_Coloration;           //
170         f32 m_Damping;              //
171 
172         //
173         FilterSize* m_pFilterSize;
174 
175         f32 m_EarlyGain;            //
176         f32 m_FusedGain;            //
177 
178         bool m_UseHpfDamping;       //
179         NN_PADDING3;
180 
181         //---------------------------------------------------------------------------
182         //
183         //
184         //
185         //---------------------------------------------------------------------------
ParamParam186         Param()
187         : m_EarlyReflectionTime( 60 ),  // msec
188           m_FusedTime( 4000 ),          // msec
189           m_PreDelayTime( 100 ),        // msec
190           m_Coloration( 0.5f ),
191           m_Damping( 0.4f ),
192           m_pFilterSize( &s_DefaultFilterSize ),
193           m_EarlyGain( 0.6f ),
194           m_FusedGain( 0.4f ),
195           m_UseHpfDamping( false )
196         {}
197     };
198 
199     //----------------------------------------
200     //
201     //
202     //---------------------------------------------------------------------------
203     //
204     //
205     //
206     //---------------------------------------------------------------------------
207     FxReverb();
208 
209     //---------------------------------------------------------------------------
210     //
211     //
212     //
213     //---------------------------------------------------------------------------
214     virtual ~FxReverb();
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     //
253     //
254     //
255     //
256     //
257     //
258     //
259     //
260     //---------------------------------------------------------------------------
261     bool SetParam( const Param& param );
262 
263     //---------------------------------------------------------------------------
264     //
265     //
266     //
267     //
268     //
269     //
270     //
271     //---------------------------------------------------------------------------
GetParam()272     const Param& GetParam() const
273     {
274         return m_Param;
275     }
276     //
277 
278     //----------------------------------------
279     //
280     //
281 
282     //---------------------------------------------------------------------------
283     //
284     //
285     //
286     //
287     //
288     //
289     //
290     //
291     //
292     //
293     //---------------------------------------------------------------------------
294     size_t GetRequiredMemSize();
295 
296     //---------------------------------------------------------------------------
297     //
298     //
299     //
300     //
301     //
302     //
303     //
304     //
305     //
306     //
307     //
308     //
309     //
310     //
311     //
312     //
313     //
314     //
315     //
316     //---------------------------------------------------------------------------
317     bool AssignWorkBuffer( uptr buffer, size_t size );
318 
319     //---------------------------------------------------------------------------
320     //
321     //
322     //
323     //
324     //
325     //
326     //
327     //
328     //
329     //
330     //---------------------------------------------------------------------------
331     void ReleaseWorkBuffer();
332     //
333 
334     /* Please see man pages for details */
335     bool Initialize();
336 
337     /* Please see man pages for details */
338     void Finalize();
339 
340     /* Please see man pages for details */
341     void UpdateBuffer( uptr data );
342 
343 private:
344     struct WorkBuffer
345     {
346         s32*  m_EarlyReflection[4]; // For first reflection
347         s32*  m_PreDelay[4];        // For pre-delay
348         s32*  m_CombFilter[4][2];   // For comb filter (2-stage)
349         s32*  m_AllPassFilter[4];   // For all-pass filter (1-stage)
350         s32   m_Lpf[4];             // For LPF
351     };
352 
353     static FilterSize s_DefaultFilterSize;
354 
355     void AllocBuffer();
356     void FreeBuffer();
357 
358     void InitializeParam();
359 
360     Param           m_Param;
361     uptr            m_pBuffer;
362     size_t          m_BufferSize;
363     FilterSize      m_FilterSize;
364     WorkBuffer      m_WorkBuffer;
365 
366     s32  m_EarlyLength;
367     s32  m_EarlyPos;
368 
369     s32  m_PreDelayLength;
370     s32  m_PreDelayPos;
371 
372     s32  m_CombFilterLength[2];
373     s32  m_CombFilterPos[2];
374     s32  m_CombFilterCoef[2];
375 
376     s32  m_AllPassFilterLength;
377     s32  m_AllPassFilterPos;
378     s32  m_AllPassFilterCoef;
379 
380     s32  m_LastLpfOut[4];
381 
382 
383     // Parameters below changed as if calculated by the InitializeParam function
384     s32 m_EarlyGain;
385     s32 m_FusedGain;
386     s32 m_LpfCoef1;
387     s32 m_LpfCoef2;
388 
389     u32 m_EarlyReflectionTimeAtInitialize;
390     u32 m_PreDelayTimeAtInitialize;
391     FilterSize m_FilterSizeAtInitialize;
392 
393     bool m_IsActive;
394 
395     NN_PADDING3;
396 };
397 
398 }}} // namespace nn::snd::CTR
399 
400 #endif // __cplusplus
401 
402 #endif /* NN_SND_FX_REVERB_H_ */
403 
404