Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
3.5 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #include "audio_pch.h"
  7. #if defined( USE_SDL )
  8. #include "snd_dev_sdl.h"
  9. #endif
  10. #if defined(OSX)
  11. #include "snd_dev_openal.h"
  12. #include "snd_dev_mac_audioqueue.h"
  13. #endif
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. bool snd_firsttime = true;
  17. /*
  18. * Global variables. Must be visible to window-procedure function
  19. * so it can unlock and free the data block after it has been played.
  20. */
  21. #if USE_AUDIO_DEVICE_V1
  22. IAudioDevice *g_AudioDevice = NULL;
  23. #else
  24. IAudioDevice2 *g_AudioDevice = NULL;
  25. #endif
  26. /*
  27. ==================
  28. S_BlockSound
  29. ==================
  30. */
  31. void S_BlockSound( void )
  32. {
  33. if ( !g_AudioDevice )
  34. return;
  35. g_AudioDevice->Pause();
  36. }
  37. /*
  38. ==================
  39. S_UnblockSound
  40. ==================
  41. */
  42. void S_UnblockSound( void )
  43. {
  44. if ( !g_AudioDevice )
  45. return;
  46. g_AudioDevice->UnPause();
  47. }
  48. void S_UpdateWindowFocus( bool bWindowHasFocus )
  49. {
  50. if ( !g_AudioDevice )
  51. return;
  52. #if !USE_AUDIO_DEVICE_V1
  53. g_AudioDevice->UpdateFocus( bWindowHasFocus );
  54. #endif
  55. }
  56. /*
  57. ==================
  58. AutoDetectInit
  59. Try to find a sound device to mix for.
  60. Returns a CAudioNULLDevice if nothing is found.
  61. ==================
  62. */
  63. #if USE_AUDIO_DEVICE_V1
  64. IAudioDevice *IAudioDevice::AutoDetectInit()
  65. {
  66. IAudioDevice *pDevice = NULL;
  67. if ( IsPC() )
  68. {
  69. #if defined( WIN32 ) && !defined( USE_SDL )
  70. if ( !pDevice )
  71. {
  72. if ( snd_firsttime )
  73. {
  74. pDevice = Audio_CreateDirectSoundDevice();
  75. }
  76. }
  77. #elif defined(OSX)
  78. if ( !CommandLine()->CheckParm( "-snd_openal" ) )
  79. {
  80. DevMsg( "Using AudioQueue Interface\n" );
  81. pDevice = Audio_CreateMacAudioQueueDevice();
  82. }
  83. if ( !pDevice )
  84. {
  85. DevMsg( "Using OpenAL Interface\n" );
  86. pDevice = Audio_CreateOpenALDevice(); // fall back to openAL if the audio queue fails
  87. }
  88. #elif defined( USE_SDL )
  89. DevMsg( "Trying SDL Audio Interface\n" );
  90. pDevice = Audio_CreateSDLAudioDevice();
  91. #ifdef NEVER
  92. // Jul 2012. mikesart. E-mail exchange with Ryan Gordon after figuring out that
  93. // Audio_CreatePulseAudioDevice() wasn't working on Ubuntu 12.04 (lots of stuttering).
  94. //
  95. // > I installed libpulse-dev, rebuilt SDL, and now SDL is using pulse
  96. // > audio and everything is working great. However I'm wondering if we
  97. // > need to fall back to PulseAudio in our codebase if SDL is doing that
  98. // > for us. I mean, is it worth me going through and debugging our Pulse
  99. // > Audio path or should I just remove it?
  100. //
  101. // Remove it...it never worked well, and only remained in case there were
  102. // concerns about relying on SDL. The SDL codepath is way easier to read,
  103. // simpler to maintain, and handles all sorts of strange audio backends,
  104. // including Pulse.
  105. if ( !pDevice )
  106. {
  107. DevMsg( "Trying PulseAudio Interface\n" );
  108. pDevice = Audio_CreatePulseAudioDevice(); // fall back to PulseAudio if SDL fails
  109. }
  110. #endif // NEVER
  111. #else
  112. #error
  113. #endif
  114. }
  115. #if defined( _X360 )
  116. else
  117. {
  118. pDevice = Audio_CreateXAudioDevice( true );
  119. if ( pDevice )
  120. {
  121. // xaudio requires threaded mixing
  122. S_EnableThreadedMixing( true );
  123. }
  124. }
  125. #endif
  126. snd_firsttime = false;
  127. if ( !pDevice )
  128. {
  129. if ( snd_firsttime )
  130. DevMsg( "No sound device initialized\n" );
  131. return Audio_GetNullDevice();
  132. }
  133. return pDevice;
  134. }
  135. #endif
  136. /*
  137. ==============
  138. SNDDMA_Shutdown
  139. Reset the sound device for exiting
  140. ===============
  141. */
  142. void SNDDMA_Shutdown( void )
  143. {
  144. g_AudioDevice->Shutdown();
  145. delete g_AudioDevice;
  146. g_AudioDevice = NULL;
  147. }