BsAudio.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsModule.h"
  6. #include "BsVector3.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Audio
  10. * @{
  11. */
  12. /** Identifier for a device that can be used for playing audio. */
  13. struct AudioDevice
  14. {
  15. WString name;
  16. };
  17. /** Provides global functionality relating to sounds and music. */
  18. class BS_CORE_EXPORT Audio : public Module<Audio>
  19. {
  20. public:
  21. virtual ~Audio() {}
  22. /**
  23. * Starts playback of the provided audio clip. This can be used for a quicker way of creating audio sources if you
  24. * don't need the full control provided by creating AudioSource manually.
  25. *
  26. * @param[in] clip Audio clip to play.
  27. * @param[in] position Position in world space to play the clip at. Only relevant if the clip is 3D.
  28. * @param[in] volume Volume to play the clip at.
  29. */
  30. void play(const HAudioClip& clip, const Vector3& position = Vector3::ZERO, float volume = 1.0f);
  31. /** Sets global audio volume. In range [0, 1]. */
  32. virtual void setVolume(float volume) = 0;
  33. /** Returns global audio volume. In range [0, 1]. */
  34. virtual float getVolume() const = 0;
  35. /** Pauses audio reproduction globally. */
  36. virtual void setPaused(bool paused) = 0;
  37. /** Checks is audio reproduction currently paused. */
  38. virtual bool isPaused() const = 0;
  39. /** Changes the device on which is the audio played back on. */
  40. virtual void setActiveDevice(const AudioDevice& device) = 0;
  41. /** Retrieves the identifier of the device that the audio is currently being played back on. */
  42. virtual AudioDevice getActiveDevice() const = 0;
  43. /** Returns the default audio device identifier. */
  44. virtual AudioDevice getDefaultDevice() const = 0;
  45. /** Returns a list of all available audio devices. */
  46. virtual const Vector<AudioDevice>& getAllDevices() const = 0;
  47. /** @name Internal
  48. * @{
  49. */
  50. /** Called once per frame. Queues streaming audio requests. */
  51. virtual void _update();
  52. /** @} */
  53. protected:
  54. friend class AudioClip;
  55. friend class AudioListener;
  56. friend class AudioSource;
  57. /**
  58. * Creates a new audio clip.
  59. *
  60. * @param[in] samples Stream containing audio samples in format specified in @p desc.
  61. * @param[in] streamSize Size of the audio data in the provided stream, in bytes.
  62. * @param[in] numSamples Number of samples in @p samples stream.
  63. * @param[in] desc Descriptor describing the type of the audio stream (format, sample rate, etc.).
  64. * @return Newly created AudioClip. Must be manually initialized.
  65. */
  66. virtual SPtr<AudioClip> createClip(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples,
  67. const AUDIO_CLIP_DESC& desc) = 0;
  68. /** Creates a new AudioListener. */
  69. virtual SPtr<AudioListener> createListener() = 0;
  70. /** Creates a new AudioSource. */
  71. virtual SPtr<AudioSource> createSource() = 0;
  72. /** Stops playback of all sources started with Audio::play calls. */
  73. void stopManualSources();
  74. private:
  75. Vector<SPtr<AudioSource>> mManualSources;
  76. Vector<SPtr<AudioSource>> mTempSources;
  77. };
  78. /** Provides easier access to Audio. */
  79. BS_CORE_EXPORT Audio& gAudio();
  80. /** @} */
  81. }