sfxALVoice.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFXALVOICE_H_
  23. #define _SFXALVOICE_H_
  24. #ifndef _SFXVOICE_H_
  25. #include "sfx/sfxVoice.h"
  26. #endif
  27. #ifndef _OPENALFNTABLE
  28. #include "sfx/openal/LoadOAL.h"
  29. #endif
  30. #ifndef _PLATFORM_THREADS_MUTEX_H_
  31. #include "platform/threads/mutex.h"
  32. #endif
  33. class SFXALBuffer;
  34. class SFXALDevice;
  35. class SFXALVoice : public SFXVoice
  36. {
  37. public:
  38. typedef SFXVoice Parent;
  39. friend class SFXALDevice;
  40. friend class SFXALBuffer;
  41. protected:
  42. SFXALVoice( const OPENALFNTABLE &oalft,
  43. SFXALBuffer *buffer,
  44. ALuint sourceName );
  45. ALuint mSourceName;
  46. /// Buggy OAL jumps around when pausing. Save playback cursor here.
  47. F32 mResumeAtSampleOffset;
  48. /// Amount by which OAL's reported sample position is offset.
  49. ///
  50. /// OAL's sample position is relative to the current queue state,
  51. /// so we manually need to keep track of how far into the total
  52. /// queue we are.
  53. U32 mSampleOffset;
  54. Mutex mMutex;
  55. const OPENALFNTABLE &mOpenAL;
  56. ///
  57. SFXALBuffer* _getBuffer() const
  58. {
  59. return ( SFXALBuffer* ) mBuffer.getPointer();
  60. }
  61. /// For non-streaming buffers, late-bind the audio buffer
  62. /// to the source as OAL will not accept writes to buffers
  63. /// already bound.
  64. void _lateBindStaticBufferIfNecessary();
  65. // SFXVoice.
  66. virtual SFXStatus _status() const;
  67. virtual void _play();
  68. virtual void _pause();
  69. virtual void _stop();
  70. virtual void _seek( U32 sample );
  71. virtual U32 _tell() const;
  72. public:
  73. static SFXALVoice* create( SFXALDevice* device,
  74. SFXALBuffer *buffer );
  75. virtual ~SFXALVoice();
  76. /// SFXVoice
  77. void setMinMaxDistance( F32 min, F32 max );
  78. void play( bool looping );
  79. void setVelocity( const VectorF& velocity );
  80. void setTransform( const MatrixF& transform );
  81. void setVolume( F32 volume );
  82. void setPitch( F32 pitch );
  83. void setCone( F32 innerAngle, F32 outerAngle, F32 outerVolume );
  84. void setRolloffFactor( F32 factor );
  85. };
  86. #endif // _SFXALVOICE_H_