cAudio 2.3.0
3d Audio Engine
Loading...
Searching...
No Matches
cAudioCapture.h
1// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2// This file is part of the "cAudio Engine"
3// For conditions of distribution and use, see copyright notice in cAudio.h
4
5#pragma once
6
7#include "cOpenALUtil.h"
8#include "cMutex.h"
9#include "cMemoryOverride.h"
10#include "IAudioCapture.h"
11#include "cSTLAllocator.h"
12#include "cAudioString.h"
13#include "IThread.h"
14
15namespace cAudio
16{
18 {
19 public:
20
21 enum Events{
22 ON_INIT,
23 ON_UPDATE,
24 ON_RELEASE,
25 ON_BEGINCAPTURE,
26 ON_ENDCAPTURE,
27 ON_USERREQUESTEDBUFFER,
28 };
29
32
33 virtual bool initialize(const char* deviceName = 0x0, unsigned int frequency = 22050, AudioFormats format = EAF_16BIT_MONO, unsigned int internalBufferSize = 8192);
34 virtual bool isReady() { return Ready; }
35 virtual void updateCaptureBuffer(bool force = false);
36 virtual void shutdown();
37 virtual bool isUpdateThreadRunning()
38 {
39 return (AudioThread != NULL && AudioThread->isRunning());
40 }
41
42 virtual const char* getDeviceName() { return toUTF8(DeviceName); }
43 virtual unsigned int getFrequency() { return Frequency; }
44 virtual AudioFormats getFormat() { return Format; }
45 virtual unsigned int getInternalBufferSize() { return InternalBufferSize; }
46 virtual unsigned int getSampleSize() { return SampleSize; }
47
48 virtual bool setDevice(const char* deviceName);
49 virtual bool setFrequency(unsigned int frequency);
50 virtual bool setFormat(AudioFormats format);
51 virtual bool setInternalBufferSize(unsigned int internalBufferSize);
52
53 virtual bool beginCapture();
54 virtual void stopCapture();
55 virtual unsigned int getCapturedAudio(void* outputBuffer, unsigned int outputBufferSize);
57
58 virtual unsigned int getCurrentCapturedAudioSize();
59 void getAvailableDevices();
60
61 virtual void registerEventHandler(ICaptureEventHandler* handler);
62 virtual void unRegisterEventHandler(ICaptureEventHandler* handler);
63 virtual void unRegisterAllEventHandlers();
64
65 protected:
66 virtual void run();
67
68 cAudioMutex Mutex;
69
72
73 bool initOpenALDevice();
74 void shutdownOpenALDevice();
75
76 unsigned int Frequency;
77 AudioFormats Format;
78 unsigned int InternalBufferSize;
79 int SampleSize;
80
81 cAudioVector<char>::Type CaptureBuffer;
82 cAudioList<ICaptureEventHandler*>::Type eventHandlerList;
83
84 bool Ready;
85 bool Capturing;
86
87 cAudioString DeviceName;
88 ALCdevice* CaptureDevice;
89
90 bool checkError();
91 ALenum convertAudioFormatEnum(AudioFormats format);
92 void signalEvent(Events sevent);
93 };
94};
Interface for capturing operations in the cAudio Engine.
Definition: IAudioCapture.h:18
Interface for recieving Capture Manager Events.
virtual bool beginCapture()
Starts capturing audio data to an internal buffer. Will clear any old data in the buffer.
virtual bool setDevice(const char *deviceName)
Sets the audio device . Will cause the capture device to be reinitialized. Calling while in use will ...
virtual bool initialize(const char *deviceName=0x0, unsigned int frequency=22050, AudioFormats format=EAF_16BIT_MONO, unsigned int internalBufferSize=8192)
Initializes the capture device to the selected settings.
virtual const char * getDeviceName()
Returns the name of the audio device being used to capture audio.
Definition: cAudioCapture.h:42
virtual void stopCapture()
Stops capturing audio data to an internal buffer.
virtual void shutdown()
Shuts down the capture device, clearing the internal buffer and setting the audio capture into an uni...
virtual unsigned int getFrequency()
Returns the frequency that the captured audio will be at.
Definition: cAudioCapture.h:43
virtual unsigned int getSampleSize()
Returns the size of a "sample" of audio data. Useful for making sure you grab audio data at sample bo...
Definition: cAudioCapture.h:46
virtual bool setFrequency(unsigned int frequency)
Sets the frequency that the captured audio will be at. Will cause the capture device to be reinitiali...
virtual void unRegisterEventHandler(ICaptureEventHandler *handler)
Removes the specified event handler from this manager.
virtual bool setFormat(AudioFormats format)
Sets the format that the captured audio will be at. Will cause the capture device to be reinitialized...
virtual AudioCaptureBuffer * getCapturedAudioBuffer()
this method is the same as getCapturedAudio but it returns an managed CaptureBuffer
virtual AudioFormats getFormat()
Returns the format of the captured audio.
Definition: cAudioCapture.h:44
virtual unsigned int getInternalBufferSize()
Returns the internal OpenAL buffer size in bytes.
Definition: cAudioCapture.h:45
virtual bool setInternalBufferSize(unsigned int internalBufferSize)
Sets the internal buffer size that OpenAL will use to store captured audio between calls to getCaptur...
virtual bool isUpdateThreadRunning()
Returns if the thread used to update all Audio Capture Objects is running.
Definition: cAudioCapture.h:37
virtual unsigned int getCapturedAudio(void *outputBuffer, unsigned int outputBufferSize)
Allows access to the audio data in the internal capture buffer.
virtual void updateCaptureBuffer(bool force=false)
Grabs samples from the OpenAL buffer into the capture buffer if the OpenAL buffer has reached half fu...
virtual unsigned int getCurrentCapturedAudioSize()
Returns the current size of the internal audio buffer in bytes.
virtual bool isReady()
Returns true if the capture device is ready to be used. False may indicate an error with the current ...
Definition: cAudioCapture.h:34
virtual void unRegisterAllEventHandlers()
Removes all event handlers attached to this manager.
virtual void registerEventHandler(ICaptureEventHandler *handler)
Registers a new event handler to this manager.
IThread * AudioThread
Our update thread.
Definition: cAudioCapture.h:71
Overrides the memory allocations for classes derived from it and makes them use the cAudio memory sys...
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:16
AudioFormats
Enumeration of audio formats supported by the engine.
Definition: EAudioFormats.h:11