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.

167 lines
3.5 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "interface.h"
  8. #include "milesbase.h"
  9. #include "vaudio/ivaudio.h"
  10. #include "dbg.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. static S32 AILCALLBACK AudioStreamEventCB( UINTa user, void *dest, S32 bytes_requested, S32 offset )
  14. {
  15. IAudioStreamEvent *pThis = static_cast<IAudioStreamEvent*>( (void *)user);
  16. #if defined( OSX ) && !defined( PLATFORM_64BITS )
  17. // save of the args to local stack vars before we screw with ESP
  18. volatile void *newDest = dest;
  19. volatile S32 newBytes = bytes_requested;
  20. volatile S32 newOffset = offset;
  21. volatile void *oldESP;
  22. // now move ESP to be aligned to 16-bytes
  23. asm volatile(
  24. "movl %%esp,%0\n"
  25. "subl $16,%%esp\n"
  26. "andl $-0x10,%%esp\n"
  27. : "=m" (oldESP) : : "%esp");
  28. int val = pThis->StreamRequestData( (void *)newDest, newBytes, newOffset );
  29. // undo the alignment
  30. asm( "movl %0,%%esp\n" ::"m" (oldESP) );
  31. return val;
  32. #else
  33. return pThis->StreamRequestData( dest, bytes_requested, offset );
  34. #endif
  35. }
  36. class CMilesMP3 : public IAudioStream
  37. {
  38. public:
  39. CMilesMP3();
  40. bool Init( IAudioStreamEvent *pHandler );
  41. virtual ~CMilesMP3();
  42. // IAudioStream functions
  43. virtual int Decode( void *pBuffer, unsigned int bufferSize );
  44. virtual int GetOutputBits();
  45. virtual int GetOutputRate();
  46. virtual int GetOutputChannels();
  47. virtual unsigned int GetPosition();
  48. virtual void SetPosition( unsigned int position );
  49. private:
  50. ASISTRUCT m_decoder;
  51. };
  52. CMilesMP3::CMilesMP3()
  53. {
  54. }
  55. bool CMilesMP3::Init( IAudioStreamEvent *pHandler )
  56. {
  57. return m_decoder.Init( pHandler, ".MP3", ".RAW", &AudioStreamEventCB );
  58. }
  59. CMilesMP3::~CMilesMP3()
  60. {
  61. m_decoder.Shutdown();
  62. }
  63. // IAudioStream functions
  64. int CMilesMP3::Decode( void *pBuffer, unsigned int bufferSize )
  65. {
  66. return m_decoder.Process( pBuffer, bufferSize );
  67. }
  68. int CMilesMP3::GetOutputBits()
  69. {
  70. return m_decoder.GetProperty( m_decoder.OUTPUT_BITS );
  71. }
  72. int CMilesMP3::GetOutputRate()
  73. {
  74. return m_decoder.GetProperty( m_decoder.OUTPUT_RATE );
  75. }
  76. int CMilesMP3::GetOutputChannels()
  77. {
  78. return m_decoder.GetProperty( m_decoder.OUTPUT_CHANNELS );
  79. }
  80. unsigned int CMilesMP3::GetPosition()
  81. {
  82. return m_decoder.GetProperty( m_decoder.POSITION );
  83. }
  84. // NOTE: Only supports seeking forward right now
  85. void CMilesMP3::SetPosition( unsigned int position )
  86. {
  87. m_decoder.Seek( position );
  88. }
  89. class CVAudio : public IVAudio
  90. {
  91. public:
  92. CVAudio()
  93. {
  94. // Assume the user will be creating multiple miles objects, so
  95. // keep miles running while this exists
  96. IncrementRefMiles();
  97. }
  98. virtual ~CVAudio()
  99. {
  100. DecrementRefMiles();
  101. }
  102. IAudioStream *CreateMP3StreamDecoder( IAudioStreamEvent *pEventHandler )
  103. {
  104. CMilesMP3 *pMP3 = new CMilesMP3;
  105. if ( !pMP3->Init( pEventHandler ) )
  106. {
  107. delete pMP3;
  108. return NULL;
  109. }
  110. return pMP3;
  111. }
  112. void DestroyMP3StreamDecoder( IAudioStream *pDecoder )
  113. {
  114. delete pDecoder;
  115. }
  116. void *CreateMilesAudioEngine()
  117. {
  118. IncrementRefMiles();
  119. HDIGDRIVER hDriver = AIL_open_digital_driver( 44100, 16, MSS_MC_51_DISCRETE, 0 );
  120. return (void *)hDriver;
  121. }
  122. void DestroyMilesAudioEngine( void *pEngine )
  123. {
  124. HDIGDRIVER hDriver = HDIGDRIVER(pEngine);
  125. AIL_close_digital_driver( hDriver );
  126. DecrementRefMiles();
  127. }
  128. };
  129. void* CreateVoiceCodec_CVAudio()
  130. {
  131. return new CVAudio;
  132. }
  133. EXPOSE_INTERFACE_FN(CreateVoiceCodec_CVAudio, IVAudio, VAUDIO_INTERFACE_VERSION );