sfxALBuffer.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 _SFXALBUFFER_H_
  23. #define _SFXALBUFFER_H_
  24. #ifndef _LOADOAL_H
  25. #include "sfx/openal/LoadOAL.h"
  26. #endif
  27. #ifndef _SFXINTERNAL_H_
  28. #include "sfx/sfxInternal.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif
  33. class SFXALVoice;
  34. class SFXALBuffer : public SFXBuffer
  35. {
  36. public:
  37. typedef SFXBuffer Parent;
  38. friend class SFXALDevice;
  39. friend class SFXALVoice;
  40. protected:
  41. /// AL buffer in case this is a static, non-streaming buffer.
  42. ALuint mALBuffer;
  43. /// Free buffers for use in queuing in case this is a streaming buffer.
  44. Vector< ALuint > mFreeBuffers;
  45. ///
  46. SFXALBuffer( const OPENALFNTABLE &oalft,
  47. const ThreadSafeRef< SFXStream >& stream,
  48. SFXDescription* description,
  49. bool useHardware );
  50. ///
  51. bool mIs3d;
  52. ///
  53. bool mUseHardware;
  54. const OPENALFNTABLE &mOpenAL;
  55. ///
  56. ALenum _getALFormat() const
  57. {
  58. return _sfxFormatToALFormat( getFormat() );
  59. }
  60. ///
  61. static ALenum _sfxFormatToALFormat( const SFXFormat& format )
  62. {
  63. if( format.getChannels() == 2 )
  64. {
  65. const U32 bps = format.getBitsPerSample();
  66. if( bps == 16 )
  67. return AL_FORMAT_STEREO8;
  68. else if( bps == 32 )
  69. return AL_FORMAT_STEREO16;
  70. }
  71. else if( format.getChannels() == 1 )
  72. {
  73. const U32 bps = format.getBitsPerSample();
  74. if( bps == 8 )
  75. return AL_FORMAT_MONO8;
  76. else if( bps == 16 )
  77. return AL_FORMAT_MONO16;
  78. }
  79. return 0;
  80. }
  81. ///
  82. SFXALVoice* _getUniqueVoice() const
  83. {
  84. return ( SFXALVoice* ) mUniqueVoice.getPointer();
  85. }
  86. // SFXBuffer.
  87. virtual void write( SFXInternal::SFXStreamPacket* const* packets, U32 num );
  88. void _flush();
  89. public:
  90. static SFXALBuffer* create( const OPENALFNTABLE &oalft,
  91. const ThreadSafeRef< SFXStream >& stream,
  92. SFXDescription* description,
  93. bool useHardware );
  94. virtual ~SFXALBuffer();
  95. };
  96. #endif // _SFXALBUFFER_H_