VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
AudioSourceComponent.hpp
Go to the documentation of this file.
1
6
7#pragma once
8#include <SDL3/SDL.h>
9#include "SDL3/SDL_audio.h"
10#include "components/ErrorUtils.hpp"
11#include "components/AssetTypes.hpp"
12#include <string>
14
15namespace vex {
16
17 struct AudioClip {
18 Uint8* buffer = nullptr;
19 Uint32 length = 0;
20 SDL_AudioSpec spec;
21 bool valid = false;
22 bool isVorbisAllocated = false;
23
24 AudioClip(const std::string& path, vex::VirtualFileSystem* vfs);
25
26 ~AudioClip() {
27 if (buffer) {
28 if (isVorbisAllocated) {
29 free(buffer);
30 } else {
31 SDL_free(buffer);
32 }
33 }
34 }
35 };
36
37enum class AudioState {
38 STOPPED,
39 PLAYING,
40 PAUSED
41};
42
44private:
45 AudioClip* clip = nullptr;
46 AudioState state = AudioState::STOPPED;
47public:
48 audio_asset_path audioFilePath;
49 bool loop = false;
50 bool is3D = false;
51 bool autoPlay = false;
52 float volume = 1.0f;
53 float pitch = 1.0f;
54 float distance = 50.0f;
55
56 bool stateDirty = false;
57
58 void setAudioClip(AudioClip* newClip) {
59 //if (clip) delete clip;
60 clip = newClip;
61 }
62
63 AudioClip* getAudioClip() {
64 return clip;
65 }
66
67 void Play() {
68 if (state != AudioState::PLAYING) {
69 state = AudioState::PLAYING;
70 stateDirty = true;
71 }
72 }
73
74 void Stop() {
75 if (state != AudioState::STOPPED) {
76 state = AudioState::STOPPED;
77 stateDirty = true;
78 }
79 }
80
81 void Pause() {
82 if (state != AudioState::PAUSED) {
83 state = AudioState::PAUSED;
84 stateDirty = true;
85 }
86 }
87
88 AudioState getState() {
89 return state;
90 }
91};
92
93}
This file defines VirtualFileSystem and VPKStream classes.
This class provides abstraction of file system needed for loading packed and unpacked assets.
Specific wrapper for Audio.