llaudioengine_openal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file audioengine_openal.cpp
  3. * @brief implementation of audio engine using OpenAL
  4. * support as a OpenAL 3D implementation
  5. *
  6. *
  7. * $LicenseInfo:firstyear=2002&license=viewergpl$
  8. *
  9. * Copyright (c) 2002-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #ifndef LL_AUDIOENGINE_OPENAL_H
  35. #define LL_AUDIOENGINE_OPENAL_H
  36. #include "llaudioengine.h"
  37. #include "lllistener_openal.h"
  38. #include "llwindgen.h"
  39. class LLAudioEngine_OpenAL final : public LLAudioEngine
  40. {
  41. protected:
  42. LOG_CLASS(LLAudioEngine_OpenAL);
  43. public:
  44. LLAudioEngine_OpenAL();
  45. bool init(void* user_data) override;
  46. std::string getDriverName(bool verbose) override;
  47. void allocateListener() override;
  48. void shutdown() override;
  49. void setInternalGain(F32 gain) override;
  50. LLAudioBuffer* createBuffer() override;
  51. LLAudioChannel* createChannel() override;
  52. bool initWind() override;
  53. void cleanupWind() override;
  54. void updateWind(LLVector3 direction, F32 camera_altitude) override;
  55. private:
  56. void* windDSP(void *newbuffer, int length);
  57. private:
  58. typedef F32 wind_sample_t;
  59. LLWindGen<wind_sample_t>* mWindGen;
  60. wind_sample_t* mWindBuf;
  61. U32 mWindBufFreq;
  62. U32 mWindBufSamples;
  63. U32 mWindBufBytes;
  64. ALuint mWindSource;
  65. int mNumEmptyWindALBuffers;
  66. };
  67. class LLAudioChannelOpenAL final : public LLAudioChannel
  68. {
  69. protected:
  70. LOG_CLASS(LLAudioChannelOpenAL);
  71. public:
  72. LLAudioChannelOpenAL();
  73. ~LLAudioChannelOpenAL() override;
  74. protected:
  75. void play() override;
  76. void playSynced(LLAudioChannel* channelp) override;
  77. void cleanup() override;
  78. bool isPlaying() override;
  79. bool updateBuffer() override;
  80. void update3DPosition() override;
  81. void updateLoop() override;
  82. protected:
  83. ALuint mALSource;
  84. ALint mLastSamplePos;
  85. };
  86. class LLAudioBufferOpenAL final : public LLAudioBuffer
  87. {
  88. friend class LLAudioChannelOpenAL;
  89. protected:
  90. LOG_CLASS(LLAudioBufferOpenAL);
  91. public:
  92. LLAudioBufferOpenAL();
  93. ~LLAudioBufferOpenAL() override;
  94. bool loadWAV(const std::string& filename) override;
  95. U32 getLength() override;
  96. protected:
  97. void cleanup();
  98. ALuint getBuffer() { return mALBuffer; }
  99. protected:
  100. ALuint mALBuffer;
  101. };
  102. #endif