BsOAAudioSource.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "BsAudioSource.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup OpenAudio
  9. * @{
  10. */
  11. /** OpenAL implementation of an AudioSource. */
  12. class BS_OA_EXPORT 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(UINT32 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 setTime) 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. private:
  46. friend class OAAudio;
  47. /** Destroys the internal representation of the audio source. */
  48. void clear();
  49. /** Rebuilds the internal representation of an audio source. */
  50. void rebuild();
  51. /** Streams new data into the source audio buffer, if needed. */
  52. void stream();
  53. /** Starts data streaming from the currently attached audio clip. */
  54. void startStreaming();
  55. /** Stops streaming data from the currently attached audio clip. */
  56. void stopStreaming();
  57. /** Pauses or resumes audio playback due to the global pause setting. */
  58. void setGlobalPause(bool pause);
  59. /**
  60. * Returns true if the sound source is three dimensional (volume and pitch varies based on listener distance
  61. * and velocity).
  62. */
  63. bool is3D() const;
  64. /**
  65. * Returns true if the audio source is receiving audio data from a separate thread (as opposed to loading it all
  66. * at once.
  67. */
  68. bool requiresStreaming() const;
  69. /** Fills the provided buffer with streaming data. */
  70. bool fillBuffer(UINT32 buffer, AudioFileInfo& info, UINT32 maxNumSamples);
  71. Vector<UINT32> mSourceIDs;
  72. float mSavedTime;
  73. bool mGloballyPaused;
  74. static const UINT32 StreamBufferCount = 3;
  75. UINT32 mStreamBuffers[StreamBufferCount];
  76. bool mBusyBuffers[StreamBufferCount];
  77. UINT32 mStreamProcessedPosition;
  78. UINT32 mStreamQueuedPosition;
  79. bool mIsStreaming;
  80. mutable Mutex mMutex;
  81. };
  82. /** @} */
  83. }