home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / audio_sdk / src / AudioLib / Sound3D.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-07-14  |  18.3 KB  |  733 lines

  1. /***********************************************************\
  2. Copyright (C) James Boer, 2002. 
  3. All rights reserved worldwide.
  4.  
  5. This software is provided "as is" without express or implied
  6. warranties. You may freely copy and compile this source into
  7. applications you distribute provided that the copyright text
  8. below is included in the resulting source code, for example:
  9. "Portions Copyright (C) James Boer, 2002"
  10. \***********************************************************/
  11.  
  12. #include "Sound3D.h"
  13. #include "AudioCommon.h"
  14. #include "AudioMgr.h"
  15.  
  16. using namespace std;
  17. using namespace Audio;
  18.  
  19. IMPLEMENT_POOL(Sound3D);
  20.  
  21. //------------------------------------------------------------------------//
  22. Sound3D::Sound3D()
  23. {
  24.     FN("Sound3D::Sound3D()");
  25.     Clear();
  26. }
  27.  
  28.  
  29. //------------------------------------------------------------------------//
  30. Sound3D::~Sound3D()
  31. {
  32.     FN("Sound3D::~Sound3D()");
  33.     Term();
  34. }
  35.  
  36.  
  37. //------------------------------------------------------------------------//
  38. void Sound3D::Clear()
  39. {
  40.     FN("Sound3D::Clear()");
  41.  
  42.     m_p3DBuffer = 0;
  43.     m_EAXBuffer.Clear();
  44.     m_ZoomFX.Clear();
  45.     m_PropertySet.Clear();
  46.     m_pSound = 0;
  47.     m_bInitialized = false;
  48.     m_Init.Clear();
  49.     m_bQueuePlayback = false;
  50.     m_bLoading = false;
  51.     m_bLoaded = false;
  52. }
  53.  
  54.  
  55.  
  56. //------------------------------------------------------------------------//
  57. bool Sound3D::Init(const Sound3DInit& init)
  58. {
  59.     FN("Sound3D::Init()");
  60.  
  61.     // Set the audio definition
  62.     m_Init = init;
  63.     SoundInit sndinit;
  64.     sndinit.m_sFileName = m_Init.m_sFileName;
  65.     sndinit.m_bStreaming = m_Init.m_bStreaming;
  66.     sndinit.m_bLooping = m_Init.m_bLooping;
  67.     sndinit.m_nPriority = 0xFFFFFFFF;
  68.     sndinit.m_Prop.m_fVolume = m_Init.m_Prop.m_fVolume;
  69.     sndinit.m_Prop.m_fPitch = m_Init.m_Prop.m_fPitch;
  70.  
  71.     if(!DXAudioMgr()->CreateSound((ISound*&)m_pSound))
  72.         return false;
  73.  
  74.     if(!m_pSound->Init(sndinit))
  75.         return false;
  76.     m_pSound->m_b3DSound = true;
  77.  
  78.     m_bInitialized = true;
  79.  
  80.     return true;
  81. }
  82.  
  83.  
  84. //------------------------------------------------------------------------//
  85. void Sound3D::Term()
  86. {
  87.     FN("Sound3D::Term()");
  88.  
  89.     // Unload the sound
  90.     Unload();
  91.  
  92.     m_EAXBuffer.Term();
  93.     m_ZoomFX.Term();
  94.     m_PropertySet.Term();
  95.  
  96.     // Terminate the sound buffer object
  97.     if(m_pSound)
  98.     {
  99.         m_pSound->Term();
  100.         m_pSound = 0;
  101.     }
  102.  
  103.     Clear();
  104. }
  105.  
  106.  
  107. //------------------------------------------------------------------------//
  108. void Sound3D::Destroy()
  109. {
  110.     FN("Sound3D::Destroy()");
  111.     Term();
  112.     Sound3D::DestroyObject(this);
  113. }
  114.  
  115.  
  116. //------------------------------------------------------------------------//
  117. bool Sound3D::Load()
  118. {
  119.     FN("Sound3D::Load()");
  120.  
  121.     // Make sure we don't reload the sound
  122.     if(IsLoaded() || IsLoading())
  123.         return true;
  124.  
  125.     // If not loading asyncronously, load immediately and return
  126.     if(!DXAudioMgr()->LoadAsync())
  127.         return DoLoad();
  128.     
  129.     // Otherwise, schedule the audio manager to asynchronously load this sound
  130.     m_bLoading = true;
  131.     DXAudioMgr()->ScheduleLoad(this);
  132.  
  133.     return true;
  134. }
  135.  
  136.  
  137. //------------------------------------------------------------------------//
  138. bool Sound3D::DoLoad()
  139. {
  140.     FN("Sound3D::DoLoad()");
  141.  
  142.     // Make sure we don't reload the sound if it's already loaded
  143.     if(IsLoaded())
  144.         return true;
  145.  
  146.     // Make sure we have a valid sound object to work with.
  147.     if(!m_pSound)
  148.         return false;
  149.  
  150.     // Ensure we're not over the buffer limit
  151.     if(!DXAudioMgr()->CanAddSound3D())
  152.         DXAudioMgr()->RemoveSound3D(this);
  153.     
  154.     if(!m_pSound->DoLoad())
  155.         return false;
  156.  
  157.     // Get the 3d sound buffer interface
  158.     HRESULT hr = m_pSound->m_pDSBuffer->QueryInterface(IID_IDirectSound3DBuffer8, (void**)&m_p3DBuffer);
  159.     if(FAILED(hr))
  160.     {
  161.         m_pSound->Unload();
  162.         return Error::Handle("Could not get 3d sound interface.  Error = %s.", DXGetErrorString(hr));
  163.     }
  164.  
  165.     // Retrieve and (re)load all property sets for this buffer
  166.     m_PropertySet.OnLoad(m_p3DBuffer);
  167.     m_EAXBuffer.OnLoad(m_p3DBuffer);
  168.     m_ZoomFX.OnLoad(m_p3DBuffer);
  169.  
  170.     // Insert the 3d sound into the loaded list
  171.     DXAudioMgr()->OnLoadSound3D(this);
  172.  
  173.     // Set all 3d properties for this buffer
  174.     if(!SetProperties(m_Init.m_Prop))
  175.         return false;
  176.  
  177.     m_bLoading = false;
  178.     m_bLoaded = true;
  179.  
  180.     if(m_bQueuePlayback)
  181.         Play();
  182.  
  183.     return true;
  184. }
  185.  
  186.  
  187. //------------------------------------------------------------------------//
  188. bool Sound3D::Unload()
  189. {
  190.     FN("Sound3D::Unload()");
  191.  
  192.     // Make sure the sound isn't already unloaded
  193.     if(!IsLoaded())
  194.         return true;
  195.  
  196.     // Wait until a sound is completely loaded before unloading it
  197.     while(IsLoading());
  198.  
  199.     // Stop the buffer before unloading
  200.     Stop();
  201.  
  202.     // Safely release the 3d buffer and property set interfaces
  203.     m_ZoomFX.OnUnload();
  204.     m_EAXBuffer.OnUnload();
  205.     m_PropertySet.OnUnload();
  206.     SAFE_RELEASE(m_p3DBuffer);
  207.  
  208.     // Unlock and unload the sound buffer
  209.     if(m_pSound)
  210.         m_pSound->Unload();
  211.  
  212.     // Remove the sound from the loaded list
  213.     DXAudioMgr()->OnUnloadSound3D(this);
  214.  
  215.     // Mark the sound as unloaded
  216.     m_bLoaded = false;
  217.  
  218.     DebugOut(1, "Unloaded sound %s", m_Init.m_sFileName.c_str());
  219.     return true;
  220. }
  221.  
  222.  
  223. //------------------------------------------------------------------------//
  224. bool Sound3D::Play()
  225. {
  226.     FN("Sound3D::Play()");
  227.  
  228.         // Mark the play time for prioritization
  229.     if(m_pSound)
  230.         m_pSound->m_nLastTimePlayed = timeGetTime();
  231.  
  232.     // Determine if we need to load this buffer before playing.  After the
  233.     // buffer is finished loading, playback will begin automatically.
  234.     if(IsLoading())
  235.     {
  236.         m_bQueuePlayback = true;
  237.         return true;
  238.     }
  239.     else if(!IsLoaded())
  240.     {
  241.         m_bQueuePlayback = true;
  242.         return Load();
  243.     }
  244.     // Clear queue play flag
  245.     m_bQueuePlayback = false;
  246.  
  247.     // Make sure we have a valid sound buffers
  248.     if(!m_pSound)
  249.         return false;
  250.  
  251.     return m_pSound->Play();
  252. }
  253.  
  254.  
  255. //------------------------------------------------------------------------//
  256. bool Sound3D::Stop()
  257. {
  258.     FN("Sound3D::Stop()");
  259.  
  260.     m_bQueuePlayback = false;
  261.  
  262.     m_Init.m_Prop.m_nReadCursor = 0;
  263.     if(!m_pSound)
  264.         return false;
  265.     return m_pSound->Stop();
  266. }
  267.  
  268.  
  269. //------------------------------------------------------------------------//
  270. bool Sound3D::Pause()
  271. {
  272.     FN("Sound3D::Pause()");
  273.     if(!m_pSound)
  274.         return false;
  275.     return m_pSound->Pause();
  276. }
  277.  
  278.  
  279. //------------------------------------------------------------------------//
  280. bool Sound3D::IsPlaying() const
  281. {
  282.     FN("Sound3D::IsPlaying()");
  283.     if(m_pSound && m_pSound->IsPlaying())
  284.         return true;
  285.     return m_bQueuePlayback;
  286. }
  287.  
  288.  
  289. //------------------------------------------------------------------------//
  290. bool Sound3D::IsPaused() const
  291. {
  292.     FN("Sound3D::IsPaused()");
  293.     if(!m_pSound)
  294.         return false;
  295.     return m_pSound->IsPaused();
  296. }
  297.  
  298.  
  299. //------------------------------------------------------------------------//
  300. bool Sound3D::IsLooping() const
  301. {
  302.     FN("Sound3D::IsLooping()");
  303.     return m_Init.m_bLooping;
  304. }
  305.  
  306.  
  307. //------------------------------------------------------------------------//
  308. bool Sound3D::SetVolume(float fVolume)
  309. {
  310.     FN("Sound3D::SetVolume(%f)", fVolume);
  311.     m_Init.m_Prop.m_fVolume = fVolume;
  312.     if(m_pSound)
  313.         return m_pSound->SetVolume(fVolume);
  314.     return true;
  315. }
  316.  
  317.  
  318. //------------------------------------------------------------------------//
  319. bool Sound3D::GetVolume(float& fVolume) const
  320. {
  321.     FN("Sound3D::GetVolume()");
  322.     fVolume = m_Init.m_Prop.m_fVolume;
  323.     return true;
  324. }
  325.  
  326.  
  327. //------------------------------------------------------------------------//
  328. bool Sound3D::SetPitch(float fPitch)
  329. {
  330.     FN("Sound3D::SetPitch(%f)", fPitch);
  331.     m_Init.m_Prop.m_fPitch = fPitch;
  332.     if(m_pSound)
  333.         return m_pSound->SetPitch(fPitch);
  334.     return true;
  335. }
  336.  
  337.  
  338. //------------------------------------------------------------------------//
  339. bool Sound3D::GetPitch(float& fPitch) const
  340. {
  341.     FN("Sound3D::GetPitch()");
  342.     fPitch = m_Init.m_Prop.m_fPitch;
  343.     return true;
  344. }
  345.  
  346.  
  347. //------------------------------------------------------------------------//
  348. bool Sound3D::SetReadCursor(uint32 nBytes)
  349. {
  350.     FN("Sound3D::SetReadCursor(%d)", nBytes);
  351.     m_Init.m_Prop.m_nReadCursor = nBytes;
  352.     if(m_pSound)
  353.         return m_pSound->SetReadCursor(nBytes);
  354.     return true;
  355. }
  356.  
  357.  
  358. //------------------------------------------------------------------------//
  359. bool Sound3D::GetReadCursor(uint32& nBytes) const
  360. {
  361.     FN("Sound3D::GetCurrentPos()");
  362.     if(!m_pSound)
  363.         return false;
  364.     return m_pSound->GetReadCursor(nBytes);
  365. }
  366.  
  367.  
  368. //------------------------------------------------------------------------//
  369. bool Sound3D::GetSourceSize(uint32& nBytes) const
  370. {
  371.     FN("Sound3D::GetSourceSize()");
  372.     if(!m_pSound)
  373.         return false;
  374.     return m_pSound->GetSourceSize(nBytes);
  375. }
  376.  
  377.  
  378. //------------------------------------------------------------------------//
  379. bool Sound3D::SetProperties(const Sound3DProp& prop)
  380. {
  381.     FN("Sound3D::Set3DProperties()");
  382.     m_Init.m_Prop = prop;
  383.  
  384.     SetVolume(m_Init.m_Prop.m_fVolume);
  385.     SetPitch(m_Init.m_Prop.m_fPitch);
  386.     SetReadCursor(m_Init.m_Prop.m_nReadCursor);
  387.  
  388.     if(m_p3DBuffer)
  389.     {
  390.         DS3DBUFFER dsprop;
  391.         memset(&dsprop, 0, sizeof(DS3DBUFFER));
  392.         dsprop.dwSize = sizeof(DS3DBUFFER);
  393.         dsprop.vPosition = m_Init.m_Prop.m_vPosition;
  394.         dsprop.vVelocity = m_Init.m_Prop.m_vVelocity;
  395.         dsprop.vConeOrientation = m_Init.m_Prop.m_vConeOrientation;
  396.         dsprop.dwInsideConeAngle = m_Init.m_Prop.m_nInsideConeAngle;
  397.         dsprop.dwOutsideConeAngle = m_Init.m_Prop.m_nOutsideConeAngle;
  398.         dsprop.flMinDistance = m_Init.m_Prop.m_fMinDistance;
  399.         dsprop.flMaxDistance = m_Init.m_Prop.m_fMaxDistance;
  400.         dsprop.lConeOutsideVolume = LinearToLogVol(m_Init.m_Prop.m_fConeOutsideVolume);
  401.         dsprop.dwMode = m_Init.m_Prop.m_nMode;
  402.         HRESULT hr = m_p3DBuffer->SetAllParameters(&dsprop, DS3D_DEFERRED);
  403.         if(FAILED(hr))
  404.             return Error::Handle("Could not set 3d parameters.  Error = %s.", DXGetErrorString(hr));
  405.     }
  406.     return true;
  407. }
  408.  
  409.  
  410. //------------------------------------------------------------------------//
  411. bool Sound3D::GetProperties(Sound3DProp& prop) const
  412. {
  413.     FN("Sound3D::Get3DProperties()");
  414.     prop = m_Init.m_Prop;
  415.     return true;
  416. }
  417.  
  418.  
  419. //------------------------------------------------------------------------//
  420. bool Sound3D::SetPosition(const AUDIOVECTOR& vPosition)
  421. {
  422.     FN("Sound3D::SetPosition()");
  423.     m_Init.m_Prop.m_vPosition = vPosition;
  424.     if(m_p3DBuffer)
  425.     {
  426.         HRESULT hr = m_p3DBuffer->SetPosition(
  427.             m_Init.m_Prop.m_vPosition.x,
  428.             m_Init.m_Prop.m_vPosition.y,
  429.             m_Init.m_Prop.m_vPosition.z,
  430.             DS3D_DEFERRED);
  431.         if(FAILED(hr))
  432.             return Error::Handle("Could not set position.  Error = %s.", DXGetErrorString(hr));
  433.     }
  434.     return true;
  435. }
  436.  
  437.  
  438. //------------------------------------------------------------------------//
  439. bool Sound3D::GetPosition(AUDIOVECTOR& vPosition) const
  440. {
  441.     FN("Sound3D::GetPosition()");
  442.     vPosition = m_Init.m_Prop.m_vPosition;
  443.     return true;
  444. }
  445.  
  446.  
  447.  
  448. //------------------------------------------------------------------------//
  449. bool Sound3D::SetVelocity(const AUDIOVECTOR& vVelocity)
  450. {
  451.     FN("Sound3D::SetVelocity()");
  452.     m_Init.m_Prop.m_vVelocity = vVelocity;
  453.     if(m_p3DBuffer)
  454.     {
  455.         HRESULT hr = m_p3DBuffer->SetVelocity(
  456.             m_Init.m_Prop.m_vVelocity.x,
  457.             m_Init.m_Prop.m_vVelocity.y,
  458.             m_Init.m_Prop.m_vVelocity.z,
  459.             DS3D_DEFERRED);
  460.         if(FAILED(hr))
  461.             return Error::Handle("Could not set 3d velocity.  Error = %s.", DXGetErrorString(hr));
  462.     }
  463.     return true;
  464. }
  465.  
  466.  
  467. //------------------------------------------------------------------------//
  468. bool Sound3D::GetVelocity(AUDIOVECTOR& vVelocity) const
  469. {
  470.     FN("Sound3D::GetVelocity()");
  471.     vVelocity = m_Init.m_Prop.m_vVelocity;
  472.     return true;
  473. }
  474.  
  475.  
  476.  
  477. //------------------------------------------------------------------------//
  478. bool Sound3D::SetMaxDistance(float fMaxDist)
  479. {
  480.     FN("Sound3D::SetMaxDistance()");
  481.     m_Init.m_Prop.m_fMaxDistance = fMaxDist;
  482.     if(m_p3DBuffer)
  483.     {
  484.         HRESULT hr = m_p3DBuffer->SetMaxDistance(m_Init.m_Prop.m_fMaxDistance, DS3D_DEFERRED);
  485.         if(FAILED(hr))
  486.             return Error::Handle("Could not set 3d max distance.  Error = %s.", DXGetErrorString(hr));
  487.     }
  488.     return true;
  489. }
  490.  
  491.  
  492. //------------------------------------------------------------------------//
  493. bool Sound3D::GetMaxDistance(float& fMaxDist) const
  494. {
  495.     FN("Sound3D::GetMaxDistance()");
  496.     fMaxDist = m_Init.m_Prop.m_fMaxDistance;
  497.     return true;
  498. }
  499.  
  500.  
  501. //------------------------------------------------------------------------//
  502. bool Sound3D::SetMinDistance(float fMinDist)
  503. {
  504.     FN("Sound3D::SetMinDistance()");
  505.     m_Init.m_Prop.m_fMinDistance = fMinDist;
  506.     if(m_p3DBuffer)
  507.     {
  508.         
  509.         HRESULT hr = m_p3DBuffer->SetMinDistance(m_Init.m_Prop.m_fMinDistance, DS3D_DEFERRED);
  510.         if(FAILED(hr))
  511.             return Error::Handle("Could not set 3d min distance.  Error = %s.", DXGetErrorString(hr));
  512.     }
  513.     return true;
  514. }
  515.  
  516.  
  517. //------------------------------------------------------------------------//
  518. bool Sound3D::GetMinDistance(float& fMinDist) const
  519. {
  520.     FN("Sound3D::GetMinDistance()");
  521.     fMinDist = m_Init.m_Prop.m_fMinDistance;
  522.     return true;
  523. }
  524.  
  525.  
  526. //------------------------------------------------------------------------//
  527. bool Sound3D::SetConeAngles(uint32 nInside, uint32 nOutside)
  528. {
  529.     FN("Sound3D::SetConeAngles()");
  530.     if(m_p3DBuffer)
  531.     {
  532.         HRESULT hr = m_p3DBuffer->SetConeAngles(
  533.             m_Init.m_Prop.m_nInsideConeAngle,
  534.             m_Init.m_Prop.m_nOutsideConeAngle,
  535.             DS3D_DEFERRED);
  536.         if(FAILED(hr))
  537.             return Error::Handle("Could not set 3d cone orientation.  Error = %s.", DXGetErrorString(hr));
  538.     }
  539.     return true;
  540. }
  541.  
  542.  
  543. //------------------------------------------------------------------------//
  544. bool Sound3D::GetConeAngles(uint32& nInside, uint32& nOutside) const
  545. {
  546.     FN("Sound3D::GetConeAngles()");
  547.     nInside = m_Init.m_Prop.m_nInsideConeAngle;
  548.     nOutside = m_Init.m_Prop.m_nOutsideConeAngle;
  549.     return true;
  550. }
  551.  
  552.  
  553. //------------------------------------------------------------------------//
  554. bool Sound3D::SetConeOrientation(const AUDIOVECTOR& vOrientation)
  555. {
  556.     FN("Sound3D::SetConeOrientation()");
  557.     if(m_p3DBuffer)
  558.     {
  559.         HRESULT hr = m_p3DBuffer->SetConeOrientation(
  560.             m_Init.m_Prop.m_vConeOrientation.x,
  561.             m_Init.m_Prop.m_vConeOrientation.y,
  562.             m_Init.m_Prop.m_vConeOrientation.z,
  563.             DS3D_DEFERRED);
  564.         if(FAILED(hr))
  565.             return Error::Handle("Could not set 3d cone orientation.  Error = %s.", DXGetErrorString(hr));
  566.     }        
  567.     return true;
  568. }
  569.  
  570.  
  571. //------------------------------------------------------------------------//
  572. bool Sound3D::GetConeOrientation(AUDIOVECTOR& vOrientation) const
  573. {
  574.     FN("Sound3D::GetConeOrientation()");
  575.     vOrientation = m_Init.m_Prop.m_vConeOrientation;
  576.     return true;
  577. }
  578.  
  579.  
  580. //------------------------------------------------------------------------//
  581. bool Sound3D::SetConeOutsideVolume(float fVolume)
  582. {
  583.     FN("Sound3D::SetConeOutsideVolume()");
  584.     m_Init.m_Prop.m_fConeOutsideVolume = fVolume;
  585.     if(m_p3DBuffer)
  586.     {
  587.         HRESULT hr = m_p3DBuffer->SetConeOutsideVolume(LinearToLogVol(fVolume), DS3D_DEFERRED);
  588.         if(FAILED(hr))
  589.             return Error::Handle("Could not set 3d cone outside volume.  Error = %s.", DXGetErrorString(hr));
  590.     }
  591.     return true;
  592. }
  593.  
  594.  
  595. //------------------------------------------------------------------------//
  596. bool Sound3D::GetConeOutsideVolume(float& fVolume) const
  597. {
  598.     FN("Sound3D::GetConeOutsideVolume()");
  599.     fVolume = m_Init.m_Prop.m_fConeOutsideVolume;
  600.     return true;
  601. }
  602.  
  603.  
  604. //------------------------------------------------------------------------//
  605. bool Sound3D::SetMode(uint32 nMode)
  606. {
  607.     FN("Sound3D::SetMode()");
  608.     if(m_p3DBuffer)
  609.     {
  610.         HRESULT hr = m_p3DBuffer->SetMode(nMode, DS3D_DEFERRED);
  611.         if(FAILED(hr))
  612.             return Error::Handle("Could not set 3d mode.  Error = %s.", DXGetErrorString(hr));
  613.     }        
  614.     return true;
  615. }
  616.  
  617.  
  618. //------------------------------------------------------------------------//
  619. bool Sound3D::GetMode(uint32& nMode) const
  620. {
  621.     FN("Sound3D::GetMode()");
  622.     nMode = m_Init.m_Prop.m_nMode;
  623.     return true;
  624. }
  625.  
  626.  
  627. //------------------------------------------------------------------------//
  628. bool Sound3D::operator < (const Sound3D& snd) const
  629. {
  630.     int iScore = 0;
  631.  
  632.     // We compare five criteria in this priority test:
  633.     // user-defined priority, current play status, 
  634.     // last time played, distance past max, and
  635.     // distance to listener
  636.     if(m_Init.m_nPriority < snd.m_Init.m_nPriority)
  637.         iScore--;
  638.     else if(m_Init.m_nPriority > snd.m_Init.m_nPriority)
  639.         iScore++;
  640.  
  641.     if(IsPlaying())
  642.         iScore++;
  643.     if(snd.IsPlaying())
  644.         iScore--;
  645.  
  646.     if(m_pSound->GetLastPlayTime() < snd.m_pSound->GetLastPlayTime())
  647.         iScore--;
  648.     else if(m_pSound->GetLastPlayTime() > snd.m_pSound->GetLastPlayTime())
  649.         iScore++;
  650.  
  651.     AUDIOVECTOR vLP, vP1, vP2;
  652.     float fDist1, fDist2;
  653.     float fMaxDist;
  654.     IListener* pListener;
  655.     AudioMgr()->GetListener(pListener);
  656.     pListener->GetPosition(vLP);
  657.     GetPosition(vP1);
  658.     snd.GetPosition(vP2);
  659.     fDist1 = sqrt((vLP.x - vP1.x) * (vLP.x - vP1.x) + 
  660.         (vLP.y - vP1.y) * (vLP.y - vP1.y) + 
  661.         (vLP.z - vP1.z) * (vLP.z - vP1.z));
  662.     fDist2 = sqrt((vLP.x - vP2.x) * (vLP.x - vP2.x) + 
  663.         (vLP.y - vP2.y) * (vLP.y - vP2.y) + 
  664.         (vLP.z - vP2.z) * (vLP.z - vP2.z));
  665.  
  666.     GetMaxDistance(fMaxDist);
  667.     if(fDist1 >= fMaxDist)
  668.         iScore -= 2;
  669.     snd.GetMaxDistance(fMaxDist);
  670.     if(fDist2 >= fMaxDist)
  671.         iScore += 2;
  672.  
  673.     if(fDist1 > fDist2)
  674.         iScore--;
  675.     else
  676.         iScore++;
  677.  
  678.     return (iScore < 0) ? true : false;
  679. }
  680.  
  681. //------------------------------------------------------------------------//
  682. // Generic property support (for driver-specific extensions)
  683. bool Sound3D::QuerySupport(const GUID& guid, uint32 nID, uint32* pTypeSupport)
  684. {
  685.     FN("Sound3D::QuerySupport()");
  686.     return m_PropertySet.QuerySupport(guid, nID, pTypeSupport);
  687. }
  688.  
  689.  
  690. //------------------------------------------------------------------------//
  691. bool Sound3D::Get(const GUID& guidProperty, uint32 nID, void* pInstanceData,
  692.         uint32 nInstanceLength, void* pPropData, 
  693.     uint32 nPropLength, uint32* pBytesReturned)
  694. {
  695.     FN("Sound3D::Get()");
  696.     return m_PropertySet.Get(guidProperty, nID, pInstanceData, nInstanceLength, pPropData, 
  697.         nPropLength, pBytesReturned);
  698. }
  699.  
  700.  
  701. //------------------------------------------------------------------------//
  702. bool Sound3D::Set(const GUID& guidProperty, uint32 nID, void* pInstanceData,
  703.     uint32 nInstanceLength, void* pPropData, uint32 nPropLength, bool bStoreProperty)
  704. {
  705.     FN("Sound3D::Set()");
  706.     return m_PropertySet.Set(
  707.         guidProperty, 
  708.         nID, 
  709.         pInstanceData, 
  710.         nInstanceLength, 
  711.         pPropData, 
  712.         nPropLength,
  713.         bStoreProperty);
  714. }
  715.  
  716.  
  717. //------------------------------------------------------------------------//
  718. IEAXBuffer* Sound3D::EAX()
  719. {
  720.     return static_cast<IEAXBuffer*>(&m_EAXBuffer);
  721. }
  722.  
  723. //------------------------------------------------------------------------//
  724. IZoomFX* Sound3D::ZoomFX()
  725. {
  726.     return static_cast<IZoomFX*>(&m_ZoomFX);
  727. }
  728.  
  729.  
  730.  
  731.  
  732.  
  733.