More documentation.

Added image for the API doc.
Fixed a bug where audio sources would not reset themselves when they stopped playing a stream due to reaching the end.
This commit is contained in:
Joshua Jones 2010-02-18 04:22:59 +00:00
parent 72169dc8f8
commit b24a4f2bb8
13 changed files with 170 additions and 74 deletions

View File

@ -34,6 +34,7 @@ static std::string safeCStr(const char* str)
else return std::string("");
}
//! Returns a list of files/directories in the supplied directory. Used internally for auto-installation of plugins.
static std::vector<std::string> getFilesInDirectory(std::string path)
{
std::vector<std::string> FileList;

View File

@ -71,7 +71,6 @@ namespace cAudio
}
#endif
//!Initialize the listener,openal,and mikmod
bool cAudioManager::initialize(const char* deviceName, int outputFrequency, int eaxEffectSlots)
{
cAudioMutexBasicLock lock(Mutex);
@ -169,7 +168,6 @@ namespace cAudio
return true;
}
//!create a sound source
IAudioSource* cAudioManager::create(const char* name, const char* filename, bool stream)
{
cAudioMutexBasicLock lock(Mutex);
@ -231,7 +229,6 @@ namespace cAudio
return NULL;
}
//!Loads the ogg file from memory *virtual file systems*
IAudioSource* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
@ -562,7 +559,6 @@ namespace cAudio
}
}
//!grabs the selected audio file via the identifier
IAudioSource* cAudioManager::getSoundByName(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
@ -575,7 +571,6 @@ namespace cAudio
return i->second;
}
//!Releases the selected audio source
void cAudioManager::releaseAllSources()
{
cAudioMutexBasicLock lock(Mutex);
@ -615,7 +610,6 @@ namespace cAudio
}
}
//!Updates all audiosources created
void cAudioManager::update()
{
cAudioMutexBasicLock lock(Mutex);
@ -632,7 +626,6 @@ namespace cAudio
}
}
//!Shuts down cAudio. Deletes all audio sources in process
void cAudioManager::shutDown()
{
if(Initialized)

View File

@ -225,7 +225,9 @@ namespace cAudio
//gets the sound source processed buffers
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
//while there is more data refill buffers with audio data.
bool wasUpdated = false;
while (processed--)
{
ALuint buffer;
@ -234,11 +236,23 @@ namespace cAudio
//if more in stream continue playing.
if(active)
{
wasUpdated = true;
alSourceQueueBuffers(Source, 1, &buffer);
}
checkError();
}
signalEvent(ON_UPDATE);
int currentBuffers = 0;
alGetSourcei(Source, AL_BUFFERS_QUEUED, &currentBuffers);
if(currentBuffers <= 1 && !wasUpdated)
{
stop();
}
return active;
}
@ -643,7 +657,10 @@ namespace cAudio
++errorcount;
getLogger()->logDebug("Audio Source", "Decoder returned an error: %i (%i of 3)", actualread, errorcount);
if(errorcount >= 3)
{
stop();
break;
}
}
if(actualread == 0)
{
@ -661,7 +678,7 @@ namespace cAudio
//Second check, in case looping is not enabled, we will return false for end of stream
if(totalread == 0)
{
return false;
return false;
}
getLogger()->logDebug("Audio Source", "Buffered %i bytes of data into buffer %i at %i hz.", totalread, buffer, Decoder->getFrequency());
alBufferData(buffer, convertAudioFormatEnum(Decoder->getFormat()), tempbuffer, totalread, Decoder->getFrequency());

View File

@ -9,7 +9,6 @@
namespace cAudio
{
//!Init Takes a string for file name
cFileSource::cFileSource(const char* filename) : pFile(NULL), Valid(false), Filesize(0)
{
std::string safeFilename = safeCStr(filename);
@ -34,31 +33,26 @@ cFileSource::~cFileSource()
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)

View File

@ -50,14 +50,12 @@ namespace cAudio
alListener3f(AL_VELOCITY, Velocity.x, Velocity.y, Velocity.z);
}
#ifdef CAUDIO_EFX_ENABLED
//!Sets the meters per user world unit for use with sound effects
void cListener::setMetersPerUnit(const float& meters)
{
cAudioMutexBasicLock lock(Mutex);
alListenerf(AL_METERS_PER_UNIT, meters);
}
//!Returns the meters per user world unit for use with sound effects
float cListener::getMetersPerUnit(void) const
{
float value = 1.0f;

View File

@ -34,25 +34,21 @@ cMemorySource::~cMemorySource()
delete[] Data;
}
//!Returns true if the DataStream is valid
bool cMemorySource::isValid()
{
return Valid;
}
//!Returns the current position of the data stream.
int cMemorySource::getCurrentPos()
{
return Pos;
}
//!Returns the data stream size
int cMemorySource::getSize()
{
return Size;
}
//!Read current Data Stream Data
int cMemorySource::read(void* output, int size)
{
@ -73,7 +69,6 @@ int cMemorySource::read(void* output, int size)
}
}
//!Seek the data stream
bool cMemorySource::seek(int amount, bool relative)
{
if(relative)

View File

@ -8,14 +8,14 @@
namespace cAudio
{
//!Read Vorbis Data
//! Read Vorbis Data
size_t VorbisRead(void *ptr, size_t byteSize,size_t sizeToRead, void *datasource)
{
IDataSource* Stream = (IDataSource*)datasource;
return Stream->read(ptr,byteSize*sizeToRead);
}
//!Seek Vorbis Data
//! Seek Vorbis Data
int VorbisSeek(void *datasource,ogg_int64_t offset,int whence)
{
IDataSource* Stream = (IDataSource*)datasource;
@ -36,7 +36,7 @@ namespace cAudio
return 0;
}
//!Returns the vorbis data that was stored.
//! Returns the vorbis data that was stored.
long VorbisTell(void *datasource)
{
return ((IDataSource*)datasource)->getCurrentPos();
@ -61,7 +61,7 @@ namespace cAudio
{
ov_clear(&oggStream);
}
//!Returns given vorbis channel format
AudioFormats cOggDecoder::getFormat()
{
if(Valid)
@ -77,7 +77,7 @@ namespace cAudio
}
return EAF_8BIT_MONO;
}
//!Returns vorbis file frequency
int cOggDecoder::getFrequency()
{
if(Valid)
@ -87,7 +87,6 @@ namespace cAudio
return 0;
}
//!Returns if vorbis file is seekable
bool cOggDecoder::isSeekingSupported()
{
if(Valid)
@ -102,7 +101,6 @@ namespace cAudio
return Valid;
}
//!Reads the vorbis data
int cOggDecoder::readAudioData(void* output, int amount)
{
if(Valid)
@ -115,7 +113,6 @@ namespace cAudio
return 0;
}
//!Sets the postion for vorbis data reader
bool cOggDecoder::setPosition(int position, bool relative)
{
if(Valid)
@ -128,7 +125,6 @@ namespace cAudio
return false;
}
//!Seeks the vorbis data
bool cOggDecoder::seek(float seconds, bool relative)
{
if(Valid)

View File

@ -16,19 +16,16 @@ namespace cAudio{
}
//!Returns wav channel format
AudioFormats cRawDecoder::getFormat()
{
return Format;
}
//!Returns wav data frequency
int cRawDecoder::getFrequency()
{
return Frequency;
}
//!Returns if seeking is supported
bool cRawDecoder::isSeekingSupported()
{
return true;
@ -39,20 +36,17 @@ namespace cAudio{
return true;
}
//!Reads wav data
int cRawDecoder::readAudioData(void* output, int amount)
{
return Stream->read(output,amount);
}
//!Sets data reader position
bool cRawDecoder::setPosition(int position, bool relative)
{
Stream->seek(position,relative);
return true;
}
//!Seeks wav data
bool cRawDecoder::seek(float seconds,bool relative)
{
int SampleSize = 1;

View File

@ -116,7 +116,6 @@ namespace cAudio
Valid = false;
}
//!Returns wav channel format
AudioFormats cWavDecoder::getFormat()
{
if(Channels == 1 && BitsPerSample == 8)
@ -129,13 +128,11 @@ namespace cAudio
return EAF_16BIT_STEREO;
}
//!Returns wav data frequency
int cWavDecoder::getFrequency()
{
return SampleRate;
}
//!Returns if seeking is supported
bool cWavDecoder::isSeekingSupported()
{
return true;
@ -146,7 +143,6 @@ namespace cAudio
return Valid;
}
//!Reads wav data
int cWavDecoder::readAudioData(void* output, int amount)
{
int currentPos = Stream->getCurrentPos();
@ -174,7 +170,6 @@ namespace cAudio
}
//!Sets data reader position
bool cWavDecoder::setPosition(int position, bool relative)
{
int currentPos = Stream->getCurrentPos();
@ -195,7 +190,6 @@ namespace cAudio
return true;
}
//!Seeks wav data
bool cWavDecoder::seek(float seconds,bool relative)
{
int amountToSeek = seconds * (float)SampleRate * (float)Channels * (float)(BitsPerSample/8);

BIN
doc/cAudioLogo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -129,102 +129,147 @@ namespace cAudio
\param minDistance: Distance from the source where attenuation begins. */
virtual void setMinDistance(const float& minDistance) = 0;
//! Sets the distance from the source where attenuation will stop
//! Sets the distance from the source where attenuation will stop.
/** Range: 0.0f to +inf
\param maxDistance: Distance where attenuation will cease. Normally the farthest range you can heard the source. */
\param maxDistance: Distance where attenuation will cease. Normally the farthest range you can hear the source. */
virtual void setMaxDistance(const float& maxDistance) = 0;
//! Sets the pitch of the source
//! Sets the pitch of the source.
/** Range: 0.0f to +inf (Default: 1.0f)
\param pitch: New pitch level. Note that higher values will speed up the playback of the sound. */
virtual void setPitch(const float& pitch) = 0;
//! Sets the source volume before attenuation and other effects
//! Range: 0.0f to +inf (Default: 1.0f)
//! Sets the source volume before attenuation and other effects.
/** Range: 0.0f to +inf (Default: 1.0f).
\param volume: New volume of the source. */
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)
//! Sets the minimum volume that the source can be attenuated to.
/** Range: 0.0f to +inf (Default: 0.0f).
\param minVolume: New minimum volume of the source. */
virtual void setMinVolume(const float& minVolume) = 0;
//! Sets the maximum volume that the source can achieve
//! Range: 0.0f to +inf (Default: 1.0f)
//! Sets the maximum volume that the source can achieve.
/** Range: 0.0f to +inf (Default: 1.0f).
\param maxVolume: New maximum volume of the source. */
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)
//! Sets the angle of the inner sound cone of the source. The cone opens up in the direction of the source as set by setDirection().
/** 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).
\param innerAngle: Inside angle of the cone. */
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)
//! Sets the angle of the outer sound cone of the source. The cone opens up in the direction of the source as set by setDirection().
/** 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).
\param outerAngle: Outside angle of the cone. */
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)
//! Sets how much the volume of the source is scaled in the outer cone.
/** Range: 0.0f to +inf (Default: 0.0f).
\param outerVolume: Volume of the source in the outside cone. */
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)
//! Sets the doppler strength, which enhances or diminishes the doppler effect. Can be used to exaggerate the doppler for a special effect.
/** Range: 0.0f to +inf (Default: 1.0f).
\param dstrength: New strength for the doppler effect. */
virtual void setDopplerStrength(const float& dstrength) = 0;
//! Overrides the doppler velocity vector
//! Overrides the doppler velocity vector. It is usually better to let the engine take care of it automatically.
/** Note: must be set every time you set the position, velocity, or direction.
\param dvelocity: New doppler vector for the source. */
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
//! Convenience function to automatically set the velocity and position for you in a single call.
/** Velocity will be set to new position - last position.
\param position: Position to move the source to. */
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;
//!Registers a new event handler to source
//! Registers a new event handler to this source
/**
\param handler: Pointer to the event handler to register. */
virtual void registerEventHandler(ISourceEventHandler* handler) = 0;
//!Unregisters specified event handler from source
//! Removes a specified event handler from this source
/**
\param handler: Pointer to the event handler to remove. */
virtual void unRegisterEventHandler(ISourceEventHandler* handler) = 0;
//!Unregisters all event handlers attached to source
//! Removes all event handlers attached to this source
virtual void unRegisterAllEventHandlers() = 0;
#ifdef CAUDIO_EFX_ENABLED
//! Returns the number of effects at one time this source can support
//! 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()
//! Attaches an EFX audio effect to this sound source to a specific slot.
/**
\param slot: Slot to attach this effect to. Range: 0 to getNumEffectSlotsAvailable().
\param effect: Pointer to an effect object to attach.
\return Whether the effect was successfully attached. */
virtual bool attachEffect(unsigned int slot, IEffect* effect) = 0;
//! Removes an EFX audio effect from this sound source
//! Range (slot): 0 to getNumEffectSlotsAvailable()
//! Removes an EFX audio effect from this sound source.
/**
\param slot: Slot of the effect to remove. Range: 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, separate from any effects
//! Attaches an audio filter to this sound source that will operate on the direct feed, separate from any effects.
/**
\param filter: Pointer to the filter to attach. Any previous filter will be dropped.
\return Whether the filter was successfully attached. */
virtual bool attachFilter(IFilter* filter) = 0;
//! Removes the previously attached filter
//! Removes a previously attached filter.
virtual void removeFilter() = 0;
#endif

View File

@ -46,6 +46,63 @@
#include "IPluginManager.h"
#include "IRefCounted.h"
/*! \mainpage cAudio 2.0.0 API documentation
*
* <img src="../cAudioLogo.jpg"></img>
*
* \section intro Introduction
*
* Welcome to the Main API Documentation for cAudio 2.0.0. cAudio is an advanced C++ wrapper around OpenAL, a professional and powerful
* audio library. Thus cAudio provides you with a number of classes to allow you to easily manipulate your audio world and
* intergrate audio effects like reverberation, doppler, attenuation, ect. cAudio also has a plugin system, allowing developers to extend
* the functionality of the library. Furthermore, cAudio is released under the zlib license, meaning it is free for you to use in your projects,
* even if they are commercial. Of course, we suggest you read the full text of the license by looking at the local license.txt file or cAudio.h.
*
* Included with the SDK is a number of tutorials. We suggest you begin with them as they will guide you through the basics of cAudio usage
* and work up to more advanced topics. If you find you need more help, found a bug, or just want to talk about cAudio, please visit our forums
* at <A HREF="http://www.deathtouchstudios.com/phpBB3/index.php" >http://www.deathtouchstudios.com/phpBB3/index.php</A>.
*
* \section links Links
*
* <A HREF="namespacec_audio.html">Namespaces</A>: Central namespace for the entire engine. A good place to begin looking.<BR>
* <A HREF="annotated.html">Class list</A>: List of all classes in the engine with descriptions.<BR>
* <A HREF="functions.html">Class members</A>: List of all methods.<BR>
*
* \section example Short example
*
* Below is a simple "Hello World" example of how to use the engine. Of course this is only the "tip of the iceburg"
* when it comes to what cAudio is capable of.
*
* \code
* #include <cAudio.h>
*
* int main()
* {
* //Create an Audio Manager
* cAudio::IAudioManager* manager = cAudio::createAudioManager(true);
*
* //Create an audio source and load a sound from a file
* cAudio::IAudioSource* mysound = manager->create("music","../../media/cAudioTheme1.ogg",true);
*
* if(mysound)
* {
* //Play our source in 2D once.
* mysound->play2d(false);
*
* //Wait for the sound to finish playing
* while(mysound->isPlaying())
* cAudio::cAudioSleep(10);
* }
*
* //Shutdown cAudio
* manager->shutDown();
* cAudio::destroyAudioManager(manager);
*
* return 0;
* }
* \endcode
*/
//! Main namespace for the entire cAudio library
namespace cAudio
{

View File

@ -9,18 +9,22 @@
namespace cAudio
{
//! Smallest number that can be represented with a 32 bit float (may not match your compiler/os varient)
const float Epsilon = 0.000001f;
//! Internal function that compared two floats while keeping the Epsilon in mind.
inline bool float_equals(const float a, const float b)
{
return (a + Epsilon >= b) && (a - Epsilon <= b);
}
//! Class for manipulating vectors in 3D space.
class cVector3
{
public:
float x, y, z;
//! Default constructor, initializes everything to 0.
cVector3(void) : x(0), y(0), z(0)
{
}
@ -29,6 +33,7 @@ namespace cAudio
{
}
//! Constructor, initializes all 3 axes to the same value.
cVector3(float n) : x(n), y(n), z(n)
{
}
@ -86,11 +91,13 @@ namespace cAudio
float &operator[] ( int i ) { return ( ( float* ) &x ) [i]; }
//! Returns the length (magnitude) of the vector.
float length() const
{
return sqrtf( x*x + y*y + z*z );
}
//! Forces the current vector to have a length of 1 while preserving the ratio of components.
void normalize()
{
float invLen = 1.0f / length();
@ -99,16 +106,19 @@ namespace cAudio
z *= invLen;
}
//! Returns the dot product of this vector with the input vector.
float dot( const cVector3& other ) const
{
return ( x * other.x + y * other.y + z * other.z );
}
//! Returns the cross product of this vector with the input vector.
cVector3 cross( const cVector3& other ) const
{
return cVector3( y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x );
}
//! Sets the components of this vector.
void set( float nx, float ny, float nz )
{
x = nx;
@ -116,11 +126,13 @@ namespace cAudio
z = nz;
}
//! Sets all components of this vector to the same number.
void set( float n )
{
x = y = z = n;
}
//! Sets this vector's components to match the input vector's.
void set( const cVector3& other )
{
x = other.x;