spAudio
|
Go to the source code of this file.
Macros | |
#define | SP_AUDIO_BLOCKING 0 |
#define | SP_AUDIO_NONBLOCKING 1 |
#define | SP_AUDIO_NO_CALLBACK 0 |
#define | SP_AUDIO_OUTPUT_POSITION_CALLBACK (1<<0) |
#define | SP_AUDIO_OUTPUT_BUFFER_CALLBACK (1<<2) |
#define | spFreeAudioDriver(audio) {_spFreeAudioDriver(audio); (audio) = NULL;} |
Typedefs | |
typedef struct _spAudio * | spAudio |
typedef unsigned long | spAudioCallbackType |
typedef spBool(* | spAudioCallbackFunc) (spAudio audio, spAudioCallbackType call_type, void *data1, void *data2, void *user_data) |
Functions | |
int | spGetNumAudioDriver (void) |
char * | xspGetAudioDriverName (int index) |
int | spGetNumAudioDriverDevice (const char *driver_name) |
char * | xspGetAudioDriverDeviceName (const char *driver_name, int index) |
Initialization | |
spAudio | spInitAudioDriver (const char *driver_name) |
spAudio | spInitAudio (void) |
void | _spFreeAudioDriver (spAudio audio) |
Device Selection | |
spBool | spGetNumAudioDevice (spAudio audio, int *num_device) |
char * | xspGetAudioDeviceName (spAudio audio, int device_index) |
spBool | spSelectAudioDevice (spAudio audio, int device_index) |
Setter and Getter | |
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) |
Open and Close | |
spBool | spOpenAudioDevice (spAudio audio, const char *mode) |
spBool | spCloseAudioDevice (spAudio audio) |
Read and Write | |
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) |
Device Control | |
spBool | spGetAudioOutputPosition (spAudio audio, spLong *position) |
spBool | spStopAudio (spAudio audio) |
spBool | spSyncAudio (spAudio audio) |
|
extern |
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.
[in] | driver_name | The name of the driver. |
|
extern |
Initializes the audio driver (constructor).
All audio I/O functions do not work before you call this function (or spInitAudioDriver() ). Multiple calls before spFreeAudio() are not accepted.
|
extern |
Frees the audio driver's resources. Use spFreeAudioDriver() instead of this.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() . |
Gets the number of audio devices.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | num_device | The address of a variable to receive the number of devices. |
SP_TRUE | Success |
SP_FALSE | Failure |
|
extern |
Gets the name of the audio device. You have to deallocate the memory by calling xspFree() .
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | device_index | 0-based device index. You can specify an index from 0 to ( spGetNumAudioDevice() - 1). The index 0 always corresponds to the default device. |
Selects an audio device which has the index specified.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | device_index | 0-based device index. You can specify an index from 0 to ( spGetNumAudioDevice() - 1). The index 0 always corresponds to the default device. |
SP_TRUE | Success |
SP_FALSE | Failure |
Sets sample rate of the current device. This function should be called before opening a device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | samp_rate | The value of sample rate in Hz. |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets sample rate of the current device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | samp_rate | The address of a variable to receive the sample rate in Hz. |
SP_TRUE | Success |
SP_FALSE | Failure |
Sets the number of channels of the current device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | num_channel | The number of channels. |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets the number of channels of the current device. This function should be called before opening a device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | num_channel | The address of a variable to receive the number of channels. |
SP_TRUE | Success |
SP_FALSE | Failure |
Sets the buffer size of the current device. This function should be called before opening a device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | buffer_size | The buffer size. |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets the buffer size of the current device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | buffer_size | The address of a variable to receive the buffer size. |
SP_TRUE | Success |
SP_FALSE | Failure |
Sets the number of buffers of the current device. This function should be called before opening a device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | num_buffer | The number of buffers. |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets the number of buffers of the current device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | num_buffer | The address of a variable to receive the number of buffers. |
SP_TRUE | Success |
SP_FALSE | Failure |
Sets the blocking mode of the current device. This function should be called before opening a device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | block_mode | The blocking mode of SP_AUDIO_BLOCKING or SP_AUDIO_NONBLOCKING . |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets the blocking mode of the current device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | block_mode | The address of a variable to receive the blocking mode. |
SP_TRUE | Success |
SP_FALSE | Failure |
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.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[in] | samp_bit | The bits/sample. |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets bits/sample of the current device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | samp_bit | The address of a variable to receive the bits/sample. |
SP_TRUE | Success |
SP_FALSE | Failure |
Gets the bits/sample specified.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | specified_samp_bit | The address of a variable to receive the bits/sample specified. |
SP_TRUE | Success |
SP_FALSE | Failure |
|
extern |
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.
[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 ): spBool func(spAudio audio, spAudioCallbackType call_type, void *data1, void *data2, void *user_data);
A class to handle audio I/O. int spBool |
[in] | call_data | The user data for the callback function. You can obtain this address as the 5th argument of the callback function. |
call_type
value on some environments. 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.
[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. |
SP_TRUE | Success |
SP_FALSE | Failure |
Closes the current audio device.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
SP_TRUE | Success |
SP_FALSE | Failure |
|
extern |
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().
"r"
mode. [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. |
|
extern |
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.
"w"
mode. [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. |
|
extern |
Reads data to a double array from the audio device. The weight
is multiplied to the data after reading.
"r"
mode. [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. |
|
extern |
Reads data to a double array from the audio device.
"r"
mode. [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. |
|
extern |
Writes a double array to the audio device. The weight
is multiplied to the data before writing.
"w"
mode. [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. |
|
extern |
Writes a double array to the audio device.
"w"
mode. [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. |
Gets the playback position.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
[out] | position | The address of a variable to receive the playback position. |
SP_TRUE | Success |
SP_FALSE | Failure |
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.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
SP_TRUE | Success |
SP_FALSE | Failure |
Synchronizes audio I/O. Note that the behavior of this function has dependence on an environment.
[in] | audio | spAudio type variable obtained by spInitAudioDriver() or spInitAudio() . |
SP_TRUE | Success |
SP_FALSE | Failure |