Moved sample sounds to a media folder and removed the copy of bling.ogg from bin

Updated logger to allow a user to create callbacks to receive log messages
Logger also gives more information, time the message was sent, the source, the importance, and the message itself.
User can now query playback devices and specify the device for the audio manager to use.  The audio manager is no longer a singleton, although creating multiple managers is not advised.
Clean up and optimization of manager initialization code.
IAudioCapture can now be told which device to capture audio from.  The user can also create multiple IAudioCaptures to capture audio from multiple sources at the same time.
Added additional error checking.
A seperate thread is used to capture audio now.
Defines added to allow a user to remove support for default codecs.
This commit is contained in:
Joshua Jones 2009-11-20 03:39:56 +00:00
parent aabf6b9306
commit 6b3e9c5a9d
26 changed files with 1123 additions and 425 deletions

View File

@ -17,8 +17,8 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
@ -86,8 +86,8 @@
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"

View File

@ -6,36 +6,70 @@
//Include our version of Sleep to free CPU usage
#include "../../include/cAudioSleep.h"
//#include "../../include/cAudioLog.h"
using namespace std;
int main(int argc, char* argv[])
{
//To make visual studio happy
cAudio::IAudio* mysound;
//Some fancy text
cout << "cAudio 1.7.1 Tutorial 1: 2DSound \n";
cout << "cAudio 1.7.1 Tutorial 1: 2DSound \n \n";
//Grap the cAudioManager
cAudio::IAudioManager* manager = cAudio::getAudioManager();
//Init the cAudio Engine
manager->init(argc,argv);
//Create a IAudio object and load a sound from a file
mysound = manager->createFromFile("bling","../../bin/bling.ogg",true);
//Create an uninitialized Audio Manager
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
if(mysound)
if(manager)
{
mysound->setVolume(0.5);
//Set the IAudio Sound to play2d and loop
mysound->play2d(true);
//Allow the user to choose a playback device
cout << "Available Playback Devices: \n";
unsigned int deviceCount = manager->getAvailableDeviceCount();
std::string defaultDeviceName = manager->getDefaultDeviceName();
for(unsigned int i=0; i<deviceCount; ++i)
{
std::string deviceName = manager->getAvailableDeviceName(i);
if(deviceName.compare(defaultDeviceName) == 0)
cout << i << "): " << deviceName << " (DEFAULT) \n";
else
cout << i << "): " << deviceName << " \n";
}
cout << std::endl;
cout << "Choose a device by number: ";
unsigned int deviceSelection = 0;
cin >> deviceSelection;
cout << std::endl;
//Sleep for 10,000 ms to let the sound play in the worker thread
cAudio::cAudioSleep(10000);
//Initialize the manager with the user settings
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
//Create a IAudio object and load a sound from a file
cAudio::IAudio* mysound = manager->createFromFile("bling","../../media/cAudioTheme2.ogg",true);
if(mysound)
{
mysound->setVolume(0.5);
//Set the IAudio Sound to play2d and loop
mysound->play2d(false);
//Wait for the sound to finish playing
while(mysound->playing())
cAudio::cAudioSleep(10);
}
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
cAudio::destroyAudioManager(manager);
}
else
{
std::cout << "Failed to create audio playback manager. \n";
}
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
std::cout << "Press any key to quit \n";
std::cin.get();
std::cin.get();
return 0;
}

View File

@ -17,8 +17,8 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
@ -86,8 +86,8 @@
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"

View File

@ -18,50 +18,97 @@ using namespace std;
int main(int argc, char* argv[])
{
//To make visual studio happy
cAudio::IAudio* mysound;
//Some fancy text
cout << "cAudio 1.7.1 Tutorial 2: 3dSound \n";
cout << "cAudio 1.7.1 Tutorial 2: 3dSound \n \n";
//Hold audio source x position
float rot = 0;
//Grap the cAudioManager
cAudio::IAudioManager* manager = cAudio::getAudioManager();
//Init the cAudio Engine
manager->init(argc,argv);
//Grab the listener object, which allows us to manipulate where "we" are in the world
//It's useful to bind this to a camera if you are using a 3d graphics engine
cAudio::IListener* listener = manager->getListener();
//Create an uninitialized Audio Manager
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
//Create a IAudio object and load a sound from a file
mysound = manager->createFromFile("bling","../../bin/bling.ogg",true);
//Set the IAudio Sound to play3d and loop
//play3d takes 4 arguments play3d(toloop,x,y,z,strength)
if(mysound && listener)
if(manager)
{
listener->setPosition(cAudio::cVector3(0,0,0));
mysound->play3d(cAudio::cVector3(0,0,0),1.0f,true);
mysound->setVolume(2.0);
while(mysound->playing())
//Allow the user to choose a playback device
cout << "Available Playback Devices: \n";
unsigned int deviceCount = manager->getAvailableDeviceCount();
std::string defaultDeviceName = manager->getDefaultDeviceName();
for(unsigned int i=0; i<deviceCount; ++i)
{
//Figure out the location of our rotated sound
rot+=0.1f * 0.017453293f; //0.1 degrees a frame
//Sound "starts" at x=5, y=0, z=0
float x = 5.0f * cosf(rot) - 0.0f * sinf(rot);
float z = 0.0f * cosf(rot) + 5.0f * sinf(rot);
mysound->setPosition(cAudio::cVector3(x,0.0,z));
//Sleep for 1 ms to free some CPU
cAudio::cAudioSleep(1);
std::string deviceName = manager->getAvailableDeviceName(i);
if(deviceName.compare(defaultDeviceName) == 0)
cout << i << "): " << deviceName << " (DEFAULT) \n";
else
cout << i << "): " << deviceName << " \n";
}
cout << std::endl;
cout << "Choose a device by number: ";
unsigned int deviceSelection = 0;
cin >> deviceSelection;
cout << std::endl;
//Initialize the manager with the user settings
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
//Grab the listener object, which allows us to manipulate where "we" are in the world
//It's useful to bind this to a camera if you are using a 3d graphics engine
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",true);
//Set the IAudio Sound to play3d and loop
//play3d takes 4 arguments play3d(toloop,x,y,z,strength)
if(mysound && listener)
{
listener->setPosition(cAudio::cVector3(0,0,0));
mysound->play3d(cAudio::cVector3(0,0,0),1.0f,true);
mysound->setVolume(1.0);
//Play for 10 seconds
const int ticksToPlay = 10000;
int currentTick = 0;
int currentSecTick = 0;
while(mysound->playing() && currentTick < ticksToPlay)
{
//Figure out the location of our rotated sound
rot+=0.1f * 0.017453293f; //0.1 degrees a frame
//Sound "starts" at x=2.5, y=0, z=0
float x = 2.5f * cosf(rot) - 0.0f * sinf(rot);
float z = 0.0f * cosf(rot) + 2.5f * sinf(rot);
mysound->setPosition(cAudio::cVector3(x,0.0,z));
++currentTick;
if(currentTick/1000 > currentSecTick)
{
++currentSecTick;
std::cout << ".";
}
//Sleep for 1 ms to free some CPU
cAudio::cAudioSleep(1);
}
}
std::cout << std::endl;
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
cAudio::destroyAudioManager(manager);
}
else
{
std::cout << "Failed to create audio playback manager. \n";
}
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
std::cout << "Press any key to quit \n";
std::cin.get();
std::cin.get();
return 0;
}

View File

@ -17,8 +17,8 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
@ -86,8 +86,8 @@
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"

View File

@ -21,34 +21,62 @@ using namespace std;
int main(int argc, char* argv[])
{
//Make visual studio happy
cAudio::IAudio* mysound = 0x0;
//Some fancy text
cout << "cAudio 1.7.1 Tutorial 3: MemoryPlayback \n";
//Grap the cAudioManager
cAudio::IAudioManager* manager = cAudio::getAudioManager();
//Init the cAudio Engine
manager->init(argc,argv);
manager->getListener()->setPosition(cAudio::cVector3(0.0,0.0,0.0));
//Create a IAudio object and load a sound from memory. using the bling array and bling size generated by bin2h.
cout << "cAudio 1.7.1 Tutorial 3: MemoryPlayback \n \n";
//Create an uninitialized Audio Manager
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
mysound = manager->createFromMemory("bling",(const char*)bling,bling_size,"wav");
if(mysound)
if(manager)
{
//Set the IAudio Sound to play2d and loop
mysound->play2d(true);
while(mysound->playing())
//Allow the user to choose a playback device
cout << "Available Playback Devices: \n";
unsigned int deviceCount = manager->getAvailableDeviceCount();
std::string defaultDeviceName = manager->getDefaultDeviceName();
for(unsigned int i=0; i<deviceCount; ++i)
{
//Sleep for 10 ms to free some CPU
cAudio::cAudioSleep(10);
std::string deviceName = manager->getAvailableDeviceName(i);
if(deviceName.compare(defaultDeviceName) == 0)
cout << i << "): " << deviceName << " (DEFAULT) \n";
else
cout << i << "): " << deviceName << " \n";
}
cout << std::endl;
cout << "Choose a device by number: ";
unsigned int deviceSelection = 0;
cin >> deviceSelection;
cout << std::endl;
//Initialize the manager with the user settings
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");
if(mysound)
{
//Set the IAudio Sound to play2d and loop
mysound->play2d(true);
//Sleep for 10,000 ms to free some CPU, also makes the example only last 10 seconds
cAudio::cAudioSleep(10000);
}
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
cAudio::destroyAudioManager(manager);
}
else
{
std::cout << "Failed to create audio playback manager. \n";
}
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
std::cout << "Press any key to quit \n";
std::cin.get();
std::cin.get();
return 0;
}

View File

@ -17,8 +17,8 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
@ -86,8 +86,8 @@
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
OutputDirectory="../../bin/win32-visual"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"

View File

@ -2,6 +2,8 @@
#include <string>
//Include IAudioManager so we can easily work with cAudio
#include "../../include/IAudioManager.h"
//Include IAudioCapture so we can capture audio
#include "../../include/IAudioCapture.h"
//Include IAudio so we can create cAudio objects
#include "../../include/IAudio.h"
//Include our version of Sleep to free CPU usage
@ -9,15 +11,12 @@
using namespace std;
#define CAPTURE_FREQUENCY 22050
#define CAPTURE_DURATION 10
#define CAPTURE_FORMAT cAudio::EAF_16BIT_MONO
const unsigned int CAPTURE_FREQUENCY = 22050;
const unsigned int CAPTURE_DURATION = 10;
const cAudio::AudioFormats CAPTURE_FORMAT = cAudio::EAF_16BIT_MONO;
int main(int argc, char* argv[])
{
//To make visual studio happy
cAudio::IAudio* mysound = NULL;
//Some fancy text
cout << "cAudio 1.7.1 Tutorial 4: Capturing Audio \n \n";
@ -32,79 +31,114 @@ int main(int argc, char* argv[])
else
formatName = "16 Bit Stereo";
//Grap the cAudioManager
cAudio::IAudioManager* manager = cAudio::getAudioManager();
//Init the cAudio Engine
manager->init(argc,argv);
//Create an Audio Manager with default settings
cAudio::IAudioManager* manager = cAudio::createAudioManager();
//! The capture interface should be grabbed after the manager has been initialized
cAudio::IAudioCapture* capture = manager->getAudioCapture();
bool captureReady = false;
cout << "Capturing Supported: " << std::boolalpha << capture->isSupported() << "\n";
if(capture->isSupported())
if(manager)
{
captureReady = capture->initialize(CAPTURE_FREQUENCY, CAPTURE_FORMAT);
cout << "Ready to capture audio: " << std::boolalpha << captureReady << "\n \n";
//Quick math to figure out how large our data should be for the duration of the record time
const int targetRecordSize = CAPTURE_FREQUENCY * CAPTURE_DURATION * capture->getSampleSize();
cout << "Capture Frequency: " << CAPTURE_FREQUENCY << "\n";
cout << "Capture Duration: " << CAPTURE_DURATION << "\n";
cout << "Capture Format: " << formatName << "\n";
cout << "Sample Size: " << capture->getSampleSize() << "\n";
cout << "Total size of audio: " << targetRecordSize << "\n";
cout << std::endl;
int currentsize = 0;
cout << "Starting capture... \n";
if(capture->beginCapture())
//! The capture interface can be gotten at any time, and can even be used completely seperate from the manager
// Also it is possible to have more than one capture interface at the same time, useful for recording from multiple sources
cAudio::IAudioCapture* capture = cAudio::createAudioCapture(false);
if(capture)
{
while(currentsize < targetRecordSize)
bool captureReady = false;
cout << "Capturing Supported: " << std::boolalpha << capture->isSupported() << "\n \n";
if(capture->isSupported())
{
cout << "Available Capture Devices: \n";
unsigned int deviceCount = capture->getAvailableDeviceCount();
std::string defaultDeviceName = capture->getDefaultDeviceName();
for(unsigned int i=0; i<deviceCount; ++i)
{
std::string deviceName = capture->getAvailableDeviceName(i);
if(deviceName.compare(defaultDeviceName) == 0)
cout << i << "): " << deviceName << " (DEFAULT) \n";
else
cout << i << "): " << deviceName << " \n";
}
cout << std::endl;
cout << "Choose a device by number: ";
unsigned int deviceSelection = 0;
cin >> deviceSelection;
cout << std::endl;
captureReady = capture->initialize(capture->getAvailableDeviceName(deviceSelection), CAPTURE_FREQUENCY, CAPTURE_FORMAT);
cout << "Ready to capture audio: " << std::boolalpha << captureReady << "\n \n";
//Quick math to figure out how large our data should be for the duration of the record time
const unsigned int targetRecordSize = CAPTURE_FREQUENCY * CAPTURE_DURATION * capture->getSampleSize();
//Print various information
cout << "Capture Device: " << capture->getDeviceName() << ". \n";
cout << "Capture Frequency: " << CAPTURE_FREQUENCY << " hertz. \n";
cout << "Capture Duration: " << CAPTURE_DURATION << " seconds. \n";
cout << "Capture Format: " << formatName << ". \n";
cout << "Sample Size: " << capture->getSampleSize() << " bytes. \n";
cout << "Target size of audio: " << targetRecordSize << " bytes. \n";
cout << std::endl;
unsigned int currentsize = 0;
cout << "Starting capture... \n";
if(capture->beginCapture())
{
while(currentsize < targetRecordSize)
{
currentsize = capture->getCurrentCapturedAudioSize();
//Sleep for 1 ms to free some CPU
cAudio::cAudioSleep(1);
}
}
capture->stopCapture();
cout << "Capture stopped... \n \n";
//Grab the total size again, ensures we get ALL the audio data
//Not completely necessary, as starting a capture again will clear the old audio data
currentsize = capture->getCurrentCapturedAudioSize();
//Sleep for 1 ms to free some CPU
cAudio::cAudioSleep(1);
char* buffer = new char[currentsize];
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);
delete buffer;
if(mysound)
{
cout << "Playing back captured audio... \n \n";
mysound->setVolume(1.0);
//Set the IAudio Sound to play2d and loop
mysound->play2d(false);
while(mysound->playing())
{
//Sleep for 10 ms to free some CPU
cAudio::cAudioSleep(10);
}
}
}
// Always remember to destroy the interface once you are done with it
cAudio::destroyAudioCapture(capture);
capture = 0x0;
}
capture->stopCapture();
cout << "Capture stopped... \n \n";
//Grab the total size again, ensures we get ALL the audio data
//Not completely necessary, as starting a capture again will clear the old audio data
currentsize = capture->getCurrentCapturedAudioSize();
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
char* buffer = new char[currentsize];
capture->getCapturedAudio(buffer, currentsize);
//Create a IAudio object and load a sound from a file
mysound = manager->createFromRaw("sound1", buffer, currentsize, CAPTURE_FREQUENCY, CAPTURE_FORMAT);
delete buffer;
if(mysound)
{
cout << "Playing back captured audio... \n \n";
mysound->setVolume(1.0);
//Set the IAudio Sound to play2d and loop
mysound->play2d(false);
while(mysound->playing())
{
//Sleep for 10 ms to free some CPU
cAudio::cAudioSleep(10);
}
}
cAudio::destroyAudioManager(manager);
}
else
{
std::cout << "Failed to create audio playback manager. \n";
}
//Delete all IAudio sounds
manager->release();
//Shutdown cAudio
manager->shutDown();
std::cout << "Press any key to quit \n";
std::cin.get();
std::cin.get();
return 0;
}

View File

@ -3,7 +3,8 @@
#include <string>
#include <iostream>
#include <vector>
#include "AL/al.h"
#include <AL/al.h>
#include <AL/alc.h>
#define BUFFER_SIZE ( 1024 * 32 )
#include "../include/IAudio.h"
@ -91,11 +92,9 @@ namespace cAudio
//!empties the queue
void empty();
//!checks openal error state
void check();
void checkError();
//!reloads a buffer
bool stream(ALuint buffer);
//!stringify an error code
std::string errorString(int code);
//! front and back buffers
ALuint buffers[3];

View File

@ -6,6 +6,7 @@
#include <AL/al.h>
#include <AL/alc.h>
#include "../Headers/cMutex.h"
#include <string>
namespace cAudio
{
@ -16,30 +17,36 @@ namespace cAudio
~cAudioCapture();
//! Checks to see if capturing audio is supported by OpenAL
//! Normally run automatically by cAudioManager::init()
bool checkCaptureExtension();
//! Grabs samples from the OpenAL buffer into the capture buffer. Should be run once every audio frame.
//! Normally run automatically by cAudioManager::update()
void updateCaptureBuffer(bool force = false);
//! Shuts down the capture device
//! Normally run automatically by cAudioManager::shutDown()
void shutdown();
//! Initializes the capture device to the selected settings
/** Note that calling this will cause the capture device to be reinitialized. Calling while in use may lead to a loss of audio data.
\param frequency: Frequency that the captured audio will be at
/** Note that calling this will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
\param deviceName: Name of the audio device to capture audio from, pass NULL to specify the default one
\param frequency: Frequency that the captured audio will be at in hz
\param format: Format of the captured audio
\param internalBufferSize: Size of the internal OpenAL buffer used to store the captured audio until the next IAudioManager::update() in bytes
\param internalBufferSize: Size of the internal OpenAL buffer used to store the captured audio between calls to getCapturedAudio() in bytes.
\return True on success, False if the capture device failed to initialize.
*/
virtual bool initialize(unsigned int frequency = 22050, AudioFormats format = EAF_16BIT_MONO, unsigned int internalBufferSize = 8192);
virtual bool initialize(const char* deviceName = 0x0, unsigned int frequency = 22050, AudioFormats format = EAF_16BIT_MONO, unsigned int internalBufferSize = 8192);
//! Returns true if the current OpenAL implementation supports capturing audio
virtual bool isSupported() { return Supported; }
//! Returns true if the capture device is ready to be used. False may indicate an error with the current settings.
virtual bool isReady() { return Ready; }
//! Grabs samples from the OpenAL buffer into the capture buffer. Should be run once every audio frame.
virtual void updateCaptureBuffer(bool force = false);
//! Shuts down the capture device
virtual void shutdown();
//! Returns the name of an available capturing device.
/** \param index: Specify which name to retrieve ( Range: 0 to getAvailableDeviceCount()-1 ) */
virtual const char* getAvailableDeviceName(unsigned int index);
//! Returns the number of capture devices available for use.
virtual unsigned int getAvailableDeviceCount();
//! Returns the name of the default system capturing device.
virtual const char* getDefaultDeviceName();
//! Returns the name of the audio device being used to capture audio
virtual const char* getDeviceName() { return DeviceName.c_str(); }
//! Returns the frequency that the captured audio will be at
virtual unsigned int getFrequency() { return Frequency; }
//! Returns the format of the captured audio
@ -49,6 +56,9 @@ namespace cAudio
//! Returns the size of a "sample" of audio data. Useful for making sure you grab audio data at sample boundaries
virtual unsigned int getSampleSize() { return SampleSize; }
//! Sets the audio device . Will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
/** \return True on success, False if the capture device failed to initialize. */
virtual bool setDevice(const char* deviceName);
//! Sets the frequency that the captured audio will be at. Will cause the capture device to be reinitialized. Calling while in use may lead to a loss of audio data.
/** \return True on success, False if the capture device failed to initialize. */
virtual bool setFrequency(unsigned int frequency);
@ -74,6 +84,9 @@ namespace cAudio
//! Returns the current size of the internal audio buffer in bytes
virtual unsigned int getCurrentCapturedAudioSize();
//! Grabs a list of available devices, as well as the default system one
void getAvailableDevices();
protected:
//Mutex for thread syncronization
cAudioMutex Mutex;
@ -84,12 +97,17 @@ namespace cAudio
unsigned int Frequency;
AudioFormats Format;
unsigned int InternalBufferSize;
int SampleSize;
std::vector<char> CaptureBuffer;
std::vector<std::string> AvailableDevices;
std::string DefaultDevice;
bool Supported;
bool Ready;
bool Capturing;
int SampleSize;
std::string DeviceName;
ALCdevice* CaptureDevice;
};
};

View File

@ -6,11 +6,11 @@
#include "cAudio.h"
#include "../include/IAudioDecoderFactory.h"
#include "cListener.h"
#include "cAudioCapture.h"
#include "../include/IAudioManager.h"
#include "../Headers/cMutex.h"
#include "../include/ILogger.h"
#include "../Headers/cLogger.h"
#include <AL/al.h>
#include <AL/alc.h>
namespace cAudio
{
@ -19,11 +19,22 @@ namespace cAudio
class cAudioManager : public IAudioManager
{
public:
cAudioManager() { }
virtual ~cAudioManager() { }
//!Inits the audio manager calling the alut/etc start ups
virtual void init(int argc,char* argv[]);
virtual bool initialize(const char* deviceName = 0x0, int outputFrequency = -1, int eaxEffectSlots = 4);
//!Shuts everything down
virtual void shutDown();
//! Returns the name of an available playback device.
/** \param index: Specify which name to retrieve ( Range: 0 to getAvailableDeviceCount()-1 ) */
virtual const char* getAvailableDeviceName(unsigned int index);
//! Returns the number of playback devices available for use.
virtual unsigned int getAvailableDeviceCount();
//! Returns the name of the default system playback device.
virtual const char* getDefaultDeviceName();
//!Creates the cAudio object
virtual IAudio* createFromFile(const std::string& identifier,const std::string& file,bool stream = false);
//!Loads ogg from memory or virtual file system
@ -35,17 +46,13 @@ namespace cAudio
virtual bool registerAudioDecoder(IAudioDecoderFactory* factory, std::string extension);
//!Unregister Audio Codec (allows you to prevent an file type from being playable with new sound sources)
//!Note that all current sound sources will still continue to use any currently allocated decoders.
//!Will delete the factory instance
//!Will NOT delete any user added factory instance, you must do that yourself
virtual void unRegisterAudioDecoder(std::string extension);
//!Returns whether an audio decoder is currently registered for this file type
virtual bool isAudioDecoderRegistered(std::string extension);
//!Returns a registered audio decoder factory
virtual IAudioDecoderFactory* getAudioDecoderFactory(std::string extension);
//!Allows you to set the listener position (DEPRECIATED! USE getListener() INSTEAD!)
virtual void setListenerPos(float x,float y,float z);
//!Set Listener Orientation (DEPRECIATED! USE getListener() INSTEAD!)
virtual void setListenerOrientation(float ux,float uy,float uz);
//!Updates the cAudio playback
virtual void update();
//!Gets you the cAudio object you want
@ -53,40 +60,31 @@ namespace cAudio
//!Releases "ALL" cAudio objects
virtual void release();
//! Grabs a list of available devices, as well as the default system one
void getAvailableDevices();
virtual IListener* getListener() { return &initlistener; }
virtual IAudioCapture* getAudioCapture() { return &initCapture; }
virtual bool IsThreadRunning() { return RunThread; }
static cAudioManager* Instance()
{
return &m_cAudioManager;
}
virtual ~cAudioManager(){
delete log;
}
protected:
cAudioManager() : RunThread(false){
log = new cLogger();}
private:
//Mutex for thread syncronization
cAudioMutex Mutex;
bool RunThread;
//Logger Object
ILogger *log;
//!Global cAudioManager
static cAudioManager m_cAudioManager;
//Make a Openal context pointer
ALCcontext *Context;
//Make a openal device pointer
ALCdevice *Device;
//!The map that holds the cAudio objects
std::map<std::string, IAudio*> audiomap;
//!Decoder map that holds all decoders by file extension
std::map<std::string, IAudioDecoderFactory*> decodermap;
//!The listener object
cListener initlistener;
//!The audio capture instance
cAudioCapture initCapture;
//! Check for OpenAL errors
void checkError();
std::vector<std::string> AvailableDevices;
std::string DefaultDevice;
};
}

View File

@ -1,26 +1,49 @@
#ifndef CLOGGERR_H_INCLUDED
#ifndef CLOGGER_H_INCLUDED
#define CLOGGER_H_INCLUDED
#include <iostream>
#include "../Include/ILogger.h"
#include "../include/ILogger.h"
#include "../Headers/cMutex.h"
#include <map>
#include <stdarg.h>
namespace cAudio{
class cLogger : public ILogger{
public:
namespace cAudio
{
class cLogger : public ILogger
{
public:
cLogger();
virtual ~cLogger();
virtual ~cLogger() { }
void setLogLevel(E_LOGLEVEL level);
void log(E_LOGLEVEL loglevel,const char* text,...);
virtual void logCritical( const char* sender, const char *msg, ... );
virtual void logError( const char* sender, const char *msg, ... );
virtual void logWarning( const char* sender, const char *msg, ... );
virtual void logInfo( const char* sender, const char *msg, ... );
virtual void logDebug( const char* sender, const char *msg, ... );
virtual const LogLevel& getLogLevel() const { return MinLogLevel; }
virtual void setLogLevel( const LogLevel& logLevel );
//! Register Log Receiver
//! Note: Any class registered will become owned by the internal thread.
//! If threading is enabled, you MUST make the receiver threadsafe if you plan to access it in your application while it is registered
virtual bool registerLogReceiver(ILogReceiver* receiver, std::string name);
//!Unregister a Log Receiver
//!Will NOT delete any user added receiver, you must do that yourself
virtual void unRegisterLogReceiver(std::string name);
//!Returns whether an log receiver is currently registered
virtual bool isLogReceiverRegistered(std::string name);
//!Returns a registered log receiver
virtual ILogReceiver* getLogReceiver(std::string name);
protected:
void broadcastMessage( LogLevel level, const char* sender, const char* msg, va_list args );
private:
E_LOGLEVEL logLevel;
//Mutex for thread syncronization
cAudioMutex Mutex;
unsigned long StartTime;
char TempTextBuf[2048];
LogLevel MinLogLevel;
std::map<std::string, ILogReceiver*> Receivers;
private:
};
};
}
#endif
#endif //! CLOGGER_H_INCLUDED

View File

@ -3,10 +3,16 @@
#include <string>
//!Grabs the current extention of a given string.
std::string getExt(const std::string& filename)
static std::string getExt(const std::string& filename)
{
if(filename.find_last_of(".") == std::string::npos) return filename;
return filename.substr(filename.find_last_of(".") + 1, filename.length()-filename.find_last_of(".")-1);
}
static std::string safeCStr(const char* str)
{
if( str != NULL ) return std::string(str);
else return std::string("");
}
#endif //! CUTILS_H_INCLUDED

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
#include "../Headers/cAudio.h"
#include "../Headers/cLogger.h"
namespace cAudio
{
@ -17,6 +18,7 @@ namespace cAudio
alGenBuffers(3, buffers);
//Creates one source to be stored.
alGenSources(1, &source);
checkError();
Mutex.unlock();
}
@ -38,6 +40,7 @@ namespace cAudio
alDeleteSources(1, &source);
//deletes the last filled buffer
alDeleteBuffers(3, buffers);
checkError();
Mutex.unlock();
}
@ -99,6 +102,8 @@ namespace cAudio
//if more in stream continue playing.
if(active)
alSourceQueueBuffers(source, 1, &buffer);
checkError();
}
Mutex.unlock();
return active;
@ -144,6 +149,7 @@ namespace cAudio
}
//std::cout << buffer << std::endl;
alBufferData(buffer, Decoder->getFormat(), tempbuffer, totalread, Decoder->getFrequency());
checkError();
return true;
}
return false;
@ -161,17 +167,23 @@ namespace cAudio
ALuint buffer;
//unqueues sources buffers to be used for others.
alSourceUnqueueBuffers(source, 1, &buffer);
checkError();
}
}
//!Checks the given functions
void cAudio::check()
void cAudio::checkError()
{
int error = alGetError();
const char* errorString;
if (error != AL_NO_ERROR)
{
std::cout<< "OpenAL error was Raised.";
errorString = alGetString(error);
if(error == AL_OUT_OF_MEMORY)
getLogger()->logCritical("Audio Source", "OpenAL Error: %s.", errorString);
else
getLogger()->logError("Audio Source", "OpenAL Error: %s.", errorString);
}
}
@ -192,6 +204,7 @@ namespace cAudio
toloop = loop;
play();
alSourcePlay(source);
checkError();
Mutex.unlock();
}
@ -207,6 +220,7 @@ namespace cAudio
toloop = loop;
play();
alSourcePlay(source);
checkError();
Mutex.unlock();
}
@ -224,6 +238,7 @@ namespace cAudio
Mutex.lock();
this->position = position;
alSource3f(source, AL_POSITION, position.x, position.y, position.z);
checkError();
Mutex.unlock();
}
@ -233,6 +248,7 @@ namespace cAudio
Mutex.lock();
this->velocity = velocity;
alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
checkError();
Mutex.unlock();
}
@ -242,6 +258,7 @@ namespace cAudio
Mutex.lock();
this->direction = direction;
alSource3f(source, AL_DIRECTION, direction.x, direction.y, direction.z);
checkError();
Mutex.unlock();
}
@ -250,6 +267,7 @@ namespace cAudio
{
Mutex.lock();
alSourcef(source, AL_ROLLOFF_FACTOR, soundstrength);
checkError();
Mutex.unlock();
}
@ -259,6 +277,7 @@ namespace cAudio
Mutex.lock();
this->pitch = pitch;
alSourcef (source, AL_PITCH, pitch);
checkError();
Mutex.unlock();
}
@ -268,6 +287,7 @@ namespace cAudio
Mutex.lock();
this->volume = volume;
alSourcef(source, AL_GAIN, volume);
checkError();
Mutex.unlock();
}
@ -277,6 +297,7 @@ namespace cAudio
Mutex.lock();
this->dstrength = dstrength;
alSourcef(source, AL_DOPPLER_FACTOR, dstrength);
checkError();
Mutex.unlock();
}
@ -286,6 +307,7 @@ namespace cAudio
Mutex.lock();
this->dvelocity = dvelocity;
alSource3f(source, AL_DOPPLER_VELOCITY, dvelocity.x, dvelocity.y, dvelocity.z);
checkError();
Mutex.unlock();
}
@ -361,8 +383,10 @@ namespace cAudio
}
//Stores the sources 3 buffers to be used in the queue
alSourceQueueBuffers(source, queueSize, buffers);
checkError();
}
alSourcePlay(source);
checkError();
Mutex.unlock();
return true;
}
@ -373,6 +397,7 @@ namespace cAudio
Mutex.lock();
playaudio = false;
alSourceStop(source);
checkError();
Mutex.unlock();
}
@ -382,6 +407,7 @@ namespace cAudio
Mutex.lock();
playaudio = false;
alSourcePause(source);
checkError();
Mutex.unlock();
}

View File

@ -1,27 +1,54 @@
#include "../Headers/cAudioCapture.h"
#include "../Headers/cUtils.h"
#include "../Headers/cThread.h"
#include "../include/cAudioSleep.h"
#include <string.h>
#include <set>
namespace cAudio
{
cAudioCapture::cAudioCapture() : Frequency(22050), Format(EAF_16BIT_MONO), InternalBufferSize(8192),
Supported(false), Ready(false), Capturing(false), SampleSize(2), CaptureDevice(NULL)
{
static bool RunAudioCaptureThread(false);
//Note: OpenAL is threadsafe, so a mutex only needs to protect the class state
#ifdef CAUDIO_USE_INTERNAL_THREAD
static cAudioMutex AudioCaptureObjectsMutex;
static std::set<IAudioCapture*> AudioCaptureObjects;
CAUDIO_DECLARE_THREAD_FUNCTION(AudioCaptureUpdateThread)
{
while(RunAudioCaptureThread)
{
AudioCaptureObjectsMutex.lock();
std::set<IAudioCapture*>::iterator it;
for ( it=AudioCaptureObjects.begin() ; it != AudioCaptureObjects.end(); it++ )
{
(*it)->updateCaptureBuffer();
}
AudioCaptureObjectsMutex.unlock();
cAudioSleep(1);
}
return 0;
}
#endif
cAudioCapture::cAudioCapture() : Frequency(22050), Format(EAF_16BIT_MONO), InternalBufferSize(8192),
SampleSize(2), Supported(false), Ready(false), Capturing(false),
CaptureDevice(NULL)
{
checkCaptureExtension();
getAvailableDevices();
}
cAudioCapture::~cAudioCapture()
{
shutdown();
}
bool cAudioCapture::checkCaptureExtension()
{
Mutex.lock();
// Check for Capture Extension support
ALCdevice* pDevice;
ALCcontext* pContext;
pContext = alcGetCurrentContext();
pDevice = alcGetContextsDevice(pContext);
Supported = ( alcIsExtensionPresent(pDevice, "ALC_EXT_CAPTURE") == AL_TRUE );
Supported = ( alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE") == AL_TRUE );
Mutex.unlock();
return Supported;
}
@ -33,10 +60,13 @@ namespace cAudio
{
if(CaptureDevice)
shutdownOpenALDevice();
CaptureDevice = alcCaptureOpenDevice(NULL, Frequency, Format, InternalBufferSize / SampleSize);
if(DeviceName.empty())
CaptureDevice = alcCaptureOpenDevice(NULL, Frequency, Format, InternalBufferSize / SampleSize);
else
CaptureDevice = alcCaptureOpenDevice(DeviceName.c_str(), Frequency, Format, InternalBufferSize / SampleSize);
if(CaptureDevice)
{
DeviceName = alcGetString(CaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER);
Ready = true;
Mutex.unlock();
return true;
@ -60,6 +90,7 @@ namespace cAudio
CaptureDevice = NULL;
Ready = false;
}
CaptureBuffer.clear();
}
Mutex.unlock();
}
@ -71,6 +102,60 @@ namespace cAudio
Mutex.unlock();
}
void cAudioCapture::getAvailableDevices()
{
// Get list of available Capture Devices
Mutex.lock();
if( alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE )
{
const char* deviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
if (deviceList)
{
while(*deviceList)
{
std::string device(deviceList);
AvailableDevices.push_back(device);
deviceList += strlen(deviceList) + 1;
}
}
// Get the name of the 'default' capture device
DefaultDevice = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
}
Mutex.unlock();
}
const char* cAudioCapture::getAvailableDeviceName(unsigned int index)
{
Mutex.lock();
if(!AvailableDevices.empty())
{
//Bounds check
if( index > (AvailableDevices.size()-1) ) index = (AvailableDevices.size()-1);
const char* deviceName = AvailableDevices[index].c_str();
Mutex.unlock();
return deviceName;
}
Mutex.unlock();
return "";
}
unsigned int cAudioCapture::getAvailableDeviceCount()
{
Mutex.lock();
unsigned int size = AvailableDevices.size();
Mutex.unlock();
return size;
}
const char* cAudioCapture::getDefaultDeviceName()
{
Mutex.lock();
const char* deviceName = DefaultDevice.empty() ? "" : DefaultDevice.c_str();
Mutex.unlock();
return deviceName;
}
void cAudioCapture::updateCaptureBuffer(bool force)
{
Mutex.lock();
@ -86,7 +171,7 @@ namespace cAudio
//Fixes a bug with the capture being forced, but no data being available
if(availbuffersize > 0)
{
const int oldBufferSize = CaptureBuffer.size();
const unsigned int oldBufferSize = CaptureBuffer.size();
CaptureBuffer.resize(oldBufferSize + availbuffersize, 0);
alcCaptureSamples(CaptureDevice, &CaptureBuffer[oldBufferSize], AvailableSamples);
}
@ -131,9 +216,10 @@ namespace cAudio
unsigned int cAudioCapture::getCapturedAudio(void* outputBuffer, unsigned int outputBufferSize)
{
Mutex.lock();
if(outputBuffer && outputBufferSize > 0)
unsigned int internalBufferSize = CaptureBuffer.size();
if(outputBuffer && outputBufferSize > 0 && internalBufferSize > 0)
{
int sizeToCopy = (outputBufferSize >= CaptureBuffer.size()) ? CaptureBuffer.size() : outputBufferSize;
int sizeToCopy = (outputBufferSize >= internalBufferSize) ? internalBufferSize : outputBufferSize;
memcpy(outputBuffer, &CaptureBuffer[0], sizeToCopy);
CaptureBuffer.erase(CaptureBuffer.begin(), CaptureBuffer.begin()+sizeToCopy);
@ -192,9 +278,21 @@ namespace cAudio
return state;
}
bool cAudioCapture::initialize(unsigned int frequency, AudioFormats format, unsigned int internalBufferSize)
bool cAudioCapture::setDevice(const char* deviceName)
{
Mutex.lock();
DeviceName = safeCStr(deviceName);
shutdownOpenALDevice();
bool state = initOpenALDevice();
Mutex.unlock();
return state;
}
bool cAudioCapture::initialize(const char* deviceName, unsigned int frequency, AudioFormats format, unsigned int internalBufferSize)
{
Mutex.lock();
DeviceName = safeCStr(deviceName);
Frequency = frequency;
InternalBufferSize = internalBufferSize;
@ -213,4 +311,48 @@ namespace cAudio
Mutex.unlock();
return state;
}
CAUDIO_API IAudioCapture* createAudioCapture(bool initializeDefault)
{
cAudioCapture* capture = new cAudioCapture;
if(capture)
{
if(initializeDefault)
capture->initialize();
#ifdef CAUDIO_USE_INTERNAL_THREAD
AudioCaptureObjectsMutex.lock();
AudioCaptureObjects.insert(capture);
//First time launch of thread
if(!RunAudioCaptureThread && AudioCaptureObjects.size() > 0)
RunAudioCaptureThread = (cAudioThread::SpawnThread(AudioCaptureUpdateThread, NULL) == 0);
AudioCaptureObjectsMutex.unlock();
#endif
}
return capture;
}
CAUDIO_API void destroyAudioCapture(IAudioCapture* capture)
{
if(capture)
{
#ifdef CAUDIO_USE_INTERNAL_THREAD
AudioCaptureObjectsMutex.lock();
AudioCaptureObjects.erase(capture);
//Kill the thread if there are no objects to process anymore
if(RunAudioCaptureThread && AudioCaptureObjects.empty())
RunAudioCaptureThread = false;
AudioCaptureObjectsMutex.unlock();
#endif
delete capture;
capture = NULL;
}
}
CAUDIO_API bool isAudioCaptureThreadRunning()
{
return RunAudioCaptureThread;
}
};

View File

@ -7,91 +7,127 @@
#include "../Headers/cRawAudioDecoderFactory.h"
#include "../Headers/cThread.h"
#include "../include/cAudioSleep.h"
#include "../Headers/cLogger.h"
#include <set>
#include <iostream>
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/efx.h>
#include <AL/efx-creative.h>
#include <AL/xram.h>
#include <iostream>
#define LOAD_AL_FUNC(x) (x = (typeof(x))alGetProcAddress(#x))
namespace cAudio
{
CAUDIO_API IAudioManager* getAudioManager(void)
{
return cAudioManager::Instance();
}
cAudioManager cAudioManager::m_cAudioManager;
static bool RunAudioManagerThread(false);
CAUDIO_DECLARE_THREAD_FUNCTION(UpdateThread)
#ifdef CAUDIO_COMPILE_WITH_OGG_DECODER
static cOggAudioDecoderFactory OggDecoderFactory;
#endif
#ifdef CAUDIO_COMPILE_WITH_WAV_DECODER
static cWavAudioDecoderFactory WavDecoderFactory;
#endif
#ifdef CAUDIO_COMPILE_WITH_RAW_DECODER
static cRawAudioDecoderFactory RawDecoderFactory;
#endif
//Note: OpenAL is threadsafe, so a mutex only needs to protect the class state
#ifdef CAUDIO_USE_INTERNAL_THREAD
static cAudioMutex AudioManagerObjectsMutex;
static std::set<IAudioManager*> AudioManagerObjects;
CAUDIO_DECLARE_THREAD_FUNCTION(AudioManagerUpdateThread)
{
while(true)
while(RunAudioManagerThread)
{
if(!cAudioManager::Instance()->IsThreadRunning())
AudioManagerObjectsMutex.lock();
std::set<IAudioManager*>::iterator it;
for ( it=AudioManagerObjects.begin() ; it != AudioManagerObjects.end(); it++ )
{
return 0;
(*it)->update();
}
cAudioManager::Instance()->update();
AudioManagerObjectsMutex.unlock();
cAudioSleep(1);
}
return 0;
}
#endif
//!Initialize the listener,openal,and mikmod
void cAudioManager::init(int argc,char* argv[])
bool cAudioManager::initialize(const char* deviceName, int outputFrequency, int eaxEffectSlots)
{
Mutex.lock();
//Make a Openal context pointer
ALCcontext *Context;
//Make a openal device pointer
ALCdevice *Device;
//Create a new device
Device = alcOpenDevice(NULL);
//Stores the EAX attributes
ALint attribs[4] = { 0 };
//Check if device can be created
if (Device == NULL){
log->log(E_LOGLEVEL_4,"cAudio Failed to Initalized:");
exit(-1);
//Stores the context attributes (MAX of 4, with 2 zeros to terminate)
ALint attribs[6] = { 0 };
unsigned int currentAttrib = 0;
if(outputFrequency > 0)
{
attribs[currentAttrib++] = ALC_FREQUENCY;
attribs[currentAttrib++] = outputFrequency;
}
if(eaxEffectSlots > 0)
{
attribs[currentAttrib++] = ALC_MAX_AUXILIARY_SENDS;
attribs[currentAttrib++] = eaxEffectSlots;
}
log->log(E_LOGLEVEL_4,"cAudio Initalized:");
//Setup attributes to request 4 slots per a sound source
attribs[0] = ALC_MAX_AUXILIARY_SENDS;
attribs[1] = 4;
//Create a new device
Device = alcOpenDevice(deviceName);
//Check if device can be created
if (Device == NULL)
{
getLogger()->logError("AudioManager", "Failed to Create OpenAL Device.");
checkError();
Mutex.unlock();
return false;
}
//Create context with eax effects for windows
#ifdef CAUDIO_EAX_ENABLED
if(alcIsExtensionPresent(Device, "ALC_EXT_EFX") == AL_FALSE){
log->log(E_LOGLEVEL_4,"cAudio: EFX isnt supported");
return;
if(alcIsExtensionPresent(Device, "ALC_EXT_EFX") == AL_FALSE)
{
getLogger()->logWarning("AudioManager", "EFX not supported.");
}
getLogger()->logInfo("AudioManager", "EFX supported and enabled.");
#endif
Context = alcCreateContext(Device, attribs);
if (Context == NULL)
{
getLogger()->logError("AudioManager", "Failed to Create OpenAL Context.");
checkError();
Mutex.unlock();
return false;
}
Context=alcCreateContext(Device, attribs);
log->log(E_LOGLEVEL_4,"cAudio: EFX Supported and Enabled.");
#else
Context=alcCreateContext(Device, NULL);
#endif
if(!alcMakeContextCurrent(Context))
{
getLogger()->logError("AudioManager", "Failed to make OpenAL Context current.");
checkError();
Mutex.unlock();
return false;
}
//Set active context
alcMakeContextCurrent(Context);
// Clear Error Code
alGetError();
getLogger()->logInfo("AudioManager", "OpenAL Version: %s", alGetString(AL_VERSION));
getLogger()->logInfo("AudioManager", "Vendor: %s", alGetString(AL_VENDOR));
getLogger()->logInfo("AudioManager", "Renderer: %s", alGetString(AL_RENDERER));
getLogger()->logInfo("AudioManager", "Supported Extensions: %s", alGetString(AL_EXTENSIONS));
initCapture.checkCaptureExtension();
initCapture.initialize();
registerAudioDecoder(new cOggAudioDecoderFactory, "ogg");
registerAudioDecoder(new cWavAudioDecoderFactory, "wav");
registerAudioDecoder(new cRawAudioDecoderFactory, "raw");
#ifdef CAUDIO_COMPILE_WITH_OGG_DECODER
registerAudioDecoder(&OggDecoderFactory, "ogg");
#endif
#ifdef CAUDIO_COMPILE_WITH_WAV_DECODER
registerAudioDecoder(&WavDecoderFactory, "wav");
#endif
#ifdef CAUDIO_COMPILE_WITH_RAW_DECODER
registerAudioDecoder(&RawDecoderFactory, "raw");
#endif
Mutex.unlock();
#ifdef CAUDIO_USE_INTERNAL_THREAD
RunThread = (cAudioThread::SpawnThread(UpdateThread, NULL) == 0);
#endif
return true;
}
//!create a sound source
@ -113,14 +149,14 @@ namespace cAudio
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
IAudio* audio = new cAudio(decoder);
audiomap[identifier] = audio;
log->log(E_LOGLEVEL_4,"cAudio: Streaming IAudio Object %s created from %s", identifier.c_str(),file.c_str());
getLogger()->logInfo("AudioManager", "Streaming Audio Source (%s) created from file %s.", identifier.c_str(), file.c_str());
Mutex.unlock();
return audio;
}
else
{
delete source;
log->log(E_LOGLEVEL_4,"cAudio: Failed to create IAudio Object %s from %s", identifier.c_str(),file.c_str());
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s) from file %s.", identifier.c_str(), file.c_str());
Mutex.unlock();
return NULL;
}
@ -157,14 +193,14 @@ namespace cAudio
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
IAudio* audio = new cAudio(decoder);
audiomap[identifier] = audio;
log->log(E_LOGLEVEL_4,"cAudio: IAudio Object %s created from memory", identifier.c_str());
getLogger()->logInfo("AudioManager", "Audio Source (%s) created from memory buffer.", identifier.c_str());
Mutex.unlock();
return audio;
}
else
{
delete source;
log->log(E_LOGLEVEL_4,"cAudio: Failed to create IAudio Object %s from memory", identifier.c_str());
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s) from memory buffer.", identifier.c_str());
Mutex.unlock();
return NULL;
}
@ -186,14 +222,14 @@ namespace cAudio
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
IAudio* audio = new cAudio(decoder);
audiomap[identifier] = audio;
log->log(E_LOGLEVEL_4,"cAudio: IAudio Object %s created from memory", identifier.c_str());
getLogger()->logInfo("AudioManager", "Raw Audio Source (%s) created from memory buffer.", identifier.c_str());
Mutex.unlock();
return audio;
}
else
{
delete source;
log->log(E_LOGLEVEL_4,"cAudio: Failed to create IAudio Object %s from memory", identifier.c_str());
getLogger()->logError("AudioManager", "Failed to create Raw Audio Source (%s) from memory buffer.", identifier.c_str());
Mutex.unlock();
return NULL;
}
@ -203,7 +239,7 @@ namespace cAudio
{
Mutex.lock();
decodermap[extension] = factory;
log->log(E_LOGLEVEL_4,"cAudio: Audio Decoder %s loaded", extension.c_str());
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", extension.c_str());
Mutex.unlock();
return true;
}
@ -214,9 +250,8 @@ namespace cAudio
std::map<std::string, IAudioDecoderFactory*>::iterator it = decodermap.find(extension);
if(it != decodermap.end())
{
delete it->second;
decodermap.erase(it);
log->log(E_LOGLEVEL_4,"cAudio: Audio Decoder %s unloaded", extension.c_str());
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s unregistered.", extension.c_str());
}
Mutex.unlock();
}
@ -269,12 +304,6 @@ namespace cAudio
i++;
}
audiomap.clear();
std::map<std::string, IAudioDecoderFactory*>::iterator it = decodermap.begin();
while ( it != decodermap.end())
{
delete it->second;
it++;
}
decodermap.clear();
Mutex.unlock();
}
@ -299,7 +328,6 @@ namespace cAudio
}*/
}
}
initCapture.updateCaptureBuffer();
Mutex.unlock();
}
@ -307,43 +335,152 @@ namespace cAudio
void cAudioManager::shutDown()
{
Mutex.lock();
//Create a openal context pointer
ALCcontext *Context;
//Create a openal device pointer
ALCdevice *Device;
//Shutdown audio capture
initCapture.shutdown();
//Grab current openal context
Context=alcGetCurrentContext();
//Grab current device context
Device=alcGetContextsDevice(Context);
//Reset context to null
alcMakeContextCurrent(NULL);
//Delete the context
alcDestroyContext(Context);
//Close the device
alcCloseDevice(Device);
log->log(E_LOGLEVEL_4,"cAudio ShutDown");
getLogger()->logInfo("AudioManager", "Manager successfully shutdown.");
Mutex.unlock();
RunThread = false;
}
//!Sets the listeners position.
void cAudioManager::setListenerPos(float x,float y,float z)
{
void cAudioManager::checkError()
{
int error = alGetError();
const char* errorString;
if (error != AL_NO_ERROR)
{
errorString = alGetString(error);
getLogger()->logError("AudioManager", "OpenAL Error: %s.", errorString);
}
if(Device)
{
error = alcGetError(Device);
if (error != AL_NO_ERROR)
{
errorString = alGetString(error);
getLogger()->logError("AudioManager", "OpenAL Error: %s.", errorString);
}
}
}
void cAudioManager::getAvailableDevices()
{
// Get list of available Playback Devices
Mutex.lock();
initlistener.setPosition(cVector3(x,y,z));
Mutex.unlock();
}
if( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE )
{
const char* deviceList = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
if (deviceList)
{
while(*deviceList)
{
std::string device(deviceList);
AvailableDevices.push_back(device);
deviceList += strlen(deviceList) + 1;
}
}
//!Sets the listener orientation
void cAudioManager::setListenerOrientation(float ux,float uy,float uz)
{
// Get the name of the 'default' capture device
DefaultDevice = alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
}
else if( alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE )
{
const char* deviceList = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
if (deviceList)
{
while(*deviceList)
{
std::string device(deviceList);
AvailableDevices.push_back(device);
deviceList += strlen(deviceList) + 1;
}
}
// Get the name of the 'default' capture device
DefaultDevice = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
}
Mutex.unlock();
}
const char* cAudioManager::getAvailableDeviceName(unsigned int index)
{
Mutex.lock();
initlistener.setUpVector(cVector3(ux,uy,uz));
if(!AvailableDevices.empty())
{
//Bounds check
if( index > (AvailableDevices.size()-1) ) index = (AvailableDevices.size()-1);
const char* deviceName = AvailableDevices[index].c_str();
Mutex.unlock();
return deviceName;
}
Mutex.unlock();
}
return "";
}
}
unsigned int cAudioManager::getAvailableDeviceCount()
{
Mutex.lock();
unsigned int size = AvailableDevices.size();
Mutex.unlock();
return size;
}
const char* cAudioManager::getDefaultDeviceName()
{
Mutex.lock();
const char* deviceName = DefaultDevice.empty() ? "" : DefaultDevice.c_str();
Mutex.unlock();
return deviceName;
}
CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault)
{
cAudioManager* manager = new cAudioManager;
if(manager)
{
if(initializeDefault)
manager->initialize();
manager->getAvailableDevices();
#ifdef CAUDIO_USE_INTERNAL_THREAD
AudioManagerObjectsMutex.lock();
AudioManagerObjects.insert(manager);
//First time launch of thread
if(!RunAudioManagerThread && AudioManagerObjects.size() > 0)
RunAudioManagerThread = (cAudioThread::SpawnThread(AudioManagerUpdateThread, NULL) == 0);
AudioManagerObjectsMutex.unlock();
#endif
}
return manager;
}
CAUDIO_API void destroyAudioManager(IAudioManager* manager)
{
if(manager)
{
#ifdef CAUDIO_USE_INTERNAL_THREAD
AudioManagerObjectsMutex.lock();
AudioManagerObjects.erase(manager);
//Kill the thread if there are no objects to process anymore
if(RunAudioManagerThread && AudioManagerObjects.empty())
RunAudioManagerThread = false;
AudioManagerObjectsMutex.unlock();
#endif
delete manager;
manager = NULL;
}
}
CAUDIO_API bool isAudioManagerThreadRunning()
{
return RunAudioManagerThread;
}
};

View File

@ -1,41 +1,143 @@
#include "../Headers/cLogger.h"
#include <time.h>
#include "../Headers/cConsoleLogReceiver.h"
namespace cAudio{
cLogger::cLogger()
namespace cAudio
{
Mutex.lock();
logLevel = E_LOGLEVEL_4;
Mutex.unlock();
}
static cLogger Logger;
static bool FirstTimeLogInit(false);
static cConsoleLogReceiver ConsoleLog;
cLogger::~cLogger()
{
Mutex.lock();
Mutex.unlock();
}
cLogger::cLogger() : StartTime(0), MinLogLevel(ELL_INFO)
{
StartTime = clock();
}
void cLogger::setLogLevel(E_LOGLEVEL level)
{
Mutex.lock();
logLevel = level;
Mutex.unlock();
}
void cLogger::logCritical( const char* sender, const char *msg, ... )
{
if(ELL_CRITICAL >= MinLogLevel)
{
Mutex.lock();
va_list args;
va_start( args, msg );
broadcastMessage( ELL_CRITICAL, sender, msg, args );
va_end( args );
Mutex.unlock();
}
}
void cLogger::logError( const char* sender, const char *msg, ... )
{
if(ELL_ERROR >= MinLogLevel)
{
Mutex.lock();
va_list args;
va_start( args, msg );
broadcastMessage( ELL_ERROR, sender, msg, args );
va_end( args );
Mutex.unlock();
}
}
void cLogger::logWarning( const char* sender, const char *msg, ... )
{
if(ELL_WARNING >= MinLogLevel)
{
Mutex.lock();
va_list args;
va_start( args, msg );
broadcastMessage( ELL_WARNING, sender, msg, args );
va_end( args );
Mutex.unlock();
}
}
void cLogger::logInfo( const char* sender, const char *msg, ... )
{
if(ELL_INFO >= MinLogLevel)
{
Mutex.lock();
va_list args;
va_start( args, msg );
broadcastMessage( ELL_INFO, sender, msg, args );
va_end( args );
Mutex.unlock();
}
}
void cLogger::logDebug( const char* sender, const char *msg, ... )
{
if(ELL_DEBUG >= MinLogLevel)
{
Mutex.lock();
va_list args;
va_start( args, msg );
broadcastMessage( ELL_DEBUG, sender, msg, args );
va_end( args );
Mutex.unlock();
}
}
void cLogger::setLogLevel( const LogLevel& logLevel )
{
Mutex.lock();
MinLogLevel = logLevel;
Mutex.unlock();
}
void cLogger::broadcastMessage( LogLevel level, const char* sender, const char* msg, va_list args )
{
float messageTime = (clock() - StartTime) / (float)CLOCKS_PER_SEC;
vsnprintf( TempTextBuf, 2048, msg, args );
void cLogger::log(E_LOGLEVEL loglevel,const char* text,...)
{
Mutex.lock();
char buffer[ 4096 ];
va_list marker;
va_start( marker, text );
vsprintf( buffer, text, marker );
va_end( marker );
if(logLevel <= loglevel)
std::map<std::string,ILogReceiver*>::iterator it = Receivers.begin();
for (it = Receivers.begin(); it != Receivers.end(); it++)
{
it->second->OnLogMessage(sender, TempTextBuf, level, messageTime);
}
}
bool cLogger::registerLogReceiver(ILogReceiver* receiver, std::string name)
{
std::cout<< buffer <<std::endl;
Mutex.lock();
Receivers[name] = receiver;
Mutex.unlock();
return true;
}
Mutex.unlock();
}
}
void cLogger::unRegisterLogReceiver(std::string name)
{
Mutex.lock();
std::map<std::string, ILogReceiver*>::iterator it = Receivers.find(name);
if(it != Receivers.end())
{
Receivers.erase(it);
}
Mutex.unlock();
}
bool cLogger::isLogReceiverRegistered(std::string name)
{
Mutex.lock();
std::map<std::string, ILogReceiver*>::iterator it = Receivers.find(name);
bool result = (it != Receivers.end());
Mutex.unlock();
return result;
}
ILogReceiver* cLogger::getLogReceiver(std::string name)
{
Mutex.lock();
std::map<std::string, ILogReceiver*>::iterator it = Receivers.find(name);
if(it != Receivers.end())
{
Mutex.unlock();
return it->second;
}
Mutex.unlock();
return NULL;
}
CAUDIO_API ILogger* getLogger()
{
if(!FirstTimeLogInit)
{
FirstTimeLogInit = true;
Logger.registerLogReceiver(&ConsoleLog, "Console");
}
return &Logger;
}
};

View File

@ -4,6 +4,7 @@
Version="9.00"
Name="cAudio"
ProjectGUID="{ACD6C202-85D4-44F5-83BF-6577A074F655}"
RootNamespace="cAudio"
Keyword="Win32Proj"
TargetFrameworkVersion="0"
>
@ -18,7 +19,7 @@
<Configuration
Name="Debug|Win32"
OutputDirectory="bin/win32-visual"
IntermediateDirectory="Debug"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="2"
UseOfMFC="0"
>
@ -94,7 +95,7 @@
<Configuration
Name="Release|Win32"
OutputDirectory="bin/win32-visual"
IntermediateDirectory="Release"
IntermediateDirectory="obj/$(ConfigurationName)"
ConfigurationType="2"
UseOfMFC="0"
>
@ -188,6 +189,10 @@
RelativePath=".\Headers\cAudioManager.h"
>
</File>
<File
RelativePath=".\Headers\cConsoleLogReceiver.h"
>
</File>
<File
RelativePath=".\Headers\cFileSource.h"
>
@ -264,6 +269,10 @@
RelativePath=".\Source\cAudioSleep.cpp"
>
</File>
<File
RelativePath=".\Source\cConsoleLogReceiver.cpp"
>
</File>
<File
RelativePath=".\Source\cFileSource.cpp"
>
@ -356,6 +365,10 @@
RelativePath=".\include\ILogger.h"
>
</File>
<File
RelativePath=".\include\ILogReceiver.h"
>
</File>
</Filter>
<Filter
Name="Util"

View File

@ -6,7 +6,6 @@
namespace cAudio
{
class IAudio
{
public:
@ -72,10 +71,8 @@ namespace cAudio
virtual bool update() = 0;
//!checks to make sure everything is ready to go
virtual bool isvalid() = 0;
//!returns the current OpenalSource
virtual const ALuint& getSource()const = 0;
protected:
private:
};
}
};
#endif //! IAUDIO_H

View File

@ -2,6 +2,7 @@
#define IAUDIOCAPTURE_H
#include "eAudioFormats.h"
#include "cAudioDefines.h"
namespace cAudio
{
@ -9,18 +10,34 @@ namespace cAudio
{
public:
//! Initializes the capture device to the selected settings
/** Note that calling this will cause the capture device to be reinitialized. Calling while in use may lead to a loss of audio data.
\param frequency: Frequency that the captured audio will be at
/** Note that calling this will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
\param deviceName: Name of the audio device to capture audio from, pass NULL to specify the default one
\param frequency: Frequency that the captured audio will be captured at in hertz
\param format: Format of the captured audio
\param internalBufferSize: Size of the internal OpenAL buffer used to store the captured audio until the next IAudioManager::update() in bytes
\param internalBufferSize: Size of the internal OpenAL buffer used to store the captured audio between calls to getCapturedAudio() in bytes.
\return True on success, False if the capture device failed to initialize.
*/
virtual bool initialize(unsigned int frequency = 22050, AudioFormats format = EAF_16BIT_MONO, unsigned int internalBufferSize = 8192) = 0;
virtual bool initialize(const char* deviceName = 0x0, unsigned int frequency = 22050, AudioFormats format = EAF_16BIT_MONO, unsigned int internalBufferSize = 8192) = 0;
//! Returns true if the current OpenAL implementation supports capturing audio
virtual bool isSupported() = 0;
//! Returns true if the capture device is ready to be used. False may indicate an error with the current settings.
virtual bool isReady() = 0;
//! Grabs samples from the OpenAL buffer into the capture buffer if the OpenAL buffer has reached half full. Should be run once every audio frame, unless threading is enabled.
/** \param force: Force capturing data from the buffer, even if the buffer is not half full */
virtual void updateCaptureBuffer(bool force = false) = 0;
//! Shuts down the capture device, clearing the internal buffer and setting the audio capture into an uninitialized state. You must call initialize() again in order to reuse this object.
virtual void shutdown() = 0;
//! Returns the name of an available capturing device.
/** \param index: Specify which name to retrieve ( Range: 0 to getAvailableDeviceCount()-1 ) */
virtual const char* getAvailableDeviceName(unsigned int index) = 0;
//! Returns the number of capture devices available for use.
virtual unsigned int getAvailableDeviceCount() = 0;
//! Returns the name of the default system capturing device.
virtual const char* getDefaultDeviceName() = 0;
//! Returns the name of the audio device being used to capture audio
virtual const char* getDeviceName() = 0;
//! Returns the frequency that the captured audio will be at
virtual unsigned int getFrequency() = 0;
//! Returns the format of the captured audio
@ -30,14 +47,25 @@ namespace cAudio
//! Returns the size of a "sample" of audio data. Useful for making sure you grab audio data at sample boundaries
virtual unsigned int getSampleSize() = 0;
//! Sets the frequency that the captured audio will be at. Will cause the capture device to be reinitialized. Calling while in use may lead to a loss of audio data.
/** \return True on success, False if the capture device failed to initialize. */
//! Sets the audio device . Will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
/**
\param deviceName: Name of the audio device to capture audio from, pass NULL to specify the default one
\return True on success, False if the capture device failed to initialize. */
virtual bool setDevice(const char* deviceName) = 0;
//! Sets the frequency that the captured audio will be at. Will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
/**
\param frequency: Frequency that the captured audio will be captured at in hertz
\return True on success, False if the capture device failed to initialize. */
virtual bool setFrequency(unsigned int frequency) = 0;
//! Sets the format that the captured audio will be at. Will cause the capture device to be reinitialized. Calling while in use may lead to a loss of audio data.
/** \return True on success, False if the capture device failed to initialize. */
//! Sets the format that the captured audio will be at. Will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
/**
\param format: Format of the captured audio
\return True on success, False if the capture device failed to initialize. */
virtual bool setFormat(AudioFormats format) = 0;
//! Sets the internal buffer size that OpenAL will use to store captured audio between calls to IAudioManager::update() in bytes. Will cause the capture device to be reinitialized. Calling while in use may lead to a loss of audio data.
/** \return True on success, False if the capture device failed to initialize. */
//! Sets the internal buffer size that OpenAL will use to store captured audio between calls to getCapturedAudio() in bytes. Will cause the capture device to be reinitialized. Calling while in use will clear the internal audio buffer.
/**
\param internalBufferSize: Size of the internal OpenAL buffer in bytes
\return True on success, False if the capture device failed to initialize. */
virtual bool setInternalBufferSize(unsigned int internalBufferSize) = 0;
//! Starts capturing audio data to an internal buffer. Will clear any old data in the buffer.
@ -46,7 +74,7 @@ namespace cAudio
//! Stops capturing audio data to an internal buffer.
virtual void stopCapture() = 0;
//! Allows access to the audio data in the internal capture buffer
/** Can be called at any time to retrieve recorded audio. It is recommended that you call it every so often to prevent the internal buffer from growing too large.
/** Can be called at any time to retrieve recorded audio. It is recommended that you call it every so often with long recordings to prevent the internal buffer from growing too large.
Once successfully retrieved, the captured audio will be deleted from the internal buffer.
\param outputBuffer: Pointer to an output array to copy audio data to.
\param outputBufferSize: Size of the output array in bytes
@ -56,8 +84,31 @@ namespace cAudio
//! Returns the current size of the internal audio buffer in bytes
virtual unsigned int getCurrentCapturedAudioSize() = 0;
protected:
IAudioCapture() { }
virtual ~IAudioCapture() { }
};
//! Creates an interface to an Audio Capture Object
/** Note: This is the only way to get access to the audio capture capabilities of cAudio.
You must delete this interface using destroyAudioCapture() once you are done with it.
\param initializeDefault: Whether to return an object initialized with the default settings. If set to false, you must make a call to initialize before audio can be captured
\return A pointer to the created object, NULL if the object could not be allocated.
*/
CAUDIO_API IAudioCapture* createAudioCapture(bool initializeDefault = true);
//! Destroys an interface to a previously created Audio Capture Object and frees the memory allocated for it
/**
\param capture: The object to destroy
*/
CAUDIO_API void destroyAudioCapture(IAudioCapture* capture);
//! Returns if the thread used to update all Audio Capture Objects is running
/** Note: Will always return false if threading is disabled.
The library automatically shuts down the thread if no Audio Capture objects exist and will restart the thread on creation of a new object.
\return True if the thread is currently running, false otherwise.
*/
CAUDIO_API bool isAudioCaptureThreadRunning();
};
#endif //! IAUDIOCAPTURE_H

View File

@ -2,8 +2,8 @@
#define IAUDIOMANAGER_H
#include <string>
#include "IListener.h"
#include "IAudioCapture.h"
#include "cAudioDefines.h"
#include "eAudioFormats.h"
namespace cAudio
{
@ -13,17 +13,27 @@ namespace cAudio
class IAudioManager
{
public:
IAudioManager() { }
virtual ~IAudioManager() { }
//!Inits the audio manager calling the alut/etc start ups
virtual void init(int argc,char* argv[]) = 0;
virtual bool initialize(const char* deviceName = 0x0, int outputFrequency = -1, int eaxEffectSlots = 4) = 0;
//!Shuts everything down
virtual void shutDown() = 0;
//!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 *getSound(std::string identifier) = 0;
virtual IAudio* getSound(std::string identifier) = 0;
//!Releases "ALL" cAudio objects (but does not shutdown the manager)
virtual void release() = 0;
//! Returns the name of an available playback device.
/** \param index: Specify which name to retrieve ( Range: 0 to getAvailableDeviceCount()-1 ) */
virtual const char* getAvailableDeviceName(unsigned int index) = 0;
//! Returns the number of playback devices available for use.
virtual unsigned int getAvailableDeviceCount() = 0;
//! Returns the name of the default system playback device.
virtual const char* getDefaultDeviceName() = 0;
//!Creates the cAudio object
virtual IAudio* createFromFile(const std::string& identifier,const std::string& file,bool stream = false) = 0;
@ -36,30 +46,39 @@ namespace cAudio
virtual bool registerAudioDecoder(IAudioDecoderFactory* factory, std::string extension) = 0;
//!Unregister Audio Codec (allows you to prevent an file type from being playable with new sound sources)
//!Note that all current sound sources will still continue to use any currently allocated decoders.
//!Will NOT delete any user added factory instance, you must do that yourself
virtual void unRegisterAudioDecoder(std::string extension) = 0;
//!Returns whether an audio decoder is currently registered for this file type
virtual bool isAudioDecoderRegistered(std::string extension) = 0;
//!Returns a registered audio decoder factory
virtual IAudioDecoderFactory* getAudioDecoderFactory(std::string extension) = 0;
//!Allows you to set the listener position (DEPRECIATED! USE getListener() INSTEAD!)
virtual void setListenerPos(float x,float y,float z) = 0;
//!set the listeners orientation (DEPRECIATED! USE getListener() INSTEAD!)
virtual void setListenerOrientation(float ux,float uy,float uz) = 0;
//!Returns an interface for the listener
virtual IListener* getListener() = 0;
//!Returns an interface for audio capture
virtual IAudioCapture* getAudioCapture() = 0;
virtual bool IsThreadRunning() = 0;
IAudioManager(){}
virtual ~IAudioManager() {}
protected:
private:
};
CAUDIO_API IAudioManager* getAudioManager(void);
//! Creates an interface to an Audio Manager
/** Note: This is the only way to get access to the audio playback capabilities of cAudio.
You must delete this interface using destroyAudioManager() once you are done with it.
\param initializeDefault: Whether to return an object initialized with the default settings. If set to false, you must make a call to initialize before you can create audio sources
\return A pointer to the created object, NULL if the object could not be allocated.
*/
CAUDIO_API IAudioManager* createAudioManager(bool initializeDefault = true);
//! Destroys an interface to a previously created Audio Manager and frees the memory allocated for it
/**
\param capture: The object to destroy
*/
CAUDIO_API void destroyAudioManager(IAudioManager* manager);
//! Returns if the thread used to update all Audio Managers is running
/** Note: Will always return false if threading is disabled.
The library automatically shuts down the thread if no Audio Managers exist and will restart the thread on creation of a new manager.
\return True if the thread is currently running, false otherwise.
*/
CAUDIO_API bool isAudioManagerThreadRunning();
}
#endif //! IAUDIOMANAGER_H

View File

@ -1,27 +1,46 @@
#ifndef ICAUDIOLOGGER_H_INCLUDED
#define ICAUDIOLOGGER_H_INCLUDED
#include <iostream>
#ifndef ILOGGER_H_INCLUDED
#define ILOGGER_H_INCLUDED
#include "ILogReceiver.h"
#include "cAudioDefines.h"
#include <string>
namespace cAudio{
namespace cAudio
{
class ILogger
{
public:
ILogger() { }
virtual ~ILogger() { }
enum E_LOGLEVEL{
E_LOGLEVEL_1,
E_LOGLEVEL_2,
E_LOGLEVEL_3,
E_LOGLEVEL_4,
virtual void logCritical( const char* sender, const char *msg, ... ) = 0;
virtual void logError( const char* sender, const char *msg, ... ) = 0;
virtual void logWarning( const char* sender, const char *msg, ... ) = 0;
virtual void logInfo( const char* sender, const char *msg, ... ) = 0;
virtual void logDebug( const char* sender, const char *msg, ... ) = 0;
};
virtual const LogLevel& getLogLevel() const = 0;
virtual void setLogLevel( const LogLevel& logLevel ) = 0;
class ILogger{
//! Register Log Receiver
//! Note: Any class registered will become owned by the internal thread.
//! If threading is enabled, you MUST make the receiver threadsafe if you plan to access it in your application while it is registered
virtual bool registerLogReceiver(ILogReceiver* receiver, std::string name) = 0;
//!Unregister a Log Receiver
//!Will NOT delete any user added receiver, you must do that yourself
virtual void unRegisterLogReceiver(std::string name) = 0;
//!Returns whether an log receiver is currently registered
virtual bool isLogReceiverRegistered(std::string name) = 0;
//!Returns a registered log receiver
virtual ILogReceiver* getLogReceiver(std::string name) = 0;
protected:
private:
};
public:
ILogger(){}
virtual ~ILogger(){}
virtual void setLogLevel(E_LOGLEVEL level) = 0;
virtual void log(E_LOGLEVEL loglevel,const char* text,...) = 0;
};
}
#endif
//! Gets the interface to the logger
/** Note: This is the only way to get access to the logging capabilities of cAudio.
\return A pointer to the object
*/
CAUDIO_API ILogger* getLogger();
};
#endif //! ILOGGER_H_INCLUDED

View File

@ -28,4 +28,9 @@
#endif
//These defines control which of the default audio codecs are compiled into the library
#define CAUDIO_COMPILE_WITH_OGG_DECODER
#define CAUDIO_COMPILE_WITH_WAV_DECODER
#define CAUDIO_COMPILE_WITH_RAW_DECODER
#endif //! CAUDIODEFINES_H

BIN
media/cAudioTheme1.ogg Normal file

Binary file not shown.

BIN
media/cAudioTheme2.ogg Normal file

Binary file not shown.