BsOAAudioSource.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsOAPrerequisites.h"
  5. #include "Audio/BsAudioSource.h"
  6. namespace bs
  7. {
  8. /** @addtogroup OpenAudio
  9. * @{
  10. */
  11. /** OpenAL implementation of an AudioSource. */
  12. class OAAudioSource : public AudioSource
  13. {
  14. public:
  15. OAAudioSource();
  16. virtual ~OAAudioSource();
  17. /** @copydoc AudioSource::setClip */
  18. void setClip(const HAudioClip& clip) override;
  19. /** @copydoc AudioSource::setPosition */
  20. void setPosition(const Vector3& position) override;
  21. /** @copydoc AudioSource::setVelocity */
  22. void setVelocity(const Vector3& velocity) override;
  23. /** @copydoc AudioSource::setVolume */
  24. void setVolume(float volume) override;
  25. /** @copydoc AudioSource::setPitch */
  26. void setPitch(float pitch) override;
  27. /** @copydoc AudioSource::setIsLooping */
  28. void setIsLooping(bool loop) override;
  29. /** @copydoc AudioSource::setPriority */
  30. void setPriority(INT32 priority) override;
  31. /** @copydoc AudioSource::setMinDistance */
  32. void setMinDistance(float distance) override;
  33. /** @copydoc AudioSource::setAttenuation */
  34. void setAttenuation(float attenuation) override;
  35. /** @copydoc AudioSource::setTime */
  36. void setTime(float time) override;
  37. /** @copydoc AudioSource::getTime */
  38. float getTime() const override;
  39. /** @copydoc AudioSource::play */
  40. void play() override;
  41. /** @copydoc AudioSource::pause */
  42. void pause() override;
  43. /** @copydoc AudioSource::stop */
  44. void stop() override;
  45. /** @copydoc AudioSource::getState */
  46. AudioSourceState getState() const override { return mState; }
  47. private:
  48. friend class OAAudio;
  49. /** Destroys the internal representation of the audio source. */
  50. void clear();
  51. /** Rebuilds the internal representation of an audio source. */
  52. void rebuild();
  53. /** Streams new data into the source audio buffer, if needed. */
  54. void stream();
  55. /** Starts data streaming from the currently attached audio clip. */
  56. void startStreaming();
  57. /** Stops streaming data from the currently attached audio clip. */
  58. void stopStreaming();
  59. /** Pauses or resumes audio playback due to the global pause setting. */
  60. void setGlobalPause(bool pause);
  61. /**
  62. * Returns true if the sound source is three dimensional (volume and pitch varies based on listener distance
  63. * and velocity).
  64. */
  65. bool is3D() const;
  66. /**
  67. * Returns true if the audio source is receiving audio data from a separate thread (as opposed to loading it all
  68. * at once.
  69. */
  70. bool requiresStreaming() const;
  71. /** Fills the provided buffer with streaming data. */
  72. bool fillBuffer(UINT32 buffer, AudioDataInfo& info, UINT32 maxNumSamples);
  73. /** Makes the current audio clip active. Should be called whenever the audio clip changes. */
  74. void applyClip();
  75. /** @copydoc IResourceListener::onClipChanged */
  76. void onClipChanged() override;
  77. Vector<UINT32> mSourceIDs;
  78. float mSavedTime;
  79. AudioSourceState mSavedState;
  80. AudioSourceState mState;
  81. bool mGloballyPaused;
  82. static const UINT32 StreamBufferCount = 3; // Maximum 32
  83. UINT32 mStreamBuffers[StreamBufferCount];
  84. UINT32 mBusyBuffers[StreamBufferCount];
  85. UINT32 mStreamProcessedPosition;
  86. UINT32 mStreamQueuedPosition;
  87. bool mIsStreaming;
  88. mutable Mutex mMutex;
  89. };
  90. /** @} */
  91. }