removal of ALUT dependency
This commit is contained in:
parent
f4bfbf0d31
commit
8cbebab31e
@ -5,7 +5,7 @@
|
|||||||
# James Turk (jpt2433@rit.edu)
|
# James Turk (jpt2433@rit.edu)
|
||||||
#
|
#
|
||||||
# Version:
|
# 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 os,os.path
|
||||||
import glob
|
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')]
|
SRC_FILES = [f.replace('src','build') for f in getFilesMulti(SRC_DIRS, '*.cpp')]
|
||||||
INC_FILES = getFilesMulti(INC_DIRS, '*.hpp')
|
INC_FILES = getFilesMulti(INC_DIRS, '*.hpp')
|
||||||
|
|
||||||
libsMap = { 'nt':('opengl32','glu32',['openal32','alut']),
|
libsMap = { 'nt':('opengl32','glu32','openal32'),
|
||||||
'posix':('GL','GLU','openal'),
|
'posix':('GL','GLU','openal'),
|
||||||
'mac':('GL','GLU','openal')}
|
'mac':('GL','GLU','openal')}
|
||||||
try:
|
try:
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\Audio_test.cpp">
|
<Unit filename="..\test\Audio_test.cpp">
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\ConfigFile_test.cpp">
|
<Unit filename="..\test\ConfigFile_test.cpp">
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\Font_test.cpp">
|
<Unit filename="..\test\Font_test.cpp">
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add library="corona"/>
|
<Add library="corona"/>
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\Input_test.cpp">
|
<Unit filename="..\test\Input_test.cpp">
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\Log_test.cpp">
|
<Unit filename="..\test\Log_test.cpp">
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\Pen_test.cpp">
|
<Unit filename="..\test\Pen_test.cpp">
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\RandGen_test.cpp">
|
<Unit filename="..\test\RandGen_test.cpp">
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add library="corona"/>
|
<Add library="corona"/>
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\filesys_test.cpp">
|
<Unit filename="..\test\filesys_test.cpp">
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<Add library="openal32"/>
|
<Add library="openal32"/>
|
||||||
<Add library="physfs"/>
|
<Add library="physfs"/>
|
||||||
<Add library="freetype"/>
|
<Add library="freetype"/>
|
||||||
<Add library="alut"/>
|
|
||||||
<Add directory="..\lib"/>
|
<Add directory="..\lib"/>
|
||||||
</Linker>
|
</Linker>
|
||||||
<Unit filename="..\test\math_test.cpp">
|
<Unit filename="..\test\math_test.cpp">
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-DPHOTON_USE_OPENAL -Wall --pedantic
|
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
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -12,7 +12,7 @@ ResourceIncludes=
|
|||||||
MakeIncludes=
|
MakeIncludes=
|
||||||
Compiler=
|
Compiler=
|
||||||
CppCompiler=-Wall --pedantic
|
CppCompiler=-Wall --pedantic
|
||||||
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lalut -lphysfs -lcorona
|
Linker=-lphoton -lglfw -lfreetype -lopengl32 -lglu32 -lopenal32 -lphysfs -lcorona
|
||||||
IsCpp=1
|
IsCpp=1
|
||||||
Icon=
|
Icon=
|
||||||
ExeOutput=..\test
|
ExeOutput=..\test
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// 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
|
#ifdef PHOTON_USE_OPENAL
|
||||||
|
|
||||||
@ -36,11 +36,54 @@ private:
|
|||||||
virtual void loadResourceData(SampleResource &res,
|
virtual void loadResourceData(SampleResource &res,
|
||||||
const ResourceDescriptor& path);
|
const ResourceDescriptor& path);
|
||||||
virtual void freeResourceData(SampleResource &res);
|
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
|
// Allow users to simply call a Sample a Sample
|
||||||
typedef Source<SampleResourceManager> 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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// James Turk (jpt2433@rit.edu)
|
// James Turk (jpt2433@rit.edu)
|
||||||
//
|
//
|
||||||
// Version:
|
// 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
|
#ifdef PHOTON_USE_OPENAL
|
||||||
|
|
||||||
@ -14,7 +14,8 @@
|
|||||||
#include "util/FileBuffer.hpp"
|
#include "util/FileBuffer.hpp"
|
||||||
|
|
||||||
#include "AL/al.h"
|
#include "AL/al.h"
|
||||||
#include "AL/alut.h" // used for loading WAVs, to be phased out
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace photon
|
namespace photon
|
||||||
{
|
{
|
||||||
@ -35,10 +36,9 @@ void SampleResourceManager::loadResourceData(SampleResource &res,
|
|||||||
util::FileBuffer buf(desc.path);
|
util::FileBuffer buf(desc.path);
|
||||||
// OpenAL variables to load into.
|
// OpenAL variables to load into.
|
||||||
ALenum format;
|
ALenum format;
|
||||||
ALsizei size;
|
uint size;
|
||||||
ALvoid* data;
|
ubyte* data;
|
||||||
ALsizei freq;
|
uint freq;
|
||||||
ALboolean loop;
|
|
||||||
|
|
||||||
// load from FileBuffer (allows loading from zip via PhysFS)
|
// load from FileBuffer (allows loading from zip via PhysFS)
|
||||||
std::vector<ubyte> filedata = buf.getData();
|
std::vector<ubyte> filedata = buf.getData();
|
||||||
@ -48,15 +48,12 @@ void SampleResourceManager::loadResourceData(SampleResource &res,
|
|||||||
|
|
||||||
AudioCore::throwOpenALError("alGenBuffers");
|
AudioCore::throwOpenALError("alGenBuffers");
|
||||||
|
|
||||||
// load WAV via alut
|
// load WAV and pass it into OpenAL buffer
|
||||||
alutLoadWAVMemory(reinterpret_cast<ALbyte*>(&filedata[0]),
|
loadWAVMemory(&filedata[0], format, data, size, freq);
|
||||||
&format, &data, &size, &freq, &loop);
|
alBufferData(res.bufferID, format, (ALvoid*)data, size, freq);
|
||||||
AudioCore::throwOpenALError("alutLoadWAVFile");
|
freeWAVMemory(data);
|
||||||
|
|
||||||
alBufferData(res.bufferID, format, data, size, freq);
|
AudioCore::throwOpenALError("alBufferData");
|
||||||
alutUnloadWAV(format, data, size, freq);
|
|
||||||
|
|
||||||
AudioCore::throwOpenALError("SampleResourceManager::loadResourceData");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SampleResourceManager::freeResourceData(SampleResource& res)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user