eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
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.

portaudio.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. // NOTE: Copy this file to portaudio.h in order to compile with V18 portaudio
  2. #ifndef PORT_AUDIO_H
  3. #define PORT_AUDIO_H
  4. #ifdef __cplusplus
  5. extern "C"
  6. {
  7. #endif /* __cplusplus */
  8. /*
  9. * $Id: portaudio.h,v 1.5 2002/03/26 18:04:22 philburk Exp $
  10. * PortAudio Portable Real-Time Audio Library
  11. * PortAudio API Header File
  12. * Latest version available at: http://www.audiomulch.com/portaudio/
  13. *
  14. * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
  15. *
  16. * Permission is hereby granted, free of charge, to any person obtaining
  17. * a copy of this software and associated documentation files
  18. * (the "Software"), to deal in the Software without restriction,
  19. * including without limitation the rights to use, copy, modify, merge,
  20. * publish, distribute, sublicense, and/or sell copies of the Software,
  21. * and to permit persons to whom the Software is furnished to do so,
  22. * subject to the following conditions:
  23. *
  24. * The above copyright notice and this permission notice shall be
  25. * included in all copies or substantial portions of the Software.
  26. *
  27. * Any person wishing to distribute modifications to the Software is
  28. * requested to send the modifications to the original developer so that
  29. * they can be incorporated into the canonical version.
  30. *
  31. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  32. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  33. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  34. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  35. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  36. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  37. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  38. *
  39. */
  40. typedef int PaError;
  41. typedef enum {
  42. paNoError = 0,
  43. paHostError = -10000,
  44. paInvalidChannelCount,
  45. paInvalidSampleRate,
  46. paInvalidDeviceId,
  47. paInvalidFlag,
  48. paSampleFormatNotSupported,
  49. paBadIODeviceCombination,
  50. paInsufficientMemory,
  51. paBufferTooBig,
  52. paBufferTooSmall,
  53. paNullCallback,
  54. paBadStreamPtr,
  55. paTimedOut,
  56. paInternalError,
  57. paDeviceUnavailable
  58. } PaErrorNum;
  59. /*
  60. Pa_Initialize() is the library initialisation function - call this before
  61. using the library.
  62. */
  63. PaError Pa_Initialize( void );
  64. /*
  65. Pa_Terminate() is the library termination function - call this after
  66. using the library.
  67. */
  68. PaError Pa_Terminate( void );
  69. /*
  70. Pa_GetHostError() returns a host specific error code.
  71. This can be called after receiving a PortAudio error code of paHostError.
  72. */
  73. long Pa_GetHostError( void );
  74. /*
  75. Pa_GetErrorText() translates the supplied PortAudio error number
  76. into a human readable message.
  77. */
  78. const char *Pa_GetErrorText( PaError errnum );
  79. /*
  80. Sample formats
  81. These are formats used to pass sound data between the callback and the
  82. stream. Each device has a "native" format which may be used when optimum
  83. efficiency or control over conversion is required.
  84. Formats marked "always available" are supported (emulated) by all
  85. PortAudio implementations.
  86. The floating point representation (paFloat32) uses +1.0 and -1.0 as the
  87. maximum and minimum respectively.
  88. paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
  89. */
  90. typedef unsigned long PaSampleFormat;
  91. #define paFloat32 ((PaSampleFormat) (1<<0)) /*always available*/
  92. #define paInt16 ((PaSampleFormat) (1<<1)) /*always available*/
  93. #define paInt32 ((PaSampleFormat) (1<<2)) /*always available*/
  94. #define paInt24 ((PaSampleFormat) (1<<3))
  95. #define paPackedInt24 ((PaSampleFormat) (1<<4))
  96. #define paInt8 ((PaSampleFormat) (1<<5))
  97. #define paUInt8 ((PaSampleFormat) (1<<6))
  98. #define paCustomFormat ((PaSampleFormat) (1<<16))
  99. /*
  100. Device enumeration mechanism.
  101. Device ids range from 0 to Pa_CountDevices()-1.
  102. Devices may support input, output or both.
  103. */
  104. typedef int PaDeviceID;
  105. #define paNoDevice -1
  106. int Pa_CountDevices( void );
  107. typedef struct
  108. {
  109. int structVersion;
  110. const char *name;
  111. int maxInputChannels;
  112. int maxOutputChannels;
  113. /* Number of discrete rates, or -1 if range supported. */
  114. int numSampleRates;
  115. /* Array of supported sample rates, or {min,max} if range supported. */
  116. const double *sampleRates;
  117. PaSampleFormat nativeSampleFormats;
  118. }
  119. PaDeviceInfo;
  120. /*
  121. Pa_GetDefaultInputDeviceID(), Pa_GetDefaultOutputDeviceID() return the
  122. default device ids for input and output respectively, or paNoDevice if
  123. no device is available.
  124. The result can be passed to Pa_OpenStream().
  125. On the PC, the user can specify a default device by
  126. setting an environment variable. For example, to use device #1.
  127. set PA_RECOMMENDED_OUTPUT_DEVICE=1
  128. The user should first determine the available device ids by using
  129. the supplied application "pa_devs".
  130. */
  131. PaDeviceID Pa_GetDefaultInputDeviceID( void );
  132. PaDeviceID Pa_GetDefaultOutputDeviceID( void );
  133. /*
  134. Pa_GetDeviceInfo() returns a pointer to an immutable PaDeviceInfo structure
  135. for the device specified.
  136. If the device parameter is out of range the function returns NULL.
  137. PortAudio manages the memory referenced by the returned pointer, the client
  138. must not manipulate or free the memory. The pointer is only guaranteed to be
  139. valid between calls to Pa_Initialize() and Pa_Terminate().
  140. */
  141. const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID device );
  142. /*
  143. PaTimestamp is used to represent a continuous sample clock with arbitrary
  144. start time that can be used for syncronization. The type is used for the
  145. outTime argument to the PortAudioCallback and as the result of Pa_StreamTime()
  146. */
  147. typedef double PaTimestamp;
  148. /*
  149. PortAudioCallback is implemented by PortAudio clients.
  150. inputBuffer and outputBuffer are arrays of interleaved samples,
  151. the format, packing and number of channels used by the buffers are
  152. determined by parameters to Pa_OpenStream() (see below).
  153. framesPerBuffer is the number of sample frames to be processed by the callback.
  154. outTime is the time in samples when the buffer(s) processed by
  155. this callback will begin being played at the audio output.
  156. See also Pa_StreamTime()
  157. userData is the value of a user supplied pointer passed to Pa_OpenStream()
  158. intended for storing synthesis data etc.
  159. return value:
  160. The callback can return a non-zero value to stop the stream. This may be
  161. useful in applications such as soundfile players where a specific duration
  162. of output is required. However, it is not necessary to utilise this mechanism
  163. as StopStream() will also terminate the stream. A callback returning a
  164. non-zero value must fill the entire outputBuffer.
  165. NOTE: None of the other stream functions may be called from within the
  166. callback function except for Pa_GetCPULoad().
  167. */
  168. typedef int (PortAudioCallback)(
  169. void *inputBuffer, void *outputBuffer,
  170. unsigned long framesPerBuffer,
  171. PaTimestamp outTime, void *userData );
  172. /*
  173. Stream flags
  174. These flags may be supplied (ored together) in the streamFlags argument to
  175. the Pa_OpenStream() function.
  176. */
  177. #define paNoFlag (0)
  178. #define paClipOff (1<<0) /* disable default clipping of out of range samples */
  179. #define paDitherOff (1<<1) /* disable default dithering */
  180. #define paPlatformSpecificFlags (0x00010000)
  181. typedef unsigned long PaStreamFlags;
  182. /*
  183. A single PortAudioStream provides multiple channels of real-time
  184. input and output audio streaming to a client application.
  185. Pointers to PortAudioStream objects are passed between PortAudio functions.
  186. */
  187. typedef void PortAudioStream;
  188. #define PaStream PortAudioStream
  189. /*
  190. Pa_OpenStream() opens a stream for either input, output or both.
  191. stream is the address of a PortAudioStream pointer which will receive
  192. a pointer to the newly opened stream.
  193. inputDevice is the id of the device used for input (see PaDeviceID above.)
  194. inputDevice may be paNoDevice to indicate that an input device is not required.
  195. numInputChannels is the number of channels of sound to be delivered to the
  196. callback. It can range from 1 to the value of maxInputChannels in the
  197. PaDeviceInfo record for the device specified by the inputDevice parameter.
  198. If inputDevice is paNoDevice numInputChannels is ignored.
  199. inputSampleFormat is the sample format of inputBuffer provided to the callback
  200. function. inputSampleFormat may be any of the formats described by the
  201. PaSampleFormat enumeration (see above). PortAudio guarantees support for
  202. the device's native formats (nativeSampleFormats in the device info record)
  203. and additionally 16 and 32 bit integer and 32 bit floating point formats.
  204. Support for other formats is implementation defined.
  205. inputDriverInfo is a pointer to an optional driver specific data structure
  206. containing additional information for device setup or stream processing.
  207. inputDriverInfo is never required for correct operation. If not used
  208. inputDriverInfo should be NULL.
  209. outputDevice is the id of the device used for output (see PaDeviceID above.)
  210. outputDevice may be paNoDevice to indicate that an output device is not required.
  211. numOutputChannels is the number of channels of sound to be supplied by the
  212. callback. See the definition of numInputChannels above for more details.
  213. outputSampleFormat is the sample format of the outputBuffer filled by the
  214. callback function. See the definition of inputSampleFormat above for more
  215. details.
  216. outputDriverInfo is a pointer to an optional driver specific data structure
  217. containing additional information for device setup or stream processing.
  218. outputDriverInfo is never required for correct operation. If not used
  219. outputDriverInfo should be NULL.
  220. sampleRate is the desired sampleRate. For full-duplex streams it is the
  221. sample rate for both input and output
  222. framesPerBuffer is the length in sample frames of all internal sample buffers
  223. used for communication with platform specific audio routines. Wherever
  224. possible this corresponds to the framesPerBuffer parameter passed to the
  225. callback function.
  226. numberOfBuffers is the number of buffers used for multibuffered communication
  227. with the platform specific audio routines. If you pass zero, then an optimum
  228. value will be chosen for you internally. This parameter is provided only
  229. as a guide - and does not imply that an implementation must use multibuffered
  230. i/o when reliable double buffering is available (such as SndPlayDoubleBuffer()
  231. on the Macintosh.)
  232. streamFlags may contain a combination of flags ORed together.
  233. These flags modify the behaviour of the streaming process. Some flags may only
  234. be relevant to certain buffer formats.
  235. callback is a pointer to a client supplied function that is responsible
  236. for processing and filling input and output buffers (see above for details.)
  237. userData is a client supplied pointer which is passed to the callback
  238. function. It could for example, contain a pointer to instance data necessary
  239. for processing the audio buffers.
  240. return value:
  241. Upon success Pa_OpenStream() returns PaNoError and places a pointer to a
  242. valid PortAudioStream in the stream argument. The stream is inactive (stopped).
  243. If a call to Pa_OpenStream() fails a non-zero error code is returned (see
  244. PaError above) and the value of stream is invalid.
  245. */
  246. PaError Pa_OpenStream( PortAudioStream** stream,
  247. PaDeviceID inputDevice,
  248. int numInputChannels,
  249. PaSampleFormat inputSampleFormat,
  250. void *inputDriverInfo,
  251. PaDeviceID outputDevice,
  252. int numOutputChannels,
  253. PaSampleFormat outputSampleFormat,
  254. void *outputDriverInfo,
  255. double sampleRate,
  256. unsigned long framesPerBuffer,
  257. unsigned long numberOfBuffers,
  258. PaStreamFlags streamFlags,
  259. PortAudioCallback *callback,
  260. void *userData );
  261. /*
  262. Pa_OpenDefaultStream() is a simplified version of Pa_OpenStream() that opens
  263. the default input and/or output devices. Most parameters have identical meaning
  264. to their Pa_OpenStream() counterparts, with the following exceptions:
  265. If either numInputChannels or numOutputChannels is 0 the respective device
  266. is not opened. This has the same effect as passing paNoDevice in the device
  267. arguments to Pa_OpenStream().
  268. sampleFormat applies to both the input and output buffers.
  269. */
  270. PaError Pa_OpenDefaultStream( PortAudioStream** stream,
  271. int numInputChannels,
  272. int numOutputChannels,
  273. PaSampleFormat sampleFormat,
  274. double sampleRate,
  275. unsigned long framesPerBuffer,
  276. unsigned long numberOfBuffers,
  277. PortAudioCallback *callback,
  278. void *userData );
  279. /*
  280. Pa_CloseStream() closes an audio stream, flushing any pending buffers.
  281. */
  282. PaError Pa_CloseStream( PortAudioStream* );
  283. /*
  284. Pa_StartStream() and Pa_StopStream() begin and terminate audio processing.
  285. Pa_StopStream() waits until all pending audio buffers have been played.
  286. Pa_AbortStream() stops playing immediately without waiting for pending
  287. buffers to complete.
  288. */
  289. PaError Pa_StartStream( PortAudioStream *stream );
  290. PaError Pa_StopStream( PortAudioStream *stream );
  291. PaError Pa_AbortStream( PortAudioStream *stream );
  292. /*
  293. Pa_StreamActive() returns one (1) when the stream is active (ie playing
  294. or recording audio), zero (0) when not playing, or a negative error number
  295. if the stream is invalid.
  296. The stream is active between calls to Pa_StartStream() and Pa_StopStream(),
  297. but may also become inactive if the callback returns a non-zero value.
  298. In the latter case, the stream is considered inactive after the last
  299. buffer has finished playing.
  300. */
  301. PaError Pa_StreamActive( PortAudioStream *stream );
  302. /*
  303. Pa_StreamTime() returns the current output time in samples for the stream.
  304. This time may be used as a time reference (for example synchronizing audio to
  305. MIDI).
  306. */
  307. PaTimestamp Pa_StreamTime( PortAudioStream *stream );
  308. /*
  309. Pa_GetCPULoad() returns the CPU Load for the stream.
  310. The "CPU Load" is a fraction of total CPU time consumed by the stream's
  311. audio processing routines including, but not limited to the client supplied
  312. callback.
  313. A value of 0.5 would imply that PortAudio and the sound generating
  314. callback was consuming roughly 50% of the available CPU time.
  315. This function may be called from the callback function or the application.
  316. */
  317. double Pa_GetCPULoad( PortAudioStream* stream );
  318. /*
  319. Pa_GetMinNumBuffers() returns the minimum number of buffers required by
  320. the current host based on minimum latency.
  321. On the PC, for the DirectSound implementation, latency can be optionally set
  322. by user by setting an environment variable.
  323. For example, to set latency to 200 msec, put:
  324. set PA_MIN_LATENCY_MSEC=200
  325. in the AUTOEXEC.BAT file and reboot.
  326. If the environment variable is not set, then the latency will be determined
  327. based on the OS. Windows NT has higher latency than Win95.
  328. */
  329. int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate );
  330. /*
  331. Pa_Sleep() puts the caller to sleep for at least 'msec' milliseconds.
  332. You may sleep longer than the requested time so don't rely on this for
  333. accurate musical timing.
  334. Pa_Sleep() is provided as a convenience for authors of portable code (such as
  335. the tests and examples in the PortAudio distribution.)
  336. */
  337. void Pa_Sleep( long msec );
  338. /*
  339. Pa_GetSampleSize() returns the size in bytes of a single sample in the
  340. supplied PaSampleFormat, or paSampleFormatNotSupported if the format is
  341. no supported.
  342. */
  343. PaError Pa_GetSampleSize( PaSampleFormat format );
  344. #ifdef __cplusplus
  345. }
  346. #endif /* __cplusplus */
  347. #endif /* PORT_AUDIO_H */