changed the IAudio objects and cAudio objects to IAudioSource and cAudioSource

This commit is contained in:
Raynaldo Rivera 2010-02-10 21:57:09 +00:00
parent fbd3ecabb4
commit b317412796
16 changed files with 358 additions and 358 deletions

View File

@ -43,7 +43,7 @@ int main(int argc, char* argv[])
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
//Create a IAudio object and load a sound from a file
cAudio::IAudio* mysound = manager->createFromFile("bling","../../media/cAudioTheme1.ogg",true);
cAudio::IAudioSource* mysound = manager->createFromFile("bling","../../media/cAudioTheme1.ogg",true);
if(mysound)
{

View File

@ -50,7 +50,7 @@ int main(int argc, char* argv[])
cAudio::IListener* listener = manager->getListener();
//Create a IAudio object and load a sound from a file
cAudio::IAudio* mysound = manager->createFromFile("bling", "../../media/bling.ogg", false);
cAudio::IAudioSource* mysound = manager->createFromFile("bling", "../../media/bling.ogg", false);
//Set the IAudio Sound to play3d and loop
//play3d takes 4 arguments play3d(toloop,x,y,z,strength)

View File

@ -48,7 +48,7 @@ int main(int argc, char* argv[])
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
//Create a IAudio object and load a sound from memory. using the bling array and bling size generated by bin2h.
cAudio::IAudio* mysound = manager->createFromMemory("bling",(const char*)bling,bling_size,"wav");
cAudio::IAudioSource* mysound = manager->createFromMemory("bling",(const char*)bling,bling_size,"wav");
if(mysound)
{

View File

@ -99,7 +99,7 @@ int main(int argc, char* argv[])
cout << "Captured " << capture->getCapturedAudio(buffer, currentsize) << " bytes of audio data. \n \n";
//Create a IAudio object and load a sound from a file
cAudio::IAudio* mysound = manager->createFromRaw("sound1", buffer, currentsize, CAPTURE_FREQUENCY, CAPTURE_FORMAT);
cAudio::IAudioSource* mysound = manager->createFromRaw("sound1", buffer, currentsize, CAPTURE_FREQUENCY, CAPTURE_FORMAT);
delete buffer;

View File

@ -54,7 +54,7 @@ int main(int argc, char* argv[])
filter->setLowFrequencyVolume(0.1f);
//Create a IAudio object and load a sound from a file
cAudio::IAudio* mysound = manager->createFromFile("bling","../../media/Footsteps.wav",false);
cAudio::IAudioSource* mysound = manager->createFromFile("bling","../../media/Footsteps.wav",false);
if(mysound)
{

View File

@ -21,7 +21,7 @@
namespace cAudio
{
class IAudio;
class IAudioSource;
class cAudioManager : public IAudioManager
{
@ -36,11 +36,11 @@ namespace cAudio
//!Updates the cAudio playback
virtual void update();
//!Gets you the cAudio object you want
virtual IAudio* getSoundByName(const char* name);
virtual IAudioSource* getSoundByName(const char* name);
//!Releases "ALL" cAudio objects
virtual void release();
//!Releases a single cAudio source
virtual void release(IAudio* source);
virtual void release(IAudioSource* source);
//! Returns the name of an available playback device.
/** \param index: Specify which name to retrieve ( Range: 0 to getAvailableDeviceCount()-1 ) */
@ -51,11 +51,11 @@ namespace cAudio
virtual const char* getDefaultDeviceName();
//!Creates the cAudio object
virtual IAudio* createFromFile(const char* name, const char* pathToFile, bool stream = false);
virtual IAudioSource* createFromFile(const char* name, const char* pathToFile, bool stream = false);
//!Loads ogg from memory or virtual file system
virtual IAudio* createFromMemory(const char* name, const char* data, size_t length, const char* extension);
virtual IAudioSource* createFromMemory(const char* name, const char* data, size_t length, const char* extension);
//!Loads raw audio from memory.
virtual IAudio* createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format);
virtual IAudioSource* createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format);
//!Register Audio Codec
virtual bool registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension);
@ -90,9 +90,9 @@ namespace cAudio
bool Initialized;
//! Holds an index for fast searching of audio sources by name
std::map<std::string, IAudio*> audioIndex;
std::map<std::string, IAudioSource*> audioIndex;
//! Holds all managed audio sources
std::vector<IAudio*> audioSources;
std::vector<IAudioSource*> audioSources;
//! Decoder map that holds all decoders by file extension
std::map<std::string, IAudioDecoderFactory*> decodermap;
//! The listener object

View File

@ -9,7 +9,7 @@
#include <AL/al.h>
#include <AL/alc.h>
#include "../include/IAudio.h"
#include "../include/IAudioSource.h"
#include "../include/cVector3.h"
#include "../Headers/cMutex.h"
#include "../include/ILogger.h"
@ -17,15 +17,15 @@
namespace cAudio
{
class cAudio : public IAudio
class cAudioSource : public IAudioSource
{
public:
#ifdef CAUDIO_EFX_ENABLED
cAudio(IAudioDecoder* decoder, ALCcontext* context, cEFXFunctions* oALFunctions);
cAudioSource(IAudioDecoder* decoder, ALCcontext* context, cEFXFunctions* oALFunctions);
#else
cAudio(IAudioDecoder* decoder, ALCcontext* context);
cAudioSource(IAudioDecoder* decoder, ALCcontext* context);
#endif
~cAudio();
~cAudioSource();
//! Plays the source with the default or last set values
virtual bool play();
@ -223,4 +223,4 @@ namespace cAudio
#endif
};
};
#endif //! CAUDIO_H_INCLUDED
#endif //! CAUDIOSOURCE_H_INCLUDED

View File

@ -162,7 +162,7 @@ namespace cAudio
}
//!create a sound source
IAudio* cAudioManager::createFromFile(const char* name, const char* pathToFile, bool stream)
IAudioSource* cAudioManager::createFromFile(const char* name, const char* pathToFile, bool stream)
{
cAudioMutexBasicLock lock(Mutex);
@ -186,7 +186,7 @@ namespace cAudio
{
if(decoder->isValid())
{
IAudio* audio = new cAudio(decoder, Context, initEffects.getEFXInterface());
IAudioSource* audio = new cAudioSource(decoder, Context, initEffects.getEFXInterface());
decoder->drop();
if(audio)
@ -236,7 +236,7 @@ namespace cAudio
{
tempsource->read(tempbuf,length);
IAudio* guy = createFromMemory(name, tempbuf, length, getExt(path).c_str());
IAudioSource* guy = createFromMemory(name, tempbuf, length, getExt(path).c_str());
delete[]tempbuf;
tempsource->drop();
return guy;
@ -258,7 +258,7 @@ namespace cAudio
}
//!Loads the ogg file from memory *virtual file systems*
IAudio* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension)
IAudioSource* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
@ -278,7 +278,7 @@ namespace cAudio
{
if(decoder->isValid())
{
IAudio* audio = new cAudio(decoder, Context, initEffects.getEFXInterface());
IAudioSource* audio = new cAudioSource(decoder, Context, initEffects.getEFXInterface());
decoder->drop();
if(audio)
@ -319,7 +319,7 @@ namespace cAudio
return NULL;
}
IAudio* cAudioManager::createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format)
IAudioSource* cAudioManager::createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format)
{
cAudioMutexBasicLock lock(Mutex);
@ -338,7 +338,7 @@ namespace cAudio
{
if(decoder->isValid())
{
IAudio* audio = new cAudio(decoder, Context, initEffects.getEFXInterface());
IAudioSource* audio = new cAudioSource(decoder, Context, initEffects.getEFXInterface());
decoder->drop();
if(audio)
@ -421,11 +421,11 @@ namespace cAudio
}
//!grabs the selected audio file via the identifier
IAudio* cAudioManager::getSoundByName(const char* name)
IAudioSource* cAudioManager::getSoundByName(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
std::string audioName = safeCStr(name);
std::map<std::string,IAudio*>::iterator i = audioIndex.find(audioName);
std::map<std::string,IAudioSource*>::iterator i = audioIndex.find(audioName);
if (i == audioIndex.end())
{
return NULL;
@ -439,7 +439,7 @@ namespace cAudio
cAudioMutexBasicLock lock(Mutex);
for(unsigned int i=0; i<audioSources.size(); ++i)
{
IAudio* source = audioSources[i];
IAudioSource* source = audioSources[i];
if(source)
source->drop();
}
@ -447,12 +447,12 @@ namespace cAudio
audioIndex.clear();
}
void cAudioManager::release(IAudio* source)
void cAudioManager::release(IAudioSource* source)
{
if(source)
{
cAudioMutexBasicLock lock(Mutex);
std::map<std::string,IAudio*>::iterator it = audioIndex.begin();
std::map<std::string,IAudioSource*>::iterator it = audioIndex.begin();
for ( it=audioIndex.begin(); it != audioIndex.end(); it++ )
{
if( it->second == source )
@ -479,7 +479,7 @@ namespace cAudio
cAudioMutexBasicLock lock(Mutex);
for(unsigned int i=0; i<audioSources.size(); ++i)
{
IAudio* source = audioSources[i];
IAudioSource* source = audioSources[i];
if (source->isValid())
{
if (source->update())

View File

@ -12,11 +12,11 @@
namespace cAudio
{
#ifdef CAUDIO_EFX_ENABLED
cAudio::cAudio(IAudioDecoder* decoder, ALCcontext* context, cEFXFunctions* oALFunctions)
cAudioSource::cAudioSource(IAudioDecoder* decoder, ALCcontext* context, cEFXFunctions* oALFunctions)
: Context(context), Source(0), Decoder(decoder), Loop(false), Valid(false),
EFX(oALFunctions), Filter(NULL), EffectSlotsAvailable(0), LastFilterTimeStamp(0)
#else
cAudio::cAudio(IAudioDecoder* decoder, ALCcontext* context)
cAudioSource::cAudioSource(IAudioDecoder* decoder, ALCcontext* context)
: Context(context), Source(0), Decoder(decoder), Loop(false), Valid(false)
#endif
{
@ -60,7 +60,7 @@ namespace cAudio
#endif
}
cAudio::~cAudio()
cAudioSource::~cAudioSource()
{
cAudioMutexBasicLock lock(Mutex);
if(Decoder)
@ -80,7 +80,7 @@ namespace cAudio
#endif
}
bool cAudio::play()
bool cAudioSource::play()
{
cAudioMutexBasicLock lock(Mutex);
if (!isPaused())
@ -117,7 +117,7 @@ namespace cAudio
return true;
}
bool cAudio::play2d(const bool& toLoop)
bool cAudioSource::play2d(const bool& toLoop)
{
cAudioMutexBasicLock lock(Mutex);
alSourcei(Source, AL_SOURCE_RELATIVE, true);
@ -127,7 +127,7 @@ namespace cAudio
return state;
}
bool cAudio::play3d(const cVector3& position, const float& soundstr, const bool& toLoop)
bool cAudioSource::play3d(const cVector3& position, const float& soundstr, const bool& toLoop)
{
cAudioMutexBasicLock lock(Mutex);
alSourcei(Source, AL_SOURCE_RELATIVE, false);
@ -139,7 +139,7 @@ namespace cAudio
return state;
}
void cAudio::pause()
void cAudioSource::pause()
{
cAudioMutexBasicLock lock(Mutex);
alSourcePause(Source);
@ -147,7 +147,7 @@ namespace cAudio
getLogger()->logDebug("Audio Source", "Source paused.");
}
void cAudio::stop()
void cAudioSource::stop()
{
cAudioMutexBasicLock lock(Mutex);
alSourceStop(Source);
@ -155,13 +155,13 @@ namespace cAudio
getLogger()->logDebug("Audio Source", "Source stopped.");
}
void cAudio::loop(const bool& loop)
void cAudioSource::loop(const bool& loop)
{
cAudioMutexBasicLock lock(Mutex);
Loop = loop;
}
bool cAudio::seek(const float& seconds, bool relative)
bool cAudioSource::seek(const float& seconds, bool relative)
{
bool state = false;
cAudioMutexBasicLock lock(Mutex);
@ -172,7 +172,7 @@ namespace cAudio
return state;
}
bool cAudio::update()
bool cAudioSource::update()
{
cAudioMutexBasicLock lock(Mutex);
if(!isValid() || !isPlaying())
@ -206,7 +206,7 @@ namespace cAudio
return active;
}
void cAudio::release()
void cAudioSource::release()
{
cAudioMutexBasicLock lock(Mutex);
//Stops the audio Source
@ -220,66 +220,66 @@ namespace cAudio
getLogger()->logDebug("Audio Source", "Audio source released.");
}
const bool cAudio::isValid() const
const bool cAudioSource::isValid() const
{
return Valid;
}
const bool cAudio::isPlaying() const
const bool cAudioSource::isPlaying() const
{
ALenum state = 0;
alGetSourcei(Source, AL_SOURCE_STATE, &state);
return (state == AL_PLAYING);
}
const bool cAudio::isPaused() const
const bool cAudioSource::isPaused() const
{
ALenum state = 0;
alGetSourcei(Source, AL_SOURCE_STATE, &state);
return (state == AL_PAUSED);
}
const bool cAudio::isStopped() const
const bool cAudioSource::isStopped() const
{
ALenum state = 0;
alGetSourcei(Source, AL_SOURCE_STATE, &state);
return (state == AL_STOPPED);
}
const bool cAudio::isLooping() const
const bool cAudioSource::isLooping() const
{
return Loop;
}
void cAudio::setPosition(const cVector3& position)
void cAudioSource::setPosition(const cVector3& position)
{
cAudioMutexBasicLock lock(Mutex);
alSource3f(Source, AL_POSITION, position.x, position.y, position.z);
checkError();
}
void cAudio::setVelocity(const cVector3& velocity)
void cAudioSource::setVelocity(const cVector3& velocity)
{
cAudioMutexBasicLock lock(Mutex);
alSource3f(Source, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
checkError();
}
void cAudio::setDirection(const cVector3& direction)
void cAudioSource::setDirection(const cVector3& direction)
{
cAudioMutexBasicLock lock(Mutex);
alSource3f(Source, AL_DIRECTION, direction.x, direction.y, direction.z);
checkError();
}
void cAudio::setRolloffFactor(const float& rolloff)
void cAudioSource::setRolloffFactor(const float& rolloff)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_ROLLOFF_FACTOR, rolloff);
checkError();
}
void cAudio::setStrength(const float& soundstrength)
void cAudioSource::setStrength(const float& soundstrength)
{
float inverseStrength = 0.0f;
if(soundstrength > 0.0f)
@ -290,84 +290,84 @@ namespace cAudio
checkError();
}
void cAudio::setMinDistance(const float& minDistance)
void cAudioSource::setMinDistance(const float& minDistance)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_REFERENCE_DISTANCE, minDistance);
checkError();
}
void cAudio::setMaxDistance(const float& maxDistance)
void cAudioSource::setMaxDistance(const float& maxDistance)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_MAX_DISTANCE, maxDistance);
checkError();
}
void cAudio::setPitch(const float& pitch)
void cAudioSource::setPitch(const float& pitch)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef (Source, AL_PITCH, pitch);
checkError();
}
void cAudio::setVolume(const float& volume)
void cAudioSource::setVolume(const float& volume)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_GAIN, volume);
checkError();
}
void cAudio::setMinVolume(const float& minVolume)
void cAudioSource::setMinVolume(const float& minVolume)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_MIN_GAIN, minVolume);
checkError();
}
void cAudio::setMaxVolume(const float& maxVolume)
void cAudioSource::setMaxVolume(const float& maxVolume)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_MAX_GAIN, maxVolume);
checkError();
}
void cAudio::setInnerConeAngle(const float& innerAngle)
void cAudioSource::setInnerConeAngle(const float& innerAngle)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_CONE_INNER_ANGLE, innerAngle);
checkError();
}
void cAudio::setOuterConeAngle(const float& outerAngle)
void cAudioSource::setOuterConeAngle(const float& outerAngle)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_CONE_OUTER_ANGLE, outerAngle);
checkError();
}
void cAudio::setOuterConeVolume(const float& outerVolume)
void cAudioSource::setOuterConeVolume(const float& outerVolume)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_CONE_OUTER_GAIN, outerVolume);
checkError();
}
void cAudio::setDopplerStrength(const float& dstrength)
void cAudioSource::setDopplerStrength(const float& dstrength)
{
cAudioMutexBasicLock lock(Mutex);
alSourcef(Source, AL_DOPPLER_FACTOR, dstrength);
checkError();
}
void cAudio::setDopplerVelocity(const cVector3& dvelocity)
void cAudioSource::setDopplerVelocity(const cVector3& dvelocity)
{
cAudioMutexBasicLock lock(Mutex);
alSource3f(Source, AL_DOPPLER_VELOCITY, dvelocity.x, dvelocity.y, dvelocity.z);
checkError();
}
void cAudio::move(const cVector3& position)
void cAudioSource::move(const cVector3& position)
{
cAudioMutexBasicLock lock(Mutex);
cVector3 oldPos = getPosition();
@ -378,35 +378,35 @@ namespace cAudio
checkError();
}
const cVector3 cAudio::getPosition() const
const cVector3 cAudioSource::getPosition() const
{
cVector3 position;
alGetSourcefv(Source, AL_POSITION, &position.x);
return position;
}
const cVector3 cAudio::getVelocity() const
const cVector3 cAudioSource::getVelocity() const
{
cVector3 velocity;
alGetSourcefv(Source, AL_VELOCITY, &velocity.x);
return velocity;
}
const cVector3 cAudio::getDirection() const
const cVector3 cAudioSource::getDirection() const
{
cVector3 direction;
alGetSourcefv(Source, AL_DIRECTION, &direction.x);
return direction;
}
const float cAudio::getRolloffFactor() const
const float cAudioSource::getRolloffFactor() const
{
float value = 0.0f;
alGetSourcef(Source, AL_ROLLOFF_FACTOR, &value);
return value;
}
const float cAudio::getStrength() const
const float cAudioSource::getStrength() const
{
float value = 0.0f;
alGetSourcef(Source, AL_ROLLOFF_FACTOR, &value);
@ -418,77 +418,77 @@ namespace cAudio
return inverseStrength;
}
const float cAudio::getMinDistance() const
const float cAudioSource::getMinDistance() const
{
float value = 0.0f;
alGetSourcef(Source, AL_REFERENCE_DISTANCE, &value);
return value;
}
const float cAudio::getMaxDistance() const
const float cAudioSource::getMaxDistance() const
{
float value = 0.0f;
alGetSourcef(Source, AL_MAX_DISTANCE, &value);
return value;
}
const float cAudio::getPitch() const
const float cAudioSource::getPitch() const
{
float value = 0.0f;
alGetSourcef(Source, AL_PITCH, &value);
return value;
}
const float cAudio::getVolume() const
const float cAudioSource::getVolume() const
{
float value = 0.0f;
alGetSourcef(Source, AL_GAIN, &value);
return value;
}
const float cAudio::getMinVolume() const
const float cAudioSource::getMinVolume() const
{
float value = 0.0f;
alGetSourcef(Source, AL_MIN_GAIN, &value);
return value;
}
const float cAudio::getMaxVolume() const
const float cAudioSource::getMaxVolume() const
{
float value = 0.0f;
alGetSourcef(Source, AL_MAX_GAIN, &value);
return value;
}
const float cAudio::getInnerConeAngle() const
const float cAudioSource::getInnerConeAngle() const
{
float value = 0.0f;
alGetSourcef(Source, AL_CONE_INNER_ANGLE, &value);
return value;
}
const float cAudio::getOuterConeAngle() const
const float cAudioSource::getOuterConeAngle() const
{
float value = 0.0f;
alGetSourcef(Source, AL_CONE_OUTER_ANGLE, &value);
return value;
}
const float cAudio::getOuterConeVolume() const
const float cAudioSource::getOuterConeVolume() const
{
float value = 0.0f;
alGetSourcef(Source, AL_CONE_OUTER_GAIN, &value);
return value;
}
const float cAudio::getDopplerStrength() const
const float cAudioSource::getDopplerStrength() const
{
float value = 0.0f;
alGetSourcef(Source, AL_DOPPLER_FACTOR, &value);
return value;
}
const cVector3 cAudio::getDopplerVelocity() const
const cVector3 cAudioSource::getDopplerVelocity() const
{
cVector3 velocity;
alGetSourcefv(Source, AL_DOPPLER_VELOCITY, &velocity.x);
@ -496,12 +496,12 @@ namespace cAudio
}
#ifdef CAUDIO_EFX_ENABLED
unsigned int cAudio::getNumEffectSlotsAvailable() const
unsigned int cAudioSource::getNumEffectSlotsAvailable() const
{
return EffectSlotsAvailable;
}
bool cAudio::attachEffect(unsigned int slot, IEffect* effect)
bool cAudioSource::attachEffect(unsigned int slot, IEffect* effect)
{
cAudioMutexBasicLock lock(Mutex);
if(slot < EffectSlotsAvailable)
@ -517,7 +517,7 @@ namespace cAudio
return false;
}
void cAudio::removeEffect(unsigned int slot)
void cAudioSource::removeEffect(unsigned int slot)
{
cAudioMutexBasicLock lock(Mutex);
if(slot < EffectSlotsAvailable)
@ -531,7 +531,7 @@ namespace cAudio
}
}
bool cAudio::attachFilter(IFilter* filter)
bool cAudioSource::attachFilter(IFilter* filter)
{
cAudioMutexBasicLock lock(Mutex);
Filter = filter;
@ -543,7 +543,7 @@ namespace cAudio
return true;
}
void cAudio::removeFilter()
void cAudioSource::removeFilter()
{
cAudioMutexBasicLock lock(Mutex);
if(Filter)
@ -554,7 +554,7 @@ namespace cAudio
}
#endif
void cAudio::empty()
void cAudioSource::empty()
{
int queued = 0;
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
@ -567,7 +567,7 @@ namespace cAudio
}
}
bool cAudio::checkError()
bool cAudioSource::checkError()
{
int error = alGetError();
const char* errorString;
@ -584,7 +584,7 @@ namespace cAudio
return false;
}
bool cAudio::stream(ALuint buffer)
bool cAudioSource::stream(ALuint buffer)
{
if(Decoder)
{
@ -634,7 +634,7 @@ namespace cAudio
return false;
}
ALenum cAudio::convertAudioFormatEnum(AudioFormats format)
ALenum cAudioSource::convertAudioFormatEnum(AudioFormats format)
{
switch(format)
{
@ -652,7 +652,7 @@ namespace cAudio
}
#ifdef CAUDIO_EFX_ENABLED
void cAudio::updateFilter(bool remove)
void cAudioSource::updateFilter(bool remove)
{
if(!remove)
{
@ -676,7 +676,7 @@ namespace cAudio
checkError();
}
void cAudio::updateEffect(unsigned int slot, bool remove)
void cAudioSource::updateEffect(unsigned int slot, bool remove)
{
if(slot < EffectSlotsAvailable)
{

View File

@ -2,80 +2,80 @@
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#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;
}
};
#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;
}
};

View File

@ -2,4 +2,4 @@
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#include "../Headers/cWavAudioDecoderFactory.h"
#include "../Headers/cWavAudioDecoderFactory.h"

View File

@ -387,10 +387,6 @@
RelativePath=".\include\EAudioFormats.h"
>
</File>
<File
RelativePath=".\include\IAudio.h"
>
</File>
<File
RelativePath=".\include\IAudioCapture.h"
>
@ -415,6 +411,10 @@
RelativePath=".\include\IAudioPlugin.h"
>
</File>
<File
RelativePath=".\include\IAudioSource.h"
>
</File>
<File
RelativePath=".\include\IDataSource.h"
>

View File

@ -12,7 +12,7 @@
namespace cAudio
{
class IAudio;
class IAudioSource;
class IAudioDecoderFactory;
class IAudioManager
@ -28,11 +28,11 @@ namespace cAudio
//!Updates the cAudio playback
virtual void update() = 0;
//!Returns an IAudio object by its "name" and 0 if the name is not found
virtual IAudio* getSoundByName(const char* name) = 0;
virtual IAudioSource* getSoundByName(const char* name) = 0;
//!Releases "ALL" cAudio objects (but does not shutdown the manager)
virtual void release() = 0;
//!Releases a single cAudio source
virtual void release(IAudio* source) = 0;
virtual void release(IAudioSource* source) = 0;
//! Returns the name of an available playback device.
/** \param index: Specify which name to retrieve ( Range: 0 to getAvailableDeviceCount()-1 ) */
@ -43,11 +43,11 @@ namespace cAudio
virtual const char* getDefaultDeviceName() = 0;
//!Creates the cAudio object
virtual IAudio* createFromFile(const char* name, const char* pathToFile, bool stream = false) = 0;
virtual IAudioSource* createFromFile(const char* name, const char* pathToFile, bool stream = false) = 0;
//!Loads audio from memory or virtual file system
virtual IAudio* createFromMemory(const char* name, const char* data, size_t length, const char* extension) = 0;
virtual IAudioSource* createFromMemory(const char* name, const char* data, size_t length, const char* extension) = 0;
//!Loads raw audio from memory.
virtual IAudio* createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format) = 0;
virtual IAudioSource* createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format) = 0;
//!Register Audio Codec
virtual bool registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension) = 0;

View File

@ -1,174 +1,174 @@
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#ifndef IAUDIO_H
#define IAUDIO_H
#include "cAudioDefines.h"
#include "IRefCounted.h"
#include "IAudioDecoder.h"
#include "cVector3.h"
#include "IEffect.h"
#include "IFilter.h"
namespace cAudio
{
class IAudio : public IRefCounted
{
public:
IAudio() {}
virtual ~IAudio() {}
//! Plays the source with the default or last set values
virtual bool play() = 0;
//! Plays the source in 2D mode
virtual bool play2d(const bool& toLoop = false) = 0;
//! Plays the source in 3D mode
virtual bool play3d(const cVector3& position, const float& soundstr = 1.0 , const bool& toLoop = false) = 0;
//! Pauses playback of the sound source
virtual void pause() = 0;
//! Stops playback of the sound source
virtual void stop() = 0;
//! Controls whether the source should loop or not
virtual void loop(const bool& toLoop) = 0;
//! Seeks through the audio stream to a specific spot
/** Note: May not be supported by all codecs
\param seconds: Number of seconds to seek
\param relative: Whether to seek from the current position or the start of the stream
\return True on success, False if the codec does not support seeking. */
virtual bool seek(const float& seconds, bool relative = false) = 0;
//! Normally called every frame by the audio manager to update the internal buffers
//! Note: For internal use only.
virtual bool update() = 0;
//! Releases all resources used by the audio source, normally used to clean up before deletion
//! Note: For internal use only.
virtual void release() = 0;
//! Returns if the source is ready to be used
virtual const bool isValid() const = 0;
//! Returns if the source is playing
virtual const bool isPlaying() const = 0;
//! Returns if the source is paused
virtual const bool isPaused() const = 0;
//! Returns if the source is stopped
virtual const bool isStopped() const = 0;
//! Returns if the source is looping
virtual const bool isLooping() const = 0;
//! Sets the position of the source in 3D space
virtual void setPosition(const cVector3& position) = 0;
//! Sets the current velocity of the source for doppler effects
virtual void setVelocity(const cVector3& velocity) = 0;
//! Sets the direction the source is facing
virtual void setDirection(const cVector3& direction) = 0;
//! Sets the factor used in attenuating the source over distance
//! Larger values make it attenuate faster, smaller values make the source carry better
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setRolloffFactor(const float& rolloff) = 0;
//! Sets how well the source carries over distance
//! Same as setRolloffFactor(1.0f/soundstrength)
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setStrength(const float& soundstrength) = 0;
//! Sets the distance from the source where attenuation will begin
//! Range: 0.0f to +inf
virtual void setMinDistance(const float& minDistance) = 0;
//! Sets the distance from the source where attenuation will stop
//! Range: 0.0f to +inf
virtual void setMaxDistance(const float& maxDistance) = 0;
//! Sets the pitch of the source
virtual void setPitch(const float& pitch) = 0;
//! Sets the source volume before attenuation and other effects
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setVolume(const float& volume) = 0;
//! Sets the minimum volume that the source can be attenuated to
//! Range: 0.0f to +inf (Default: 0.0f)
virtual void setMinVolume(const float& minVolume) = 0;
//! Sets the maximum volume that the source can achieve
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setMaxVolume(const float& maxVolume) = 0;
//! Sets the angle of the inner sound cone of the source
//! Note: This causes the sound to be loudest only if the listener is inside this cone
//! Range: 0.0f to 360.0f (Default: 360.0f)
virtual void setInnerConeAngle(const float& innerAngle) = 0;
//! Sets the angle of the outer sound cone of the source
//! Note: If the listener is outside of this cone, the sound cannot be heard. Between the inner cone angle and this angle, the sound volume will fall off
//! Range: 0.0f to 360.0f (Default: 360.0f)
virtual void setOuterConeAngle(const float& outerAngle) = 0;
//! Sets how much the volume of the source is scaled in the outer cone
//! Range: 0.0f to +inf (Default: 0.0f)
virtual void setOuterConeVolume(const float& outerVolume) = 0;
//! Sets the doppler strength, which enhances or diminishes the doppler effect
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setDopplerStrength(const float& dstrength) = 0;
//! Overrides the doppler velocity vector
virtual void setDopplerVelocity(const cVector3& dvelocity) = 0;
//! Convenience function to automatically set the velocity and position for you in a single call
//! Velocity will be set to new position - last position
virtual void move(const cVector3& position) = 0;
//! Returns the audio objects position
virtual const cVector3 getPosition() const = 0;
//! Returns the audio objects velocity
virtual const cVector3 getVelocity() const = 0;
//! Returns the audio objects direction
virtual const cVector3 getDirection() const = 0;
//! Returns the factor used in attenuating the source over distance
virtual const float getRolloffFactor() const = 0;
//! Returns the strength of the source
virtual const float getStrength() const = 0;
//! Returns the distance from the source where attenuation will begin
virtual const float getMinDistance() const = 0;
//! Returns the distance from the source where attenuation will stop
virtual const float getMaxDistance() const = 0;
//! Returns the pitch of the source
virtual const float getPitch() const = 0;
//! Returns the source volume before attenuation and other effects
virtual const float getVolume() const = 0;
//! Returns the minimum volume that the source can be attenuated to
virtual const float getMinVolume() const = 0;
//! Returns the maximum volume that the source can achieve
virtual const float getMaxVolume() const = 0;
//! Returns the angle of the inner sound cone of the source
virtual const float getInnerConeAngle() const = 0;
//! Returns the angle of the outer sound cone of the source
virtual const float getOuterConeAngle() const = 0;
//! Returns how much the volume of the source is scaled in the outer cone
virtual const float getOuterConeVolume() const = 0;
//! Returns the doppler strength, which enhances or diminishes the doppler effect
virtual const float getDopplerStrength() const = 0;
//! Returns the override for the doppler velocity vector
virtual const cVector3 getDopplerVelocity() const = 0;
#ifdef CAUDIO_EFX_ENABLED
//! Returns the number of effects at one time this source can support
virtual unsigned int getNumEffectSlotsAvailable() const = 0;
//! Attaches an EFX audio effect to this sound source to a specific slot
//! Range (slot): 0 to getNumEffectSlotsAvailable()
virtual bool attachEffect(unsigned int slot, IEffect* effect) = 0;
//! Removes an EFX audio effect from this sound source
//! Range (slot): 0 to getNumEffectSlotsAvailable()
virtual void removeEffect(unsigned int slot) = 0;
//! Attaches an audio filter to this sound source that will operate on the direct feed, seperate from any effects
virtual bool attachFilter(IFilter* filter) = 0;
//! Removes the previously attached filter
virtual void removeFilter() = 0;
#endif
protected:
private:
};
};
#endif //! IAUDIO_H
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#ifndef IAUDIOSOURCE_H
#define IAUDIOSOURCE_H
#include "cAudioDefines.h"
#include "IRefCounted.h"
#include "IAudioDecoder.h"
#include "cVector3.h"
#include "IEffect.h"
#include "IFilter.h"
namespace cAudio
{
class IAudioSource : public IRefCounted
{
public:
IAudioSource() {}
virtual ~IAudioSource() {}
//! Plays the source with the default or last set values
virtual bool play() = 0;
//! Plays the source in 2D mode
virtual bool play2d(const bool& toLoop = false) = 0;
//! Plays the source in 3D mode
virtual bool play3d(const cVector3& position, const float& soundstr = 1.0 , const bool& toLoop = false) = 0;
//! Pauses playback of the sound source
virtual void pause() = 0;
//! Stops playback of the sound source
virtual void stop() = 0;
//! Controls whether the source should loop or not
virtual void loop(const bool& toLoop) = 0;
//! Seeks through the audio stream to a specific spot
/** Note: May not be supported by all codecs
\param seconds: Number of seconds to seek
\param relative: Whether to seek from the current position or the start of the stream
\return True on success, False if the codec does not support seeking. */
virtual bool seek(const float& seconds, bool relative = false) = 0;
//! Normally called every frame by the audio manager to update the internal buffers
//! Note: For internal use only.
virtual bool update() = 0;
//! Releases all resources used by the audio source, normally used to clean up before deletion
//! Note: For internal use only.
virtual void release() = 0;
//! Returns if the source is ready to be used
virtual const bool isValid() const = 0;
//! Returns if the source is playing
virtual const bool isPlaying() const = 0;
//! Returns if the source is paused
virtual const bool isPaused() const = 0;
//! Returns if the source is stopped
virtual const bool isStopped() const = 0;
//! Returns if the source is looping
virtual const bool isLooping() const = 0;
//! Sets the position of the source in 3D space
virtual void setPosition(const cVector3& position) = 0;
//! Sets the current velocity of the source for doppler effects
virtual void setVelocity(const cVector3& velocity) = 0;
//! Sets the direction the source is facing
virtual void setDirection(const cVector3& direction) = 0;
//! Sets the factor used in attenuating the source over distance
//! Larger values make it attenuate faster, smaller values make the source carry better
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setRolloffFactor(const float& rolloff) = 0;
//! Sets how well the source carries over distance
//! Same as setRolloffFactor(1.0f/soundstrength)
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setStrength(const float& soundstrength) = 0;
//! Sets the distance from the source where attenuation will begin
//! Range: 0.0f to +inf
virtual void setMinDistance(const float& minDistance) = 0;
//! Sets the distance from the source where attenuation will stop
//! Range: 0.0f to +inf
virtual void setMaxDistance(const float& maxDistance) = 0;
//! Sets the pitch of the source
virtual void setPitch(const float& pitch) = 0;
//! Sets the source volume before attenuation and other effects
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setVolume(const float& volume) = 0;
//! Sets the minimum volume that the source can be attenuated to
//! Range: 0.0f to +inf (Default: 0.0f)
virtual void setMinVolume(const float& minVolume) = 0;
//! Sets the maximum volume that the source can achieve
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setMaxVolume(const float& maxVolume) = 0;
//! Sets the angle of the inner sound cone of the source
//! Note: This causes the sound to be loudest only if the listener is inside this cone
//! Range: 0.0f to 360.0f (Default: 360.0f)
virtual void setInnerConeAngle(const float& innerAngle) = 0;
//! Sets the angle of the outer sound cone of the source
//! Note: If the listener is outside of this cone, the sound cannot be heard. Between the inner cone angle and this angle, the sound volume will fall off
//! Range: 0.0f to 360.0f (Default: 360.0f)
virtual void setOuterConeAngle(const float& outerAngle) = 0;
//! Sets how much the volume of the source is scaled in the outer cone
//! Range: 0.0f to +inf (Default: 0.0f)
virtual void setOuterConeVolume(const float& outerVolume) = 0;
//! Sets the doppler strength, which enhances or diminishes the doppler effect
//! Range: 0.0f to +inf (Default: 1.0f)
virtual void setDopplerStrength(const float& dstrength) = 0;
//! Overrides the doppler velocity vector
virtual void setDopplerVelocity(const cVector3& dvelocity) = 0;
//! Convenience function to automatically set the velocity and position for you in a single call
//! Velocity will be set to new position - last position
virtual void move(const cVector3& position) = 0;
//! Returns the audio objects position
virtual const cVector3 getPosition() const = 0;
//! Returns the audio objects velocity
virtual const cVector3 getVelocity() const = 0;
//! Returns the audio objects direction
virtual const cVector3 getDirection() const = 0;
//! Returns the factor used in attenuating the source over distance
virtual const float getRolloffFactor() const = 0;
//! Returns the strength of the source
virtual const float getStrength() const = 0;
//! Returns the distance from the source where attenuation will begin
virtual const float getMinDistance() const = 0;
//! Returns the distance from the source where attenuation will stop
virtual const float getMaxDistance() const = 0;
//! Returns the pitch of the source
virtual const float getPitch() const = 0;
//! Returns the source volume before attenuation and other effects
virtual const float getVolume() const = 0;
//! Returns the minimum volume that the source can be attenuated to
virtual const float getMinVolume() const = 0;
//! Returns the maximum volume that the source can achieve
virtual const float getMaxVolume() const = 0;
//! Returns the angle of the inner sound cone of the source
virtual const float getInnerConeAngle() const = 0;
//! Returns the angle of the outer sound cone of the source
virtual const float getOuterConeAngle() const = 0;
//! Returns how much the volume of the source is scaled in the outer cone
virtual const float getOuterConeVolume() const = 0;
//! Returns the doppler strength, which enhances or diminishes the doppler effect
virtual const float getDopplerStrength() const = 0;
//! Returns the override for the doppler velocity vector
virtual const cVector3 getDopplerVelocity() const = 0;
#ifdef CAUDIO_EFX_ENABLED
//! Returns the number of effects at one time this source can support
virtual unsigned int getNumEffectSlotsAvailable() const = 0;
//! Attaches an EFX audio effect to this sound source to a specific slot
//! Range (slot): 0 to getNumEffectSlotsAvailable()
virtual bool attachEffect(unsigned int slot, IEffect* effect) = 0;
//! Removes an EFX audio effect from this sound source
//! Range (slot): 0 to getNumEffectSlotsAvailable()
virtual void removeEffect(unsigned int slot) = 0;
//! Attaches an audio filter to this sound source that will operate on the direct feed, seperate from any effects
virtual bool attachFilter(IFilter* filter) = 0;
//! Removes the previously attached filter
virtual void removeFilter() = 0;
#endif
protected:
private:
};
};
#endif //! IAUDIO_H

View File

@ -29,7 +29,7 @@
#include "cAudioDefines.h"
#include "cAudioSleep.h"
#include "EAudioFormats.h"
#include "IAudio.h"
#include "IAudioSource.h"
#include "IAudioCapture.h"
#include "IAudioDecoder.h"
#include "IAudioDecoderFactory.h"

View File

@ -12,7 +12,7 @@
//Include IAudioManager so we can easily work with cAudio
#include "../../include/IAudioManager.h"
//Include IAudio so we can create cAudio objects
#include "../../include/IAudio.h"
#include "../../include/IAudioSource.h"
//Include The cAudio vector class
#include "../../include/cVector3.h"
//Include our version of Sleep to free CPU usage
@ -25,7 +25,7 @@ using namespace std;
#define MAXAUDIOSOURCES 64
#define TESTDURATION 10
cAudio::IAudio* AudioSources[MAXAUDIOSOURCES];
cAudio::IAudioSource* AudioSources[MAXAUDIOSOURCES];
inline float getRandomFloat(float fMin, float fMax)
{