Open Source Tomb Raider Engine
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.

Sound.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*!
  2. * \file Sound.h
  3. * \brief This is the audio manager Header
  4. *
  5. * Defining UNIT_TEST_SOUND builds Sound class as a console unit test
  6. *
  7. * \author Mongoose
  8. * \author xythobuz
  9. */
  10. #ifndef __OPENRAIDER_MONGOOSE_SOUND_H_
  11. #define __OPENRAIDER_MONGOOSE_SOUND_H_
  12. /*!
  13. * \brief This is the audio manager for OpenRaider
  14. */
  15. class Sound {
  16. public:
  17. typedef enum {
  18. SoundFlagsNone = 0, //!< No FX
  19. SoundFlagsLoop = 1 //!< Enable looping during playback
  20. } SoundFlags;
  21. /*!
  22. * \brief Constructs an object of Sound
  23. */
  24. Sound();
  25. /*!
  26. * \brief Deconstructs an object of Sound
  27. */
  28. ~Sound();
  29. /*!
  30. * \brief Initialize sound system
  31. * \returns 0 on success or < 0 error flags
  32. */
  33. int init();
  34. /*!
  35. * \brief Move listener and repositions them
  36. * \param pos New position for listener
  37. * \param angle New orientation for listener
  38. */
  39. void listenAt(float pos[3], float angle[3]);
  40. /*!
  41. * \brief Move sound source to position
  42. * \param source valid source id
  43. * \param pos new position for source
  44. */
  45. void sourceAt(int source, float pos[3]);
  46. /*!
  47. * \brief Load wav file from disk
  48. * \param filename not NULL!
  49. * \param source not NULL! Returns new source ID or -1 on error.
  50. * \param flags (un)set options. Use SoundFlags enum
  51. * \returns 0 for no error or < 0 error flag
  52. */
  53. int addFile(char *filename, int *source, unsigned int flags);
  54. /*!
  55. * \brief Load wav file from buffer
  56. * \param wav not NULL! Is a valid waveform buffer!
  57. * \param length length of wav buffer
  58. * \param source not NULL! Returns new source ID or -1 on error.
  59. * \param flags (un)set options. Use SoundFlags enum
  60. * \returns 0 for no error or < 0 error flag
  61. */
  62. int addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags);
  63. /*!
  64. * \brief Play sound source
  65. * \param source sound source to play
  66. */
  67. void play(int source);
  68. /*!
  69. * \brief Stop playing sound source
  70. * \param source sound source to stop
  71. */
  72. void stop(int source);
  73. private:
  74. bool mInit; //!< Guard to ensure ausio system is active
  75. unsigned int mBuffer[256]; //!< Audio buffer id list
  76. unsigned int mSource[256]; //!< Audio source id list
  77. unsigned int mNextBuffer; //!< Audio buffer id cursor
  78. unsigned int mNextSource; //!< Audio source id cursor
  79. };
  80. #endif