Om
1.0.0
A universal framework for multimedia simulation
|
A class that maintains a default input and output device abstraction layer. More...
#include <omDefaultSoundDevice.h>
Public Member Functions | |
DefaultSoundDevice () | |
Create a new default sound device with the current default input and output devices. More... | |
DefaultSoundDevice (const DefaultSoundDevice &other) | |
Create a copy of the specified default sound device. More... | |
~DefaultSoundDevice () | |
Destroy a DefaultSoundDevice object, stopping the input/output of any audio. More... | |
DefaultSoundDevice & | operator= (const DefaultSoundDevice &other) |
Assign the state from one DefaultSoundDevice to this object. More... | |
void | start () |
Start sending audio to the device. More... | |
void | stop () |
Stop sending/receiving audio data to the device. More... | |
Bool | isRunning () const |
Return whether or not the device is currently sending/receiving audio. More... | |
Size | getInputChannelCount () const |
Get the number of input channels that this device has. More... | |
UTF8String | getInputChannelName (Index inputChannelIndex) const |
Return a human-readable name for the input channel at the specified index. More... | |
Size | getOutputChannelCount () const |
Get the number of output channels that this device has. More... | |
UTF8String | getOutputChannelName (Index outputChannelIndex) const |
Return a human-readable name for the output channel at the specified index. More... | |
SampleRate | getInputSampleRate () const |
Get the current sampling rate for the default input device. More... | |
SampleRate | getOutputSampleRate () const |
Get the current sampling rate for the default output device. More... | |
Time | getInputLatency () const |
Return the one-way input latency in seconds of this sound device. More... | |
Time | getOutputLatency () const |
Return the one-way output latency in seconds of this sound device. More... | |
UTF8String | getInputName () const |
Get a string representing the name of the default input device. More... | |
UTF8String | getInputManufacturer () const |
Get a string representing the name of the default input device's manufacturer. More... | |
UTF8String | getOutputName () const |
Get a string representing the name of the default input device. More... | |
UTF8String | getOutputManufacturer () const |
Get a string representing the name of the default input device's manufacturer. More... | |
const SoundDeviceDelegate & | getDelegate () const |
Return a reference to the delegate object that is responding to events for this device manager. More... | |
void | setDelegate (const SoundDeviceDelegate &newDelegate) |
Replace the delegate object that is responding to events for this device manager. More... | |
Bool | isValid () const |
Return whether or not this device represents a valid device. More... | |
Bool | isInput () const |
Return whether or not this device is an input device. More... | |
Bool | isOutput () const |
Return whether or not this device is an output device. More... | |
Bool | isDefaultInput () const |
Return whether or not this device represents the current default system input device. More... | |
Bool | isDefaultOutput () const |
Return whether or not this device represents the current default system output device. More... | |
Float | getCurrentCPUUsage () const |
Return a value indicating the fraction of available CPU time being used to process audio for the last frame. More... | |
Float | getAverageCPUUsage () const |
Return a value indicating the average fraction of available CPU time being used to process audio. More... | |
A class that maintains a default input and output device abstraction layer.
This class automatically keeps track of the current default system input and output devices and acts as a wrapper for those devices with the same interface as the SoundDevice class. This allows the user to not have to manage this information themselves and simplifies basic audio application development.
om::sound::devices::DefaultSoundDevice::DefaultSoundDevice | ( | ) |
Create a new default sound device with the current default input and output devices.
om::sound::devices::DefaultSoundDevice::DefaultSoundDevice | ( | const DefaultSoundDevice & | other | ) |
Create a copy of the specified default sound device.
om::sound::devices::DefaultSoundDevice::~DefaultSoundDevice | ( | ) |
Destroy a DefaultSoundDevice object, stopping the input/output of any audio.
DefaultSoundDevice& om::sound::devices::DefaultSoundDevice::operator= | ( | const DefaultSoundDevice & | other | ) |
Assign the state from one DefaultSoundDevice to this object.
void om::sound::devices::DefaultSoundDevice::start | ( | ) |
Start sending audio to the device.
If this device has no output callback, zeroes are sent to the device until a callback function is bound to the device. If the device is invalid, this method has no effect.
This method has the effect of starting a new audio rendering thread which will then handle requesting audio data from the output callback function until the callback function is changed or removed or the device's output is stopped using the stop() method.
void om::sound::devices::DefaultSoundDevice::stop | ( | ) |
Stop sending/receiving audio data to the device.
If the device is currently outputing audio, the output of further audio is stopped. Otherwise, the method has no effect. If the device is invalid, this method has no effect.
This method has the effect of stopping the audio rendering thread that was started in the start() method.
Bool om::sound::devices::DefaultSoundDevice::isRunning | ( | ) | const |
Return whether or not the device is currently sending/receiving audio.
If audio is currently being requested and sent to the device, TRUE is returned. Otherwise, FALSE is returned. If the device is invalid, FALSE is always returned.
Size om::sound::devices::DefaultSoundDevice::getInputChannelCount | ( | ) | const |
Get the number of input channels that this device has.
If the device is invalid, this method always returns 0.
UTF8String om::sound::devices::DefaultSoundDevice::getInputChannelName | ( | Index | inputChannelIndex | ) | const |
Return a human-readable name for the input channel at the specified index.
This is a string provided by the device driver which names the input channel with the given index. If an invalid channel index is specified, an empty string is returned.
Size om::sound::devices::DefaultSoundDevice::getOutputChannelCount | ( | ) | const |
Get the number of output channels that this device has.
If the device is invalid, this method always returns 0.
UTF8String om::sound::devices::DefaultSoundDevice::getOutputChannelName | ( | Index | outputChannelIndex | ) | const |
Return a human-readable name for the output channel at the specified index.
This is a string provided by the device driver which names the output channel with the given index. If an invalid channel index is specified, an empty string is returned.
SampleRate om::sound::devices::DefaultSoundDevice::getInputSampleRate | ( | ) | const |
Get the current sampling rate for the default input device.
This is the sample rate of the device's clock.
SampleRate om::sound::devices::DefaultSoundDevice::getOutputSampleRate | ( | ) | const |
Get the current sampling rate for the default output device.
This is the sample rate of the device's clock.
Time om::sound::devices::DefaultSoundDevice::getInputLatency | ( | ) | const |
Return the one-way input latency in seconds of this sound device.
This is the total time that it takes for the sound device to preset input, given an analogue input signal.
Time om::sound::devices::DefaultSoundDevice::getOutputLatency | ( | ) | const |
Return the one-way output latency in seconds of this sound device.
This is the total time that it takes for the sound device to produce output, given input audio data.
UTF8String om::sound::devices::DefaultSoundDevice::getInputName | ( | ) | const |
Get a string representing the name of the default input device.
UTF8String om::sound::devices::DefaultSoundDevice::getInputManufacturer | ( | ) | const |
Get a string representing the name of the default input device's manufacturer.
UTF8String om::sound::devices::DefaultSoundDevice::getOutputName | ( | ) | const |
Get a string representing the name of the default input device.
UTF8String om::sound::devices::DefaultSoundDevice::getOutputManufacturer | ( | ) | const |
Get a string representing the name of the default input device's manufacturer.
|
inline |
Return a reference to the delegate object that is responding to events for this device manager.
void om::sound::devices::DefaultSoundDevice::setDelegate | ( | const SoundDeviceDelegate & | newDelegate | ) |
Replace the delegate object that is responding to events for this device manager.
Bool om::sound::devices::DefaultSoundDevice::isValid | ( | ) | const |
Return whether or not this device represents a valid device.
If a SoundDevice is created with a SoundDeviceID that does not represent a valid system audio device or if a device is removed after it is created, the SoundDevice is marked as invalid and this method will return FALSE. Otherwise, if the device is valid, the method returns TRUE.
If a device is invalid, the output callback method will not be called anymore and the application should switch to a different device. The application should periodically check the return value of this function to see if the device has been removed.
Bool om::sound::devices::DefaultSoundDevice::isInput | ( | ) | const |
Return whether or not this device is an input device.
If this is true, the device will have at least one output channel. Otherwise, the device should have 0 output channels.
Bool om::sound::devices::DefaultSoundDevice::isOutput | ( | ) | const |
Return whether or not this device is an output device.
If this is true, the device will have at least one output channel. Otherwise, the device should have 0 output channels.
|
inline |
Return whether or not this device represents the current default system input device.
This method will return TRUE unless there is no default input device or if the default input device has no channels.
|
inline |
Return whether or not this device represents the current default system output device.
This method will return TRUE unless there is no default output device or if the default output device has no channels.
Float om::sound::devices::DefaultSoundDevice::getCurrentCPUUsage | ( | ) | const |
Return a value indicating the fraction of available CPU time being used to process audio for the last frame.
This value lies in the range [0,1] where 0 indicates that no time is used, and 1 indicates that 100% of the available time is used. Going over 100% of the available time means that the audio processing thread has stalled, producing clicks or pops in the audio due to dropped frames.
This is the CPU usage amount for the last processed frame of audio. Use this value to obtain an instantaneous usage metric.
Float om::sound::devices::DefaultSoundDevice::getAverageCPUUsage | ( | ) | const |
Return a value indicating the average fraction of available CPU time being used to process audio.
This value lies in the range [0,1] where 0 indicates that no time is used, and 1 indicates that 100% of the available time is used. Going over 100% of the available time means that the audio processing thread has stalled, producing clicks or pops in the audio due to dropped frames.
This average value is computed using an envelope filter with a fast attack time and a release time of half a second. This value is computed to give a long-time indication of the CPU usage over many processing frames.