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.

93 lines
2.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "soundsystem.h"
  9. #include "tier2/riff.h"
  10. #include "filesystem.h"
  11. #include "tier1/strtools.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Implements Audio IO on the engine's COMMON filesystem
  16. //-----------------------------------------------------------------------------
  17. class COM_IOReadBinary : public IFileReadBinary
  18. {
  19. public:
  20. FileHandle_t open( const char *pFileName );
  21. int read( void *pOutput, int size, FileHandle_t file );
  22. void seek( FileHandle_t file, int pos );
  23. unsigned int tell( FileHandle_t file );
  24. unsigned int size( FileHandle_t file );
  25. void close( FileHandle_t file );
  26. };
  27. // prepend sound/ to the filename -- all sounds are loaded from the sound/ directory
  28. FileHandle_t COM_IOReadBinary::open( const char *pFileName )
  29. {
  30. char namebuffer[512];
  31. FileHandle_t hFile;
  32. Q_strncpy(namebuffer, "sound", sizeof( namebuffer ) );
  33. //HACK HACK HACK the server is sending back sound names with slashes in front...
  34. if (pFileName[0]!='/')
  35. {
  36. Q_strncat(namebuffer,"/", sizeof( namebuffer ), COPY_ALL_CHARACTERS );
  37. }
  38. Q_strncat( namebuffer, pFileName, sizeof( namebuffer ), COPY_ALL_CHARACTERS );
  39. hFile = g_pFullFileSystem->Open( namebuffer, "rb", "GAME" );
  40. return hFile;
  41. }
  42. int COM_IOReadBinary::read( void *pOutput, int size, FileHandle_t file )
  43. {
  44. if ( !file )
  45. return 0;
  46. return g_pFullFileSystem->Read( pOutput, size, file );
  47. }
  48. void COM_IOReadBinary::seek( FileHandle_t file, int pos )
  49. {
  50. if ( !file )
  51. return;
  52. g_pFullFileSystem->Seek( file, pos, FILESYSTEM_SEEK_HEAD );
  53. }
  54. unsigned int COM_IOReadBinary::tell( FileHandle_t file )
  55. {
  56. if ( !file )
  57. return 0;
  58. return g_pFullFileSystem->Tell( file );
  59. }
  60. unsigned int COM_IOReadBinary::size( FileHandle_t file )
  61. {
  62. if (!file)
  63. return 0;
  64. return g_pFullFileSystem->Size( file );
  65. }
  66. void COM_IOReadBinary::close( FileHandle_t file )
  67. {
  68. if (!file)
  69. return;
  70. g_pFullFileSystem->Close( file );
  71. }
  72. static COM_IOReadBinary io;
  73. IFileReadBinary *g_pSndIO = &io;