2010-02-09 05:18:39 +01:00
|
|
|
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
|
|
|
|
// This file is part of the "cAudio Engine"
|
|
|
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
|
|
|
|
2009-06-21 05:24:30 +02:00
|
|
|
#ifndef CAUDIOMANAGER_H_INCLUDED
|
|
|
|
#define CAUDIOMANAGER_H_INCLUDED
|
2009-12-01 02:41:15 +01:00
|
|
|
|
2009-06-21 05:24:30 +02:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2009-12-01 02:41:15 +01:00
|
|
|
|
2010-02-09 05:18:39 +01:00
|
|
|
#include "cAudioSource.h"
|
2009-06-21 05:24:30 +02:00
|
|
|
#include "../include/IAudioDecoderFactory.h"
|
|
|
|
#include "cListener.h"
|
|
|
|
#include "../include/IAudioManager.h"
|
2009-08-29 13:24:31 +02:00
|
|
|
#include "../Headers/cMutex.h"
|
2010-01-11 01:39:08 +01:00
|
|
|
#include "../Headers/cAudioEffects.h"
|
2009-11-20 04:39:56 +01:00
|
|
|
|
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
2009-06-21 05:24:30 +02:00
|
|
|
|
|
|
|
namespace cAudio
|
|
|
|
{
|
2010-02-10 22:57:09 +01:00
|
|
|
class IAudioSource;
|
2009-06-21 05:24:30 +02:00
|
|
|
|
|
|
|
class cAudioManager : public IAudioManager
|
|
|
|
{
|
2009-08-26 01:56:35 +02:00
|
|
|
public:
|
2010-02-13 05:47:59 +01:00
|
|
|
|
|
|
|
enum Events{
|
|
|
|
ON_INIT,
|
|
|
|
ON_UPDATE,
|
|
|
|
ON_RELEASE,
|
|
|
|
ON_SOURCECREATE,
|
|
|
|
ON_DECODERREGISTER,
|
|
|
|
ON_DATASOURCEREGISTER,
|
|
|
|
};
|
|
|
|
|
2009-12-07 23:25:08 +01:00
|
|
|
cAudioManager() : Device(NULL), Context(NULL), EFXSupported(false), Initialized(false) { }
|
2009-11-20 04:39:56 +01:00
|
|
|
virtual ~cAudioManager() { }
|
2009-09-12 07:59:28 +02:00
|
|
|
|
2009-08-08 07:51:32 +02:00
|
|
|
//!Inits the audio manager calling the alut/etc start ups
|
2009-11-20 04:39:56 +01:00
|
|
|
virtual bool initialize(const char* deviceName = 0x0, int outputFrequency = -1, int eaxEffectSlots = 4);
|
2009-08-26 01:56:35 +02:00
|
|
|
//!Shuts everything down
|
|
|
|
virtual void shutDown();
|
2009-12-01 02:41:15 +01:00
|
|
|
//!Updates the cAudio playback
|
|
|
|
virtual void update();
|
|
|
|
//!Gets you the cAudio object you want
|
2010-02-10 22:57:09 +01:00
|
|
|
virtual IAudioSource* getSoundByName(const char* name);
|
2009-12-01 02:41:15 +01:00
|
|
|
//!Releases "ALL" cAudio objects
|
|
|
|
virtual void release();
|
2010-01-19 05:04:40 +01:00
|
|
|
//!Releases a single cAudio source
|
2010-02-10 22:57:09 +01:00
|
|
|
virtual void release(IAudioSource* source);
|
2009-11-20 04:39:56 +01:00
|
|
|
|
|
|
|
//! 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();
|
|
|
|
|
2009-08-08 07:51:32 +02:00
|
|
|
//!Creates the cAudio object
|
2010-02-10 22:57:09 +01:00
|
|
|
virtual IAudioSource* createFromFile(const char* name, const char* pathToFile, bool stream = false);
|
2010-02-11 16:29:40 +01:00
|
|
|
//!Loads data from memory or virtual file system
|
2010-02-10 22:57:09 +01:00
|
|
|
virtual IAudioSource* createFromMemory(const char* name, const char* data, size_t length, const char* extension);
|
2009-08-26 01:56:35 +02:00
|
|
|
//!Loads raw audio from memory.
|
2010-02-10 22:57:09 +01:00
|
|
|
virtual IAudioSource* createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format);
|
2010-02-11 16:29:40 +01:00
|
|
|
//!Loads audio from alternative data source.
|
|
|
|
virtual IAudioSource* createFromSource(const char* name, const char* source);
|
|
|
|
|
2009-08-26 01:56:35 +02:00
|
|
|
//!Register Audio Codec
|
2009-12-01 02:41:15 +01:00
|
|
|
virtual bool registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension);
|
2009-08-11 19:57:20 +02:00
|
|
|
//!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.
|
2009-11-20 04:39:56 +01:00
|
|
|
//!Will NOT delete any user added factory instance, you must do that yourself
|
2009-12-01 02:41:15 +01:00
|
|
|
virtual void unRegisterAudioDecoder(const char* extension);
|
2009-08-11 19:57:20 +02:00
|
|
|
//!Returns whether an audio decoder is currently registered for this file type
|
2009-12-01 02:41:15 +01:00
|
|
|
virtual bool isAudioDecoderRegistered(const char* extension);
|
2009-08-11 19:57:20 +02:00
|
|
|
//!Returns a registered audio decoder factory
|
2009-12-01 02:41:15 +01:00
|
|
|
virtual IAudioDecoderFactory* getAudioDecoderFactory(const char* extension);
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2010-02-11 16:29:40 +01:00
|
|
|
//!Register a alternative source
|
|
|
|
virtual bool registerSource(const char* identifier,IDataSource* datasource);
|
|
|
|
//! Unregister source (allows you to prevent creation of audio files from specific source)
|
|
|
|
//!Note that all current sound sources will still continue to use any currently used source.
|
|
|
|
//!Will NOT delete any user added factory instance, you must do that yourself
|
|
|
|
virtual void unRegisterSource(const char* source);
|
|
|
|
//!Checks if the source type is registered.
|
|
|
|
virtual bool isSourceRegistered(const char* source);
|
|
|
|
|
2010-02-13 05:47:59 +01:00
|
|
|
//!Registers a new event handler to the manager
|
|
|
|
virtual void registerEventHandler(IManagerEventHandler* handler);
|
|
|
|
//!Unregisters specified event handler from manager
|
|
|
|
virtual void unRegisterEventHandler(IManagerEventHandler* handler) ;
|
|
|
|
//!Unregisters all event handlers attached to the manager
|
|
|
|
virtual void unRegisterAllEventHandlers();
|
2010-02-11 16:29:40 +01:00
|
|
|
|
2009-11-20 04:39:56 +01:00
|
|
|
//! Grabs a list of available devices, as well as the default system one
|
|
|
|
void getAvailableDevices();
|
2009-06-21 05:24:30 +02:00
|
|
|
|
2009-11-20 04:39:56 +01:00
|
|
|
virtual IListener* getListener() { return &initlistener; }
|
2010-02-13 03:34:50 +01:00
|
|
|
|
|
|
|
#ifdef CAUDIO_EFX_ENABLED
|
2010-01-11 01:39:08 +01:00
|
|
|
virtual IAudioEffects* getEffects() { return &initEffects; }
|
2010-02-13 03:34:50 +01:00
|
|
|
#endif
|
2009-08-29 13:24:31 +02:00
|
|
|
|
2009-08-26 01:56:35 +02:00
|
|
|
private:
|
2010-02-13 05:47:59 +01:00
|
|
|
|
|
|
|
//Signals a event to all event handlers
|
|
|
|
void signalEvent(Events sevent);
|
|
|
|
|
2009-08-29 13:24:31 +02:00
|
|
|
//Mutex for thread syncronization
|
|
|
|
cAudioMutex Mutex;
|
2009-11-20 04:39:56 +01:00
|
|
|
|
|
|
|
//Make a Openal context pointer
|
2009-12-01 02:41:15 +01:00
|
|
|
ALCcontext* Context;
|
2009-11-20 04:39:56 +01:00
|
|
|
//Make a openal device pointer
|
2009-12-01 02:41:15 +01:00
|
|
|
ALCdevice* Device;
|
2009-11-20 04:39:56 +01:00
|
|
|
|
2009-12-07 23:25:08 +01:00
|
|
|
//Holds whether EFX is supported
|
|
|
|
bool EFXSupported;
|
|
|
|
|
|
|
|
//Whether the manager is currently initialized and ready to go.
|
|
|
|
bool Initialized;
|
|
|
|
|
2009-12-01 02:41:15 +01:00
|
|
|
//! Holds an index for fast searching of audio sources by name
|
2010-02-10 22:57:09 +01:00
|
|
|
std::map<std::string, IAudioSource*> audioIndex;
|
2009-12-01 02:41:15 +01:00
|
|
|
//! Holds all managed audio sources
|
2010-02-10 22:57:09 +01:00
|
|
|
std::vector<IAudioSource*> audioSources;
|
2009-12-07 23:25:08 +01:00
|
|
|
//! Decoder map that holds all decoders by file extension
|
2009-08-08 07:51:32 +02:00
|
|
|
std::map<std::string, IAudioDecoderFactory*> decodermap;
|
2010-02-11 16:29:40 +01:00
|
|
|
//! Archive map that holds all datasource types
|
|
|
|
std::map<std::string, IDataSource*> datasourcemap;
|
2010-02-13 05:47:59 +01:00
|
|
|
//! List of all attached event handlers
|
|
|
|
std::list<IManagerEventHandler*> eventHandlerList;
|
|
|
|
|
2010-02-11 16:29:40 +01:00
|
|
|
|
2009-12-07 23:25:08 +01:00
|
|
|
//! The listener object
|
2009-08-08 07:51:32 +02:00
|
|
|
cListener initlistener;
|
2010-02-13 03:34:50 +01:00
|
|
|
#ifdef CAUDIO_EFX_ENABLED
|
2010-01-11 01:39:08 +01:00
|
|
|
//! Interface for audio effects
|
|
|
|
cAudioEffects initEffects;
|
2010-02-13 03:34:50 +01:00
|
|
|
#endif
|
2009-11-20 04:39:56 +01:00
|
|
|
//! Check for OpenAL errors
|
2010-01-11 01:39:08 +01:00
|
|
|
bool checkError();
|
2009-11-20 04:39:56 +01:00
|
|
|
|
|
|
|
std::vector<std::string> AvailableDevices;
|
|
|
|
std::string DefaultDevice;
|
2009-06-21 05:24:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //! CAUDIOMANAGER_H_INCLUDED
|