MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PlaySound3d

Method PlaySound3d

sndlib/sdlsound.cpp:378–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378int lnxsound::PlaySound3d(play_information *play_info, int sound_index, pos_state *cur_pos, float adjusted_volume,
379 bool f_looped, float reverb) //, uint16_t frequency
380{
381 float volume = adjusted_volume; // Adjust base volume by sent volume, let 3d stuff do the rest
382
383 if (sound_device == 0)
384 return -1;
385
386 ASSERT(Sounds[sound_index].used != 0);
387 if (Sounds[sound_index].used == 0)
388 return -1;
389
390 float dist;
391 vector dir_to_sound = *cur_pos->position - m_emulated_listener.position;
392 float pan;
393
394 dist = vm_NormalizeVector(&dir_to_sound);
395 if (dist < .1f) {
396 dir_to_sound = m_emulated_listener.orient.fvec;
397 }
398
399 if (dist >= Sounds[sound_index].max_distance) {
400 return -1;
401 } else if (dist > Sounds[sound_index].min_distance) {
402 volume *= (1.0f - ((dist - Sounds[sound_index].min_distance) /
403 (Sounds[sound_index].max_distance - Sounds[sound_index].min_distance)));
404 }
405
406 pan = (dir_to_sound * m_emulated_listener.orient.rvec);
407
408 if (volume < 0.0f)
409 volume = 0.0f;
410 else if (volume > 1.0f)
411 volume = 1.0f;
412
413 if (pan < -1.0f)
414 pan = -1.0f;
415 else if (pan > 1.0f)
416 pan = 1.0f;
417
418 return PlaySound2d(play_info, sound_index, volume, pan, f_looped);
419}
420
421void lnxsound::AdjustSound(int sound_uid, float f_volume, float f_pan, uint16_t frequency) {
422 int current_slot;

Callers 1

Emulate3dSoundMethod · 0.80

Calls 1

vm_NormalizeVectorFunction · 0.85

Tested by

no test coverage detected