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