1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_Sound3DEngine.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_Sound3DEngine.h
18  *
19  * @file snd_Sound3DEngine.h
20  */
21 
22 #ifndef NW_SND_SOUND_3D_ENGINE_H_
23 #define NW_SND_SOUND_3D_ENGINE_H_
24 
25 #include <nw/snd/snd_Sound3DManager.h>
26 #include <nw/snd/snd_Sound3DCalculator.h>
27 
28 namespace nw {
29 namespace snd {
30 
31 //---------------------------------------------------------------------------
32 //! @brief    3D サウンドのパラメータ演算エンジンクラスです。
33 //!
34 //!           3D サウンドアクターや 3D サウンドリスナーの位置情報などから、
35 //!           サウンドに設定する音量やパンなどの各種パラメータを計算します。
36 //!           このクラスでは、3D サウンドの標準的なパラメータ計算が定義されています。
37 //!
38 //!           3D サウンドマネージャーには、初期状態でこのクラスのインスタンスが登録されています。
39 //!
40 //!           3D サウンドエンジンをカスタマイズしたい場合、
41 //!           このクラスを継承して独自のエンジンクラスを作成することができます。
42 //!           カスタマイズしたエンジンクラスは、
43 //!           @ref Sound3DManager::SetEngine で 3D サウンドマネージャーに登録し、
44 //!           デフォルトのエンジンクラスの代わりに使用することができます。
45 //!
46 //! @see Sound3DManager クラス
47 //! @see Sound3DManager::SetEngine
48 //!
49 //! @date 2010/03/12 初版
50 //---------------------------------------------------------------------------
51 class Sound3DEngine : public internal::ISound3DEngine
52 {
53   public:
54 
55     //! @name コンストラクタ/デストラクタ
56     //@{
57     //---------------------------------------------------------------------------
58     //! @brief    コンストラクタです。
59     //!
60     //! @date 2010/03/12 初版
61     //---------------------------------------------------------------------------
62     Sound3DEngine();
63 
64     //---------------------------------------------------------------------------
65     //! @brief    デストラクタです。
66     //!
67     //! @date 2010/03/12 初版
68     //---------------------------------------------------------------------------
~Sound3DEngine()69     virtual ~Sound3DEngine() {}
70     //@}
71 
72 
73     //! @name 設定
74     //@{
75     //---------------------------------------------------------------------------
76     //! @brief    パン計算用パラメータ構造体を設定します。
77     //!
78     //!           設定したパラメータは、3D サウンドエンジン内のパン計算の際に使用されます。
79     //!
80     //! @param[in] calcPanParam   パン計算用パラメータ構造体です。
81     //!
82     //! @see Sound3DCalculator::CalcPanParam 構造体
83     //!
84     //! @date 2010/03/12 初版
85     //---------------------------------------------------------------------------
SetCalcPanParam(const Sound3DCalculator::CalcPanParam & calcPanParam)86     void SetCalcPanParam( const Sound3DCalculator::CalcPanParam& calcPanParam )
87     {
88         m_CalcPanParam = calcPanParam;
89     }
90 
91     //---------------------------------------------------------------------------
92     //! @brief    現在設定されているパン計算用パラメータ構造体を取得します。
93     //!
94     //! @return   パン計算用パラメータ構造体を返します。
95     //!
96     //! @see Sound3DCalculator::CalcPanParam 構造体
97     //!
98     //! @date 2010/03/12 初版
99     //---------------------------------------------------------------------------
GetCalcPanParam()100     const Sound3DCalculator::CalcPanParam& GetCalcPanParam() const
101     {
102         return m_CalcPanParam;
103     }
104     //@}
105 
106   protected:
107     //---------------------------------------------------------------------------
108     //! @brief    UpdateAmbientParam で音量計算をする必要があることを示すフラグです。
109     //!
110     //! @see UpdateAmbientParam
111     //!
112     //! @date 2010/03/12 初版
113     //---------------------------------------------------------------------------
114     static const u32 UPDATE_VOLUME      = ( 1 << 0 );
115 
116     //---------------------------------------------------------------------------
117     //! @brief    UpdateAmbientParam でプライオリティ計算をする必要があることを示すフラグです。
118     //!
119     //! @see UpdateAmbientParam
120     //!
121     //! @date 2010/03/12 初版
122     //---------------------------------------------------------------------------
123     static const u32 UPDATE_PRIORITY    = ( 1 << 1 );
124 
125     //---------------------------------------------------------------------------
126     //! @brief    UpdateAmbientParam でパン計算をする必要があることを示すフラグです。
127     //!
128     //! @see UpdateAmbientParam
129     //!
130     //! @date 2010/03/12 初版
131     //---------------------------------------------------------------------------
132     static const u32 UPDATE_PAN         = ( 1 << 2 );
133 
134     //---------------------------------------------------------------------------
135     //! :private
136     //!
137     //! @brief    UpdateAmbientParam でサラウンドパン計算をする必要があることを示すフラグです。
138     //!
139     //! @date 2010/03/12 初版
140     //---------------------------------------------------------------------------
141     static const u32 UPDATE_SPAN        = ( 1 << 3 );
142 
143     //---------------------------------------------------------------------------
144     //! :private
145     //!
146     //! @brief    UpdateAmbientParam で
147     //!           biquad フィルタのかかり具合を計算する必要があることを示すフラグです。
148     //!
149     //! @date 2010/03/12 初版
150     //---------------------------------------------------------------------------
151     static const u32 UPDATE_FILTER      = ( 1 << 4 );
152 
153     //---------------------------------------------------------------------------
154     //! @brief    UpdateAmbientParam でピッチ計算をする必要があることを示すフラグです。
155     //!
156     //! @see UpdateAmbientParam
157     //!
158     //! @date 2010/03/12 初版
159     //---------------------------------------------------------------------------
160     static const u32 UPDATE_PITCH       = ( 1 << 5 );
161 
162     //---------------------------------------------------------------------------
163     //! @brief    サウンド開始前のプライオリティ計算のために
164     //!           UpdateAmbientParam が呼ばれた事を示すフラグです。
165     //!
166     //! @see UpdateAmbientParam
167     //!
168     //! @date 2010/03/12 初版
169     //---------------------------------------------------------------------------
170     static const u32 UPDATE_START_PRIORITY = ( 1 << 24 );
171 
172     //! @name パラメータ
173     //@{
174     //---------------------------------------------------------------------------
175     //! @brief    3D サウンドのパラメータ演算を行う関数です。
176     //!
177     //!           この関数はサウンドの開始時とサウンドの毎フレームの更新で呼び出されます。
178     //!
179     //!           カスタマイズした 3D サウンドエンジンクラスを作成する場合、
180     //!           この関数をオーバーライドして、 ambientParam にパラメータ演算の結果を格納します。
181     //!           格納された値は、毎フレームのサウンド処理に反映されます。
182     //!
183     //!           パラメータ計算には、3D サウンドリスナーや 3D サウンドアクターの情報を使用します。
184     //!           3D サウンドリスナーは、sound3DManager から取得できます。
185     //!           また、sound3DParam は計算に使用するパラメータの構造体で、
186     //!           アクターの座標などや、サウンドごとの 3D サウンド設定を含みます。
187     //!
188     //!           updateFlag は、どのパラメータを計算する必要があるかを示したビットフラグです。
189     //!           ambientParam 構造体内の、
190     //!           各フラグに対応したパラメータがサウンドに対して反映されます。
191     //!           フラグがたっていないパラメータを更新した場合の動作は不定です。
192     //!
193     //!           - UPDATE_VOLUME ... ambientParam.volume @n
194     //!           - UPDATE_PAN ... ambientParam.pan @n
195     //!           - UPDATE_PRIORITY ... ambientParam.priority @n
196     //!           - UPDATE_PITCH ... ambientParam.pitch @n
197     //!
198     //!           サウンド再生開始前に行われるプライオリティ計算のためにこの関数が呼ばれた場合には、
199     //!           updateFlag  に UPDATE_START_PRIORITY が設定されます。
200     //!           (このとき UPDATE_PRIORITY  も同時に設定されています。)
201     //!
202     //!           引数として渡される ambientParam 構造体には、
203     //!           前回の 3D サウンド計算結果が格納されています。
204     //!           UpdateAmbientParam 関数をオーバーライドする際、
205     //!           ここで渡される値と今回計算される値とを比較することで急激なパラメータ変化を避け、
206     //!           プチノイズを抑制することが可能になります。
207     //!
208     //! @param[in] sound3DManager 3D サウンドマネージャです。
209     //! @param[in] sound3DParam   3D サウンドパラメータです。
210     //! @param[in] soundId        サウンドの ID です。
211     //! @param[in] updateFlag     どのパラメータを更新するかを示したフラグです。
212     //! @param[out] ambientParam  計算結果を格納するパラメータ構造体です。
213     //!
214     //! @see Sound3DManager クラス
215     //! @see Sound3DParam 構造体
216     //! @see SoundAmbientParam 構造体
217     //!
218     //! @date 2010/03/12 初版
219     //---------------------------------------------------------------------------
220     virtual void UpdateAmbientParam(
221         const Sound3DManager* sound3DManager,
222         const Sound3DParam* sound3DParam,
223         u32 soundId,
224         u32 updateFlag,
225         SoundAmbientParam* ambientParam
226     );
227     //@}
228 
229   private:
230     virtual int GetAmbientPriority(
231         const Sound3DManager* sound3DManager,
232         const Sound3DParam* sound3DParam,
233         u32 soundId
234     );
235     virtual void UpdateAmbientParam(
236         const Sound3DManager* sound3DManager,
237         const Sound3DParam* sound3DParam,
238         u32 soundId,
239         SoundAmbientParam* ambientParam
240     );
241 
242     Sound3DCalculator::CalcPanParam m_CalcPanParam;
243 };
244 
245 } // namespace nw::snd
246 } // namespace nw
247 
248 
249 #endif /* NW_SND_SOUND_3D_ENGINE_H_ */
250 
251