Polyphase Game Engine
Loading...
Searching...
No Matches
Audio3d.h
Go to the documentation of this file.
1#pragma once
2
3#include "Nodes/3D/Node3d.h"
4
5#include "Assets/SoundWave.h"
6
8{
9public:
10
12
13 Audio3D();
14 ~Audio3D();
15
16 virtual const char* GetTypeName() const override;
17 virtual void GatherProperties(std::vector<Property>& outProps) override;
18 virtual void GatherProxyDraws(std::vector<DebugDraw>& inoutDraws) override;
19
20 virtual void Create() override;
21 virtual void Destroy() override;
22 virtual void Start() override;
23 virtual void Tick(float deltaTime) override;
24 virtual void EditorTick(float deltaTime) override;
25
26 void SetSoundWave(SoundWave* soundWave);
27 SoundWave* GetSoundWave();
28
29 void SetInnerRadius(float innerRadius);
30 float GetInnerRadius() const;
31
32 void SetOuterRadius(float outerRadius);
33 float GetOuterRadius() const;
34
35 void SetVolume(float volume);
36 float GetVolume() const;
37
38 void SetPitch(float pitch);
39 float GetPitch() const;
40
41 void SetStartOffset(float startOffset);
42 float GetStartOffset() const;
43
44 void SetPriority(int32_t priority);
45 int32_t GetPriority() const;
46
47 void SetAttenuationFunc(AttenuationFunc func);
48 AttenuationFunc GetAttenuationFunc() const;
49
50 void SetAudioClass(int8_t audioClass);
51 int8_t GetAudioClass() const;
52
53 void SetLoop(bool loop);
54 bool GetLoop() const;
55
56 void SetAutoPlay(bool autoPlay);
57 bool GetAutoPlay() const;
58
59 float GetPlayTime() const;
60 // Duration of the assigned SoundWave in seconds (0 if no wave).
61 float GetDuration() const;
62 // Current play position as [0, 1] of the assigned wave's duration. Looping wraps via fmod,
63 // non-looping clamps at 1.0. Returns 0 when there's no wave or duration is 0.
64 float GetPlayTimeNormalized() const;
65 bool IsPlaying() const;
66 bool IsAudible() const;
67
68 void Play();
69 void Stop();
70 void Pause();
71
72 // Old methods kept for script compatibility; these do the same thing as the above Play/Pause/Stop.
73 void PlayAudio();
74 void PauseAudio();
75 void StopAudio();
76 void ResetAudio();
77
78
79 void PlayAudio(SoundWave* soundWave, bool loop);
80
81 // One-shot 3D voice at this node's world position, using its inner/outer radius
82 // and attenuation curve. Pass volume < 0 / pitch < 0 to inherit this node's
83 // current values (default). Does not loop.
84 void PlayOneShot(SoundWave* soundWave, float volume = -1.0f, float pitch = -1.0f, int priority = 0);
85
86 // Seek playback to an absolute time in seconds. If a voice is currently bound it is
87 // released; the next AudioManager tick re-spawns it at the new cursor (or stays silent
88 // until PlayAudio() if the node is paused). Cursor wraps via mod against duration.
89 void Seek(float seconds);
90 // Seek to a [0, 1] fraction of the assigned wave's duration. Drop-in for slider scrubbing.
91 void SeekNormalized(float t);
92
93 // Audio analysis — wraps AUD_Get* on this node's currently-bound voice.
94 // All return 0 / zero-fill when the node isn't currently audible.
95 float GetRMS() const;
96 float GetLoudness() const;
97 float GetLoudnessDb() const;
98 float GetFrequencies(float startHz, float endHz) const;
99 void GetSpectrum(float startHz, float endHz, float* outBins, uint32_t numBins) const;
100
101 void NotifyAudible(bool audible);
102
103 // Called by AudioManager when this node's voice plays to its natural end (non-looping).
104 // Emits the "OnFinished" signal and invokes the script's OnFinished() callback.
105 void OnSoundFinished();
106
107 static bool HandlePropChange(Datum* datum, uint32_t index, const void* newValue);
108
109protected:
110
111 void TickCommon(float deltaTime);
112
113 // Properties
115 float mInnerRadius = 0.0f;
116 float mOuterRadius = 15.0f;
117 float mVolume = 1.0f;
118 float mPitch = 1.0f;
119 float mStartOffset = 0.0f;
120 int32_t mPriority = 0;
122 int8_t mAudioClass = -1;
123 bool mLoop = false;
124 bool mAutoPlay = false;
125
126 // State
127 float mPlayTime = 0.0f;
128 bool mPlaying = false;
129 bool mAudible = false;
130};
void PlayAudio(uint32_t sourceIndex, SoundWave *soundWave, Audio3D *component, float volumeMult, float pitchMult, int32_t priority, glm::vec3 position, float innerRadius, float outerRadius, AttenuationFunc attenFunc, int32_t audioClass, bool loop, float startTime)
Definition AudioManager.cpp:174
void StopAudio(uint32_t sourceIndex)
Definition AudioManager.cpp:231
AttenuationFunc
Definition EngineTypes.h:485
bool IsPlaying()
Definition Engine.cpp:1502
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition AssetRef.h:18
Definition Audio3d.h:8
DECLARE_NODE(Audio3D, Node3D)
SoundWaveRef mSoundWave
Definition Audio3d.h:114
Definition Datum.h:169
Definition Node3d.h:14
virtual void Create() override
Definition Node3d.cpp:96
virtual const char * GetTypeName() const override
Definition Node3d.cpp:119
virtual void Destroy() override
Definition Node3d.cpp:101
virtual void Tick(float deltaTime) override
Definition Node3d.cpp:114
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Node3d.cpp:124
virtual void GatherProxyDraws(std::vector< DebugDraw > &inoutDraws)
Definition Node3d.cpp:298
void TickCommon(float deltaTime)
Definition Node.cpp:588
virtual void EditorTick(float deltaTime)
Definition Node.cpp:578
virtual void Stop()
Definition Node.cpp:519
static bool HandlePropChange(Datum *datum, uint32_t index, const void *newValue)
Definition Node.cpp:89
virtual void Start()
Definition Node.cpp:474
Definition SoundWave.h:6