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