1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_Sound3DCalculator.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_Sound3DCalculator.h
20  *
21  * @file snd_Sound3DCalculator.h
22  */
23 
24 
25 #ifndef NW_SND_SOUND_3D_CALCULATOR_H_
26 #define NW_SND_SOUND_3D_CALCULATOR_H_
27 
28 #include <nw/math/math_Constant.h>      // nw::math::F_PI
29 #include <nw/math/math_Types.h>         // nw::math::VEC3
30 #include <nw/snd/snd_SoundArchive.h>    // Sound3DInfo::DecayCurve
31 
32 namespace nw {
33 namespace snd {
34 
35 class Sound3DManager;
36 class Sound3DListener;
37 struct Sound3DParam;
38 
39 //---------------------------------------------------------------------------
40 //! @brief    3D サウンドの標準的なパラメータ計算処理をまとめたクラスです。
41 //!
42 //!           @ref Sound3DEngine クラスから呼び出されています。
43 //!
44 //!           カスタマイズして独自の 3D サウンドエンジンを作成する場合には、
45 //!           このクラスの関数を利用することができます。
46 //!
47 //! @see Sound3DEngine クラス
48 //!
49 //! @date 2010/03/12 初版
50 //---------------------------------------------------------------------------
51 class Sound3DCalculator
52 {
53 public:
54     //---------------------------------------------------------------------------
55     //! @brief    パン計算ためのパラメータ構造体です。
56     //!
57     //!           @ref CalcPan でパン計算を行う際に参照するパラメータ構造体です。
58     //!
59     //!           stereoSpeakerAngle は、パン計算を行う際に使用するスピーカーの位置を設定します。
60     //!           スピーカー配置は左右対称で、
61     //!           左右それぞれのスピーカーの正面からの角度をラジアンで指定します。
62     //!           ステレオモードのスピーカー配置は 45 度です。
63     //!
64     //! @see CalcPan
65     //!
66     //! @date 2010/05/11 speakerAngleStereo を stereoSpeakerAngle に名前変更
67     //! @date 2010/03/12 初版
68     //---------------------------------------------------------------------------
69     struct CalcPanParam
70     {
71         //! ステレオモードのときのスピーカー位置の中央からの角度(ラジアン)です。
72         f32 stereoSpeakerAngle;
73         f32 surroundSpeakerFrontAngle;
74         f32 surroundSpeakerRearAngle;
75         f32 surroundPanOffset;
76 
77         //---------------------------------------------------------------------------
78         //! @brief    コンストラクタです。
79         //!
80         //! @date 2010/03/12 初版
81         //---------------------------------------------------------------------------
CalcPanParamCalcPanParam82         CalcPanParam()
83         : stereoSpeakerAngle( nw::math::F_PI / 4.0f ),              // 45度
84           surroundSpeakerFrontAngle( nw::math::F_PI / 6.0f ),       // 30度
85           surroundSpeakerRearAngle( nw::math::F_PI * 2.0f / 3.0f ), // 120度
86           surroundPanOffset( 0.0f )
87         {}
88     };
89 
90     //! @name パラメータ計算
91     //@{
92     //---------------------------------------------------------------------------
93     //! @brief    3D サウンドの音量と優先度の標準的なパラメータ計算を行います。
94     //!
95     //!           3D サウンドでは音量と優先度が連動しますので、
96     //!           この関数でまとめて計算を行います。
97     //!
98     //! @param[in] manager            計算に使用する 3D サウンドマネージャです。
99     //! @param[in] listener           計算に使用する 3D サウンドリスナーです。
100     //! @param[in] actorParam         計算に使用する 3D サウンドパラメータです。
101     //! @param[out] volumePtr         音量の計算結果を格納するポインタです。
102     //! @param[out] priorityPtr       優先度の計算結果を格納するポインタです。
103     //!
104     //! @see Sound3DManager クラス
105     //! @see Sound3DListener クラス
106     //! @see Sound3DParam 構造体
107     //!
108     //! @date 2010/03/12 初版
109     //---------------------------------------------------------------------------
110     static void CalcVolumeAndPriority(
111         const Sound3DManager& manager,
112         const Sound3DListener& listener,
113         const Sound3DParam& actorParam,
114         f32* volumePtr,
115         int* priorityPtr
116     );
117 
118     //---------------------------------------------------------------------------
119     //! @brief    3D サウンドのパンの標準的なパラメータ計算を行います。
120     //!
121     //! @param[in] manager            計算に使用する 3D サウンドマネージャです。
122     //! @param[in] listener           計算に使用する 3D サウンドリスナーです。
123     //! @param[in] actorParam         計算に使用する 3D サウンドパラメータです。
124     //! @param[in] calcPanParam       パン計算に使用するパラメータです。
125     //! @param[out] panPtr            パンの計算結果を格納するポインタです。
126     //! @param[out] spanPtr           現在は無効です。
127     //!
128     //! @see Sound3DManager クラス
129     //! @see Sound3DListener クラス
130     //! @see Sound3DParam 構造体
131     //! @see CalcPanParam 構造体
132     //!
133     //! @date 2010/03/12 初版
134     //---------------------------------------------------------------------------
135     static void CalcPan(
136         const Sound3DManager& manager,
137         const Sound3DListener& listener,
138         const Sound3DParam& actorParam,
139         const CalcPanParam& calcPanParam,
140         f32* panPtr,
141         f32* spanPtr
142     );
143     // @param[out] surroundPanPtr サラウンドパンの計算結果を格納するポインタです。
144 
145     //---------------------------------------------------------------------------
146     //! @brief    3D サウンドの音程の標準的なパラメータ計算を行います。
147     //!
148     //! @param[in] manager            計算に使用する 3D サウンドマネージャです。
149     //! @param[in] listener           計算に使用する 3D サウンドリスナーです。
150     //! @param[in] actorParam         計算に使用する 3D サウンドパラメータです。
151     //! @param[out] pitchPtr          音程の計算結果を格納するポインタです。
152     //!
153     //! @see Sound3DManager クラス
154     //! @see Sound3DListener クラス
155     //! @see Sound3DParam 構造体
156     //!
157     //! @date 2010/03/12 初版
158     //---------------------------------------------------------------------------
159     static void CalcPitch(
160         const Sound3DManager& manager,
161         const Sound3DListener& listener,
162         const Sound3DParam& actorParam,
163         f32* pitchPtr
164     );
165 
166     //---------------------------------------------------------------------------
167     //! :private
168     //!
169     //! @brief    3D サウンドの biquad フィルタのかかり具合の標準的なパラメータ計算を行います。
170     //!
171     //! @param[in] manager                計算に使用する 3D サウンドマネージャです。
172     //! @param[in] listener               計算に使用する 3D サウンドリスナーです。
173     //! @param[in] actorParam             計算に使用する 3D サウンドパラメータです。
174     //! @param[out] biquadFilterValuePtr biquad フィルタのかかり具合の計算結果を格納するポインタです。
175     //!
176     //! @see Sound3DManager クラス
177     //! @see Sound3DListener クラス
178     //! @see Sound3DParam 構造体
179     //!
180     //! @date 2010/03/12 初版
181     //---------------------------------------------------------------------------
182     static void CalcBiquadFilterValue(
183         const Sound3DManager& manager,
184         const Sound3DListener& listener,
185         const Sound3DParam& actorParam,
186         f32* biquadFilterValuePtr
187     );
188     //@}
189 
190 private:
191     static void CalcVolumeAndPriorityImpl(
192         f32 actorDistance,
193         SoundArchive::Sound3DInfo::DecayCurve decayCurve,
194         f32 decayRatio,
195         int maxPriorityReduction,
196         f32 maxVolumeDistance,
197         f32 unitDistance,
198         f32* volumePtr,
199         int* priorityPtr
200     );
201     static void CalcPanImpl(
202         const nw::math::VEC3& pos,
203         f32 interiorSize,
204         f32 actorDistance,
205         f32 panRange,
206         f32 stereoSpeakerAngle,
207         f32 surroundSpeakerFrontAngle,
208         f32 surroundSpeakerRearAngle,
209         f32 surroundPanOffset,
210         f32* panPtr,
211         f32* surroundPanPtr
212     );
213     static void CalcPanSurround(
214         const nw::math::VEC3& pos,
215         f32 interiorSize,
216         f32 actorDistance,
217         f32 panRange,
218         f32 surroundSpeakerFrontAngle,
219         f32 surroundSpeakerRearAngle,
220         f32 surroundPanOffset,
221         f32* panPtr,
222         f32* surroundPanPtr
223     );
224 #if 0
225     static void CalcPanStereo(
226         const nw::math::VEC3& pos,
227         f32 interiorSize,
228         f32 actorDistance,
229         f32 panRange,
230         f32 stereoSpeakerAngle,
231         f32* panPtr,
232         f32* surroundPanPtr
233     );
234 #endif
235     static void CalcAngleAndDistance(
236         const nw::math::VEC3& pos,
237         f32 actorDistance,
238         f32 interiorSize,
239         f32* anglePtr,
240         f32* distancePtr
241     );
242 };
243 
244 } // namespace nw::snd
245 } // namespace nw
246 
247 
248 #endif /* NW_SND_SOUND_3D_CALCULATOR_H_ */
249 
250