Soundsystem update

This commit is contained in:
Adam
2014-03-09 20:04:38 +01:00
parent e4c443042b
commit 5c142d98ec
3 changed files with 82 additions and 36 deletions
@@ -26,23 +26,8 @@
<ClCompile Include="Model.cpp" />
<ClCompile Include="Engine.h" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="GUIManager.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="Renderer.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>
<ClInclude Include="Component.h" />
@@ -124,21 +109,6 @@
</ClInclude>
<ClInclude Include="Renderer.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" />
</ItemGroup>
<ItemGroup>
+12 -1
View File
@@ -3,6 +3,9 @@
#include "System.h"
#include "Components/SoundEmitter.h"
#include <AL/al.h>
#include <AL/alc.h>
#include <windows.h>
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> component) override;
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:
ALCcontext* context;
char type[4];
DWORD size, chunkSize;
short formatType, channels;
DWORD sampleRate, avgBytesPerSec;
short bytesPerSample, bitsPerSample;
DWORD dataSize;
};
+70 -5
View File
@@ -1,10 +1,12 @@
#include "SoundSystem.h"
#include "World.h"
#include <AL/al.h>
#include <AL/alc.h>
//#include <fstream>
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<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;
}
}