1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Utility/BsModule.h"
7#include "Math/BsVector3.h"
8
9namespace bs
10{
11 /** @addtogroup Audio
12 * @{
13 */
14
15 /** Identifier for a device that can be used for playing audio. */
16 struct BS_SCRIPT_EXPORT(m:Audio,pl:true) AudioDevice
17 {
18 String name;
19 };
20
21 /** Provides global functionality relating to sounds and music. */
22 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Audio) Audio : public Module<Audio>
23 {
24 public:
25 virtual ~Audio() = default;
26
27 /**
28 * Starts playback of the provided audio clip. This can be used for a quicker way of creating audio sources if you
29 * don't need the full control provided by creating AudioSource manually.
30 *
31 * @param[in] clip Audio clip to play.
32 * @param[in] position Position in world space to play the clip at. Only relevant if the clip is 3D.
33 * @param[in] volume Volume to play the clip at.
34 */
35 void play(const HAudioClip& clip, const Vector3& position = Vector3::ZERO, float volume = 1.0f);
36
37 /** Determines global audio volume. In range [0, 1]. */
38 BS_SCRIPT_EXPORT(n:Volume,pr:setter)
39 virtual void setVolume(float volume) = 0;
40
41 /** @copydoc setVolume() */
42 BS_SCRIPT_EXPORT(n:Volume,pr:getter)
43 virtual float getVolume() const = 0;
44
45 /** Determines if audio reproduction is paused globally. */
46 BS_SCRIPT_EXPORT(n:Paused,pr:setter)
47 virtual void setPaused(bool paused) = 0;
48
49 /** @copydoc setPaused() */
50 BS_SCRIPT_EXPORT(n:Paused,pr:getter)
51 virtual bool isPaused() const = 0;
52
53 /** Determines the device on which is the audio played back on. */
54 BS_SCRIPT_EXPORT(n:ActiveDevice,pr:setter)
55 virtual void setActiveDevice(const AudioDevice& device) = 0;
56
57 /** @copydoc setActiveDevice() */
58 BS_SCRIPT_EXPORT(n:ActiveDevice,pr:getter)
59 virtual AudioDevice getActiveDevice() const = 0;
60
61 /** Returns the default audio device identifier. */
62 BS_SCRIPT_EXPORT(n:DefaultDevice,pr:getter)
63 virtual AudioDevice getDefaultDevice() const = 0;
64
65 /** Returns a list of all available audio devices. */
66 BS_SCRIPT_EXPORT(n:AllDevices,pr:getter)
67 virtual const Vector<AudioDevice>& getAllDevices() const = 0;
68
69 /** @name Internal
70 * @{
71 */
72
73 /** Called once per frame. Queues streaming audio requests. */
74 virtual void _update();
75
76 /** @} */
77 protected:
78 friend class AudioClip;
79 friend class AudioListener;
80 friend class AudioSource;
81
82 /**
83 * Creates a new audio clip.
84 *
85 * @param[in] samples Stream containing audio samples in format specified in @p desc.
86 * @param[in] streamSize Size of the audio data in the provided stream, in bytes.
87 * @param[in] numSamples Number of samples in @p samples stream.
88 * @param[in] desc Descriptor describing the type of the audio stream (format, sample rate, etc.).
89 * @return Newly created AudioClip. Must be manually initialized.
90 */
91 virtual SPtr<AudioClip> createClip(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples,
92 const AUDIO_CLIP_DESC& desc) = 0;
93
94 /** Creates a new AudioListener. */
95 virtual SPtr<AudioListener> createListener() = 0;
96
97 /** Creates a new AudioSource. */
98 virtual SPtr<AudioSource> createSource() = 0;
99
100 /** Stops playback of all sources started with Audio::play calls. */
101 void stopManualSources();
102
103 private:
104 Vector<SPtr<AudioSource>> mManualSources;
105 Vector<SPtr<AudioSource>> mTempSources;
106 };
107
108 /** Provides easier access to Audio. */
109 BS_CORE_EXPORT Audio& gAudio();
110
111 /** @} */
112}