caudio/Source/cFileSource.cpp
Joshua Jones 28a22c7f73 Fixed problem with the msvc project not outputting a .lib file.
Updated tutorials to fix minor bugs and pathing issues.  Also fixed crash bug on failure to create the audio object.
Added msvc projects for all tutorials.
Updated the listener class to be self contained and only handle stuff related to the OpenAL listener.  It does NOT init OpenAL anymore, that has been moved to cAudioManager.
Extended the listener class to support all settings that native OpenAL supports.
Cleaned up cFileSource and fixed a crash bug on NULL file handle
Fixed returning bad audio buffer chunk sizes from the cOggDecoder on errors in the ogg stream
Seeking can now be down in fractions of a second now, changed the seconds field from int to float
Fixed various odd formatting.
Fixed potential crash bug in cMemorySource if memory could not be allocated.
cMemorySource will no longer clear the buffer you give to it before filling it with data.  This prevents an overwrite from happening in case of error but the user should provide a zeroed buffer to cMemorySource anyway for safety.
Relative seeking is now supported by cOggDecoder.
2009-08-08 05:51:32 +00:00

78 lines
1.4 KiB
C++

#include "../Headers/cFileSource.h"
#include <cstring>
namespace cAudio
{
//!Init Takes a string for file name
cFileSource::cFileSource(const std::string& filename) : pFile(NULL), Valid(false), Filesize(0)
{
if(filename.length() != 0)
{
pFile = fopen(filename.c_str(),"rb");
if(pFile)
Valid = true;
}
if(Valid)
{
fseek(pFile, 0, SEEK_END);
Filesize = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
}
}
cFileSource::~cFileSource()
{
if(pFile)
fclose(pFile);
}
//!Returns true if the FileSource is valid
bool cFileSource::isValid()
{
return Valid;
}
//!Returns the current position of the file stream.
int cFileSource::getCurrentPos()
{
return ftell(pFile);
}
//!Returns the file size
int cFileSource::getSize()
{
return Filesize;
}
//!Read current FileSource Data
int cFileSource::read(void* output, int size)
{
return fread(output, sizeof(char), size, pFile);
}
//!Seek the file stream
bool cFileSource::seek(int amount, bool relative)
{
if(relative == true)
{
int oldamount = ftell(pFile);
fseek(pFile, amount, SEEK_CUR);
//check against the absolute position
if(oldamount+amount != ftell(pFile))
return false;
}
else
{
fseek(pFile, amount, SEEK_SET);
if(amount != ftell(pFile))
return false;
}
return true;
}
};