#include <soundio.h>
Public Member Functions | |
virtual bool | SndOpen (bool sink, bool source, ErrorInfo *error=0)=0 |
Request that the underlying device be opened. | |
virtual void | SndClose (void)=0 |
Request that an opened underlying device be closed. | |
virtual void | SndGetProps (SoundIoProps &props) const =0 |
Get Basic Capabilities. | |
virtual void | SndGetFormat (SoundIoFormat &format) const =0 |
Get Current PCM Data Stream Format. | |
virtual bool | SndSetFormat (SoundIoFormat &format, ErrorInfo *error=0)=0 |
Set Current PCM Data Stream Format. | |
virtual void | SndGetIBuf (SoundIoBuffer &fillme)=0 |
Request Input Buffer Access. | |
virtual void | SndDequeueIBuf (sio_sampnum_t nsamples)=0 |
Request Dequeueing of Input Samples. | |
virtual void | SndGetOBuf (SoundIoBuffer &fillme)=0 |
Request Output Buffer Access. | |
virtual void | SndQueueOBuf (sio_sampnum_t nsamples)=0 |
Request Queueing of Output Samples. | |
virtual void | SndGetQueueState (SoundIoQueueState &qs)=0 |
Query the queue state of the device. | |
virtual bool | SndAsyncStart (bool sink, bool source, ErrorInfo *error=0)=0 |
Request start of asynchronous audio handling. | |
virtual void | SndAsyncStop (void)=0 |
Request halting of asynchronous audio handling. | |
virtual bool | SndIsAsyncStarted (void) const =0 |
Query whether asynchronous audio handling has been started. | |
Public Attributes | |
Callback< void, SoundIo *, SoundIoQueueState & > | cb_NotifyPacket |
Notification of Audio Packet Data Availability. | |
Callback< void, SoundIo *, ErrorInfo & > | cb_NotifyAsyncStop |
Notification of Asynchronous Audio Processing Termination. |
SoundIo abstracts a full-duplex PCM audio hardware device, including input and output queues, and asynchronous notification.
There are SoundIo derived classes for handling ALSA and OSS type sound card interfaces on Linux. See SoundIoCreateOss() and SoundIoCreateAlsa(). SoundIo is implemented by HfpSession for streaming voice audio over Bluetooth.
virtual bool SndOpen | ( | bool | sink, | |
bool | source, | |||
ErrorInfo * | error = 0 | |||
) | [pure virtual] |
Request that the underlying device be opened.
Attempts to open the underlying resource, if applicable. For sound card driver frontends, such as the ALSA and OSS modules, this method causes the sound card device to be opened and claimed.
The details of the device to be opened are assumed to have been set when the SoundIo derived object was constructed. These details might include the name and basic configuration of the device, e.g. SoundIoCreateAlsa(). Such details are not provided to this method.
[in] | sink | Set to true to open the output side of the device |
[in] | source | Set to true to open the input side of the device |
[out] | error | Error information structure. If this method fails and returns false, and error is not 0, error will be filled out with information on the cause of the failure. |
true | Open Succeeded, SoundIo is now usable | |
false | Open Failed. If the error parameter is not 0, it will be filled out with specific information about the failure. Typical reasons for failure include:
|
virtual void SndClose | ( | void | ) | [pure virtual] |
Request that an opened underlying device be closed.
Closes an underlying device that was previously opened with SndOpen(). Resources should be released. For sound card driver frontends, such as the ALSA and OSS modules, this method causes the underlying devices to be closed and released.
virtual void SndGetProps | ( | SoundIoProps & | props | ) | const [pure virtual] |
Get Basic Capabilities.
This method fills in a structure describing the basic capabilities of the interface. Some modules, such as the ALSA and OSS frontends, support full-duplex, asynchronous operation. Others, such as the file module, support only input-only or output-only synchronous operation.
[out] | props | Properties structure to be filled out |
props.has_clock
will be set to true
if the object supports asynchronous notification through SoundIo::cb_NotifyPacket, false
otherwise.
props.does_source
will be set to true
if the object supports input, false
otherwise.
props.does_sink
will be set to true
if the object supports output, false
otherwise.
props.does_loop
will be set to true
if the object's input buffer grows immediately as data is submitted to its output buffer, false
otherwise.
virtual void SndGetFormat | ( | SoundIoFormat & | format | ) | const [pure virtual] |
Get Current PCM Data Stream Format.
This method fills out a SoundIoFormat structure based on the object's currently configured PCM data stream format. This method may be invoked on objects in the open or closed states, but in general, the result should only be considered meaningful for objects in the open state.
[out] | format | Structure to be filled with the object's currently configured data stream format. |
virtual bool SndSetFormat | ( | SoundIoFormat & | format, | |
ErrorInfo * | error = 0 | |||
) | [pure virtual] |
Set Current PCM Data Stream Format.
This method attempts to reconfigure the PCM data stream format of the object. This method may be invoked on objects in the open or closed states.
[in,out] | format | Structure containing the new format parameters to be applied to the object, which is filled with the resulting effective parameters on return. |
[out] | error | Error information structure. If this method fails and returns false, and error is not 0, error will be filled out with information on the cause of the failure. |
true | Parameters accepted and applied. Note that in some cases, for objects in the closed state, this is a tentative approval of the stream format. | |
false | One or more mandatory parameter values are not supported by the object. |
The other fields of the SoundIoFormat object, including SoundIoFormat::packet_samps, are guidelines. The object may use any convenient value for these fields. On success, the contents of the format
parameter will be updated to reflect the effective values.
virtual void SndGetIBuf | ( | SoundIoBuffer & | fillme | ) | [pure virtual] |
Request Input Buffer Access.
Clients of SoundIo objects access their input and output sample buffers directly. This method requests access to the object's input (capture) buffer.
[in,out] | fillme | The buffer descriptor containing the requested size, to be filled with the memory location and actual size. |
fillme.m_size
field. If this value is zero, the largest possible buffer will be requested.fillme.m_data
field. The valid size of the buffer, in sample records, is returned through the fillme.m_size
field. If fillme.m_size
is set to zero on return, no input samples are available, and fillme.m_data
should be considered invalid. If a specific buffer size was requested, the resulting buffer size should never be larger, but may be smaller.Buffers returned through this method will remain valid until:
This method will only return useful results when invoked on objects in the open state.
Implemented in SoundIoBufferBaseSync.
virtual void SndDequeueIBuf | ( | sio_sampnum_t | nsamples | ) | [pure virtual] |
Request Dequeueing of Input Samples.
When a SoundIo client has finished processing input samples accessed through SndGetIBuf(), or merely wishes to discard them, it may do so using this method. Input samples need not have been accessed using SndGetIBuf() in order to be dequeued through this method.
nsamples | Number of sample records to remove from the start of the input queue |
Implemented in SoundIoBufferBaseSync.
virtual void SndGetOBuf | ( | SoundIoBuffer & | fillme | ) | [pure virtual] |
Request Output Buffer Access.
Clients of SoundIo objects access their input and output sample buffers directly. This method requests access to the object's input (capture) buffer.
[in,out] | fillme | The buffer descriptor containing the requested size, to be filled with the memory location and actual size. |
fillme.m_size
field. If this value is zero, the largest possible buffer will be requested.fillme.m_data
field. The valid size of the buffer, in sample records, is returned through the fillme.m_size
field. If fillme.m_size
is set to zero on return, no input samples are available, and fillme.m_data
should be considered invalid. If a specific buffer size was requested, the resulting buffer size should never be larger, but may be smaller.Buffers returned through this method will remain valid until:
This method will only return useful results when invoked on objects in the open state.
Implemented in SoundIoBufferBaseSync.
virtual void SndQueueOBuf | ( | sio_sampnum_t | nsamples | ) | [pure virtual] |
Request Queueing of Output Samples.
When a SoundIo client has finished filling part or all of an output buffer accessed via SndGetOBuf(), it may request the sample records be propagated to their destination with this method.
nsamples | Number of sample records copied into the output buffer to be propagated |
Attempting to queue more samples than were previously returned by SndGetOBuf() is not permitted and should cause an assertion failure.
Implemented in SoundIoBufferBaseSync.
virtual void SndGetQueueState | ( | SoundIoQueueState & | qs | ) | [pure virtual] |
Query the queue state of the device.
This method fills out a SoundIoQueueState structure with the fill levels of the sample buffers of the SoundIo object. This information is required by the SoundIoPump class, which uses it to make transfer size decisions.
For sound cards and other clocked sources, this information is assumed to represent the state of the local device buffers, which must fill and drain as the device processes samples.
For unclocked sinks, this information is assumed to represent a minimum number of samples available. SoundIoPump will not transfer more than qs.out_queued
samples.
[out] | qs | Queue state structure to be filled in |
Implemented in SoundIoBufferBaseSync.
virtual bool SndAsyncStart | ( | bool | sink, | |
bool | source, | |||
ErrorInfo * | error = 0 | |||
) | [pure virtual] |
Request start of asynchronous audio handling.
For SoundIo objects that support asynchronous operation, this method can be used to initiate it.
[in] | sink | Set to true to start asynchronous output |
[in] | source | Set to true to start asynchronous input |
[out] | error | Error information structure. If this method fails and returns false, and error is not 0, error will be filled out with information on the cause of the failure. |
true | Asynchronous audio handling mode has been started | |
false | Error enabling asynchronous data mode |
Once asynchronous audio handling is successfully started, it may be spontaneously aborted due to an unexpected condition, such as a sound card catching on fire. In this case, the SoundIo object will automatically halt asynchronous audio handling, and will inform its client of this by making a call to SoundIo::cb_NotifyAsyncStop with the second parameter set to describe the reason for stopping.
virtual void SndAsyncStop | ( | void | ) | [pure virtual] |
Request halting of asynchronous audio handling.
For SoundIo objects that are currently operating in asynchronous mode, this method can be used to halt processing and cease future calls to SoundIo::cb_NotifyPacket.
virtual bool SndIsAsyncStarted | ( | void | ) | const [pure virtual] |
Query whether asynchronous audio handling has been started.
true | Asynchronous audio handling is started | |
false | Asynchronous audio handling is not started |
Callback<void, SoundIo*, SoundIoQueueState&> cb_NotifyPacket |
Notification of Audio Packet Data Availability.
The cb_NotifyPacket callback is invoked slightly after each packet period boundary, as measured from the hardware clock of the audio device.
SoundIo* | Pointer to the SoundIo-derived object that initiated the call. This object may have new input sample records, or may have completed handling of part or all of its output queue. | |
SoundIoQueueState& | A SoundIoQueueState structure describing the state of the sample buffers of the device:
|
Callback<void, SoundIo*, ErrorInfo&> cb_NotifyAsyncStop |
Notification of Asynchronous Audio Processing Termination.
The cb_NotifyAsyncStop callback is invoked when a condition internal to the SoundIo object occurs that forces asynchronous audio processing to be halted. This may include the unplugging of a USB sound card, or the remote disconnection of a Bluetooth SCO socket.
This method will only be invoked when asynchronous audio handling has been started with SndAsyncStart(), and has been halted for a reason other than SndAsyncStop() or SndClose() being invoked. Once this callback has been invoked, no further calls to SoundIo::cb_NotifyPacket should be expected until asynchronous processing is resumed with SndAsyncStart().
SoundIo* | Pointer to the SoundIo-derived object that initiated the call. | |
ErrorInfo& | Error code describing why processing has been halted. |