Soundsystem update
This commit is contained in:
@@ -26,23 +26,8 @@
|
|||||||
<ClCompile Include="Model.cpp" />
|
<ClCompile Include="Model.cpp" />
|
||||||
<ClCompile Include="Engine.h" />
|
<ClCompile Include="Engine.h" />
|
||||||
<ClCompile Include="Texture.cpp" />
|
<ClCompile Include="Texture.cpp" />
|
||||||
<ClCompile Include="GUIManager.cpp">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Renderer.cpp" />
|
<ClCompile Include="Renderer.cpp" />
|
||||||
<ClCompile Include="ShaderProgram.cpp" />
|
<ClCompile Include="ShaderProgram.cpp" />
|
||||||
<ClCompile Include="Frame.cpp">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="TextFrame.cpp">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="MenuFrame.cpp">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="GameFrame.cpp">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Component.h" />
|
<ClInclude Include="Component.h" />
|
||||||
@@ -124,21 +109,6 @@
|
|||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Renderer.h" />
|
<ClInclude Include="Renderer.h" />
|
||||||
<ClInclude Include="Texture.h" />
|
<ClInclude Include="Texture.h" />
|
||||||
<ClInclude Include="GUIManager.h">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Frame.h">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="TextFrame.h">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="MenuFrame.h">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GameFrame.h">
|
|
||||||
<Filter>GUI</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GameWorld.h" />
|
<ClInclude Include="GameWorld.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
#include "Components/SoundEmitter.h"
|
#include "Components/SoundEmitter.h"
|
||||||
|
#include <AL/al.h>
|
||||||
|
#include <AL/alc.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
namespace System
|
namespace System
|
||||||
{
|
{
|
||||||
@@ -18,9 +21,17 @@ public:
|
|||||||
void Update(double dt, EntityID entity, EntityID parent) override;
|
void Update(double dt, EntityID entity, EntityID parent) override;
|
||||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||||
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
||||||
void LoadFile(std::string fileName);
|
void LoadFile(const char* fileName);
|
||||||
|
void CreateListener(int ID);
|
||||||
|
void CreateSource(int ID);
|
||||||
private:
|
private:
|
||||||
ALCcontext* context;
|
ALCcontext* context;
|
||||||
|
char type[4];
|
||||||
|
DWORD size, chunkSize;
|
||||||
|
short formatType, channels;
|
||||||
|
DWORD sampleRate, avgBytesPerSec;
|
||||||
|
short bytesPerSample, bitsPerSample;
|
||||||
|
DWORD dataSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include "SoundSystem.h"
|
#include "SoundSystem.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include <AL/al.h>
|
//#include <fstream>
|
||||||
#include <AL/alc.h>
|
|
||||||
|
|
||||||
System::SoundSystem::SoundSystem(World* world)
|
System::SoundSystem::SoundSystem(World* world)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//initialize OpenAL
|
||||||
ALCdevice* Device = alcOpenDevice(nullptr);
|
ALCdevice* Device = alcOpenDevice(nullptr);
|
||||||
|
|
||||||
if(Device)
|
if(Device)
|
||||||
@@ -32,10 +34,73 @@ void System::SoundSystem::Update(double dt, EntityID entity, EntityID parent)
|
|||||||
|
|
||||||
void System::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName)
|
void System::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user