From 8d9c74bc4f9652739143163f6861682999fbfbe5 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Thu, 22 Sep 2022 13:21:30 -0400 Subject: [PATCH] finish openal and ALUT --- Makefile | 2 +- engine/xe_engine.cpp | 7 +++++ engine/xe_engine.hpp | 4 +-- engine/xe_sound.cpp | 14 +-------- engine/xe_sound_device.cpp | 64 -------------------------------------- engine/xe_sound_device.hpp | 25 --------------- lib/openal | 1 + 7 files changed, 11 insertions(+), 106 deletions(-) delete mode 100644 engine/xe_sound_device.cpp delete mode 100644 engine/xe_sound_device.hpp create mode 160000 lib/openal diff --git a/Makefile b/Makefile index e31683e..f143175 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ CCFLAGS += $(INCFLAGS) LDFLAGS = -lm LDFLAGS += $(INCFLAGS) -LDFLAGS += lib/glfw/src/libglfw3.a +LDFLAGS += -lglfw LDFLAGS += lib/glm/glm/libglm_static.a LDFLAGS += -lopenal LDFLAGS += -lalut diff --git a/engine/xe_engine.cpp b/engine/xe_engine.cpp index 9384094..af2c470 100644 --- a/engine/xe_engine.cpp +++ b/engine/xe_engine.cpp @@ -1,6 +1,8 @@ #include "xe_engine.hpp" #include "xe_image.hpp" + #include +#include namespace xe { @@ -9,6 +11,11 @@ XeEngine::XeEngine(int width, int height, std::string name) : xeWindow{width, he xeRenderer{xeWindow, xeDevice}, xeCamera{} { loadDescriptorPool(); + alutInit(0, NULL); +}; + +XeEngine::~XeEngine() { + alutExit(); }; void XeEngine::loadDescriptorPool() { diff --git a/engine/xe_engine.hpp b/engine/xe_engine.hpp index 285edf3..d86c6a9 100644 --- a/engine/xe_engine.hpp +++ b/engine/xe_engine.hpp @@ -6,7 +6,6 @@ #include "xe_camera.hpp" #include "xe_descriptors.hpp" #include "xe_image.hpp" -#include "xe_sound_device.hpp" #include #include @@ -18,7 +17,7 @@ class XeEngine { XeEngine(int width, int height, std::string name); - ~XeEngine() {}; + ~XeEngine(); XeEngine(const XeEngine&) = delete; XeEngine operator=(const XeEngine&) = delete; @@ -45,7 +44,6 @@ class XeEngine { XeDevice xeDevice; XeRenderer xeRenderer; XeCamera xeCamera; - XeSoundDevice xeSoundDevice; std::chrono::_V2::system_clock::time_point currentTime; float frameTime; diff --git a/engine/xe_sound.cpp b/engine/xe_sound.cpp index d315179..09589fa 100644 --- a/engine/xe_sound.cpp +++ b/engine/xe_sound.cpp @@ -8,20 +8,8 @@ namespace xe { XeSound::XeSound(const std::string& filename) { - // ALvoid *data; - // ALsizei size, freq; - // ALenum format; - // ALboolean loop; - // char *bufferData; - - alutInit(0, NULL); - - std::cout << std::hex << alutGetError() << "\n"; - buffer = alutCreateBufferFromFile(filename.c_str()); - std::cout << std::hex << alutGetError() << "\n"; - alGenSources(1, &source); alSourcef(source, AL_GAIN, 1.f); @@ -30,13 +18,13 @@ XeSound::XeSound(const std::string& filename) { alSource3f(source, AL_VELOCITY, 0, 0, 0); alSourcei(source, AL_LOOPING, AL_FALSE); alSourcei(source, AL_BUFFER, buffer); + alSourcef(source, AL_GAIN, 3.f); } XeSound::~XeSound() { alDeleteSources(1, &source); alDeleteBuffers(1, &buffer); - alutExit(); } void XeSound::play() { diff --git a/engine/xe_sound_device.cpp b/engine/xe_sound_device.cpp deleted file mode 100644 index 3bc931d..0000000 --- a/engine/xe_sound_device.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "xe_sound_device.hpp" - -#include -#include -#include - -namespace xe { - -XeSoundDevice::XeSoundDevice() { - -// ALboolean enumeration; -// enumeration = alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"); -// if (enumeration == AL_FALSE) { -// fprintf(stderr, "enumeration extension not available\n"); -// listAudioDevices(alcGetString(NULL, ALC_DEVICE_SPECIFIER)); -// } - -// listAudioDevices(alcGetString(NULL, ALC_DEVICE_SPECIFIER)); - -// const ALCchar* name = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); - -// device = alcOpenDevice(name); -// if (!device) { -// std::runtime_error("failed to get sound device"); -// } - -// std::cout << "Audio Device: " << alcGetString(device, ALC_DEVICE_SPECIFIER) << "\n"; - -// context = alcCreateContext(device, NULL); -// if(!alcMakeContextCurrent(context)) { -// std::runtime_error("failed to make sound context current"); -// } - -// alListener3f(AL_POSITION, 0.f, 0.f, 0.f); -// alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f); -// ALfloat frontAndUpVectors[] = { -// /* front*/1.f, 0.f, 0.f, -// /* up */ 0.f, 1.f, 0.f -// }; -// alListenerfv(AL_ORIENTATION, frontAndUpVectors); - -// } - -// void XeSoundDevice::listAudioDevices(const ALCchar* devices) { -// const ALCchar *device = devices, *next = devices + 1; -// size_t len = 0; - -// fprintf(stdout, "Devices list: "); -// while (device && *device != '\0' && next && *next != '\0') { -// fprintf(stdout, "%s, ", device); -// len = strlen(device); -// device += (len + 1); -// next += (len + 2); -// } -// std::cout << "\n"; -} - -XeSoundDevice::~XeSoundDevice() { - // alcMakeContextCurrent(nullptr); - // alcDestroyContext(context); - // alcCloseDevice(device); -} - -} \ No newline at end of file diff --git a/engine/xe_sound_device.hpp b/engine/xe_sound_device.hpp deleted file mode 100644 index a6a034e..0000000 --- a/engine/xe_sound_device.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace xe { - -class XeSoundDevice { - - public: - - XeSoundDevice(); - ~XeSoundDevice(); - - private: - - void listAudioDevices(const ALCchar* devices); - - ALCdevice* device; - ALCcontext* context; - -}; - -} \ No newline at end of file diff --git a/lib/openal b/lib/openal new file mode 160000 index 0000000..c52df6d --- /dev/null +++ b/lib/openal @@ -0,0 +1 @@ +Subproject commit c52df6d78ab7131a543326cd2257f267036754e1