1 #ifndef INCLUDE_AL_AUDIO_IO_HPP
2 #define INCLUDE_AL_AUDIO_IO_HPP
52 #include "al/io/al_AudioIOData.hpp"
71 bool isRunning()
const;
74 void printError(
const char *text =
"")
const;
75 void printInfo()
const;
77 bool supportsFPS(
double fps);
79 void inDevice(
int index);
80 void outDevice(
int index);
82 void channels(
int num,
bool forOutput);
83 void setStreamName(std::string name);
87 void setInDeviceChans(
int num);
88 void setOutDeviceChans(
int num);
92 bool open(
int framesPerSecond,
unsigned int framesPerBuffer,
void *userdata);
95 bool start(
int framesPerSecond,
int framesPerBuffer,
void *userdata);
102 static bool deviceIsValid(
int num);
103 static int deviceMaxInputChannels(
int num);
104 static int deviceMaxOutputChannels(
int num);
105 static double devicePreferredSamplingRate(
int num);
106 static std::string deviceName(
int num);
107 static int numDevices();
110 bool mRunning{
false};
112 std::shared_ptr<void> mBackendData;
135 virtual bool valid()
const {
return mValid; }
153 void setImpl(
int deviceNum);
154 static void initDevices();
178 int framesPerBuf = 64,
double framesPerSec = 44100.0,
179 int outChans = 2,
int inChans = 0);
182 int framesPerBuf = 64,
double framesPerSec = 44100.0,
183 int outChans = 2,
int inChans = 0);
206 bool autoZeroOut()
const {
return mAutoZeroOut; }
237 unsigned int n)
override;
270 std::vector<AudioCallback *> mAudioCallbacks;
273 void resizeBuffer(
bool forOutput);
274 void operator=(
const AudioIO &) =
delete;
276 std::unique_ptr<AudioBackend> mBackend;
static int numDevices()
Returns number of audio i/o devices available.
static AudioDevice defaultOutput()
Get system's default output device.
AudioDevice(int deviceNum=-1)
virtual bool hasOutput() const
Returns whether device has output.
virtual bool valid() const
Returns whether device is valid.
AudioDevice(const std::string &nameKeyword, StreamMode stream=StreamMode(INPUT|OUTPUT))
static void printAll()
Prints info about all available i/o devices to stdout.
virtual bool hasInput() const
Returns whether device has input.
static AudioDevice defaultInput()
Get system's default input device.
virtual void print() const
Prints info about specific i/o device to stdout.
virtual int channelsOutMax() const
Get maximum number of output channels supported.
virtual int channelsInMax() const
Get maximum number of input channels supported.
uint64_t framesPerBuffer() const
Get frames/buffer of audio I/O stream.
double framesPerSecond() const
Get frames/second of audio I/O streams.
unsigned int channelsIn() const
Get effective number of input channels.
unsigned int channelsOut() const
Get effective number of output channels.
unsigned int frame() const
Get current frame number.
unsigned int channelsBus() const
Get number of allocated bus channels.
bool clipOut() const
Returns clipOut setting.
int channelsOutDevice() const
Get number of channels opened on output device.
int channelsInDevice() const
Get number of channels opened on input device.
bool open()
Opens audio device.
uint64_t framesPerBuffer() const
Get frames/buffer of audio I/O stream.
AudioIO & remove(AudioCallback &v)
Remove all input event handlers matching argument.
void init(void(*callback)(AudioIOData &), void *userData, int framesPerBuf=64, double framesPerSec=44100.0, int outChans=2, int inChans=0)
void channels(int num, bool forOutput) override
void clipOut(bool v)
Set whether to clip output between -1 and 1.
bool stop()
Stops the audio IO.
bool supportsFPS(double fps)
Return true if fps supported, otherwise false.
bool zeroNANs() const
Returns whether to zero NANs in output buffer going to DAC.
double time() const
Get current stream time in seconds.
bool isOpen()
Returns true if device has been opened.
void print() const
Prints info about current i/o devices to stdout.
bool start()
Starts the audio IO. Will open audio device if necessary.
virtual void framesPerBuffer(unsigned int n) override
Set number of frames per processing buffer.
double time(int frame) const
Get current stream time in seconds of frame.
double cpu() const
Returns current CPU usage of audio thread.
void setStreamName(std::string name)
Set name of this stream. Currently only has an effect when using jack.
audioCallback callback
User specified callback function.
void deviceOut(const AudioDevice &v)
Set output device.
void processAudio()
Call callback manually.
bool isRunning()
Returns true if audio is running.
virtual void framesPerSecond(double v) override
Set number of frames per second.
bool close()
Closes audio device. Will stop active IO.
AudioIO & append(AudioCallback &v)
Add an AudioCallback handler (internal callback is always called first)
void device(const AudioDevice &v)
Set input/output device (must be duplex)
static const char * errorText(int errNum)
Returns error string.
void deviceIn(const AudioDevice &v)
Set input device.
void initWithDefaults(void(*callback)(AudioIOData &), void *userData, bool use_out, bool use_in, int framesPerBuffer=256)
AudioIO()
Creates AudioIO using default I/O devices.
void zeroNANs(bool v)
Set whether to zero NANs in output buffer going to DAC.
void channelsBus(int num) override
Set number of bus channels.
void(* audioCallback)(AudioIOData &io)
Audio callback type.