cAudioCapture.h
00001
00002
00003
00004
00005 #ifndef CAUDIOCAPTURE_H
00006 #define CAUDIOCAPTURE_H
00007
00008 #include "../include/IAudioCapture.h"
00009 #include <vector>
00010 #include <AL/al.h>
00011 #include <AL/alc.h>
00012 #include "../Headers/cMutex.h"
00013 #include <string>
00014 #include <list>
00015
00016 namespace cAudio
00017 {
00018 class cAudioCapture : public IAudioCapture
00019 {
00020 public:
00021
00022 enum Events{
00023 ON_INIT,
00024 ON_UPDATE,
00025 ON_RELEASE,
00026 ON_BEGINCAPTURE,
00027 ON_ENDCAPTURE,
00028 ON_USERREQUESTEDBUFFER,
00029 };
00030
00031 cAudioCapture();
00032 ~cAudioCapture();
00033
00035 bool checkCaptureExtension();
00036
00037 virtual bool initialize(const char* deviceName = 0x0, unsigned int frequency = 22050, AudioFormats format = EAF_16BIT_MONO, unsigned int internalBufferSize = 8192);
00038 virtual bool isSupported() { return Supported; }
00039 virtual bool isReady() { return Ready; }
00040 virtual void updateCaptureBuffer(bool force = false);
00041 virtual void shutdown();
00042
00043 virtual const char* getAvailableDeviceName(unsigned int index);
00044 virtual unsigned int getAvailableDeviceCount();
00045 virtual const char* getDefaultDeviceName();
00046
00047 virtual const char* getDeviceName() { return DeviceName.c_str(); }
00048 virtual unsigned int getFrequency() { return Frequency; }
00049 virtual AudioFormats getFormat() { return Format; }
00050 virtual unsigned int getInternalBufferSize() { return InternalBufferSize; }
00051 virtual unsigned int getSampleSize() { return SampleSize; }
00052
00053 virtual bool setDevice(const char* deviceName);
00054 virtual bool setFrequency(unsigned int frequency);
00055 virtual bool setFormat(AudioFormats format);
00056 virtual bool setInternalBufferSize(unsigned int internalBufferSize);
00057
00058 virtual bool beginCapture();
00059 virtual void stopCapture();
00060 virtual unsigned int getCapturedAudio(void* outputBuffer, unsigned int outputBufferSize);
00061
00062 virtual unsigned int getCurrentCapturedAudioSize();
00063 void getAvailableDevices();
00064
00065 virtual void registerEventHandler(ICaptureEventHandler* handler);
00066 virtual void unRegisterEventHandler(ICaptureEventHandler* handler);
00067 virtual void unRegisterAllEventHandlers();
00068
00069 protected:
00070 cAudioMutex Mutex;
00071
00072 bool initOpenALDevice();
00073 void shutdownOpenALDevice();
00074
00075 unsigned int Frequency;
00076 AudioFormats Format;
00077 unsigned int InternalBufferSize;
00078 int SampleSize;
00079
00080 std::vector<char> CaptureBuffer;
00081 std::vector<std::string> AvailableDevices;
00082 std::string DefaultDevice;
00083 std::list<ICaptureEventHandler*> eventHandlerList;
00084
00085 bool Supported;
00086 bool Ready;
00087 bool Capturing;
00088
00089 std::string DeviceName;
00090 ALCdevice* CaptureDevice;
00091
00092 bool checkError();
00093 ALenum convertAudioFormatEnum(AudioFormats format);
00094 void signalEvent(Events sevent);
00095 };
00096 };
00097
00098 #endif