GlistEngine
Loading...
Searching...
No Matches
gSound.h
Go to the documentation of this file.
1/*
2 * gSound.h
3 *
4 * Created on: April 13, 2025
5 * Author: Metehan Gezer
6 */
7
8#ifndef GLISTENGINE_GSOUND_H
9#define GLISTENGINE_GSOUND_H
10
11#include "gBaseSound.h"
12#include "miniaudio.h"
13
14
15ma_engine* gGetSoundEngine();
16
25class gSound : public gBaseSound {
26public:
27
29 virtual ~gSound();
30
37 int load(const std::string& fullPath) override;
38
45 int loadSound(const std::string& soundPath) override;
46
50 void play() override;
51
52 bool isLoaded() override;
53
54 bool isPlaying() override;
55
56 bool isPaused() override;
57
63 void setPaused(bool isPaused) override;
64
68 void stop() override;
69
73 void close() override;
74
80 int getDuration() override;
81
87 int getPosition() override;
88
94 void setPosition(int position) override;
95
97
103 void setLoopType(LoopType loopType) override;
104
110 float getVolume() override;
111
117 void setVolume(float volume) override;
118
124 const std::string& getPath() override;
125
126private:
127 ma_sound sound;
128 bool isloaded = false;
129 bool isplaying = false;
130 bool ispaused = false;
131 float volume = 0.5f; // Current volume level [0-1].
132 LoopType looptype = LOOPTYPE_DEFAULT;
133 std::string filepath; // Path to the loaded audio file.
134 int duration = 0; // Duration of the sound in milliseconds.
135 int lastposition = 0; // Last known position, only used for pause/resume logic.
136};
137
138#endif //GLISTENGINE_GSOUND_H
Definition gBaseSound.h:15
LoopType
Definition gBaseSound.h:17
@ LOOPTYPE_DEFAULT
Definition gBaseSound.h:18
A sound class using miniaudio with ma_engine and ma_sound.
Definition gSound.h:25
bool isLoaded() override
virtual ~gSound()
void play() override
Starts sound playback and resets the position to the beginning.
float getVolume() override
Gets the current volume level.
void setPaused(bool isPaused) override
Pauses or resumes the playback.
LoopType getLoopType() override
void setPosition(int position) override
Sets the current playback position in milliseconds.
bool isPaused() override
int getDuration() override
Returns the total duration of the sound in milliseconds.
bool isPlaying() override
void stop() override
Stops playback and resets position to the beginning.
const std::string & getPath() override
Gets the path to the currently loaded file.
int load(const std::string &fullPath) override
Loads a sound file from the full file system path.
void setLoopType(LoopType loopType) override
Sets the loop type for playback.
int getPosition() override
Returns the current playback position in milliseconds.
int loadSound(const std::string &soundPath) override
Loads the sound file from the given project-relative path.
void setVolume(float volume) override
Sets the volume level.
void close() override
Unloads and frees the sound resource.
ma_engine * gGetSoundEngine()