You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
12KB

  1. /************************************************************************/
  2. /*! \defgroup C-interface
  3. @{
  4. \brief C interface to realtime audio i/o C++ classes.
  5. RtAudio offers a C-style interface, principally for use in binding
  6. RtAudio to other programming languages. All structs, enums, and
  7. functions listed here have direct analogs (and simply call to)
  8. items in the C++ RtAudio class and its supporting classes and
  9. types
  10. */
  11. /************************************************************************/
  12. /*!
  13. \file rtaudio_c.h
  14. */
  15. #ifndef RTAUDIO_C_H
  16. #define RTAUDIO_C_H
  17. #if defined(RTAUDIO_EXPORT)
  18. #if defined _WIN32 || defined __CYGWIN__
  19. #define RTAUDIOAPI __declspec(dllexport)
  20. #else
  21. #define RTAUDIOAPI __attribute__((visibility("default")))
  22. #endif
  23. #else
  24. #define RTAUDIOAPI //__declspec(dllimport)
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /*! \typedef typedef unsigned long rtaudio_format_t;
  30. \brief RtAudio data format type.
  31. - \e RTAUDIO_FORMAT_SINT8: 8-bit signed integer.
  32. - \e RTAUDIO_FORMAT_SINT16: 16-bit signed integer.
  33. - \e RTAUDIO_FORMAT_SINT24: 24-bit signed integer.
  34. - \e RTAUDIO_FORMAT_SINT32: 32-bit signed integer.
  35. - \e RTAUDIO_FORMAT_FLOAT32: Normalized between plus/minus 1.0.
  36. - \e RTAUDIO_FORMAT_FLOAT64: Normalized between plus/minus 1.0.
  37. See \ref RtAudioFormat.
  38. */
  39. typedef unsigned long rtaudio_format_t;
  40. #define RTAUDIO_FORMAT_SINT8 0x01
  41. #define RTAUDIO_FORMAT_SINT16 0x02
  42. #define RTAUDIO_FORMAT_SINT24 0x04
  43. #define RTAUDIO_FORMAT_SINT32 0x08
  44. #define RTAUDIO_FORMAT_FLOAT32 0x10
  45. #define RTAUDIO_FORMAT_FLOAT64 0x20
  46. /*! \typedef typedef unsigned long rtaudio_stream_flags_t;
  47. \brief RtAudio stream option flags.
  48. The following flags can be OR'ed together to allow a client to
  49. make changes to the default stream behavior:
  50. - \e RTAUDIO_FLAGS_NONINTERLEAVED: Use non-interleaved buffers (default = interleaved).
  51. - \e RTAUDIO_FLAGS_MINIMIZE_LATENCY: Attempt to set stream parameters for lowest possible latency.
  52. - \e RTAUDIO_FLAGS_HOG_DEVICE: Attempt grab device for exclusive use.
  53. - \e RTAUDIO_FLAGS_ALSA_USE_DEFAULT: Use the "default" PCM device (ALSA only).
  54. - \e RTAUDIO_FLAGS_JACK_DONT_CONNECT: Do not automatically connect ports (JACK only).
  55. See \ref RtAudioStreamFlags.
  56. */
  57. typedef unsigned int rtaudio_stream_flags_t;
  58. #define RTAUDIO_FLAGS_NONINTERLEAVED 0x1
  59. #define RTAUDIO_FLAGS_MINIMIZE_LATENCY 0x2
  60. #define RTAUDIO_FLAGS_HOG_DEVICE 0x4
  61. #define RTAUDIO_FLAGS_SCHEDULE_REALTIME 0x8
  62. #define RTAUDIO_FLAGS_ALSA_USE_DEFAULT 0x10
  63. #define RTAUDIO_FLAGS_JACK_DONT_CONNECT = 0x20
  64. /*! \typedef typedef unsigned long rtaudio_stream_status_t;
  65. \brief RtAudio stream status (over- or underflow) flags.
  66. Notification of a stream over- or underflow is indicated by a
  67. non-zero stream \c status argument in the RtAudioCallback function.
  68. The stream status can be one of the following two options,
  69. depending on whether the stream is open for output and/or input:
  70. - \e RTAUDIO_STATUS_INPUT_OVERFLOW: Input data was discarded because of an overflow condition at the driver.
  71. - \e RTAUDIO_STATUS_OUTPUT_UNDERFLOW: The output buffer ran low, likely producing a break in the output sound.
  72. See \ref RtAudioStreamStatus.
  73. */
  74. typedef unsigned int rtaudio_stream_status_t;
  75. #define RTAUDIO_STATUS_INPUT_OVERFLOW 0x1
  76. #define RTAUDIO_STATUS_OUTPUT_UNDERFLOW 0x2
  77. //! RtAudio callback function prototype.
  78. /*!
  79. All RtAudio clients must create a function of this type to read
  80. and/or write data from/to the audio stream. When the underlying
  81. audio system is ready for new input or output data, this function
  82. will be invoked.
  83. See \ref RtAudioCallback.
  84. */
  85. typedef int (*rtaudio_cb_t)(void *out, void *in, unsigned int nFrames,
  86. double stream_time, rtaudio_stream_status_t status,
  87. void *userdata);
  88. /*! \brief Error codes for RtAudio.
  89. See \ref RtAudioError.
  90. */
  91. typedef enum rtaudio_error {
  92. RTAUDIO_ERROR_WARNING, /*!< A non-critical error. */
  93. RTAUDIO_ERROR_DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
  94. RTAUDIO_ERROR_UNSPECIFIED, /*!< The default, unspecified error type. */
  95. RTAUDIO_ERROR_NO_DEVICES_FOUND, /*!< No devices found on system. */
  96. RTAUDIO_ERROR_INVALID_DEVICE, /*!< An invalid device ID was specified. */
  97. RTAUDIO_ERROR_MEMORY_ERROR, /*!< An error occured during memory allocation. */
  98. RTAUDIO_ERROR_INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
  99. RTAUDIO_ERROR_INVALID_USE, /*!< The function was called incorrectly. */
  100. RTAUDIO_ERROR_DRIVER_ERROR, /*!< A system driver error occured. */
  101. RTAUDIO_ERROR_SYSTEM_ERROR, /*!< A system error occured. */
  102. RTAUDIO_ERROR_THREAD_ERROR, /*!< A thread error occured. */
  103. } rtaudio_error_t;
  104. //! RtAudio error callback function prototype.
  105. /*!
  106. \param err Type of error.
  107. \param msg Error description.
  108. See \ref RtAudioErrorCallback.
  109. */
  110. typedef void (*rtaudio_error_cb_t)(rtaudio_error_t err, const char *msg);
  111. //! Audio API specifier. See \ref RtAudio::Api.
  112. typedef enum rtaudio_api {
  113. RTAUDIO_API_UNSPECIFIED, /*!< Search for a working compiled API. */
  114. RTAUDIO_API_LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
  115. RTAUDIO_API_LINUX_PULSE, /*!< The Linux PulseAudio API. */
  116. RTAUDIO_API_LINUX_OSS, /*!< The Linux Open Sound System API. */
  117. RTAUDIO_API_UNIX_JACK, /*!< The Jack Low-Latency Audio Server API. */
  118. RTAUDIO_API_MACOSX_CORE, /*!< Macintosh OS-X Core Audio API. */
  119. RTAUDIO_API_WINDOWS_WASAPI, /*!< The Microsoft WASAPI API. */
  120. RTAUDIO_API_WINDOWS_ASIO, /*!< The Steinberg Audio Stream I/O API. */
  121. RTAUDIO_API_WINDOWS_DS, /*!< The Microsoft DirectSound API. */
  122. RTAUDIO_API_DUMMY, /*!< A compilable but non-functional API. */
  123. RTAUDIO_API_NUM, /*!< Number of values in this enum. */
  124. } rtaudio_api_t;
  125. #define NUM_SAMPLE_RATES 16
  126. #define MAX_NAME_LENGTH 512
  127. //! The public device information structure for returning queried values.
  128. //! See \ref RtAudio::DeviceInfo.
  129. typedef struct rtaudio_device_info {
  130. int probed;
  131. unsigned int output_channels;
  132. unsigned int input_channels;
  133. unsigned int duplex_channels;
  134. int is_default_output;
  135. int is_default_input;
  136. rtaudio_format_t native_formats;
  137. unsigned int preferred_sample_rate;
  138. int sample_rates[NUM_SAMPLE_RATES];
  139. char name[MAX_NAME_LENGTH];
  140. } rtaudio_device_info_t;
  141. //! The structure for specifying input or ouput stream parameters.
  142. //! See \ref RtAudio::StreamParameters.
  143. typedef struct rtaudio_stream_parameters {
  144. unsigned int device_id;
  145. unsigned int num_channels;
  146. unsigned int first_channel;
  147. } rtaudio_stream_parameters_t;
  148. //! The structure for specifying stream options.
  149. //! See \ref RtAudio::StreamOptions.
  150. typedef struct rtaudio_stream_options {
  151. rtaudio_stream_flags_t flags;
  152. unsigned int num_buffers;
  153. int priority;
  154. char name[MAX_NAME_LENGTH];
  155. } rtaudio_stream_options_t;
  156. typedef struct rtaudio *rtaudio_t;
  157. //! Determine the current RtAudio version. See \ref RtAudio::getVersion().
  158. RTAUDIOAPI const char *rtaudio_version(void);
  159. //! Determine the number of available compiled audio APIs, the length
  160. //! of the array returned by rtaudio_compiled_api(). See \ref
  161. //! RtAudio::getCompiledApi().
  162. RTAUDIOAPI unsigned int rtaudio_get_num_compiled_apis(void);
  163. //! Return an array of rtaudio_api_t compiled into this instance of
  164. //! RtAudio. This array is static (do not free it) and has the length
  165. //! returned by rtaudio_get_num_compiled_apis(). See \ref
  166. //! RtAudio::getCompiledApi().
  167. RTAUDIOAPI const rtaudio_api_t *rtaudio_compiled_api(void);
  168. //! Return the name of a specified rtaudio_api_t. This string can be
  169. //! used to look up an API by rtaudio_compiled_api_by_name(). See
  170. //! \ref RtAudio::getApiName().
  171. RTAUDIOAPI const char *rtaudio_api_name(rtaudio_api_t api);
  172. //! Return the display name of a specified rtaudio_api_t. See \ref
  173. //! RtAudio::getApiDisplayName().
  174. RTAUDIOAPI const char *rtaudio_api_display_name(rtaudio_api_t api);
  175. //! Return the rtaudio_api_t having the given name. See \ref
  176. //! RtAudio::getCompiledApiByName().
  177. RTAUDIOAPI rtaudio_api_t rtaudio_compiled_api_by_name(const char *name);
  178. RTAUDIOAPI const char *rtaudio_error(rtaudio_t audio);
  179. //! Create an instance of struct rtaudio.
  180. RTAUDIOAPI rtaudio_t rtaudio_create(rtaudio_api_t api);
  181. //! Free an instance of struct rtaudio.
  182. RTAUDIOAPI void rtaudio_destroy(rtaudio_t audio);
  183. //! Returns the audio API specifier for the current instance of
  184. //! RtAudio. See RtAudio::getCurrentApi().
  185. RTAUDIOAPI rtaudio_api_t rtaudio_current_api(rtaudio_t audio);
  186. //! Queries for the number of audio devices available. See \ref
  187. //! RtAudio::getDeviceCount().
  188. RTAUDIOAPI int rtaudio_device_count(rtaudio_t audio);
  189. //! Return a struct rtaudio_device_info for a specified device number.
  190. //! See \ref RtAudio::getDeviceInfo().
  191. RTAUDIOAPI rtaudio_device_info_t rtaudio_get_device_info(rtaudio_t audio,
  192. int i);
  193. //! Returns the index of the default output device. See \ref
  194. //! RtAudio::getDefaultOutputDevice().
  195. RTAUDIOAPI unsigned int rtaudio_get_default_output_device(rtaudio_t audio);
  196. //! Returns the index of the default input device. See \ref
  197. //! RtAudio::getDefaultInputDevice().
  198. RTAUDIOAPI unsigned int rtaudio_get_default_input_device(rtaudio_t audio);
  199. //! Opens a stream with the specified parameters. See \ref RtAudio::openStream().
  200. //! \return an \ref rtaudio_error.
  201. RTAUDIOAPI int
  202. rtaudio_open_stream(rtaudio_t audio, rtaudio_stream_parameters_t *output_params,
  203. rtaudio_stream_parameters_t *input_params,
  204. rtaudio_format_t format, unsigned int sample_rate,
  205. unsigned int *buffer_frames, rtaudio_cb_t cb,
  206. void *userdata, rtaudio_stream_options_t *options,
  207. rtaudio_error_cb_t errcb);
  208. //! Closes a stream and frees any associated stream memory. See \ref RtAudio::closeStream().
  209. RTAUDIOAPI void rtaudio_close_stream(rtaudio_t audio);
  210. //! Starts a stream. See \ref RtAudio::startStream().
  211. RTAUDIOAPI int rtaudio_start_stream(rtaudio_t audio);
  212. //! Stop a stream, allowing any samples remaining in the output queue
  213. //! to be played. See \ref RtAudio::stopStream().
  214. RTAUDIOAPI int rtaudio_stop_stream(rtaudio_t audio);
  215. //! Stop a stream, discarding any samples remaining in the
  216. //! input/output queue. See \ref RtAudio::abortStream().
  217. RTAUDIOAPI int rtaudio_abort_stream(rtaudio_t audio);
  218. //! Returns 1 if a stream is open and false if not. See \ref RtAudio::isStreamOpen().
  219. RTAUDIOAPI int rtaudio_is_stream_open(rtaudio_t audio);
  220. //! Returns 1 if a stream is running and false if it is stopped or not
  221. //! open. See \ref RtAudio::isStreamRunning().
  222. RTAUDIOAPI int rtaudio_is_stream_running(rtaudio_t audio);
  223. //! Returns the number of elapsed seconds since the stream was
  224. //! started. See \ref RtAudio::getStreamTime().
  225. RTAUDIOAPI double rtaudio_get_stream_time(rtaudio_t audio);
  226. //! Set the stream time to a time in seconds greater than or equal to
  227. //! 0.0. See \ref RtAudio::setStreamTime().
  228. RTAUDIOAPI void rtaudio_set_stream_time(rtaudio_t audio, double time);
  229. //! Returns the internal stream latency in sample frames. See \ref
  230. //! RtAudio::getStreamLatency().
  231. RTAUDIOAPI int rtaudio_get_stream_latency(rtaudio_t audio);
  232. //! Returns actual sample rate in use by the stream. See \ref
  233. //! RtAudio::getStreamSampleRate().
  234. RTAUDIOAPI unsigned int rtaudio_get_stream_sample_rate(rtaudio_t audio);
  235. //! Specify whether warning messages should be printed to stderr. See
  236. //! \ref RtAudio::showWarnings().
  237. RTAUDIOAPI void rtaudio_show_warnings(rtaudio_t audio, int show);
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. #endif /* RTAUDIO_C_H */
  242. /*! }@ */