Skip to content

Commit 1e2b731

Browse files
committed
SoundInstance const noexcept
1 parent b453643 commit 1e2b731

6 files changed

Lines changed: 20 additions & 30 deletions

File tree

3DRadSpace/Engine3DRadSpace/Audio/AudioBuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ std::expected<AudioBuffer, AudioBuffer::OGGLoadError> AudioBuffer::FromOGG(const
222222
{
223223
long read = ov_read(
224224
&vf,
225-
buffer + offset,
225+
buffer,
226226
4096,
227227
std::endian::native == std::endian::big, // 1 if big-endian, 0 if little-endian
228228
sizeof(short),
@@ -231,7 +231,7 @@ std::expected<AudioBuffer, AudioBuffer::OGGLoadError> AudioBuffer::FromOGG(const
231231
);
232232
if(!read) break;
233233

234-
if(bytesRead < 0)
234+
if(read < 0)
235235
{
236236
//Faulty OGG file.
237237
delete[] buffer;

3DRadSpace/Engine3DRadSpace/Audio/AudioEngine.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace Engine3DRadSpace::Audio
1616

1717
bool _hasEAX2support = false;
1818

19-
std::vector<SoundInstance*> _instances;
20-
2119
void _initializeContext();
2220
public:
2321
AudioEngine();
@@ -35,8 +33,6 @@ namespace Engine3DRadSpace::Audio
3533

3634
void SwitchAudioDevice(const std::string& deviceName);
3735

38-
bool HasEAX2Support() const noexcept;
39-
4036
~AudioEngine();
4137

4238
void Update() const noexcept;

3DRadSpace/Engine3DRadSpace/Audio/Sound.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ AudioBuffer Sound::_attemptLoading(const std::filesystem::path& path)
2121

2222
Sound::Sound(Internal::AssetUUIDReader dummy) :
2323
_audio(nullptr),
24-
_sound(nullptr,0,0,0,0,0),
2524
_bufferID(0)
2625
{
2726
}
2827

2928
Sound::Sound(AudioEngine *audio, const std::filesystem::path& path) :
30-
_audio(audio),
31-
_sound(std::move(_attemptLoading(path)))
29+
_audio(audio)
3230
{
31+
AudioBuffer sound(std::move(_attemptLoading(path)));
32+
3333
//Generate OpenAL sound buffer
3434
alGenBuffers(1, &_bufferID); //Create one buffer
35-
alBufferData(_bufferID, _sound._format, _sound._buffer.get(), _sound._size, _sound._sampleRate); //Set buffer.
35+
alBufferData(_bufferID, sound._format, sound._buffer.get(), sound._size, sound._sampleRate); //Set buffer.
3636
if(audio->CheckErrors().has_value()) throw Exception("Failed to copy OpenAL buffer!");
3737
}
3838

@@ -44,8 +44,8 @@ Reflection::UUID Sound::GetUUID() const noexcept
4444

4545
const char* Sound::FileExtension() const noexcept
4646
{
47-
return "All supported audio formats(*.wav;*.ogg)\0*.wav;*.ogg\0"
48-
"Waveform Audio File Format(*.wav)\0 *.wav\0"
47+
return "All supported audio formats(*.wav;*.wave;*.ogg)\0*.wav;*.wave;*.ogg\0"
48+
"Waveform Audio File Format(*.wav;*.wave)\0*.wav;*.wave\0"
4949
"Ogg Vorbis Compressed Audio Format(*.ogg)\0*.ogg\0"
5050
"All Files(*.*)\0*.*\0\0";
5151
}

3DRadSpace/Engine3DRadSpace/Audio/Sound.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Engine3DRadSpace::Audio
1313
{
1414
protected:
1515
AudioEngine* _audio;
16-
AudioBuffer _sound;
1716
unsigned int _bufferID;
1817

1918
AudioBuffer _attemptLoading(const std::filesystem::path& path);

3DRadSpace/Engine3DRadSpace/Audio/SoundInstance.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SoundInstance::SoundInstance(Sound* sound):
3333
if(_audio->CheckErrors().has_value()) throw Logging::Exception("Failed to assign buffer to source!");
3434
}
3535

36-
const AudioSource& SoundInstance::GetSource()
36+
const AudioSource& SoundInstance::GetSource() noexcept
3737
{
3838
alGetSourcef(_sourceID, AL_PITCH, &_source.Pitch);
3939
alGetSourcef(_sourceID, AL_GAIN, &_source.Gain);
@@ -121,10 +121,10 @@ void SoundInstance::SetSource(const AudioSource& source)
121121
auto looping = _source.Looping ? AL_TRUE : AL_FALSE;
122122
alSourcei(_sourceID, AL_LOOPING, looping);
123123

124-
if(_audio->CheckErrors().has_value()) throw int(5);
124+
if(_audio->CheckErrors().has_value()) throw Logging::Exception("Error setting source properties");
125125
}
126126

127-
SoundState SoundInstance::GetState()
127+
SoundState SoundInstance::GetState() const noexcept
128128
{
129129
int sourceState;
130130
alGetSourcei(_sourceID, AL_SOURCE_STATE, &sourceState);
@@ -146,26 +146,21 @@ SoundState SoundInstance::GetState()
146146
}
147147
}
148148

149-
void SoundInstance::Play()
149+
void SoundInstance::Play(bool dontOverlap) const noexcept
150150
{
151-
//if(GetState() == SoundState::Playing) return; //do not overlap the same sound instance
152-
//alGetError();
151+
if(GetState() == SoundState::Playing && dontOverlap) return;
153152

154153
alSourcePlay(_sourceID);
155-
156-
if(_audio->CheckErrors().has_value()) throw int(5);
157154
}
158155

159-
void Engine3DRadSpace::Audio::SoundInstance::Stop()
156+
void Engine3DRadSpace::Audio::SoundInstance::Stop() const noexcept
160157
{
161158
alSourceStop(_sourceID);
162-
if(_audio->CheckErrors().has_value()) throw float(5);
163159
}
164160

165-
void Engine3DRadSpace::Audio::SoundInstance::Pause()
161+
void Engine3DRadSpace::Audio::SoundInstance::Pause() const noexcept
166162
{
167163
alSourcePause(_sourceID);
168-
if(_audio->CheckErrors().has_value()) throw float(6);
169164
}
170165

171166
SoundInstance::~SoundInstance()

3DRadSpace/Engine3DRadSpace/Audio/SoundInstance.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace Engine3DRadSpace::Audio
1515
SoundInstance(Sound* sound, const AudioSource& source);
1616
SoundInstance(Sound* sound);
1717

18-
const AudioSource &GetSource();
18+
const AudioSource& GetSource() noexcept;
1919
void SetSource(const AudioSource& source);
20-
SoundState GetState();
20+
SoundState GetState() const noexcept;
2121

2222
void SetPitch(float pitch);
2323
void SetGain(float gain);
@@ -50,9 +50,9 @@ namespace Engine3DRadSpace::Audio
5050
bool IsLooping();
5151
void SetLooping(bool looping);
5252

53-
void Play();
54-
void Stop();
55-
void Pause();
53+
void Play(bool dontOverlap = true) const noexcept;
54+
void Stop() const noexcept;
55+
void Pause() const noexcept;
5656

5757
~SoundInstance();
5858
};

0 commit comments

Comments
 (0)