add static source type, various bug and compiler error/warning fixes

This commit is contained in:
Arthur Danskin 2015-09-27 15:11:51 -07:00
parent 5c93210189
commit 36943a1885
45 changed files with 1095 additions and 550 deletions

View File

@ -4,8 +4,7 @@
#pragma once
#include <al.h>
#include <alc.h>
#include "cOpenALUtil.h"
#include "cMutex.h"
#include "cMemoryOverride.h"
#include "IAudioCapture.h"
@ -36,8 +35,8 @@ namespace cAudio
virtual void updateCaptureBuffer(bool force = false);
virtual void shutdown();
virtual bool isUpdateThreadRunning()
{
return (AudioThread != NULL && AudioThread->isRunning());
{
return (AudioThread != NULL && AudioThread->isRunning());
}
virtual const char* getDeviceName() { return toUTF8(DeviceName); }
@ -68,7 +67,7 @@ namespace cAudio
cAudioMutex Mutex;
//! Our update thread
//! Our update thread
IThread* AudioThread;
bool initOpenALDevice();
@ -92,4 +91,4 @@ namespace cAudio
ALenum convertAudioFormatEnum(AudioFormats format);
void signalEvent(Events sevent);
};
};
};

View File

@ -18,6 +18,7 @@
namespace cAudio
{
class IAudioSource;
class IAudioBuffer;
class cAudioManager : public IAudioManager, public cMemoryOverride, public IThreadWorker
{
@ -31,11 +32,11 @@ namespace cAudio
ON_DATASOURCEREGISTER,
};
cAudioManager() : AudioThread(NULL), AudioContext(NULL), Initialized(false), MasterVolume(1.0f) { }
cAudioManager() : Initialized(false), AudioThread(NULL), AudioContext(NULL), MasterVolume(1.0f) { }
virtual ~cAudioManager();
virtual bool initialize(const char* deviceName = 0x0, int outputFrequency = -1, int eaxEffectSlots = 4);
virtual void shutDown();
virtual void shutDown();
virtual void update();
virtual IAudioSource* getSoundByName(const char* name);
virtual void releaseAllSources();
@ -46,6 +47,10 @@ namespace cAudio
virtual void setMasterVolume(float vol);
virtual float getMasterVolume() const;
virtual void setSpeedOfSound(float speed);
virtual float getSpeedOfSound() const;
virtual void setDopplerFactor(float factor) const;
virtual float getDopplerFactor() const;
virtual void stopAllSounds();
virtual IAudioSource* create(const char* name, const char* filename, bool stream = false);
@ -53,6 +58,9 @@ namespace cAudio
virtual IAudioSource* createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format);
virtual IAudioSource* createFromAudioBuffer(const char* name, AudioCaptureBuffer* pBiffer, unsigned int frequency, AudioFormats format);
virtual IAudioBuffer* createBuffer(const char* filename);
virtual IAudioSource* createStatic(IAudioBuffer* buffer);
virtual bool registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension);
virtual void unRegisterAudioDecoder(const char* extension);
virtual bool isAudioDecoderRegistered(const char* extension);
@ -77,6 +85,8 @@ namespace cAudio
virtual IAudioEffects* getEffects();
#endif
virtual cAudioMutex *getMutex() { return &Mutex; }
protected:
virtual void run();
@ -101,6 +111,7 @@ namespace cAudio
typedef cAudioMap<cAudioString, IAudioSource*>::Type::iterator audioIndexIterator;
//! Holds all managed audio sources
cAudioVector<IAudioSource*>::Type audioSources;
cAudioVector<IAudioSource*>::Type updateSources;
//! Holds audio sources which gets deleted from the audioManager
cAudioVector<IAudioSource*>::Type managedAudioSources;
//! Holds audio sources which gets deleted from the audioManager

View File

@ -7,9 +7,8 @@
#include <list>
#include <string>
#include <vector>
#include <al.h>
#include <alc.h>
#include "cOpenALUtil.h"
#include "cMutex.h"
#include "cEFXFunctions.h"
#include "cMemoryOverride.h"
@ -21,8 +20,8 @@
namespace cAudio
{
class cAudioSource : public IAudioSource, public cMemoryOverride
class cAudioSourceBase : public IAudioSource, public cMemoryOverride
{
public:
@ -34,38 +33,13 @@ namespace cAudio
ON_STOP,
};
#if CAUDIO_EFX_ENABLED == 1
cAudioSource(IAudioDecoder* decoder, IAudioDeviceContext* context, cEFXFunctions* oALFunctions);
#else
cAudioSource(IAudioDecoder* decoder, IAudioDeviceContext* context);
#endif
~cAudioSource();
cAudioSourceBase(IAudioDeviceContext* context);
virtual ~cAudioSourceBase();
virtual bool play();
virtual bool play2d(const bool& toLoop = false);
virtual bool play3d(const cVector3& position, const float& soundstr = 1.0 , const bool& toLoop = false);
virtual void pause();
virtual void stop();
virtual void loop(const bool& toLoop);
virtual bool seek(const float& seconds, bool relative = false);
virtual bool isPlaying() const;
virtual bool isPaused() const;
virtual bool isStopped() const;
virtual float getTotalAudioTime();
virtual int getTotalAudioSize();
virtual int getCompressedAudioSize();
virtual float getCurrentAudioTime();
virtual int getCurrentAudioPosition();
virtual int getCurrentCompressedAudioPosition();
virtual bool update();
virtual const bool isValid() const;
virtual const bool isPlaying() const;
virtual const bool isPaused() const;
virtual const bool isStopped() const;
virtual const bool isLooping() const;
virtual void setPosition(const cVector3& position);
virtual void setVelocity(const cVector3& velocity);
virtual void setDirection(const cVector3& direction);
@ -89,31 +63,90 @@ namespace cAudio
virtual void move(const cVector3& position);
virtual const cVector3 getPosition() const;
virtual const cVector3 getVelocity() const;
virtual const cVector3 getDirection() const;
virtual cVector3 getPosition() const;
virtual cVector3 getVelocity() const;
virtual cVector3 getDirection() const;
virtual const float getRolloffFactor() const;
virtual const float getStrength() const;
virtual const float getMinDistance() const;
virtual const float getMaxDistance() const;
virtual float getRolloffFactor() const;
virtual float getStrength() const;
virtual float getMinDistance() const;
virtual float getMaxDistance() const;
virtual const float getPitch() const;
virtual const float getVolume() const;
virtual const float getMinVolume() const;
virtual const float getMaxVolume() const;
virtual bool isRelative() const;
virtual float calculateGain() const;
virtual const float getInnerConeAngle() const;
virtual const float getOuterConeAngle() const;
virtual const float getOuterConeVolume() const;
virtual float getPitch() const;
virtual float getVolume() const;
virtual float getMinVolume() const;
virtual float getMaxVolume() const;
virtual const float getDopplerStrength() const;
virtual const cVector3 getDopplerVelocity() const;
virtual float getInnerConeAngle() const;
virtual float getOuterConeAngle() const;
virtual float getOuterConeVolume() const;
virtual float getDopplerStrength() const;
virtual cVector3 getDopplerVelocity() const;
virtual void registerEventHandler(ISourceEventHandler* handler);
virtual void unRegisterEventHandler(ISourceEventHandler* handler);
virtual void unRegisterAllEventHandlers();
protected:
//! Mutex for thread synchronization
cAudioMutex Mutex;
//! Signals a event to all event handlers
void signalEvent(Events sevent);
//! The context that owns this source
IAudioDeviceContext* Context;
//! Holds the current volume
float Volume;
//! OpenAL source
ALuint Source;
ALenum oldState;
//! List of registered event handlers
cAudioVector<ISourceEventHandler*>::Type eventHandlerList;
};
class cAudioSource : public cAudioSourceBase {
public:
#if CAUDIO_EFX_ENABLED == 1
cAudioSource(IAudioDecoder* decoder, IAudioDeviceContext* context, cEFXFunctions* oALFunctions);
#else
cAudioSource(IAudioDecoder* decoder, IAudioDeviceContext* context);
#endif
~cAudioSource();
virtual bool play();
virtual bool play2d(const bool& toLoop = false);
virtual bool play3d(const cVector3& position, const float& soundstr = 1.0 , const bool& toLoop = false);
virtual void pause();
virtual void stop();
virtual void loop(const bool& toLoop);
virtual bool seek(const float& seconds, bool relative = false);
virtual bool setBuffer(IAudioBuffer* buffer) { return false; }
virtual IAudioBuffer *getBuffer() { return NULL; }
virtual float getTotalAudioTime();
virtual int getTotalAudioSize();
virtual int getCompressedAudioSize();
virtual float getCurrentAudioTime();
virtual int getCurrentAudioPosition();
virtual int getCurrentCompressedAudioPosition();
virtual bool update();
virtual bool isValid() const;
virtual bool isLooping() const;
virtual bool drop(); //! Override the default behavior
#if CAUDIO_EFX_ENABLED == 1
@ -126,31 +159,14 @@ namespace cAudio
#endif
private:
//! Mutex for thread synchronization
cAudioMutex Mutex;
//! Empties the current working buffer queue
void empty();
//! Checks for OpenAL errors and reports them
bool checkError() const;
//! Streams audio data from the decoder into a buffer
bool stream(ALuint buffer);
//! Signals a event to all event handlers
void signalEvent(Events sevent);
//! Converts our audio format enum to OpenAL's
ALenum convertAudioFormatEnum(AudioFormats format);
//! The context that owns this source
IAudioDeviceContext* Context;
//! Holds the current volume
float Volume;
//! Internal audio buffers
ALuint Buffers[CAUDIO_SOURCE_NUM_BUFFERS];
//! OpenAL source
ALuint Source;
ALenum oldState;
//! cAudio decoder being used to stream data
IAudioDecoder* Decoder;
@ -159,8 +175,10 @@ namespace cAudio
//! Stores whether the source is ready to be used
bool Valid;
//! List of registered event handlers
cAudioList<ISourceEventHandler*>::Type eventHandlerList;
//! position of first buffer in seconds
float BufferTime;
//! position of first buffer in bytes
int BufferPosition;
#if CAUDIO_EFX_ENABLED == 1
//! Holds pointers to all the EFX related functions

View File

@ -0,0 +1,248 @@
#include "cAudioSource.h"
namespace cAudio
{
class cAudioBuffer : public IAudioBuffer
{
ALuint Buffer;
bool Valid;
float TotalTime;
public:
cAudioBuffer(IAudioDecoder *decoder)
{
Buffer = 0;
Valid = false;
TotalTime = decoder->getTotalTime();
decoder->setPosition(0, false);
const int totalSize = decoder->getTotalSize()&~1;
if (totalSize > 0)
{
cAudioVector<char>::Type data(totalSize, 0);
int totalread = 0;
unsigned errorcount = 0;
while (totalread < totalSize)
{
const int actualread = decoder->readAudioData(&data[totalread], totalSize - totalread);
if (actualread > 0) {
totalread += actualread;
} else if (actualread < 0) {
++errorcount;
getLogger()->logDebug("Audio Buffer", "Decoder returned an error: %i (%i of 3)", actualread, errorcount);
if(errorcount >= 3) {
break;
}
} else {
break;
}
}
if (totalread != totalSize) {
getLogger()->logError("Audio Buffer", "Stopped short");
}
alGenBuffers(1, &Buffer);
checkALError();
const ALsizei freq = decoder->getFrequency();
const ALenum format = convertAudioFormatEnum(decoder->getFormat());
getLogger()->logDebug("Audio Buffer", "Buffered %d bytes of data into buffer %d at %d hz.", totalread, (int)Buffer, (int)freq);
alBufferData(Buffer, format, &data[0], data.size(), freq);
checkALError();
Valid = true;
}
}
~cAudioBuffer()
{
if (Valid)
{
alDeleteBuffers(1, &Buffer);
}
}
bool isValid() const { return Valid; }
unsigned getBuffer() const { return Buffer; }
int getChannels() const
{
ALint channels = 0;
alGetBufferi(Buffer, AL_CHANNELS, &channels);
return channels;
}
int getTotalAudioSize() const
{
ALint size = -1;
alGetBufferi(Buffer, AL_SIZE, &size);
return size;
}
float getTotalAudioTime() const { return TotalTime; }
};
class cAudioStaticSource : public cAudioSourceBase
{
IAudioBuffer* Buffer;
public:
cAudioStaticSource(IAudioBuffer* buffer, IAudioDeviceContext* context)
: cAudioSourceBase(context), Buffer(NULL)
{
setBuffer(buffer);
}
~cAudioStaticSource()
{
if (Buffer)
Buffer->drop();
}
bool setBuffer(IAudioBuffer* buffer)
{
if (isPlaying())
stop();
if (Buffer)
Buffer->drop();
Buffer = buffer;
if (Buffer) {
Buffer->grab();
alSourcei(Source, AL_BUFFER, Buffer->getBuffer());
checkALError();
}
return true;
}
IAudioBuffer *getBuffer()
{
return Buffer;
}
bool play()
{
alSourcePlay(Source);
checkALError();
getLogger()->logDebug("Audio Static Source", "Source playing.");
signalEvent(ON_PLAY);
oldState = AL_PLAYING;
return true;
}
bool play2d(const bool& toLoop)
{
alSourcei(Source, AL_SOURCE_RELATIVE, true);
alSourcei(Source, AL_LOOPING, toLoop);
checkALError();
return play();
}
bool play3d(const cVector3& position, const float& soundstr, const bool& toLoop)
{
alSourcei(Source, AL_SOURCE_RELATIVE, false);
alSourcei(Source, AL_LOOPING, toLoop);
checkALError();
setPosition(position);
setStrength(soundstr);
return play();
}
void pause()
{
alSourcePause(Source);
checkALError();
getLogger()->logDebug("Audio Static Source", "Source paused.");
signalEvent(ON_PAUSE);
oldState = AL_PAUSED;
}
void stop()
{
alSourceStop(Source);
alSourceRewind(Source);
checkALError();
getLogger()->logDebug("Audio Static Source", "Source stopped.");
signalEvent(ON_STOP);
oldState = AL_STOPPED;
}
void loop(const bool& toLoop)
{
alSourcei(Source, AL_LOOPING, toLoop);
checkALError();
}
bool seek(const float& seconds, bool relative)
{
float start = relative ? getCurrentAudioTime() : 0.f;
alSourcef(Source, AL_SEC_OFFSET, start + seconds);
checkALError();
return true;
}
float getTotalAudioTime() { return Buffer ? Buffer->getTotalAudioTime() : 0.f; }
int getTotalAudioSize() { return Buffer ? Buffer->getTotalAudioSize() : 0; }
int getCompressedAudioSize() { return -1; }
float getCurrentAudioTime()
{
float time = -1;
alGetSourcef(Source, AL_SEC_OFFSET, &time);
return time;
}
int getCurrentAudioPosition()
{
int offset = -1;
alGetSourcei(Source, AL_BYTE_OFFSET, &offset);
return offset;
}
int getCurrentCompressedAudioPosition() { return -1; }
bool update()
{
if(isValid() || isPlaying()) {
signalEvent(ON_UPDATE);
}
ALenum state;
alGetSourcei(Source, AL_SOURCE_STATE, &state);
checkALError();
if(state == AL_STOPPED && oldState != state)
{
getLogger()->logDebug("Audio Static Source", "Source stopped.");
signalEvent(ON_STOP);
oldState = state;
}
return state != AL_STOPPED;
}
bool isValid() const
{
return Buffer ? Buffer->isValid() : false;
}
bool isLooping() const
{
ALint looping = false;
alGetSourcei(Source, AL_LOOPING, &looping);
return looping == AL_TRUE;
}
#if CAUDIO_EFX_ENABLED == 1
virtual unsigned int getNumEffectSlotsAvailable() const { return 0; }
virtual bool attachEffect(unsigned int slot, IEffect* effect) { return false; }
virtual void removeEffect(unsigned int slot) {}
virtual bool attachFilter(IFilter* filter) { return false; }
virtual void removeFilter() {}
#endif
};
}

View File

@ -7,9 +7,7 @@
#include "cAudioDefines.h"
#if CAUDIO_MAKE_THREAD_SAFE == 1
#ifdef CAUDIO_PLATFORM_WIN
#include <windows.h> //Basic windows include
#else
#ifndef CAUDIO_PLATFORM_WIN
#include <pthread.h> //Assumed linux system
#endif
#endif
@ -61,4 +59,4 @@ namespace cAudio
protected:
cAudioMutex* Mutex;
};
};
};

View File

@ -4,14 +4,13 @@
#pragma once
#include <al.h>
#include <alc.h>
#include "IAudioDeviceContext.h"
#include "cMemoryOverride.h"
#include "cMutex.h"
#include "cAudioEffects.h"
#include "cOpenALUtil.h"
namespace cAudio
{
class cOpenALDeviceContext : public IAudioDeviceContext, public cMemoryOverride
@ -26,30 +25,30 @@ namespace cAudio
virtual IAudioEffects* getEffects() const;
ALCcontext* getOpenALContext() const;
private:
//! Check for OpenAL errors
bool checkError();
//! Mutex for thread synchronization
private:
//! Check for OpenAL errors
bool checkError();
//! Mutex for thread synchronization
cAudioMutex Mutex;
//! An OpenAL context pointer
ALCcontext* Context;
//! An OpenAL device pointer
//! An OpenAL context pointer
ALCcontext* Context;
//! An OpenAL device pointer
ALCdevice* Device;
IAudioManager* AudioManager;
bool Initialized;
//! Holds whether EFX is supported
//! Holds whether EFX is supported
bool EFXSupported;
#if CAUDIO_EFX_ENABLED == 1
//! Interface for audio effects
cAudioEffects initEffects;
#if CAUDIO_EFX_ENABLED == 1
//! Interface for audio effects
cAudioEffects initEffects;
#endif
};
}
}

69
cAudio/Headers/cOpenALUtil.h Executable file
View File

@ -0,0 +1,69 @@
#ifndef CAUDIO_COPENALUTIL_H
#define CAUDIO_COPENALUTIL_H
#include "cAudio.h"
#if !defined(CAUDIO_PLATFORM_LINUX)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
#if DEBUG
#ifndef __func__
#define __func__ __FUNCTION__
#endif
#define checkALError() checkALErrorInternal(__FILE__, __func__, __LINE__)
#else
#define checkALError() (false)
#endif
namespace cAudio {
//! Checks for OpenAL errors and reports them
inline bool checkALErrorInternal(const char* file, const char *func, int line)
{
ALenum error = AL_NO_ERROR;
bool anyError = false;
while ((error = alGetError()) != AL_NO_ERROR)
{
const char* errorString = alGetString(error);
if(error == AL_OUT_OF_MEMORY) {
getLogger()->logCritical("Audio Source", "OpenAL Error: %s:%d:%s, %s.", file, line, func, errorString);
} else if (error == -1) {
// this occurs randomly and relatively freqently with Apple's OpenAL and does not seem to cause serious problems.
getLogger()->logWarning("Audio Source", "OpenAL Warning %s:%d:%s, %s.", file, line, func, errorString);
} else {
getLogger()->logError("Audio Source", "OpenAL Error: %s:%d:%s, %s.", file, line, func, errorString);
}
anyError = true;
}
return anyError;
}
//! Converts our audio format enum to OpenAL's
inline ALenum convertAudioFormatEnum(AudioFormats format)
{
switch(format)
{
case EAF_8BIT_MONO:
return AL_FORMAT_MONO8;
case EAF_16BIT_MONO:
return AL_FORMAT_MONO16;
case EAF_8BIT_STEREO:
return AL_FORMAT_STEREO8;
case EAF_16BIT_STEREO:
return AL_FORMAT_STEREO16;
default:
return AL_FORMAT_MONO8;
};
}
}
#endif

View File

@ -13,8 +13,6 @@
#ifdef CAUDIO_COMPILE_WITH_PLUGIN_SUPPORT
#ifdef CAUDIO_PLATFORM_WIN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
struct HINSTANCE__;
typedef struct HINSTANCE__* hInstance;

View File

@ -8,11 +8,10 @@
#include "cAudioDefines.h"
#include "IThread.h"
#ifdef CAUDIO_PLATFORM_WIN
#include <windows.h> //Basic windows includes
#include <process.h>
#else
#include <pthread.h> //Assumed linux system
#ifdef CAUDIO_PLATFORM_WIN
#include <process.h>
#else
#include <pthread.h> //Assumed linux system
#endif
namespace cAudio
@ -44,4 +43,4 @@ namespace cAudio
bool IsInit;
bool Loop;
};
};
};

View File

@ -9,8 +9,6 @@
#include "cAudioString.h"
#ifdef CAUDIO_PLATFORM_WIN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <direct.h>
# include <io.h>
#endif
@ -25,14 +23,14 @@ namespace cAudio
{
//! Grabs the current extention of a given string.
static cAudioString getExt(const cAudioString& filename)
inline cAudioString getExt(const cAudioString& filename)
{
if(filename.find_last_of(_CTEXT(".")) == cAudioString::npos) return filename;
return filename.substr(filename.find_last_of(_CTEXT(".")) + 1, filename.length()-filename.find_last_of(_CTEXT("."))-1);
}
//! Returns a list of files/directories in the supplied directory. Used internally for auto-installation of plugins.
static cAudioVector<cAudioString>::Type getFilesInDirectory(cAudioString path)
inline cAudioVector<cAudioString>::Type getFilesInDirectory(cAudioString path)
{
cAudioVector<cAudioString>::Type FileList;
#ifdef CAUDIO_PLATFORM_WIN

View File

@ -14,4 +14,4 @@ namespace cAudio
EAF_16BIT_MONO,
EAF_16BIT_STEREO
};
};
};

View File

@ -150,4 +150,4 @@ namespace cAudio
char* buffer;
size_t length;
};
};
};

View File

@ -17,5 +17,6 @@ namespace cAudio
virtual void update() = 0;
virtual IAudioManager* getAudioManager() const = 0;
virtual IAudioEffects* getEffects() const = 0;
virtual ~IAudioDeviceContext(){}
};
}

View File

@ -24,5 +24,6 @@ namespace cAudio
virtual cAudioString getDeviceDescription(unsigned int idx) = 0;
virtual cAudioString getDefaultDeviceName() = 0;
virtual bool isSupported() = 0;
virtual ~IAudioDeviceList(){}
};
}

View File

@ -234,4 +234,4 @@ namespace cAudio
};
};
#endif
#endif

View File

@ -15,8 +15,10 @@
namespace cAudio
{
class IAudioSource;
class IAudioBuffer;
class IAudioDecoderFactory;
class AudioCaptureBuffer;
class cAudioMutex;
//! Interface for the playback capabilities of cAudio.
class IAudioManager
@ -89,6 +91,18 @@ namespace cAudio
//! Get the master volume.
virtual float getMasterVolume() const = 0;
//! Set Speed of Sound (for doppler computations)
virtual void setSpeedOfSound(float speed) = 0;
//! Get Speed of Sound (for doppler computations)
virtual float getSpeedOfSound() const = 0;
//! Set Doppler Factor
virtual void setDopplerFactor(float factor) const = 0;
//! Get Doppler Factor
virtual float getDopplerFactor() const = 0;
//! Stops all playing sounds.
virtual void stopAllSounds() = 0;
@ -133,6 +147,20 @@ namespace cAudio
*/
virtual IAudioSource* createFromAudioBuffer(const char* name, AudioCaptureBuffer* pBiffer, unsigned int frequency, AudioFormats format) = 0;
//! Creates a Audio Sample using the highest priority data source that has the referenced filename
/**
\param filename: Path to the file to load audio data from.
\return A pointer to an Audio Source or NULL if creation failed.
*/
virtual IAudioBuffer* createBuffer(const char* filename) = 0;
//! Creates an Audio Source from an Audio Buffer object (see createAudioBuffer())
/**
\param buffer: The buffer to play, or NULL to create an empty static source
\return A pointer to an Audio Source or NULL if creation failed.
*/
virtual IAudioSource* createStatic(IAudioBuffer* buffer) = 0;
//! Register an Audio Decoder.
/**
\param factory: Pointer to the factory instance to use.
@ -207,6 +235,8 @@ namespace cAudio
//! Returns the interface for the listener.
virtual IListener* getListener() = 0;
virtual cAudioMutex *getMutex() = 0;
#if CAUDIO_EFX_ENABLED == 1
//! Returns the interface for audio effects.
virtual IAudioEffects* getEffects() = 0;

View File

@ -52,4 +52,4 @@ namespace cAudio
\param capture: Pointer to the soon to be destroyed capture interface. */
virtual void onDestoryAudioCapture(IAudioCapture* capture) { }
};
};
};

View File

@ -14,6 +14,20 @@
namespace cAudio
{
//! interface for a sample (audio buffer): completely loaded into memory, shareable across sources
class IAudioBuffer : public IRefCounted
{
public:
virtual ~IAudioBuffer() {}
virtual bool isValid() const = 0;
virtual unsigned getBuffer() const = 0;
virtual int getChannels() const = 0;
virtual int getTotalAudioSize() const = 0;
virtual float getTotalAudioTime() const = 0;
};
//! Interface for a single audio source, which allow you to manipulate sound sources (speakers) in 2D or 3D space.
class IAudioSource : public IRefCounted
{
@ -39,7 +53,7 @@ namespace cAudio
\param toLoop: Whether to loop (restart) the audio when the end is reached.
\return True if the source is playing, false if not. */
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;
@ -57,6 +71,15 @@ namespace cAudio
\return True on success, False if the codec does not support seeking. */
virtual bool seek(const float& seconds, bool relative = false) = 0;
//! Change the audio buffer associated with the source
/** Note: Only supported on sources created with createFromBuffer() or createForBuffer()
\return True on success, False if the sample does not support setting buffers or is currently playing */
virtual bool setBuffer(IAudioBuffer* buffer) = 0;
//! Get the audio buffer associated with the source
/** \return buffer on succes, NULL if no buffer or sample is streaming */
virtual IAudioBuffer *getBuffer() = 0;
//! Returns the total amount of time in the audio stream. See IAudioDecoder for details.
virtual float getTotalAudioTime() = 0;
@ -79,19 +102,19 @@ namespace cAudio
virtual bool update() = 0;
//! Returns if the source is ready to be used.
virtual const bool isValid() const = 0;
virtual bool isValid() const = 0; //
//! Returns if the source is playing.
virtual const bool isPlaying() const = 0;
virtual bool isPlaying() const = 0;
//! Returns if the source is paused.
virtual const bool isPaused() const = 0;
virtual bool isPaused() const = 0;
//! Returns if the source is stopped.
virtual const bool isStopped() const = 0;
virtual bool isStopped() const = 0;
//! Returns if the source is looping.
virtual const bool isLooping() const = 0;
virtual bool isLooping() const = 0;
//! Sets the position of the source in 3D space.
/**
@ -183,52 +206,58 @@ namespace cAudio
virtual void move(const cVector3& position) = 0;
//! Returns the audio objects position
virtual const cVector3 getPosition() const = 0;
virtual cVector3 getPosition() const = 0;
//! Returns the audio objects velocity
virtual const cVector3 getVelocity() const = 0;
virtual cVector3 getVelocity() const = 0;
//! Returns the audio objects direction
virtual const cVector3 getDirection() const = 0;
virtual cVector3 getDirection() const = 0;
//! Returns the factor used in attenuating the source over distance
virtual const float getRolloffFactor() const = 0;
virtual float getRolloffFactor() const = 0;
//! Returns the strength of the source
virtual const float getStrength() const = 0;
virtual float getStrength() const = 0;
//! Returns the distance from the source where attenuation will begin
virtual const float getMinDistance() const = 0;
virtual float getMinDistance() const = 0;
//! Returns the distance from the source where attenuation will stop
virtual const float getMaxDistance() const = 0;
virtual float getMaxDistance() const = 0;
//! Return true for 2d sounds, false for 3d sounds
virtual bool isRelative() const = 0;
//! Return gain, taking into account volume as well as distance attenuation
virtual float calculateGain() const = 0;
//! Returns the pitch of the source
virtual const float getPitch() const = 0;
virtual float getPitch() const = 0;
//! Returns the source volume before attenuation and other effects
virtual const float getVolume() const = 0;
virtual float getVolume() const = 0;
//! Returns the minimum volume that the source can be attenuated to
virtual const float getMinVolume() const = 0;
virtual float getMinVolume() const = 0;
//! Returns the maximum volume that the source can achieve
virtual const float getMaxVolume() const = 0;
virtual float getMaxVolume() const = 0;
//! Returns the angle of the inner sound cone of the source
virtual const float getInnerConeAngle() const = 0;
virtual float getInnerConeAngle() const = 0;
//! Returns the angle of the outer sound cone of the source
virtual const float getOuterConeAngle() const = 0;
virtual float getOuterConeAngle() const = 0;
//! Returns how much the volume of the source is scaled in the outer cone
virtual const float getOuterConeVolume() const = 0;
virtual float getOuterConeVolume() const = 0;
//! Returns the doppler strength, which enhances or diminishes the doppler effect
virtual const float getDopplerStrength() const = 0;
virtual float getDopplerStrength() const = 0;
//! Returns the override for the doppler velocity vector
virtual const cVector3 getDopplerVelocity() const = 0;
virtual cVector3 getDopplerVelocity() const = 0;
//! Registers a new event handler to this source
/**
@ -272,4 +301,4 @@ namespace cAudio
protected:
private:
};
};
};

View File

@ -29,5 +29,6 @@ namespace cAudio
//! This function is called whe user requests data from the capture buffer.
virtual void onUserRequestBuffer() = 0;
virtual ~ICaptureEventHandler(){}
};
};

View File

@ -33,7 +33,7 @@ namespace cAudio
{
public:
ILogReceiver() { }
~ILogReceiver() { }
virtual ~ILogReceiver() { }
//! Called on every logged message that is greater than or equal to the minimum log level.
/**

View File

@ -27,6 +27,8 @@ namespace cAudio
//! This function is called when a data source is registered.
virtual void onDataSourceRegister() = 0;
virtual ~IManagerEventHandler(){}
};
};

View File

@ -28,5 +28,7 @@ namespace cAudio
//! Returns the largest possible single allocation that can be made.
virtual size_t getMaxAllocationSize() = 0;
virtual ~IMemoryProvider() {}
};
};

View File

@ -15,7 +15,7 @@ namespace cAudio
{
public:
IPluginManager() { }
~IPluginManager() { }
virtual ~IPluginManager() { }
//! Installs a plugin using a statically linked plugin implementation.
/**

View File

@ -11,19 +11,21 @@ namespace cAudio
{
public:
//! This function is called when a source updates its buffers.
virtual void onUpdate() = 0;
virtual void onUpdate(){}
//! This function is called when a source is released and soon to be deleted.
virtual void onRelease() = 0;
virtual void onRelease(){}
//! This function is called when a source starts playing.
virtual void onPlay() = 0;
virtual void onPlay(){}
//! This function is called when a source stopped playback.
virtual void onStop() = 0;
virtual void onStop(){}
//! This function is called when a source is paused.
virtual void onPause() = 0;
virtual void onPause(){}
virtual ~ISourceEventHandler(){}
};
};

View File

@ -13,11 +13,13 @@ namespace cAudio
virtual void join() = 0;
virtual void shutdown() = 0;
virtual bool isRunning() = 0;
virtual ~IThread(){}
};
class IThreadWorker
{
public:
virtual void run() = 0;
virtual ~IThreadWorker(){}
};
}
}

View File

@ -7,7 +7,7 @@
#include "cAudioDefines.h"
#include "IMemoryProvider.h"
#ifdef CAUDIO_DEBUG
#if 0 /* defined(CAUDIO_DEBUG) */
#define CAUDIO_NEW new (__FILE__, __LINE__, __FUNCTION__)
#define CAUDIO_DELETE delete
#define CAUDIO_MALLOC(size) cAudio::getMemoryProvider()->Allocate(size, __FILE__, __LINE__, __FUNCTION__)
@ -25,4 +25,4 @@ namespace cAudio
/** Used by cAudio for all allocations of memory
\return A pointer to the memory provider */
CAUDIO_API IMemoryProvider* getMemoryProvider();
};
};

View File

@ -47,3 +47,20 @@
# define CAUDIO_COMPILER_MINGW
# endif
#endif
#ifdef CAUDIO_PLATFORM_WIN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS 1
#if defined(_DEBUG) && !defined(DEBUG)
#define DEBUG _DEBUG
#endif
#ifndef DEBUG
#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0
#endif
#include <windows.h> //Basic windows includes
#endif

View File

@ -11,4 +11,4 @@ namespace cAudio
//! Causes the current thread to give up control for a certain duration.
/** \param ms: amount of miliseconds to sleep */
CAUDIO_API void cAudioSleep(unsigned int ms);
};
};

View File

@ -13,8 +13,6 @@
#include <stdlib.h>
#ifdef CAUDIO_PLATFORM_WIN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <direct.h>
# include <io.h>
#endif
@ -26,12 +24,12 @@ namespace cAudio
# define _CTEXT(x) L ## x
# define cstrcmp wcscmp
# define cAudioChar wchar_t
# define cfopen _wfopen
# define cfopen(N, M) _wfopen((N).c_str(), L ## M)
#else
# define _CTEXT(x) x
# define cstrcmp strcmp
# define cAudioChar char
# define cfopen fopen
# define cfopen(N, M) fopen(toUTF8(N), M)
#endif
#if CAUDIO_REROUTE_STRING_ALLOCATIONS == 1
@ -46,55 +44,13 @@ namespace cAudio
#if defined(CAUDIO_PLATFORM_WIN)
static const TCHAR* toWINSTR(const char* str)
{
#if (defined(UNICODE) || defined(_UNICODE))
static int id = 0;
static wchar_t buffer[8][1024];
id = ++id & 0x7;
int slen = strlen(str);
int buff_size = MultiByteToWideChar(CP_UTF8, 0, str, (int)(slen < 1023 ? slen : 1023), buffer[id], 1023);
buffer[id][buff_size] = 0;
buffer[id][1023] = 0;
return buffer[id];
#else
return str;
#endif
}
static const TCHAR* toWINSTR(const wchar_t* str)
{
#if (defined(UNICODE) || defined(_UNICODE))
return str;
#else
static int id = 0;
static char buffer[8][1024];
id = ++id & 0x7;
int slen = wcslen(str);
int buff_size = WideCharToMultiByte(CP_UTF8, 0, str, (int)(slen < 1023 ? slen : 1023), buffer[id], 1023, 0, false);
buffer[id][buff_size] = 0;
buffer[id][1023] = 0;
return buffer[id];
#endif
}
static wchar_t* charToWChar(const char* text)
{
size_t size = strlen(text) + 1;
wchar_t* wa = new wchar_t[size];
mbstowcs(wa, text, size);
return wa;
}
static const char* toUTF8(const cAudioString& str)
{
static int id = 0;
static char buffer[8][1024];
id = ++id & 0x7;
int buff_size = WideCharToMultiByte(CP_UTF8, 0, charToWChar(str.c_str()), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
int buff_size = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
buffer[id][buff_size] = 0;
buffer[id][1023] = 0;
return buffer[id];
@ -102,34 +58,20 @@ namespace cAudio
static cAudioString fromUTF8(const char* str)
{
wchar_t* buffer = 0;
int buff_size = MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), 0, 0);
if (buff_size == 0)
return cAudioString();
buffer = new wchar_t[buff_size + 1];
memset((void*)buffer, 0, sizeof(wchar_t) * (buff_size + 1));
MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), buffer, buff_size);
char* convert = new char[buff_size+1];
wcstombs(convert, buffer, sizeof(wchar_t) * (buff_size + 1));
cAudioString s(convert);
delete[] buffer;
int str_len = (int)strlen(str);
int buf_size = MultiByteToWideChar(CP_UTF8, 0, str, str_len, 0, 0);
cAudioString s(buf_size, L'\0');
MultiByteToWideChar(CP_UTF8, 0, str, str_len, &s[0], buf_size);
return s;
}
#else
static const char* toWINSTR(const char* str)
{
return str;
}
static const char* toUTF8(const cAudioString& str)
inline const char* toUTF8(const cAudioString& str)
{
return str.c_str();
}
static cAudioString fromUTF8(const char* str)
inline cAudioString fromUTF8(const char* str)
{
return cAudioString(str);
}

View File

@ -62,7 +62,7 @@ namespace cAudio
pointer allocate( size_type count, typename std::allocator<void>::const_pointer ptr = 0 )
{
(void)ptr;
register size_type size = count*sizeof( T );
size_type size = count*sizeof( T );
pointer p = static_cast<pointer>(CAUDIO_MALLOC(size));