1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: snd_Voice.h 4 5 Copyright (C)2009 Nintendo Co., Ltd. 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 $Rev: 28627 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_SND_VOICE_H_ 17 #define NN_SND_VOICE_H_ 18 19 #include <nn/os.h> 20 #include <nn/Result.h> 21 22 #include <nn/snd/CTR/Common/snd_Types.h> 23 24 #ifdef __cplusplus 25 26 /*! @file 27 @brief Voice に関する関数、およびクラス定義 28 */ 29 30 namespace nn { namespace snd { namespace CTR { 31 32 /*! 33 @brief ライブラリがボイスを解放する際に呼び出すコールバック関数の型定義です。 34 @param[in] pVoice 解放したボイスオブジェクトへの参照 35 @param[in] userArg ユーザーパラメータ 36 */ 37 typedef void (*VoiceDropCallbackFunc)(class Voice *, uptr userArg); 38 39 class VoiceImpl; 40 class VoiceManager; 41 42 /*! 43 @brief Voice を操作するクラスです。 44 */ 45 class Voice 46 { 47 friend class VoiceManager; 48 49 public: 50 51 /*! 52 @brief ボイスの状態を表す列挙型です。 53 */ 54 enum State 55 { 56 STATE_PLAY, //!< 再生指令状態を表します。 57 STATE_STOP, //!< 停止状態を表します。 58 STATE_PAUSE //!< 一時停止状態を表します。再生を再開する際は、SetState により再生状態を設定して下さい。 59 }; 60 61 private: 62 const s32 m_Id; // ボイス番号(管理用) 63 64 State m_State; // 状態 65 InterpolationType m_InterpolationType; // 補間方法 66 NN_PADDING1; 67 68 FilterType m_FilterType; // フィルタタイプ 69 MonoFilterCoefficients m_MonoFilterCoeffs; // 単極フィルタ係数 70 BiquadFilterCoefficients m_BiquadFilterCoeffs; // 双極フィルタ係数 71 NN_PADDING2; 72 73 s32 m_SampleRate; // 標本化周波数 74 f32 m_Pitch; // ピッチ(SampleRate に対する比) 75 76 s32 m_Priority; // 優先度 77 Voice * m_PriorVoice; // 優先度が高い Voice へのポインタ 78 Voice * m_InferiorVoice; // 優先度が低い Voice へのポインタ 79 80 VoiceDropCallbackFunc m_Callback; // Voice がシステムにより解放された場合に呼び出されるコールバック関数 81 uptr m_UserArg; // 上記コールバック呼び出し時のユーザ引数 82 83 MixParam m_MixParam; // 各チャンネルへのゲイン 84 f32 m_Volume; // ボリューム 85 86 VoiceImpl* m_pImpl; 87 88 void Initialize(); 89 void UpdateStatus(const void* pVars); 90 void UpdateWaveBufferList(); GetId()91 s32 GetId() const { return m_Id; } GetImpl()92 VoiceImpl* GetImpl() const { return m_pImpl; } 93 94 public: 95 Voice(s32 id); 96 ~Voice(); 97 98 /*! 99 @name バッファ追加 100 @{ 101 */ 102 /*! 103 @brief ボイスに対してサンプルデータ情報を追加します。 104 @param[in] buffer バッファ情報構造体のポインタ 105 */ 106 void AppendWaveBuffer(WaveBuffer* buffer); 107 /*! 108 @} 109 */ 110 111 /*! 112 @name パラメータ設定 113 @{ 114 */ 115 /*! 116 @brief ボイスのチャンネル数を設定します。 117 @param[in] channelCount チャンネル数 118 */ 119 void SetChannelCount(s32 channelCount); 120 121 /*! 122 @brief ボイスにリンクされるサンプルの形式を設定します。 123 @param[in] format サンプルの形式 124 */ 125 void SetSampleFormat(SampleFormat format); 126 127 /*! 128 @brief 3D サラウンドが有効な場合に、フロントチャンネルをバイパスするかを設定します。 129 @param[in] flag true ならフロントバイパス、false ならフロントにも 3D サラウンドを適用 130 */ 131 void SetFrontBypassFlag(bool flag); 132 133 /*! 134 @brief 再生開始時にボリューム 0 からの短いフェードインを用いるかどうかを指定します。 135 @param[in] flag On/Off フラグ 136 */ 137 void SetStartFrameFadeInFlag(bool flag); 138 139 /*! 140 @brief ボイスのサンプリングレートを設定します。 141 @param[in] sampleRate サンプリングレート 142 */ 143 void SetSampleRate(s32 sampleRate); 144 145 /*! 146 @brief ボイスのピッチを設定します。 147 @param[in] pitch サンプリングレートに対する再生速度比 148 */ 149 void SetPitch(f32 pitch); 150 151 /*! 152 @brief Adpcm の係数を設定します。 153 @param[in] param Adpcm 係数構造体への参照 154 */ 155 void SetAdpcmParam(const AdpcmParam& param); 156 157 /*! 158 @brief ボイスの優先度を設定します。 159 @param[in] priority 優先度 160 */ 161 void SetPriority(s32 priority); 162 163 /*! 164 @brief ボイスの状態を設定します。 165 @param[in] state 状態 166 */ 167 void SetState(State state); 168 169 /*! 170 @brief ボイスの各チャンネルのゲインを設定します。 171 @param[in] mixParam ゲイン構造体への参照 172 */ 173 void SetMixParam(const MixParam& mixParam); 174 175 /*! 176 @brief ボイスのボリュームを設定します。 177 @param[in] volume ボリューム値 178 */ 179 void SetVolume(f32 volume); 180 181 /*! 182 @brief ボイスの補間方法を設定します。 183 @param[in] type 補間方法 184 */ 185 void SetInterpolationType(InterpolationType type); 186 187 /*! 188 @brief フィルタタイプを設定します。 189 @param[in] type フィルタタイプ 190 */ 191 void SetFilterType(FilterType type); 192 193 /*! 194 @brief 単極フィルタを有効/無効にします。 195 @param[in] enable true なら有効、false なら無効 196 */ 197 void EnableMonoFilter(bool enable); 198 199 /*! :overload coef_ptr 200 @brief 単極フィルタの係数を設定します。 201 @param[in] pCoeff 係数バッファ 202 */ 203 void SetMonoFilterCoefficients(const MonoFilterCoefficients* pCoeff); 204 205 /*! :overload coef_ref 206 @brief 単極フィルタの係数を設定します。 207 @param[in] coeff 係数バッファ 208 */ 209 void SetMonoFilterCoefficients(const MonoFilterCoefficients& coeff); 210 211 /*! :overload freq 212 @brief 指定したカットオフ周波数を持つ、単極ローパスフィルタを設定します。 213 @param[in] cutoff カットオフ周波数 214 */ 215 void SetMonoFilterCoefficients(u16 cutoff); 216 217 /*! 218 @brief 双極フィルタを有効/無効にします。 219 @param[in] enable true なら有効、false なら無効 220 */ 221 void EnableBiquadFilter(bool enable); 222 223 /*! :overload coef_ptr 224 @brief 双極フィルタの係数を設定します。 225 @param[in] pCoeff 係数バッファ 226 */ 227 void SetBiquadFilterCoefficients(const BiquadFilterCoefficients* pCoeff); 228 229 /*! :overload coef_ref 230 @brief 双極フィルタの係数を設定します。 231 @param[in] coeff 係数バッファ 232 */ 233 void SetBiquadFilterCoefficients(const BiquadFilterCoefficients& coeff); 234 /*! 235 @} 236 */ 237 238 /*! 239 @name パラメータ取得 240 @{ 241 */ 242 /*! 243 @brief ボイスのピッチを取得します。 244 @return ピッチを返します。 245 */ GetPitch()246 inline f32 GetPitch() const { return m_Pitch; } 247 248 /*! 249 @brief ボイスの優先度を取得します。 250 @return 優先度を返します。 251 */ GetPriority()252 inline s32 GetPriority() const { return m_Priority; } 253 254 /*! 255 @brief ボイスの状態を取得します。 256 @return 状態を返します。 257 */ GetState()258 inline Voice::State GetState() const { return m_State; } 259 260 /*! 261 @brief ボイスの各チャンネルのゲインを取得します。 262 @return ゲイン構造体への参照を返します。 263 */ GetMixParam()264 inline const MixParam& GetMixParam() const { return m_MixParam; } 265 266 /*! 267 @brief ボイスのボリュームを取得します。 268 @return ボリューム値を返します。 269 */ GetVolume()270 inline f32 GetVolume() const { return m_Volume; } 271 272 /*! 273 @brief ボイスの補間方法を取得します。 274 @return 現在の補間方法を返します。 275 */ GetInterpolationType()276 inline InterpolationType GetInterpolationType() const { return m_InterpolationType; } 277 278 /*! 279 @brief フィルタの使用状況を取得します。 280 @return フィルタタイプ。 281 */ GetFilterType()282 inline FilterType GetFilterType() const { return m_FilterType; } 283 284 /*! :overload coef_ptr 285 @brief 単極フィルタの係数を取得します。 286 @param[out] pCoeff 係数バッファ 287 */ 288 void GetMonoFilterCoefficients(MonoFilterCoefficients* pCoeff); 289 290 /*! :overload coef_ref 291 @brief 単極フィルタの係数を取得します。 292 @param[out] coeff 係数バッファ 293 */ 294 void GetMonoFilterCoefficients(MonoFilterCoefficients& coeff); 295 296 /*! :overload coef_ptr 297 @brief 双極フィルタの係数を取得します。 298 @param[out] pCoeff 係数バッファ 299 */ 300 void GetBiquadFilterCoefficients(BiquadFilterCoefficients* pCoeff); 301 302 /*! :overload coef_ref 303 @brief 双極フィルタの係数を取得します。 304 @param[out] coeff 係数バッファ 305 */ 306 void GetBiquadFilterCoefficients(BiquadFilterCoefficients& coeff); 307 /*! 308 @} 309 */ 310 311 /*! 312 @name 再生状況取得 313 @{ 314 */ 315 /*! 316 @brief 使用中のバッファ内での再生位置を取得します。 317 @return 再生位置をサンプル数で返します。 318 */ 319 s32 GetPlayPosition() const; 320 321 /*! 322 @brief ボイスの再生状態を取得します。 323 @return ボイスの再生状態を返します。 324 */ 325 bool IsPlaying() const; 326 /*! 327 @} 328 */ 329 330 /*! 331 @name Bcwav 関連 332 @{ 333 */ 334 /*! 335 @brief Bcwav ファイルを解釈し、再生準備を行います。 336 @param[in] addrBcwav Bcwav ファイルの先頭アドレス 337 @param[in] pWaveBuffer0 初回再生時に使用する nn::snd::WaveBuffer へのポインタ 338 @param[in] pWaveBuffer1 ループ再生時に使用する nn::snd::WaveBuffer へのポインタ 339 @param[in] channelIndex 使用するチャンネル 340 @return 成功なら true, 失敗なら false を返します。 341 */ 342 bool SetupBcwav(uptr addrBcwav, WaveBuffer* pWaveBuffer0, WaveBuffer* pWaveBuffer1, Bcwav::ChannelIndex channelIndex = Bcwav::CHANNEL_INDEX_L); 343 /*! 344 @} 345 */ 346 347 private: 348 void SetChannelCountCommand(s32 channelCount); 349 void SetSampleFormatCommand(SampleFormat format); 350 void SetFrontBypassFlagCommand(bool flag); 351 void SetStartFrameFadeInFlagCommand(bool flag); 352 void SetSampleRateCommand(s32 sampleRate); 353 void SetPitchCommand(f32 pitch); 354 void SetInterpolationTypeCommand(InterpolationType type); 355 void SetFilterTypeCommand(FilterType type); 356 void EnableMonoFilterCommand(bool enable); 357 void SetMonoFilterCoefficientsCommand(const MonoFilterCoefficients& coeff); 358 void SetMonoFilterCoefficientsCommand(u16 cutoff); 359 void EnableBiquadFilterCommand(bool enable); 360 void SetBiquadFilterCoefficientsCommand(const BiquadFilterCoefficients& coeff); 361 void SetAdpcmParamCommand(const AdpcmParam& param); 362 void SetStateCommand(State state); 363 void SetMixParamCommand(const MixParam& mixParam); 364 void SetVolumeCommand(f32 volume); 365 bool SetupBcwavCommand(uptr addrBcwav, WaveBuffer* pWaveBuffer0, WaveBuffer* pWaveBuffer1, Bcwav::ChannelIndex channelIndex); 366 }; // class Voice 367 368 /*! 369 @name Voice 操作 370 @{ 371 */ 372 /*! 373 @brief ボイスを取得します。 374 @param[in] priority 優先順位 375 @param[in] callback コールバック関数のアドレス 376 @param[in] userArg ユーザ引数 377 @return 成功した場合、Voice オブジェクトのアドレスを返します。失敗した場合、NULL を返します。 378 */ 379 Voice* AllocVoice(s32 priority, VoiceDropCallbackFunc callback, uptr userArg); 380 381 /*! 382 @brief ボイスを解放します。 383 @param[in] pVoice ボイスオブジェクトのアドレス。 384 */ 385 void FreeVoice(Voice* pVoice); 386 /*! 387 @} 388 */ 389 390 }}} // namespace nn::snd::CTR 391 392 #endif // __cplusplus 393 394 #endif //NN_SND_VOICE_H_ 395