Om
1.0.0
A universal framework for multimedia simulation
|
A class that represents a system sound device. More...
#include <omSoundDevice.h>
Public Member Functions | |
SoundDevice (const SoundDeviceID &newDeviceID) | |
Create a SoundDevice for the specified SoundDeviceID. More... | |
SoundDevice (const SoundDevice &other) | |
Create a copy of the specified SoundDevice object. More... | |
~SoundDevice () | |
Destroy a SoundDevice object, stopping the input/output of any audio. More... | |
SoundDevice & | operator= (const SoundDevice &other) |
Assign the state from one SoundDevice to this object. More... | |
Bool | start () |
Start sending audio to the device. More... | |
Bool | 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 | getSampleRate () const |
Get the current sample rate at which audio is being sent to the device. More... | |
Bool | setSampleRate (SampleRate newSampleRate) |
Set the current sample rate at which audio should be sent to the device. More... | |
Bool | isNativeSampleRate (SampleRate sampleRate) |
Return whether or not the specified sample rate is a native sample rate for this device. More... | |
const ArrayList< SampleRate > & | getNativeSampleRates () const |
Return a list of the native sampling rates for this output audio 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... | |
const UTF8String & | getName () const |
Get a string representing the name of this device. More... | |
const UTF8String & | getManufacturer () const |
Get a string representing the name of this device's manufacturer. More... | |
SoundDeviceID | getID () const |
Return an object that uniquely identifies this sound device. 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... | |
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... | |
A class that represents a system sound device.
A SoundDevice provides an easy-to-use platform-independent interface for sending audio to an audio device. It allows the user to access commonly needed parameters such as the device's sample rate and name.
The class also provides automatic sample rate conversion if the input audio sample rate is not the same as the device's current sample rate. If one does not wish to incurr a performance penalty from the sample rate conversion, the class also allows the user to attempt to set the device's sample rate.
om::sound::devices::SoundDevice::SoundDevice | ( | const SoundDeviceID & | newDeviceID | ) |
Create a SoundDevice for the specified SoundDeviceID.
om::sound::devices::SoundDevice::SoundDevice | ( | const SoundDevice & | other | ) |
Create a copy of the specified SoundDevice object.
om::sound::devices::SoundDevice::~SoundDevice | ( | ) |
Destroy a SoundDevice object, stopping the input/output of any audio.
SoundDevice& om::sound::devices::SoundDevice::operator= | ( | const SoundDevice & | other | ) |
Assign the state from one SoundDevice to this object.
Bool om::sound::devices::SoundDevice::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 or if an error occurs, FALSE is returned indicating that the method had no effect. If TRUE is returned, the device was started successfully.
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.
Bool om::sound::devices::SoundDevice::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.
|
inline |
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.
|
inline |
Get the number of input channels that this device has.
If the device is invalid, this method always returns 0.
UTF8String om::sound::devices::SoundDevice::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.
|
inline |
Get the number of output channels that this device has.
If the device is invalid, this method always returns 0.
UTF8String om::sound::devices::SoundDevice::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::SoundDevice::getSampleRate | ( | ) | const |
Get the current sample rate at which audio is being sent to the device.
This is the sample rate of the device's clock. Any input audio that doesn't match this sample rate is automatically converted to this sample rate. If the device is invalid, a sample rate of 0 is returned.
Bool om::sound::devices::SoundDevice::setSampleRate | ( | SampleRate | newSampleRate | ) |
Set the current sample rate at which audio should be sent to the device.
This method sets the sample rate of the device's clock. If the specified new sample rate is not a natively supported sample rate or if there was an error in setting the new sample rate, FALSE is returned and this method has no effect on the device's state. Otherwise, if the sample rate is a native format, TRUE is returned and the device's output sample rate is changed. If the device is invalid, FALSE is returned and the method has no effect.
newSampleRate | - the sample rate to which the device's clock will be set to. |
|
inline |
Return whether or not the specified sample rate is a native sample rate for this device.
For a sample rate to be native, no sample rate conversion is necessary before sending the audio to the device if it is of that sampling rate.
sampleRate | - the sample rate to test to see if it is a native format. |
|
inline |
Return a list of the native sampling rates for this output audio device.
For a sample rate to be native, no sample rate conversion is necessary before sending the audio to the device if it is of that sampling rate.
Time om::sound::devices::SoundDevice::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::SoundDevice::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.
|
inline |
Get a string representing the name of this device.
This name is usually specified by the hardware driver as a human-readable identifier for the device. If the device is not valid, the empty string is returned.
|
inline |
Get a string representing the name of this device's manufacturer.
This name is usually specified by the hardware driver as a human-readable identifier for the device's manufacturer. If the device is not valid, the empty string is returned.
|
inline |
Return an object that uniquely identifies this sound device.
|
inline |
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.
|
inline |
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.
|
inline |
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.
Bool om::sound::devices::SoundDevice::isDefaultInput | ( | ) | const |
Return whether or not this device represents the current default system input device.
Bool om::sound::devices::SoundDevice::isDefaultOutput | ( | ) | const |
Return whether or not this device represents the current default system output device.
|
inline |
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.
|
inline |
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.
|
inline |
Return a reference to the delegate object that is responding to events for this device manager.
void om::sound::devices::SoundDevice::setDelegate | ( | const SoundDeviceDelegate & | newDelegate | ) |
Replace the delegate object that is responding to events for this device manager.