1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_Sound3DListener.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: $
16  *---------------------------------------------------------------------------*/
17 
18 /**
19  * :include nw/snd/snd_Sound3DListener.h
20  *
21  * @file snd_Sound3DListener.h
22  */
23 
24 #ifndef NW_SND_SOUND_3D_LISTENER_H_
25 #define NW_SND_SOUND_3D_LISTENER_H_
26 
27 #include <nw/math/math_Types.h>     // nw::math::MTX34, VEC3
28 #include <nw/ut/ut_LinkList.h>
29 
30 namespace nw {
31 namespace snd {
32 
33 //---------------------------------------------------------------------------
34 //! @brief    3D 空間内でのリスニングポイントを表す 3D サウンドリスナークラスです。
35 //!
36 //!           リスナーは @ref Sound3DManager クラスに登録して使用します。
37 //!           リスナーに設定されたリスナー行列の情報を用いて、
38 //!           サウンドのパラメータを計算して設定します。
39 //!
40 //! @see Sound3DManager クラス
41 //! @see Sound3DManager::AddListener
42 //!
43 //! @date 2010/03/12 初版
44 //---------------------------------------------------------------------------
45 class Sound3DListener
46 {
47 public:
48     //! @name コンストラクタ
49     //@{
50     //---------------------------------------------------------------------------
51     //! @brief    コンストラクタです。
52     //!
53     //!           インテリアサイズ、最大音量範囲、減衰単位距離はそれぞれ
54     //!           1.0 で初期化されます。
55     //!
56     //! @date 2010/03/12 初版
57     //---------------------------------------------------------------------------
58     Sound3DListener();
59     //@}
60 
61     //! @name リスナー行列
62     //@{
63     //---------------------------------------------------------------------------
64     //! @brief    リスナー行列を設定します。
65     //!
66     //!           3D リスナーのリスナー行列を設定します。
67     //!           設定された行列は、3D サウンドのパラメータ計算で使用されます。
68     //!
69     //!           新しくリスナー行列を設定した際、前回設定されたリスナー行列との差分を計算し、
70     //!           リスナーの速度が自動的に設定されます。
71     //!           リスナーの速度は、ドップラー効果による音程変化に反映されます。
72     //!           速度は @ref SetVelocity で明示的に設定することも可能です。
73     //!
74     //!           座標が別の位置に飛んだ場合、飛んだ距離の差分で速度が計算されてしまうため、
75     //!           極めて高速で移動したように処理され、急激な音程変化が発生します。
76     //!           このような場合、この関数を呼び出した後で、
77     //!           @ref SetVelocity を呼び出し、
78     //!           速度を明示的に設定する必要があることに注意してください。
79     //!
80     //! @param[in] mtx    リスナー行列です。
81     //!
82     //! @see GetMatrix
83     //! @see SetVelocity
84     //! @see nw::math::MTX34 構造体
85     //!
86     //! @date 2010/03/12 初版
87     //---------------------------------------------------------------------------
88     void SetMatrix( const nw::math::MTX34& mtx );
89 
90     //---------------------------------------------------------------------------
91     //! @brief    現在設定されているリスナー行列を取得します。
92     //!
93     //! @return   現在設定されているリスナー行列を返します。
94     //!
95     //! @see SetMatrix
96     //! @see nw::math::MTX34 構造体
97     //!
98     //! @date 2010/03/12 初版
99     //---------------------------------------------------------------------------
GetMatrix()100     const nw::math::MTX34& GetMatrix() const { return m_Mtx; }
101 
102     //---------------------------------------------------------------------------
103     //! @brief    リスナー行列をリセットします。
104     //!
105     //!           3D サウンドリスナーのリスナー行列と速度をゼロクリアします。
106     //!
107     //!           この関数でリセットした直後の @ref SetMatrix の呼び出しでは、
108     //!           3D サウンドリスナーの速度は設定されません。
109     //!
110     //! @see SetMatrix
111     //! @see SetVelocity
112     //!
113     //! @date 2010/03/12 初版
114     //---------------------------------------------------------------------------
115     void ResetMatrix();
116 
117     //---------------------------------------------------------------------------
118     //! @brief    設定されているリスナーの位置情報を取得します。
119     //!
120     //!           この情報は、@ref SetMatrix で設定されたリスナー行列を元に計算されます。
121     //!
122     //! @return   現在設定されているリスナーの位置情報を返します。
123     //!
124     //! @see SetMatrix
125     //! @see nw::math::VEC3 構造体
126     //!
127     //! @date 2010/03/12 初版
128     //---------------------------------------------------------------------------
GetPosition()129     const nw::math::VEC3& GetPosition() const { return m_Position; }
130 
131     //---------------------------------------------------------------------------
132     //! @brief    リスナーの速度を設定します。
133     //!
134     //!           設定された速度は、ドップラー効果による音程変化に反映されます。
135     //!
136     //!           3D サウンドリスナーの速度は @ref SetMatrix で座標を設定した際、
137     //!           前回の登録座標との差分から自動的に設定されますが、
138     //!           この関数を使用すると 3D サウンドリスナーの速度を手動で設定することができます。
139     //!
140     //! @param[in] velocity   リスナーの速度です。
141     //!
142     //! @see GetVelocity
143     //! @see SetMatrix
144     //! @see nw::math::VEC3 構造体
145     //!
146     //! @date 2010/03/12 初版
147     //---------------------------------------------------------------------------
148     void SetVelocity( const nw::math::VEC3& velocity );
149 
150     //---------------------------------------------------------------------------
151     //! @brief    設定されているリスナーの速度を取得します。
152     //!
153     //!           通常、@ref SetMatrix で座標を設定した際、
154     //!           前回の登録座標との差分から自動的に設定されますが、
155     //!           @ref SetVelocity を使用して手動で設定することも可能です。
156     //!
157     //! @return   現在設定されているリスナーの速度を返します。
158     //!
159     //! @see SetVelocity
160     //! @see SetMatrix
161     //! @see nw::math::VEC3 構造体
162     //!
163     //! @date 2010/03/12 初版
164     //---------------------------------------------------------------------------
GetVelocity()165     const nw::math::VEC3& GetVelocity() const { return m_Velocity; }
166     //@}
167 
168     //! @name パラメータ
169     //@{
170     //---------------------------------------------------------------------------
171     //! @brief    インテリアサイズを設定します。
172     //!
173     //!           インテリアサイズとは、パンが変化するエリアの大きさで、
174     //!           リスナーからの距離(半径)で設定します。
175     //!           インテリアサイズを大きくすると、パン変化が緩やかになります。
176     //!           逆にインテリアサイズを小さくすると、パン変化が急になります。
177     //!
178     //!           リスナーからの距離が離れると音量は減衰していきますが、
179     //!           減衰量は最大音量範囲の設定 (@ref SetMaxVolumeDistance で設定します)
180     //!           に依存します。
181     //!
182     //! @param[in] interiorSize   インテリアサイズです。
183     //!
184     //! @see GetInteriorSize
185     //! @see SetMaxVolumeDistance
186     //!
187     //! @date 2010/03/12 初版
188     //---------------------------------------------------------------------------
189     void SetInteriorSize( f32 interiorSize );
190 
191     //---------------------------------------------------------------------------
192     //! @brief    現在設定されているインテリアサイズを取得します。
193     //!
194     //! @return   現在設定されているインテリアサイズを返します。
195     //!
196     //! @see SetInteriorSize
197     //!
198     //! @date 2010/03/12 初版
199     //---------------------------------------------------------------------------
GetInteriorSize()200     f32 GetInteriorSize() const { return m_InteriorSize; }
201 
202     //---------------------------------------------------------------------------
203     //! @brief    最大音量範囲を設定します。
204     //!
205     //!           リスナーとアクターの距離が最大音量範囲よりも小さければ、
206     //!           そのアクターが再生するサウンドは音量の減衰無く再生されます。
207     //!           最大音量範囲を超えると、その距離に応じて再生するサウンドの音量が減衰されます。
208     //!
209     //! @param[in] maxVolumeDistance  最大音量範囲です。
210     //!
211     //! @see GetMaxVolumeDistance
212     //!
213     //! @date 2010/03/12 初版
214     //---------------------------------------------------------------------------
215     void SetMaxVolumeDistance( f32 maxVolumeDistance );
216 
217     //---------------------------------------------------------------------------
218     //! @brief    現在設定されている最大音量範囲を取得します。
219     //!
220     //! @return   現在設定されている最大音量範囲を返します。
221     //!
222     //! @see SetMaxVolumeDistance
223     //!
224     //! @date 2010/03/12 初版
225     //---------------------------------------------------------------------------
GetMaxVolumeDistance()226     f32 GetMaxVolumeDistance() const { return m_MaxVolumeDistance; }
227 
228     //---------------------------------------------------------------------------
229     //! @brief    音量減衰の単位距離を設定します。
230     //!
231     //!           一般的に 3D サウンドアクターと 3D サウンドリスナーの距離が離れると、
232     //!           サウンドの音量は減衰していきます。
233     //!           減衰の速度は、サウンドごとに設定される減衰係数と、
234     //!           この単位距離によって定まります。
235     //!
236     //!           サウンドが単位距離だけリスナーから離れるたびに、
237     //!           サウンドの音量が減衰係数に応じて下がります。
238     //!           減衰の仕方はサウンドごとに設定される減衰曲線に従います。
239     //!
240     //! @param[in] unitDistance   音量減衰の単位距離です。
241     //!
242     //! @see GetUnitDistance
243     //!
244     //! @date 2010/03/12 初版
245     //---------------------------------------------------------------------------
246     void SetUnitDistance( f32 unitDistance );
247 
248     //---------------------------------------------------------------------------
249     //! @brief    現在設定されている音量減衰の単位距離を取得します。
250     //!
251     //! @return   現在設定されている音量減衰の単位距離を返します。
252     //!
253     //! @see SetUnitDistance
254     //!
255     //! @date 2010/03/12 初版
256     //---------------------------------------------------------------------------
GetUnitDistance()257     f32 GetUnitDistance() const { return m_UnitDistance; }
258 
259     //---------------------------------------------------------------------------
260     //! @brief    リスナーにユーザーパラメータを設定します。
261     //!
262     //! @param[in] param ユーザーパラメータです。
263     //!
264     //! @see GetUserParam
265     //!
266     //! @date 2010/03/12 初版
267     //---------------------------------------------------------------------------
SetUserParam(u32 param)268     void SetUserParam( u32 param ) { m_UserParam = param; }
269 
270     //---------------------------------------------------------------------------
271     //! @brief    設定されているユーザーパラメータを取得します。
272     //!
273     //! @return   現在設定されているリスナーのユーザーパラメータを返します。
274     //!
275     //! @see SetUserParam
276     //!
277     //! @date 2010/03/12 初版
278     //---------------------------------------------------------------------------
GetUserParam()279     u32 GetUserParam() const { return m_UserParam; }
280 
281     //---------------------------------------------------------------------------
282     //! :private
283     //!
284     //! @brief
285     //!
286     //! @date 2010/03/12 初版
287     //---------------------------------------------------------------------------
288     void SetUnitBiquadFilterValue( f32 value );
289 
290     //---------------------------------------------------------------------------
291     //! :private
292     //!
293     //! @brief
294     //!
295     //! @date 2010/03/12 初版
296     //---------------------------------------------------------------------------
GetUnitBiquadFilterValue()297     f32 GetUnitBiquadFilterValue() const { return m_UnitBiquadFilterValue; }
298 
299     //---------------------------------------------------------------------------
300     //! :private
301     //!
302     //! @brief
303     //!
304     //! @date 2010/03/12 初版
305     //---------------------------------------------------------------------------
306     void SetMaxBiquadFilterValue( f32 value );
307 
308     //---------------------------------------------------------------------------
309     //! :private
310     //!
311     //! @brief
312     //!
313     //! @date 2010/03/12 初版
314     //---------------------------------------------------------------------------
GetMaxBiquadFilterValue()315     f32 GetMaxBiquadFilterValue() const { return m_MaxBiquadFilterValue; }
316     //@}
317 
318 private:
319     void CalcPositionFromMatrix( const nw::math::MTX34& mtx, nw::math::VEC3* pos );
320 
321     nw::math::MTX34 m_Mtx;
322     nw::math::VEC3 m_Position;
323     nw::math::VEC3 m_Velocity;
324     f32 m_InteriorSize;
325     f32 m_MaxVolumeDistance;
326     f32 m_UnitDistance;
327     u32 m_UserParam;
328     f32 m_UnitBiquadFilterValue;
329     f32 m_MaxBiquadFilterValue;
330     bool m_ResetMatrixFlag;
331 
332 public:
333     //! @details :private
334     ut::LinkListNode m_LinkNode;
335 };
336 
337 } // namespace nw::snd
338 } // namespace nw
339 
340 
341 #endif /* NW_SND_SOUND_3D_LISTENER_H_ */
342 
343