[187] | 1 | 'このファイルには、DirectMusicをCOMインターフェイスレベルで扱うための関数が定義されています。
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | '-------------------------------------------------
|
---|
| 5 | ' DirectMusicに必要なヘッダファイルをインクルード
|
---|
| 6 | '-------------------------------------------------
|
---|
| 7 | #include <directx9\dmusic.sbp>
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | Dim dx_lpDMPerformance As *IDirectMusicPerformance8 'パフォーマンス
|
---|
| 11 | Dim dx_lpDMLoader As *IDirectMusicLoader8 'ローダー
|
---|
| 12 |
|
---|
| 13 | 'DirectMusicを初期化する関数
|
---|
| 14 | Function dx_InitDMusic() As Long
|
---|
| 15 | Dim hr As DWord
|
---|
| 16 |
|
---|
| 17 | 'パフォーマンスの生成
|
---|
| 18 | hr = CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC,
|
---|
| 19 | IID_IDirectMusicPerformance8, dx_lpDMPerformance)
|
---|
| 20 | If hr Then
|
---|
| 21 | dx_InitDMusic=0
|
---|
| 22 | Exit Function
|
---|
| 23 | End If
|
---|
| 24 |
|
---|
| 25 | 'パフォーマンスの初期化
|
---|
| 26 | hr = dx_lpDMPerformance->InitAudio(NULL, NULL, hMainWnd,
|
---|
| 27 | DMUS_APATH_SHARED_STEREOPLUSREVERB, 64, DMUS_AUDIOF_ALL, NULL)
|
---|
| 28 | If hr Then
|
---|
| 29 | dx_InitDMusic=0
|
---|
| 30 | Exit Function
|
---|
| 31 | End If
|
---|
| 32 |
|
---|
| 33 | 'ローダーの生成
|
---|
| 34 | hr = CoCreateInstance(CLSID_DirectMusicLoader, NULL,
|
---|
| 35 | CLSCTX_INPROC, IID_IDirectMusicLoader8, dx_lpDMLoader)
|
---|
| 36 | If hr Then
|
---|
| 37 | dx_InitDMusic=0
|
---|
| 38 | Exit Function
|
---|
| 39 | End If
|
---|
| 40 |
|
---|
| 41 | dx_InitDMusic=1
|
---|
| 42 | End Function
|
---|
| 43 |
|
---|
| 44 | ' DirectMusicを終了するための関数
|
---|
| 45 | Sub dx_QuitDMusic()
|
---|
| 46 | If dx_lpDMLoader Then dx_lpDMLoader->Release()
|
---|
| 47 | If dx_lpDMPerformance Then
|
---|
| 48 | 'すべてのサウンドを停止
|
---|
| 49 | dx_lpDMPerformance->Stop(NULL, NULL, 0, 0)
|
---|
| 50 |
|
---|
| 51 | 'パフォーマンスオブジェクトを閉じる
|
---|
| 52 | dx_lpDMPerformance->CloseDown()
|
---|
| 53 |
|
---|
| 54 | '解放
|
---|
| 55 | dx_lpDMPerformance->Release()
|
---|
| 56 | End If
|
---|
| 57 | End Sub
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | '------------------------
|
---|
| 61 | ' サウンド再生用のクラス
|
---|
| 62 | '------------------------
|
---|
| 63 |
|
---|
| 64 | 'エフェクト フラグ
|
---|
| 65 | Enum EFFECT_FLAGS
|
---|
| 66 | NO_EFFECT = 0 'エフェクト無し
|
---|
| 67 | EFFECT_STANDARD_CHORUS = 1 'コーラス
|
---|
| 68 | EFFECT_STANDARD_COMPRESSOR = 2 'コンプレッサー
|
---|
| 69 | EFFECT_STANDARD_DISTORTION = 3 'ディストーション
|
---|
| 70 | EFFECT_STANDARD_ECHO = 4 'エコー
|
---|
| 71 | EFFECT_STANDARD_FLANGER = 5 'フランジ
|
---|
| 72 | EFFECT_STANDARD_GARGLE = 6 'ガーグル
|
---|
| 73 | EFFECT_STANDARD_I3DL2REVERB = 7 'Interactive 3D Level 2 リバーブ
|
---|
| 74 | EFFECT_STANDARD_PARAMEQ = 8 'パラメトリック イコライザ
|
---|
| 75 | EFFECT_WAVES_REVERB = 9 'Waves リバーブ
|
---|
| 76 | End Enum
|
---|
| 77 |
|
---|
| 78 | Class CAudio
|
---|
| 79 | Protected
|
---|
| 80 | lpDMSegment As *IDirectMusicSegment8 'セグメント
|
---|
| 81 | lpDMAudioPath As *IDirectMusicAudioPath8 'オーディオパス
|
---|
| 82 | lpDSBuffer As LPDIRECTSOUNDBUFFER8 'サウンドバッファ
|
---|
| 83 |
|
---|
| 84 | dwFlags As DWord
|
---|
| 85 | dwLength As DWord 'サウンド長(ミリ秒)
|
---|
| 86 |
|
---|
| 87 | Function LoadAndSetting(pszFileName As *Char) As Long
|
---|
| 88 | Dim hr As DWord
|
---|
| 89 |
|
---|
| 90 | Release()
|
---|
| 91 |
|
---|
| 92 | 'サウンドの長さをdwLengthへ格納(ミリ秒単位)
|
---|
| 93 | Dim mop As MCI_OPEN_PARMS
|
---|
| 94 | Dim msep As MCI_SET_PARMS
|
---|
| 95 | Dim msp As MCI_STATUS_PARMS
|
---|
| 96 | mop.dwCallback=hMainWnd As DWord
|
---|
| 97 | mop.lpstrElementName=pszFileName
|
---|
| 98 | msep.dwTimeFormat=MCI_FORMAT_MILLISECONDS
|
---|
| 99 | mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT,mop)
|
---|
| 100 | mciSendCommand(mop.wDeviceID,MCI_SET,MCI_SET_TIME_FORMAT,msep)
|
---|
| 101 | msp.dwItem=MCI_STATUS_LENGTH
|
---|
| 102 | mciSendCommand(mop.wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,msp)
|
---|
| 103 | dwLength=msp.dwReturn
|
---|
| 104 | mciSendCommand(mop.wDeviceID,MCI_CLOSE,MCI_WAIT,ByVal VarPtr(hr))
|
---|
| 105 |
|
---|
| 106 | 'Unicodeに変換
|
---|
| 107 | Dim wstrFileName[MAX_PATH-1] As WCHAR
|
---|
| 108 | MultiByteToWideChar(CP_ACP, 0, pszFileName, -1, wstrFileName, MAX_PATH)
|
---|
| 109 |
|
---|
| 110 | hr = dx_lpDMLoader->LoadObjectFromFile(CLSID_DirectMusicSegment,
|
---|
| 111 | IID_IDirectMusicSegment8, wstrFileName, VarPtr(lpDMSegment))
|
---|
| 112 | If hr Then
|
---|
| 113 | LoadAndSetting=0
|
---|
| 114 | Exit Function
|
---|
| 115 | End If
|
---|
| 116 |
|
---|
| 117 | 'バンドのダウンロード
|
---|
| 118 | hr = lpDMSegment->Download(dx_lpDMPerformance)
|
---|
| 119 | If hr Then
|
---|
| 120 | LoadAndSetting=0
|
---|
| 121 | Exit Function
|
---|
| 122 | End If
|
---|
| 123 |
|
---|
| 124 | LoadAndSetting=1
|
---|
| 125 | End Function
|
---|
| 126 |
|
---|
| 127 | Private
|
---|
| 128 | Sub Release()
|
---|
| 129 | If lpDMSegment Then
|
---|
| 130 | Stop()
|
---|
| 131 |
|
---|
| 132 | lpDMSegment->Unload(dx_lpDMPerformance)
|
---|
| 133 |
|
---|
| 134 | If lpDSBuffer Then lpDSBuffer->Release()
|
---|
| 135 | If lpDMAudioPath Then lpDMAudioPath->Release()
|
---|
| 136 | lpDMSegment->Release()
|
---|
| 137 | End If
|
---|
| 138 | End Sub
|
---|
| 139 |
|
---|
| 140 | Public
|
---|
| 141 | 'コンストラクタ
|
---|
| 142 | Sub CAudio()
|
---|
| 143 | lpDMSegment=0
|
---|
| 144 | lpDMAudioPath=0
|
---|
| 145 | lpDSBuffer=0
|
---|
| 146 | dwFlags=0
|
---|
| 147 | End Sub
|
---|
| 148 |
|
---|
| 149 | 'デストラクタ
|
---|
| 150 | Sub ~CAudio()
|
---|
| 151 | Release()
|
---|
| 152 | End Sub
|
---|
| 153 |
|
---|
| 154 | 'ファイルパスを指定
|
---|
| 155 | Function Load(pszFileName As *Char) As Long
|
---|
| 156 | Dim hr As DWord
|
---|
| 157 |
|
---|
| 158 | hr=LoadAndSetting(pszFileName)
|
---|
| 159 | If hr=FALSE Then
|
---|
| 160 | Load=FALSE
|
---|
| 161 | Exit Function
|
---|
| 162 | End If
|
---|
| 163 |
|
---|
| 164 | 'オーディオパスの生成
|
---|
| 165 | hr = dx_lpDMPerformance->CreateStandardAudioPath(DMUS_APATH_DYNAMIC_STEREO, 64, FALSE, VarPtr(lpDMAudioPath))
|
---|
| 166 | If hr Then
|
---|
| 167 | Load=0
|
---|
| 168 | Exit Function
|
---|
| 169 | End If
|
---|
| 170 |
|
---|
| 171 | 'サウンドバッファの取得
|
---|
| 172 | hr = lpDMAudioPath->GetObjectInPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0,
|
---|
| 173 | GUID_NULL, 0, IID_IDirectSoundBuffer8, VarPtr(lpDSBuffer))
|
---|
| 174 | If hr Then
|
---|
| 175 | Load=0
|
---|
| 176 | Exit Function
|
---|
| 177 | End If
|
---|
| 178 |
|
---|
| 179 | ' オーディオパスのアクティブ化
|
---|
| 180 | lpDMAudioPath->Activate(TRUE)
|
---|
| 181 |
|
---|
| 182 | Load=1
|
---|
| 183 | End Function
|
---|
| 184 |
|
---|
| 185 | '再生
|
---|
| 186 | Function Play() As Long
|
---|
| 187 | Dim hr As DWord
|
---|
| 188 |
|
---|
| 189 | 'セグメントの再生
|
---|
| 190 | hr = dx_lpDMPerformance->PlaySegmentEx(lpDMSegment,
|
---|
| 191 | NULL,
|
---|
| 192 | NULL,
|
---|
| 193 | dwFlags,
|
---|
| 194 | 0,
|
---|
| 195 | NULL,
|
---|
| 196 | NULL,
|
---|
| 197 | lpDMAudioPath)
|
---|
| 198 | If hr Then
|
---|
| 199 | Play=FALSE
|
---|
| 200 | Exit Function
|
---|
| 201 | End If
|
---|
| 202 |
|
---|
| 203 | Play=TRUE
|
---|
| 204 | End Function
|
---|
| 205 |
|
---|
| 206 | '停止
|
---|
| 207 | Function Stop() As Long
|
---|
| 208 | Dim hr As Long
|
---|
| 209 |
|
---|
| 210 | 'セグメントの停止
|
---|
| 211 | hr=dx_lpDMPerformance->StopEx(lpDMSegment, 0, 0)
|
---|
| 212 |
|
---|
| 213 | If hr=S_OK Then Stop=TRUE Else Stop=FALSE
|
---|
| 214 | End Function
|
---|
| 215 |
|
---|
| 216 | '長さを取得
|
---|
| 217 | Function GetLength() As DWord
|
---|
| 218 | GetLength=dwLength
|
---|
| 219 | End Function
|
---|
| 220 |
|
---|
| 221 | 'プライマリセグメントにセット
|
---|
| 222 | Sub SetPrimary()
|
---|
| 223 | dwFlags=0
|
---|
| 224 | End Sub
|
---|
| 225 |
|
---|
| 226 | 'セカンダリセグメントにセット
|
---|
| 227 | Sub SetSecondary()
|
---|
| 228 | dwFlags=DMUS_SEGF_SECONDARY
|
---|
| 229 | End Sub
|
---|
| 230 |
|
---|
| 231 | Function SetEffect(EffectFlag As EFFECT_FLAGS) As Long
|
---|
| 232 | Dim hr As DWord
|
---|
| 233 |
|
---|
| 234 | If EffectFlag=NO_EFFECT Then
|
---|
| 235 | lpDSBuffer->SetFX(0, NULL, NULL)
|
---|
| 236 |
|
---|
| 237 | SetEffect=1
|
---|
| 238 | Exit Function
|
---|
| 239 | End If
|
---|
| 240 |
|
---|
| 241 | 'エフェクトの設定
|
---|
| 242 | Dim effect As DSEFFECTDESC
|
---|
| 243 | effect.dwSize = SizeOf(DSEFFECTDESC)
|
---|
| 244 | effect.dwFlags = 0
|
---|
| 245 | Select Case EffectFlag
|
---|
| 246 | Case EFFECT_STANDARD_CHORUS
|
---|
| 247 | effect.guidDSFXClass = GUID_DSFX_STANDARD_CHORUS
|
---|
| 248 | Case EFFECT_STANDARD_COMPRESSOR
|
---|
| 249 | effect.guidDSFXClass = GUID_DSFX_STANDARD_COMPRESSOR
|
---|
| 250 | Case EFFECT_STANDARD_DISTORTION
|
---|
| 251 | effect.guidDSFXClass = GUID_DSFX_STANDARD_DISTORTION
|
---|
| 252 | Case EFFECT_STANDARD_ECHO
|
---|
| 253 | effect.guidDSFXClass = GUID_DSFX_STANDARD_ECHO
|
---|
| 254 | Case EFFECT_STANDARD_FLANGER
|
---|
| 255 | effect.guidDSFXClass = GUID_DSFX_STANDARD_FLANGER
|
---|
| 256 | Case EFFECT_STANDARD_GARGLE
|
---|
| 257 | effect.guidDSFXClass = GUID_DSFX_STANDARD_GARGLE
|
---|
| 258 | Case EFFECT_STANDARD_I3DL2REVERB
|
---|
| 259 | effect.guidDSFXClass = GUID_DSFX_STANDARD_I3DL2REVERB
|
---|
| 260 | Case EFFECT_STANDARD_PARAMEQ
|
---|
| 261 | effect.guidDSFXClass = GUID_DSFX_STANDARD_PARAMEQ
|
---|
| 262 | Case EFFECT_WAVES_REVERB
|
---|
| 263 | effect.guidDSFXClass = GUID_DSFX_WAVES_REVERB
|
---|
| 264 | End Select
|
---|
| 265 | effect.dwReserved1 = 0
|
---|
| 266 | effect.dwReserved2 = 0
|
---|
| 267 | lpDSBuffer->SetFX(1, VarPtr(effect), NULL)
|
---|
| 268 |
|
---|
| 269 | SetEffect=1
|
---|
| 270 | End Function
|
---|
| 271 |
|
---|
| 272 | 'リピート回数を設定
|
---|
| 273 | Function SetRepeats(dwRepeats As DWord) As Long
|
---|
| 274 | If lpDMSegment->SetRepeats(dwRepeats)=S_OK Then
|
---|
| 275 | SetRepeats=TRUE
|
---|
| 276 | Else
|
---|
| 277 | SetRepeats=FALSE
|
---|
| 278 | End If
|
---|
| 279 | End Function
|
---|
| 280 |
|
---|
| 281 | 'シーク
|
---|
| 282 | Sub Seek(dwSeekTime As DWord) As Long
|
---|
| 283 | End Sub
|
---|
| 284 |
|
---|
| 285 | 'プレイ中であるかどうかを調べる
|
---|
| 286 | Function IsPlaying() As Long
|
---|
| 287 | If dx_lpDMPerformance->IsPlaying(lpDMSegment,NULL)=S_OK Then
|
---|
| 288 | IsPlaying=TRUE
|
---|
| 289 | Else
|
---|
| 290 | IsPlaying=FALSE
|
---|
| 291 | End If
|
---|
| 292 | End Function
|
---|
| 293 |
|
---|
| 294 | End Class
|
---|
| 295 |
|
---|
| 296 | '3D空間内音源
|
---|
| 297 | Class CAudio3D
|
---|
| 298 | Inherits CAudio
|
---|
| 299 |
|
---|
| 300 | lpDS3DBuffer As LPDIRECTSOUND3DBUFFER8 '3D空間内の音源
|
---|
| 301 |
|
---|
| 302 | Public
|
---|
| 303 | Sub CAudio3D()
|
---|
| 304 | CAudio()
|
---|
| 305 |
|
---|
| 306 | lpDS3DBuffer=0
|
---|
| 307 | End Sub
|
---|
| 308 | Sub ~CAudio3D()
|
---|
| 309 | If lpDS3DBuffer Then lpDS3DBuffer->Release()
|
---|
| 310 | End Sub
|
---|
| 311 |
|
---|
| 312 | 'ファイルパスを指定
|
---|
| 313 | Function Load(pszFileName As BytePtr) As Long
|
---|
| 314 | Dim hr As DWord
|
---|
| 315 |
|
---|
| 316 | hr=LoadAndSetting(pszFileName)
|
---|
| 317 | If hr=FALSE Then
|
---|
| 318 | Load=FALSE
|
---|
| 319 | Exit Function
|
---|
| 320 | End If
|
---|
| 321 |
|
---|
| 322 | 'オーディオパスの生成
|
---|
| 323 | hr = dx_lpDMPerformance->CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D, 64, FALSE, VarPtr(lpDMAudioPath))
|
---|
| 324 | If hr Then
|
---|
| 325 | Load=0
|
---|
| 326 | Exit Function
|
---|
| 327 | End If
|
---|
| 328 |
|
---|
| 329 | '3Dサウンドバッファの取得
|
---|
| 330 | hr = lpDMAudioPath->GetObjectInPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0,
|
---|
| 331 | GUID_NULL, 0, IID_IDirectSound3DBuffer8, VarPtr(lpDS3DBuffer))
|
---|
| 332 | If hr Then
|
---|
| 333 | Load=0
|
---|
| 334 | Exit Function
|
---|
| 335 | End If
|
---|
| 336 |
|
---|
| 337 | 'サウンドバッファの取得
|
---|
| 338 | hr = lpDMAudioPath->GetObjectInPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0,
|
---|
| 339 | GUID_NULL, 0, IID_IDirectSoundBuffer8, VarPtr(lpDSBuffer))
|
---|
| 340 | If hr Then
|
---|
| 341 | Load=0
|
---|
| 342 | Exit Function
|
---|
| 343 | End If
|
---|
| 344 |
|
---|
| 345 | ' オーディオパスのアクティブ化
|
---|
| 346 | lpDMAudioPath->Activate(TRUE)
|
---|
| 347 |
|
---|
| 348 | Load=1
|
---|
| 349 | End Function
|
---|
| 350 |
|
---|
| 351 | Function SetEffect(EffectFlag As EFFECT_FLAGS) As Long
|
---|
| 352 | 'CAudio3Dではエフェクトをサポートしない
|
---|
| 353 | SetEffect=0
|
---|
| 354 | End Function
|
---|
| 355 |
|
---|
| 356 | Function GetFrequency(lpdwFrequency As *DWord) As Long
|
---|
| 357 | Dim hr As Long
|
---|
| 358 | hr=lpDSBuffer->GetFrequency(lpdwFrequency)
|
---|
| 359 | If hr=S_OK Then
|
---|
| 360 | GetFrequency=TRUE
|
---|
| 361 | Else
|
---|
| 362 | GetFrequency=FALSE
|
---|
| 363 | End If
|
---|
| 364 | End Function
|
---|
| 365 |
|
---|
| 366 | Function SetFrequency(dwFrequency As DWord) As Long
|
---|
| 367 | Dim hr As Long
|
---|
| 368 | hr=lpDSBuffer->SetFrequency(dwFrequency)
|
---|
| 369 | If hr=S_OK Then
|
---|
| 370 | SetFrequency=TRUE
|
---|
| 371 | Else
|
---|
| 372 | SetFrequency=FALSE
|
---|
| 373 | End If
|
---|
| 374 | End Function
|
---|
| 375 |
|
---|
| 376 |
|
---|
| 377 | '--------------------------
|
---|
| 378 | ' 音源に関するメソッド
|
---|
| 379 | '--------------------------
|
---|
| 380 |
|
---|
| 381 | '最短距離の設定(この距離を超えると減衰が始まる)
|
---|
| 382 | Function SetMinDistance(distance As Single) As Long
|
---|
| 383 | Dim hr As Long
|
---|
| 384 | hr=lpDS3DBuffer->SetMinDistance(distance, DS3D_DEFERRED)
|
---|
| 385 | If hr=S_OK Then
|
---|
| 386 | SetMinDistance=TRUE
|
---|
| 387 | Else
|
---|
| 388 | SetMinDistance=FALSE
|
---|
| 389 | End If
|
---|
| 390 | End Function
|
---|
| 391 |
|
---|
| 392 | '最長距離の設定(聞こえる音量が0になり、減衰の計算がストップする距離)
|
---|
| 393 | Function SetMaxDistance(distance As Single) As Long
|
---|
| 394 | Dim hr As Long
|
---|
| 395 | hr=lpDS3DBuffer->SetMaxDistance(distance, DS3D_DEFERRED)
|
---|
| 396 | If hr=S_OK Then
|
---|
| 397 | SetMaxDistance=TRUE
|
---|
| 398 | Else
|
---|
| 399 | SetMaxDistance=FALSE
|
---|
| 400 | End If
|
---|
| 401 | End Function
|
---|
| 402 |
|
---|
| 403 | '音源の位置の設定
|
---|
| 404 | Function SetPosition(x As Single, y As Single, z As Single) As Long
|
---|
| 405 | Dim hr As Long
|
---|
| 406 | hr=lpDS3DBuffer->SetPosition(x,y,z,DS3D_DEFERRED)
|
---|
| 407 | If hr=S_OK Then
|
---|
| 408 | SetPosition=TRUE
|
---|
| 409 | Else
|
---|
| 410 | SetPosition=FALSE
|
---|
| 411 | End If
|
---|
| 412 | End Function
|
---|
| 413 |
|
---|
| 414 | '音源の速度の設定
|
---|
| 415 | Function SetVelocity(x As Single, y As Single, z As Single) As Long
|
---|
| 416 | Dim hr As Long
|
---|
| 417 | hr=lpDS3DBuffer->SetVelocity(x,y,z,DS3D_DEFERRED)
|
---|
| 418 | If hr=S_OK Then
|
---|
| 419 | SetVelocity=TRUE
|
---|
| 420 | Else
|
---|
| 421 | SetVelocity=FALSE
|
---|
| 422 | End If
|
---|
| 423 | End Function
|
---|
| 424 |
|
---|
| 425 | '音源のコーン角度の設定
|
---|
| 426 | Function SetConeAngles(dwInsideAngle As DWord, dwOutsideAngle As DWord) As Long
|
---|
| 427 | Dim hr As Long
|
---|
| 428 | hr=lpDS3DBuffer->SetConeAngles(dwInsideAngle,dwOutsideAngle,DS3D_DEFERRED)
|
---|
| 429 | If hr=S_OK Then
|
---|
| 430 | SetConeAngles=TRUE
|
---|
| 431 | Else
|
---|
| 432 | SetConeAngles=FALSE
|
---|
| 433 | End If
|
---|
| 434 | End Function
|
---|
| 435 |
|
---|
| 436 | '音源のコーン方向の設定
|
---|
| 437 | Function SetConeOrientation(x As Single, y As Single, z As Single) As Long
|
---|
| 438 | Dim hr As Long
|
---|
| 439 | hr=lpDS3DBuffer->SetConeOrientation(x,y,z,DS3D_DEFERRED)
|
---|
| 440 | If hr=S_OK Then
|
---|
| 441 | SetConeOrientation=TRUE
|
---|
| 442 | Else
|
---|
| 443 | SetConeOrientation=FALSE
|
---|
| 444 | End If
|
---|
| 445 | End Function
|
---|
| 446 |
|
---|
| 447 | '音源の外部角度の外側ボリュームの設定(1/100 dB 単位で指定)
|
---|
| 448 | Function SetConeOutsideVolume(ConeOutsideVolume As Long)
|
---|
| 449 | Dim hr As Long
|
---|
| 450 | hr=lpDS3DBuffer->SetConeOutsideVolume(ConeOutsideVolume,DS3D_DEFERRED)
|
---|
| 451 | If hr=S_OK Then
|
---|
| 452 | SetConeOutsideVolume=TRUE
|
---|
| 453 | Else
|
---|
| 454 | SetConeOutsideVolume=FALSE
|
---|
| 455 | End If
|
---|
| 456 | End Function
|
---|
| 457 | End Class
|
---|
| 458 |
|
---|
| 459 | 'リスナー
|
---|
| 460 | Class CListener
|
---|
| 461 | lpDS3DListener As LPDIRECTSOUND3DLISTENER8
|
---|
| 462 | Public
|
---|
| 463 | Sub CListener()
|
---|
| 464 | Dim hr As Long
|
---|
| 465 | Dim lpDMAudioPath As *IDirectMusicAudioPath8 'オーディオパス
|
---|
| 466 |
|
---|
| 467 | 'オーディオパスの生成
|
---|
| 468 | hr = dx_lpDMPerformance->CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D, 64, FALSE, VarPtr(lpDMAudioPath))
|
---|
| 469 | If hr Then
|
---|
| 470 | lpDMAudioPath=0
|
---|
| 471 | Exit Sub
|
---|
| 472 | End If
|
---|
| 473 |
|
---|
| 474 | 'リスナーの取得
|
---|
| 475 | hr = lpDMAudioPath->GetObjectInPath(0, DMUS_PATH_PRIMARY_BUFFER, 0,
|
---|
| 476 | GUID_NULL, 0, IID_IDirectSound3DListener8, VarPtr(lpDS3DListener))
|
---|
| 477 | If hr Then
|
---|
| 478 | lpDS3DListener=0
|
---|
| 479 | Exit Sub
|
---|
| 480 | End If
|
---|
| 481 |
|
---|
| 482 | 'オーディオパスを破棄
|
---|
| 483 | lpDMAudioPath->Release()
|
---|
| 484 | End Sub
|
---|
| 485 | Sub ~CListener()
|
---|
| 486 | If lpDS3DListener Then lpDS3DListener->Release()
|
---|
| 487 | End Sub
|
---|
| 488 |
|
---|
| 489 | 'リスナーの位置の設定
|
---|
| 490 | Function SetPosition(x As Single, y As Single, z As Single) As Long
|
---|
| 491 | Dim hr As Long
|
---|
| 492 | hr=lpDS3DListener->SetPosition(x,y,z,DS3D_DEFERRED)
|
---|
| 493 | If hr=S_OK Then
|
---|
| 494 | SetPosition=TRUE
|
---|
| 495 | Else
|
---|
| 496 | SetPosition=FALSE
|
---|
| 497 | End If
|
---|
| 498 | End Function
|
---|
| 499 |
|
---|
| 500 | 'リスナーの速度の設定
|
---|
| 501 | Function SetVelocity(x As Single, y As Single, z As Single) As Long
|
---|
| 502 | Dim hr As Long
|
---|
| 503 | hr=lpDS3DListener->SetVelocity(x,y,z,DS3D_DEFERRED)
|
---|
| 504 | If hr=S_OK Then
|
---|
| 505 | SetVelocity=TRUE
|
---|
| 506 | Else
|
---|
| 507 | SetVelocity=FALSE
|
---|
| 508 | End If
|
---|
| 509 | End Function
|
---|
| 510 |
|
---|
| 511 | 'リスナーの方向の設定
|
---|
| 512 | Function SetOrientation(FrontX As Single, FrontY As Single, FrontZ As Single, TopX As Single, TopY As Single, TopZ As Single) As Long
|
---|
| 513 | Dim hr As Long
|
---|
| 514 | hr=lpDS3DListener->SetOrientation(
|
---|
| 515 | FrontX,FrontY,FrontZ,
|
---|
| 516 | TopX,TopY,TopZ,
|
---|
| 517 | DS3D_DEFERRED)
|
---|
| 518 | If hr=S_OK Then
|
---|
| 519 | SetOrientation=TRUE
|
---|
| 520 | Else
|
---|
| 521 | SetOrientation=FALSE
|
---|
| 522 | End If
|
---|
| 523 | End Function
|
---|
| 524 |
|
---|
| 525 | 'リスナー及び音源の状況を更新する
|
---|
| 526 | Function CommitSettings() As BOOL
|
---|
| 527 | Dim hr As Long
|
---|
| 528 | hr=lpDS3DListener->CommitDeferredSettings()
|
---|
| 529 | If hr=S_OK Then
|
---|
| 530 | CommitSettings=TRUE
|
---|
| 531 | Else
|
---|
| 532 | CommitSettings=FALSE
|
---|
| 533 | End If
|
---|
| 534 | End Function
|
---|
| 535 | End Class
|
---|