removal of ALUT dependency

This commit is contained in:
James Turk 2005-08-10 05:36:30 +00:00
parent f4bfbf0d31
commit 8cbebab31e
25 changed files with 139 additions and 39 deletions

View File

@ -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:

View File

@ -33,7 +33,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\Audio_test.cpp">

View File

@ -31,7 +31,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\ConfigFile_test.cpp">

View File

@ -32,7 +32,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\Font_test.cpp">

View File

@ -32,7 +32,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add library="corona"/>
<Add directory="..\lib"/>
</Linker>

View File

@ -32,7 +32,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\Input_test.cpp">

View File

@ -31,7 +31,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\Log_test.cpp">

View File

@ -32,7 +32,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\Pen_test.cpp">

View File

@ -31,7 +31,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\RandGen_test.cpp">

View File

@ -32,7 +32,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add library="corona"/>
<Add directory="..\lib"/>
</Linker>

View File

@ -31,7 +31,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\filesys_test.cpp">

View File

@ -31,7 +31,6 @@
<Add library="openal32"/>
<Add library="physfs"/>
<Add library="freetype"/>
<Add library="alut"/>
<Add directory="..\lib"/>
</Linker>
<Unit filename="..\test\math_test.cpp">

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<SampleResourceManager> 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
}
}

View File

@ -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 <iostream>
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<ubyte> filedata = buf.getData();
@ -48,15 +48,12 @@ void SampleResourceManager::loadResourceData(SampleResource &res,
AudioCore::throwOpenALError("alGenBuffers");
// load WAV via alut
alutLoadWAVMemory(reinterpret_cast<ALbyte*>(&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;
}
}
}