diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters index ca2171c..e936774 100644 --- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters @@ -26,23 +26,8 @@ - - GUI - - - GUI - - - GUI - - - GUI - - - GUI - @@ -124,21 +109,6 @@ - - GUI - - - GUI - - - GUI - - - GUI - - - GUI - diff --git a/Escape-the-Dawn/Systems/SoundSystem.h b/Escape-the-Dawn/Systems/SoundSystem.h index f6e8acc..45a77cd 100644 --- a/Escape-the-Dawn/Systems/SoundSystem.h +++ b/Escape-the-Dawn/Systems/SoundSystem.h @@ -3,6 +3,9 @@ #include "System.h" #include "Components/SoundEmitter.h" +#include +#include +#include namespace System { @@ -18,9 +21,17 @@ public: void Update(double dt, EntityID entity, EntityID parent) override; void OnComponentCreated(std::string type, std::shared_ptr component) override; void PlaySound(std::shared_ptr emitter, std::string fileName); - void LoadFile(std::string fileName); + void LoadFile(const char* fileName); + void CreateListener(int ID); + void CreateSource(int ID); private: ALCcontext* context; + char type[4]; + DWORD size, chunkSize; + short formatType, channels; + DWORD sampleRate, avgBytesPerSec; + short bytesPerSample, bitsPerSample; + DWORD dataSize; }; diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp b/Escape-the-Dawn/Systems/SoundsSystem.cpp index 8dd2ef4..e9e01af 100644 --- a/Escape-the-Dawn/Systems/SoundsSystem.cpp +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp @@ -1,10 +1,12 @@ #include "SoundSystem.h" #include "World.h" -#include -#include +//#include + System::SoundSystem::SoundSystem(World* world) { + + //initialize OpenAL ALCdevice* Device = alcOpenDevice(nullptr); if(Device) @@ -32,10 +34,73 @@ void System::SoundSystem::Update(double dt, EntityID entity, EntityID parent) void System::SoundSystem::PlaySound(std::shared_ptr emitter, std::string fileName) { - LoadFile(fileName); + //LoadFile(fileName); } -void System::SoundSystem::LoadFile(std::string fileName) +void System::SoundSystem::LoadFile(const char* fileName) { - loadWavFile() + FILE *fp = NULL; + fp = fopen("Sounds/" + fileName, "rb"); + + + //CHECK FOR VALID WAVE-FILE + fread(type, sizeof(char), 4, fp); + if(type[0]!='R' || type[1]!='I' || type[2]!='F' || type[3]!='F') + return LOG_ERROR("ERROR: No RIFF in WAVE-file"); + + fread(&size, sizeof(DWORD), 1, fp); + fread(type, sizeof(char), 4, fp); + if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E') + return LOG_ERROR("ERROR: Not WAVE-file"); + + fread(type, sizeof(char), 4, fp); + if(type[0]!='f' || type[1]!='m' || type[2]!='t' || type[3]!=' ') + return LOG_ERROR("ERROR: No fmt in WAVE-file"); + + //READ THE DATA FROM WAVE-FILE + fread(&chunkSize, sizeof(DWORD), 1, fp); + fread(&formatType, sizeof(short), 1, fp); + fread(&channels, sizeof(short), 1, fp); + fread(&sampleRate, sizeof(DWORD), 1, fp); + fread(&avgBytesPerSec, sizeof(DWORD), 1, fp); + fread(&bytesPerSample, sizeof(short), 1, fp); + fread(&bitsPerSample, sizeof(short), 1, fp); + + fread(type, sizeof(char), 4, fp); + if(type[0]!='d' || type[1]!='a' || type[2]!='t' || type[3]!='a') + return LOG_ERROR("ERROR: WAVE-file Missing data"); + + fread(&dataSize, sizeof(DWORD), 1, fp); + + unsigned char* buf = new unsigned char[dataSize]; + fread(buf, sizeof(BYTE), dataSize, fp); + +} + +void System::SoundSystem::CreateSource(int ID) +{ + ALuint source; + ALuint buffer; + ALuint frequnzy = sampleRate; + ALuint format = 0; + + alGenBuffers(1, &buffer); + alGenBuffers(1, &source); + + if(bitsPerSample == 8) + { + if(channels == 1) + format = AL_FORMAT_MONO8; + else if(channels == 2) + format = AL_FORMAT_STEREO8; + } + + if(bitsPerSample == 16) + { + if (channels == 1) + format = AL_FORMAT_MONO16; + else if (channels == 2) + format = AL_FORMAT_STEREO16; + } + } \ No newline at end of file