A class to handle audio I/O.
More...
#include <sp/spAudio.h>
|
(Note that these are not member symbols.)
|
#define | spFreeAudio(audio) spFreeAudioDriver(audio) |
|
|
spAudio | spInitAudioDriver (const char *driver_name) |
|
spAudio | spInitAudio (void) |
|
void | _spFreeAudioDriver (spAudio audio) |
|
|
spBool | spGetNumAudioDevice (spAudio audio, int *num_device) |
|
char * | xspGetAudioDeviceName (spAudio audio, int device_index) |
|
spBool | spSelectAudioDevice (spAudio audio, int device_index) |
|
|
spBool | spSetAudioSampleRate (spAudio audio, double samp_rate) |
|
spBool | spGetAudioSampleRate (spAudio audio, double *samp_rate) |
|
spBool | spSetAudioChannel (spAudio audio, int num_channel) |
|
spBool | spGetAudioChannel (spAudio audio, int *num_channel) |
|
spBool | spSetAudioBufferSize (spAudio audio, int buffer_size) |
|
spBool | spGetAudioBufferSize (spAudio audio, int *buffer_size) |
|
spBool | spSetAudioNumBuffer (spAudio audio, int num_buffer) |
|
spBool | spGetAudioNumBuffer (spAudio audio, int *num_buffer) |
|
spBool | spSetAudioBlockingMode (spAudio audio, int block_mode) |
|
spBool | spGetAudioBlockingMode (spAudio audio, int *block_mode) |
|
spBool | spSetAudioSampleBit (spAudio audio, int samp_bit) |
|
spBool | spGetAudioSampleBit (spAudio audio, int *samp_bit) |
|
spBool | spGetAudioSpecifiedSampleBit (spAudio audio, int *specified_samp_bit) |
|
spAudioCallbackType | spSetAudioCallbackFunc (spAudio audio, spAudioCallbackType call_type, spAudioCallbackFunc call_func, void *call_data) |
|
|
spBool | spOpenAudioDevice (spAudio audio, const char *mode) |
|
spBool | spCloseAudioDevice (spAudio audio) |
|
|
long | spReadAudio (spAudio audio, void *data, long length) |
|
long | spWriteAudio (spAudio audio, void *data, long length) |
|
long | spReadAudioDoubleWeighted (spAudio audio, double *data, long length, double weight) |
|
long | spReadAudioDouble (spAudio audio, double *data, long length) |
|
long | spWriteAudioDoubleWeighted (spAudio audio, double *data, long length, double weight) |
|
long | spWriteAudioDouble (spAudio audio, double *data, long length) |
|
|
spBool | spGetAudioOutputPosition (spAudio audio, spLong *position) |
|
spBool | spStopAudio (spAudio audio) |
|
spBool | spSyncAudio (spAudio audio) |
|
A class to handle audio I/O.
Actually, spAudio is not a class, but a typedefed type by typedef struct _spAudio *spAudio;
. You can use this class after initialization by spInitAudio() or spInitAudioDriver() , should free resources of this class after use by spFreeAudio() or spFreeAudioDriver() .
Normal audio I/O procedure is as follows.
- Get spAudio by spInitAudio() or spInitAudioDriver() .
- Select an audio device by spSelectAudioDevice() . If you don't call this function, the default device will be used.
- Set information of the current device by spSetAudioXXX
- Open the current device by spOpenAudioDevice()
- Check the device information by spGetAudioXXX if necessary since the current information is sometimes not indentical to the information you set.
- Call spReadAudio() for input or spWriteAudio() for output repeatedly.
- Flush buffers by spSyncAudio() if you want to restart I/O.
- Close the current device by spCloseAudioDevice()
- Free resources of spAudio by spFreeAudio() or spFreeAudioDriver() .
- See also
- spInitAudio() , spInitAudioDriver() , spFreeAudio() , spFreeAudioDriver()
- Examples
- driver.c, iotest.c, playsin.c, and rec.c.
◆ spInitAudioDriver()
spAudio spInitAudioDriver |
( |
const char * | driver_name | ) |
|
|
related |
Initializes the audio driver (constructor).
All audio I/O functions do not work before you call this function (or spInitAudio() ). Multiple calls before spFreeAudioDriver() with one driver are not accepted. Some environments accept multiple calls of this function with different drivers.
- Parameters
-
[in] | driver_name | The name of the driver. |
- See also
- spFreeAudioDriver()
◆ spInitAudio()
◆ _spFreeAudioDriver()
void _spFreeAudioDriver |
( |
spAudio | audio | ) |
|
|
related |
◆ spGetNumAudioDevice()
Gets the number of audio devices.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ xspGetAudioDeviceName()
char * xspGetAudioDeviceName |
( |
spAudio | audio, |
|
|
int | device_index ) |
|
related |
Gets the name of the audio device. You have to deallocate the memory by calling xspFree() .
- Parameters
-
- Returns
- A null-terminated string indicating the name of the device. You have to deallocate the memory by calling xspFree() .
◆ spSelectAudioDevice()
Selects an audio device which has the index specified.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioSampleRate()
Sets sample rate of the current device. This function should be called before opening a device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioSampleRate()
spBool spGetAudioSampleRate |
( |
spAudio | audio, |
|
|
double * | samp_rate ) |
|
related |
Gets sample rate of the current device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioChannel()
Sets the number of channels of the current device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioChannel()
Gets the number of channels of the current device. This function should be called before opening a device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioBufferSize()
Sets the buffer size of the current device. This function should be called before opening a device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioBufferSize()
Gets the buffer size of the current device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioNumBuffer()
Sets the number of buffers of the current device. This function should be called before opening a device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioNumBuffer()
Gets the number of buffers of the current device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioBlockingMode()
Sets the blocking mode of the current device. This function should be called before opening a device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioBlockingMode()
spBool spGetAudioBlockingMode |
( |
spAudio | audio, |
|
|
int * | block_mode ) |
|
related |
Gets the blocking mode of the current device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioSampleBit()
Sets bits/sample of the current device. This function should be called before opening a device. 16, 24 and 32 bits/sample are supported currently. For the device not supporting 24 and 32 bits/sample, the data is internally converted to 16 bits/sample data.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioSampleBit()
Gets bits/sample of the current device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spGetAudioSpecifiedSampleBit()
spBool spGetAudioSpecifiedSampleBit |
( |
spAudio | audio, |
|
|
int * | specified_samp_bit ) |
|
related |
Gets the bits/sample specified.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSetAudioCallbackFunc()
Sets a callback function. This function should be called before opening a device. The callback types of SP_AUDIO_OUTPUT_POSITION_CALLBACK and SP_AUDIO_OUTPUT_BUFFER_CALLBACK are only supported currently.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | call_type | The callback type. Multiple types can be specified by using '|'. |
[in] | call_func | The callback function which has the following signature ( spAudioCallbackFunc ):
A class to handle audio I/O.
unsigned long spAudioCallbackType Definition spAudio.h:63
|
[in] | call_data | The user data for the callback function. You can obtain this address as the 5th argument of the callback function. |
- Returns
- The callack type which can be set successfully. This value sometimes differs from
call_type
value on some environments.
◆ spOpenAudioDevice()
Opens the current audio device. If you want full-duplex I/O, open with read mode then do with write mode. The second open with write mode will fail if the device doesn't accept full-duplex I/O.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | mode | Device opening mode. 'r' means read mode, 'w' means write mode. 'ro' and 'wo' which mean read only and write only modes are also supported. Although these ‘only’ modes invalidate full-duplex I/O, sometimes improve sound quality especially for Linux OSS environment. |
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spCloseAudioDevice()
Closes the current audio device.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spReadAudio()
long spReadAudio |
( |
spAudio | audio, |
|
|
void * | data, |
|
|
long | length ) |
|
related |
Reads raw data from the audio device. This function blocks processing until the read length reaches length
unless the blocking mode is disabled by spSetAudioBlockingMode().
- Warning
- This function can be used when spOpenAudioDevice() is called with
"r"
mode.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | data | The address of a buffer to receive raw data from the audio device. The type of the buffer must be 'short' for up to 16 bits/sample, 'long' for up to 32 bits/sample. |
[in] | length | The length of the buffer. This length is not the size in bytes of the buffer, but the number of elements of the buffer. |
- Returns
- The read length for success, or -1 for failure.
◆ spWriteAudio()
long spWriteAudio |
( |
spAudio | audio, |
|
|
void * | data, |
|
|
long | length ) |
|
related |
Writes raw data to the audio device. Since writing data is performed asynchronously, the function call finishes before playing whole specified data. The timing of the finish depends on your environment.
- Warning
- This function can be used when spOpenAudioDevice() is called with
"w"
mode.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | data | The address of a buffer to send raw data to the audio device. The type of the buffer must be 'short' for up to 16 bits/sample, 'long' for up to 32 bits/sample. |
[in] | length | The length of the buffer. This length is not the size in bytes of the buffer, but the number of elements of the buffer. |
- Returns
- The written length for success, -1 for failure.
◆ spReadAudioDoubleWeighted()
long spReadAudioDoubleWeighted |
( |
spAudio | audio, |
|
|
double * | data, |
|
|
long | length, |
|
|
double | weight ) |
|
related |
Reads data to a double array from the audio device. The weight
is multiplied to the data after reading.
- Warning
- This function can be used when spOpenAudioDevice() is called with
"r"
mode.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | data | The address of a double array to receive data from the audio device. |
[in] | length | The length of the buffer. This length is not the size in bytes of the buffer, but the number of elements of the buffer. |
[in] | weight | a weighting factor multiplied to each element in data after reading. |
- Returns
- The read length for success, -1 for failure.
◆ spReadAudioDouble()
long spReadAudioDouble |
( |
spAudio | audio, |
|
|
double * | data, |
|
|
long | length ) |
|
related |
Reads data to a double array from the audio device.
- Warning
- This function can be used when spOpenAudioDevice() is called with
"r"
mode.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | data | The address of a double array to receive data from the audio device. |
[in] | length | The length of the buffer. This length is not the size in bytes of the buffer, but the number of elements of the buffer. |
- Returns
- The read length for success, -1 for failure.
◆ spWriteAudioDoubleWeighted()
long spWriteAudioDoubleWeighted |
( |
spAudio | audio, |
|
|
double * | data, |
|
|
long | length, |
|
|
double | weight ) |
|
related |
Writes a double array to the audio device. The weight
is multiplied to the data before writing.
- Warning
- This function can be used when spOpenAudioDevice() is called with
"w"
mode.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | data | The address of a double array to send data to the audio device. The data range must be basically from -1 to 1 inclusive. |
[in] | length | The length of the buffer. This length is not the size in bytes of the buffer, but the number of elements of the buffer. |
[in] | weight | a weighting factor multiplied to each element in data before writing. |
- Returns
- The written length for success, -1 for failure.
◆ spWriteAudioDouble()
long spWriteAudioDouble |
( |
spAudio | audio, |
|
|
double * | data, |
|
|
long | length ) |
|
related |
Writes a double array to the audio device.
- Warning
- This function can be used when spOpenAudioDevice() is called with
"w"
mode.
- Parameters
-
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | data | The address of a double array to send data to the audio device. The data range must be basically from -1 to 1 inclusive. |
[in] | length | The length of the buffer. This length is not the size in bytes of the buffer, but the number of elements of the buffer. |
- Returns
- The written length for success, -1 for failure.
◆ spGetAudioOutputPosition()
spBool spGetAudioOutputPosition |
( |
spAudio | audio, |
|
|
spLong * | position ) |
|
related |
Gets the playback position.
- Note
- Since this function is not supported on some environments, the function call on those environments always fails.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spStopAudio()
Stops audio I/O as soon as possible. Note that the behavior of this function has dependence on an environment. The function call on some environments will decrease a processing load starting to increase from beginning of audio I/O.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spSyncAudio()
Synchronizes audio I/O. Note that the behavior of this function has dependence on an environment.
- Parameters
-
- Return values
-
SP_TRUE | Success |
SP_FALSE | Failure |
◆ spFreeAudio
Frees the default audio driver's resources (destructor).
- Parameters
-