diff --git a/SConstruct b/SConstruct
index 0760d98..c709f49 100644
--- a/SConstruct
+++ b/SConstruct
@@ -5,7 +5,7 @@
# James Turk (jpt2433@rit.edu)
#
# Version:
-# $Id: SConstruct,v 1.19 2005/08/08 21:39:40 cozman Exp $
+# $Id: SConstruct,v 1.20 2005/08/10 05:36:30 cozman Exp $
import os,os.path
import glob
@@ -27,7 +27,7 @@ INC_DIRS = ["include/%s" % d for d in SUB_DIRS]
SRC_FILES = [f.replace('src','build') for f in getFilesMulti(SRC_DIRS, '*.cpp')]
INC_FILES = getFilesMulti(INC_DIRS, '*.hpp')
-libsMap = { 'nt':('opengl32','glu32',['openal32','alut']),
+libsMap = { 'nt':('opengl32','glu32','openal32'),
'posix':('GL','GLU','openal'),
'mac':('GL','GLU','openal')}
try:
diff --git a/codeblocks/AudioTest.cbp b/codeblocks/AudioTest.cbp
index d1be023..7bd5a2f 100644
--- a/codeblocks/AudioTest.cbp
+++ b/codeblocks/AudioTest.cbp
@@ -33,7 +33,6 @@
-
diff --git a/codeblocks/ConfigFileTest.cbp b/codeblocks/ConfigFileTest.cbp
index 19584a3..61e4c2f 100644
--- a/codeblocks/ConfigFileTest.cbp
+++ b/codeblocks/ConfigFileTest.cbp
@@ -31,7 +31,6 @@
-
diff --git a/codeblocks/FontTest.cbp b/codeblocks/FontTest.cbp
index b0d6410..7c74499 100644
--- a/codeblocks/FontTest.cbp
+++ b/codeblocks/FontTest.cbp
@@ -32,7 +32,6 @@
-
diff --git a/codeblocks/ImageTest.cbp b/codeblocks/ImageTest.cbp
index 7a3cb30..81b5b50 100644
--- a/codeblocks/ImageTest.cbp
+++ b/codeblocks/ImageTest.cbp
@@ -32,7 +32,6 @@
-
diff --git a/codeblocks/InputTest.cbp b/codeblocks/InputTest.cbp
index c047ffb..9dd91a4 100644
--- a/codeblocks/InputTest.cbp
+++ b/codeblocks/InputTest.cbp
@@ -32,7 +32,6 @@
-
diff --git a/codeblocks/LogTest.cbp b/codeblocks/LogTest.cbp
index 19cfcb3..406105a 100644
--- a/codeblocks/LogTest.cbp
+++ b/codeblocks/LogTest.cbp
@@ -31,7 +31,6 @@
-
diff --git a/codeblocks/PenTest.cbp b/codeblocks/PenTest.cbp
index f5a5bdd..c899faa 100644
--- a/codeblocks/PenTest.cbp
+++ b/codeblocks/PenTest.cbp
@@ -32,7 +32,6 @@
-
diff --git a/codeblocks/RandGenTest.cbp b/codeblocks/RandGenTest.cbp
index b308b9a..53638d9 100644
--- a/codeblocks/RandGenTest.cbp
+++ b/codeblocks/RandGenTest.cbp
@@ -31,7 +31,6 @@
-
diff --git a/codeblocks/TextureTest.cbp b/codeblocks/TextureTest.cbp
index 9801a63..c3b5952 100644
--- a/codeblocks/TextureTest.cbp
+++ b/codeblocks/TextureTest.cbp
@@ -32,7 +32,6 @@
-
diff --git a/codeblocks/filesysTest.cbp b/codeblocks/filesysTest.cbp
index 9c2856d..b7e4215 100644
--- a/codeblocks/filesysTest.cbp
+++ b/codeblocks/filesysTest.cbp
@@ -31,7 +31,6 @@
-
diff --git a/codeblocks/mathTest.cbp b/codeblocks/mathTest.cbp
index 01a3587..02feb64 100644
--- a/codeblocks/mathTest.cbp
+++ b/codeblocks/mathTest.cbp
@@ -31,7 +31,6 @@
-
diff --git a/devcpp/AudioTest.dev b/devcpp/AudioTest.dev
index 9e45e8d..87aa8cb 100644
--- a/devcpp/AudioTest.dev
+++ b/devcpp/AudioTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-DPHOTON_USE_OPENAL -Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/ConfigFileTest.dev b/devcpp/ConfigFileTest.dev
index e7abaf5..e1b6b5f 100644
--- a/devcpp/ConfigFileTest.dev
+++ b/devcpp/ConfigFileTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/FontTest.dev b/devcpp/FontTest.dev
index 12119a2..fa387aa 100644
--- a/devcpp/FontTest.dev
+++ b/devcpp/FontTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/ImageTest.dev b/devcpp/ImageTest.dev
index fbfb126..2eb9ef0 100644
--- a/devcpp/ImageTest.dev
+++ b/devcpp/ImageTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/InputTest.dev b/devcpp/InputTest.dev
index 1fda2d8..322cdc3 100644
--- a/devcpp/InputTest.dev
+++ b/devcpp/InputTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/LogTest.dev b/devcpp/LogTest.dev
index e318d37..9274fd3 100644
--- a/devcpp/LogTest.dev
+++ b/devcpp/LogTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/PenTest.dev b/devcpp/PenTest.dev
index c23a92f..78373fa 100644
--- a/devcpp/PenTest.dev
+++ b/devcpp/PenTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/RandGenTest.dev b/devcpp/RandGenTest.dev
index 083e3d4..0151d91 100644
--- a/devcpp/RandGenTest.dev
+++ b/devcpp/RandGenTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/TextureTest.dev b/devcpp/TextureTest.dev
index 2a7681e..46cdeca 100644
--- a/devcpp/TextureTest.dev
+++ b/devcpp/TextureTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/filesysTest.dev b/devcpp/filesysTest.dev
index a419067..7d05977 100644
--- a/devcpp/filesysTest.dev
+++ b/devcpp/filesysTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/devcpp/mathTest.dev b/devcpp/mathTest.dev
index 17ddd72..f1fda07 100644
--- a/devcpp/mathTest.dev
+++ b/devcpp/mathTest.dev
@@ -12,7 +12,7 @@ ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall --pedantic
-Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
+Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
IsCpp=1
Icon=
ExeOutput=..\test
diff --git a/include/audio/SampleResourceManager.hpp b/include/audio/SampleResourceManager.hpp
index 3942fff..14f8f47 100644
--- a/include/audio/SampleResourceManager.hpp
+++ b/include/audio/SampleResourceManager.hpp
@@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
-// $Id: SampleResourceManager.hpp,v 1.2 2005/07/18 05:14:18 cozman Exp $
+// $Id: SampleResourceManager.hpp,v 1.3 2005/08/10 05:36:31 cozman Exp $
#ifdef PHOTON_USE_OPENAL
@@ -36,11 +36,54 @@ private:
virtual void loadResourceData(SampleResource &res,
const ResourceDescriptor& path);
virtual void freeResourceData(SampleResource &res);
+
+ void loadWAVMemory(const ubyte* memory, ALenum& format, ubyte*& data,
+ uint& size, uint& freq);
+ void freeWAVMemory(ubyte*& data);
};
// Allow users to simply call a Sample a Sample
typedef Source Sample;
+// Structure defined to specification of WAV file
+// Based on http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
+struct WaveHeader
+{
+ // Big Endian
+ // static const uint RIFF = 0x52494646;
+ // static const uint WAVE = 0x57415645;
+ // static const uint FMT = 0x666d7420;
+ // static const uint DATA = 0x64617461;
+
+ // Little Endian
+ static const uint RIFF = 0x46464952;
+ static const uint WAVE = 0x45564157;
+ static const uint FMT = 0x20746d66;
+ static const uint DATA = 0x61746164;
+
+ struct RIFFHeader
+ {
+ uint chunkID; // 4 bytes
+ uint chunkSize; // 4 bytes
+ uint format; // 4 bytes
+ } riff; // 16 bytes
+
+ struct WaveFormat
+ {
+ uint chunkID; // 4 bytes
+ uint size; // 4 bytes
+ short format; // 2 bytes
+ short numChannels; // 2 bytes
+ uint sampleRate; // 4 bytes
+ uint byteRate; // 4 bytes
+ short blockAlign; // 2 bytes
+ short bitsPerSample; // 2 bytes
+ } fmt; // 24 bytes
+
+ uint chunkID; // 4 bytes
+ uint dataSize; // 4 bytes
+}; // 38 bytes
+
}
}
diff --git a/src/audio/SampleResourceManager.cpp b/src/audio/SampleResourceManager.cpp
index eba4c5d..05cc086 100644
--- a/src/audio/SampleResourceManager.cpp
+++ b/src/audio/SampleResourceManager.cpp
@@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// Version:
-// $Id: SampleResourceManager.cpp,v 1.3 2005/07/18 05:14:18 cozman Exp $
+// $Id: SampleResourceManager.cpp,v 1.4 2005/08/10 05:36:30 cozman Exp $
#ifdef PHOTON_USE_OPENAL
@@ -14,7 +14,8 @@
#include "util/FileBuffer.hpp"
#include "AL/al.h"
-#include "AL/alut.h" // used for loading WAVs, to be phased out
+
+#include
namespace photon
{
@@ -35,10 +36,9 @@ void SampleResourceManager::loadResourceData(SampleResource &res,
util::FileBuffer buf(desc.path);
// OpenAL variables to load into.
ALenum format;
- ALsizei size;
- ALvoid* data;
- ALsizei freq;
- ALboolean loop;
+ uint size;
+ ubyte* data;
+ uint freq;
// load from FileBuffer (allows loading from zip via PhysFS)
std::vector filedata = buf.getData();
@@ -48,15 +48,12 @@ void SampleResourceManager::loadResourceData(SampleResource &res,
AudioCore::throwOpenALError("alGenBuffers");
- // load WAV via alut
- alutLoadWAVMemory(reinterpret_cast(&filedata[0]),
- &format, &data, &size, &freq, &loop);
- AudioCore::throwOpenALError("alutLoadWAVFile");
+ // load WAV and pass it into OpenAL buffer
+ loadWAVMemory(&filedata[0], format, data, size, freq);
+ alBufferData(res.bufferID, format, (ALvoid*)data, size, freq);
+ freeWAVMemory(data);
- alBufferData(res.bufferID, format, data, size, freq);
- alutUnloadWAV(format, data, size, freq);
-
- AudioCore::throwOpenALError("SampleResourceManager::loadResourceData");
+ AudioCore::throwOpenALError("alBufferData");
}
void SampleResourceManager::freeResourceData(SampleResource& res)
@@ -68,6 +65,77 @@ void SampleResourceManager::freeResourceData(SampleResource& res)
}
}
+void SampleResourceManager::loadWAVMemory(const ubyte* memory, ALenum& format, ubyte*& data,
+ uint& size, uint& freq)
+{
+ WaveHeader wavHeader;
+
+ std::memcpy(&wavHeader, memory, sizeof(WaveHeader));
+
+ // check vital fields of WAV file for validation
+ if(wavHeader.fmt.format != 1)
+ {
+ throw ResourceException("Error loading WAV: Non-PCM format WAV");
+ }
+ if(wavHeader.riff.chunkID != WaveHeader::RIFF)
+ {
+ throw ResourceException("Error loading WAV: Invalid RIFF chunk.");
+ }
+ if(wavHeader.riff.format != WaveHeader::WAVE)
+ {
+ throw ResourceException("Error loading WAV: Invalid WAVE header.");
+ }
+ if(wavHeader.fmt.chunkID != WaveHeader::FMT)
+ {
+ throw ResourceException("Error loading WAV: Invalid FMT chunk.");
+ }
+ if(wavHeader.chunkID != WaveHeader::DATA)
+ {
+ throw ResourceException("Error loading WAV: Invalid DATA chunk.");
+ }
+
+ // set OpenAL format based on channels & bitsPerSample
+ if(wavHeader.fmt.numChannels == 1 && wavHeader.fmt.bitsPerSample == 8)
+ {
+ format = AL_FORMAT_MONO8;
+ }
+ else if(wavHeader.fmt.numChannels == 1 && wavHeader.fmt.bitsPerSample == 16)
+ {
+ format = AL_FORMAT_MONO16;
+ }
+ else if(wavHeader.fmt.numChannels == 2 && wavHeader.fmt.bitsPerSample == 8)
+ {
+ format = AL_FORMAT_STEREO8;
+ }
+ else if(wavHeader.fmt.numChannels == 2 && wavHeader.fmt.bitsPerSample == 16)
+ {
+ format = AL_FORMAT_STEREO16;
+ }
+ else
+ {
+ throw ResourceException("Error loading WAV: Invalid audio format.");
+ }
+
+ // copy size and frequency
+ size = wavHeader.dataSize;
+ freq = wavHeader.fmt.sampleRate;
+
+ // allocate space and copy data
+ data = new ubyte[size];
+ std::memcpy(data, memory+sizeof(WaveHeader), size);
+}
+
+void SampleResourceManager::freeWAVMemory(ubyte*& data)
+{
+ if(data == 0)
+ {
+ assert(0);
+ }
+
+ delete[] data;
+ data = 0;
+}
+
}
}