MxEngine
AudioSource.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include "Utilities/Math/Math.h"
32 #include "Platform/AudioAPI.h"
33 #include "Utilities/ECS/Component.h"
34 
35 namespace MxEngine
36 {
38  {
39  MAKE_COMPONENT(AudioSource);
40 
43  float currentVolume = 1.0f;
44  float currentSpeed = 1.0f;
45  Vector3 velocity = MakeVector3(0.0f);
46  Vector3 direction = MakeVector3(0.0f, 0.0f, 1.0f);
47  float outerAngleVolume = 0.0f;
48  float outerAngle = 360.0f;
49  float innerAngle = 360.0f;
50  float rollofFactor = 1.0f;
51  float referenceDistance = 1.0f;
52  bool isLooping = false;
53  bool isPlaying = false;
54  bool isRelative = false;
55  public:
56  void OnUpdate();
57  void Init();
58  ~AudioSource();
59  AudioSource() = default;
60  AudioSource(const AResource<AudioBuffer>& buffer);
61 
62  void Load(const AResource<AudioBuffer>& buffer);
63  AResource<AudioBuffer> GetLoadedSource() const;
64 
65  void Play();
66  void Stop();
67  void Pause();
68  void Reset();
69  void Replay();
70  void SetVolume(float volume);
71  void SetLooping(bool value);
72  void SetRelative(bool value);
73  void SetPlaybackSpeed(float speed);
74  void SetVelocity(const Vector3& velocity);
75  void SetDirection(const Vector3& direction);
76  void SetOuterAngle(float angle);
77  void SetInnerAngle(float angle);
78  void SetOuterAngleVolume(float volume);
79  void SetRollofFactor(float factor);
80  void SetReferenceDistance(float distance);
81  void MakeOmnidirectional();
82  bool IsOmnidirectional() const;
83  bool IsLooping() const;
84  bool IsPlaying() const;
85  bool IsRelative() const;
86  float GetVolume() const;
87  float GetSpeed() const;
88  float GetOuterAngleVolume() const;
89  float GetOuterAngle() const;
90  float GetInnerAngle() const;
91  const Vector3& GetVelocity() const;
92  const Vector3& GetDirection() const;
93  float GetRollofFactor() const;
94  float GetReferenceDistance() const;
95  };
96 }
Definition: AbstractFactory.h:61
Definition: AudioSource.h:37
Definition: Application.cpp:49