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