| 364 | |
| 365 | |
| 366 | handle Soloud::play3d(AudioSource &aSound, float aPosX, float aPosY, float aPosZ, float aVelX, float aVelY, float aVelZ, float aVolume, bool aPaused, unsigned int aBus) |
| 367 | { |
| 368 | handle h = play(aSound, aVolume, 0, 1, aBus); |
| 369 | lockAudioMutex(); |
| 370 | int v = getVoiceFromHandle(h); |
| 371 | if (v < 0) |
| 372 | { |
| 373 | unlockAudioMutex(); |
| 374 | return h; |
| 375 | } |
| 376 | m3dData[v].mHandle = h; |
| 377 | mVoice[v]->mFlags |= AudioSourceInstance::PROCESS_3D; |
| 378 | set3dSourceParameters(h, aPosX, aPosY, aPosZ, aVelX, aVelY, aVelZ); |
| 379 | |
| 380 | int samples = 0; |
| 381 | if (aSound.mFlags & AudioSource::DISTANCE_DELAY) |
| 382 | { |
| 383 | vec3 pos; |
| 384 | pos.mX = aPosX; |
| 385 | pos.mY = aPosY; |
| 386 | pos.mZ = aPosZ; |
| 387 | if (!(mVoice[v]->mFlags & AudioSource::LISTENER_RELATIVE)) |
| 388 | { |
| 389 | pos.mX -= m3dPosition[0]; |
| 390 | pos.mY -= m3dPosition[1]; |
| 391 | pos.mZ -= m3dPosition[2]; |
| 392 | } |
| 393 | float dist = pos.mag(); |
| 394 | samples += (int)floor((dist / m3dSoundSpeed) * mSamplerate); |
| 395 | } |
| 396 | |
| 397 | update3dVoices((unsigned int *)&v, 1); |
| 398 | updateVoiceRelativePlaySpeed(v); |
| 399 | int j; |
| 400 | for (j = 0; j < MAX_CHANNELS; j++) |
| 401 | { |
| 402 | mVoice[v]->mChannelVolume[j] = m3dData[v].mChannelVolume[j]; |
| 403 | } |
| 404 | |
| 405 | updateVoiceVolume(v); |
| 406 | |
| 407 | // Fix initial voice volume ramp up |
| 408 | int i; |
| 409 | for (i = 0; i < MAX_CHANNELS; i++) |
| 410 | { |
| 411 | mVoice[v]->mCurrentChannelVolume[i] = mVoice[v]->mChannelVolume[i] * mVoice[v]->mOverallVolume; |
| 412 | } |
| 413 | |
| 414 | if (mVoice[v]->mOverallVolume < 0.01f) |
| 415 | { |
| 416 | // Inaudible. |
| 417 | mVoice[v]->mFlags |= AudioSourceInstance::INAUDIBLE; |
| 418 | |
| 419 | if (mVoice[v]->mFlags & AudioSourceInstance::INAUDIBLE_KILL) |
| 420 | { |
| 421 | stopVoice(v); |
| 422 | } |
| 423 | } |