Skip to content

Commit

Permalink
Stop using deprecated alut method
Browse files Browse the repository at this point in the history
  • Loading branch information
dosu0 committed Apr 1, 2024
1 parent 22d05da commit 0ce3707
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
34 changes: 14 additions & 20 deletions src/audio/audio.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#include "audio.h"
#include "alut.h"
#include "util/util.h"

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

#define alClearErrorState alGetError

char* alGetErrorString(ALenum err) {
Expand All @@ -33,17 +24,20 @@ char* alGetErrorString(ALenum err) {
int add_sound(AudioEngine* self, Sound sound, char* path) {
int result = OK;
ALenum err;
ALsizei size, freq;
ALsizei size;
ALfloat freq;
ALenum format;
ALvoid* data;
#ifdef OS_MAC
alutLoadWAVFile(path, &format, &data, &size, &freq);
#else
ALboolean loop;
alutLoadWAVFile((ALbyte*)path, &format, &data, &size, &freq, &loop);
#endif

alBufferData(self->audio_buffers[sound], format, data, size, freq);
ALvoid* sound_data = alutLoadMemoryFromFile(path, &format, &size, &freq);

if (!sound_data) {
error("[openal::alutCreateBufferFromFile] error: %s",
alutGetErrorString(alutGetError()));
result = ERR;
goto cleanup;
}

alBufferData(self->audio_buffers[sound], format, sound_data, size, freq);

if ((err = alGetError()) != AL_NO_ERROR) {
error("[openal::alBufferData] error: %s", alGetErrorString(err));
Expand All @@ -68,7 +62,7 @@ int add_sound(AudioEngine* self, Sound sound, char* path) {
alSourcei(self->audio_sources[sound], AL_LOOPING, AL_FALSE);

cleanup:
alutUnloadWAV(format, data, size, freq);
free(sound_data);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct {
ALuint audio_sources[NUM_SOUNDS];
} AudioEngine;

int audio_engine_init(AudioEngine *self);
int audio_engine_play_sound(AudioEngine *self, Sound sound);
int audio_engine_init(AudioEngine* self);
int audio_engine_play_sound(AudioEngine* self, Sound sound);

#endif

0 comments on commit 0ce3707

Please sign in to comment.