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.

portaudio19.h 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. // NOTE: Copy this file to portaudio.h in order to compile with V19 portaudio
  2. #ifndef PORTAUDIO_H
  3. #define PORTAUDIO_H
  4. /*
  5. * $Id: portaudio.h 1061 2006-06-19 22:46:41Z lschwardt $
  6. * PortAudio Portable Real-Time Audio Library
  7. * PortAudio API Header File
  8. * Latest version available at: http://www.portaudio.com/
  9. *
  10. * Copyright (c) 1999-2002 Ross Bencina and Phil Burk
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining
  13. * a copy of this software and associated documentation files
  14. * (the "Software"), to deal in the Software without restriction,
  15. * including without limitation the rights to use, copy, modify, merge,
  16. * publish, distribute, sublicense, and/or sell copies of the Software,
  17. * and to permit persons to whom the Software is furnished to do so,
  18. * subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be
  21. * included in all copies or substantial portions of the Software.
  22. *
  23. * Any person wishing to distribute modifications to the Software is
  24. * requested to send the modifications to the original developer so that
  25. * they can be incorporated into the canonical version.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  30. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  31. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  32. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  33. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  34. */
  35. /** @file
  36. @brief The PortAudio API.
  37. */
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif /* __cplusplus */
  42. /** Retrieve the release number of the currently running PortAudio build,
  43. eg 1900.
  44. */
  45. int Pa_GetVersion( void );
  46. /** Retrieve a textual description of the current PortAudio build,
  47. eg "PortAudio V19-devel 13 October 2002".
  48. */
  49. const char* Pa_GetVersionText( void );
  50. /** Error codes returned by PortAudio functions.
  51. Note that with the exception of paNoError, all PaErrorCodes are negative.
  52. */
  53. typedef int PaError;
  54. typedef enum PaErrorCode
  55. {
  56. paNoError = 0,
  57. paNotInitialized = -10000,
  58. paUnanticipatedHostError,
  59. paInvalidChannelCount,
  60. paInvalidSampleRate,
  61. paInvalidDevice,
  62. paInvalidFlag,
  63. paSampleFormatNotSupported,
  64. paBadIODeviceCombination,
  65. paInsufficientMemory,
  66. paBufferTooBig,
  67. paBufferTooSmall,
  68. paNullCallback,
  69. paBadStreamPtr,
  70. paTimedOut,
  71. paInternalError,
  72. paDeviceUnavailable,
  73. paIncompatibleHostApiSpecificStreamInfo,
  74. paStreamIsStopped,
  75. paStreamIsNotStopped,
  76. paInputOverflowed,
  77. paOutputUnderflowed,
  78. paHostApiNotFound,
  79. paInvalidHostApi,
  80. paCanNotReadFromACallbackStream, /**< @todo review error code name */
  81. paCanNotWriteToACallbackStream, /**< @todo review error code name */
  82. paCanNotReadFromAnOutputOnlyStream, /**< @todo review error code name */
  83. paCanNotWriteToAnInputOnlyStream, /**< @todo review error code name */
  84. paIncompatibleStreamHostApi,
  85. paBadBufferPtr
  86. } PaErrorCode;
  87. /** Translate the supplied PortAudio error code into a human readable
  88. message.
  89. */
  90. const char *Pa_GetErrorText( PaError errorCode );
  91. /** Library initialization function - call this before using PortAudio.
  92. This function initialises internal data structures and prepares underlying
  93. host APIs for use. This function MUST be called before using any other
  94. PortAudio API functions.
  95. If Pa_Initialize() is called multiple times, each successful
  96. call must be matched with a corresponding call to Pa_Terminate().
  97. Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not
  98. required to be fully nested.
  99. Note that if Pa_Initialize() returns an error code, Pa_Terminate() should
  100. NOT be called.
  101. @return paNoError if successful, otherwise an error code indicating the cause
  102. of failure.
  103. @see Pa_Terminate
  104. */
  105. PaError Pa_Initialize( void );
  106. /** Library termination function - call this when finished using PortAudio.
  107. This function deallocates all resources allocated by PortAudio since it was
  108. initializied by a call to Pa_Initialize(). In cases where Pa_Initialise() has
  109. been called multiple times, each call must be matched with a corresponding call
  110. to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically
  111. close any PortAudio streams that are still open.
  112. Pa_Terminate() MUST be called before exiting a program which uses PortAudio.
  113. Failure to do so may result in serious resource leaks, such as audio devices
  114. not being available until the next reboot.
  115. @return paNoError if successful, otherwise an error code indicating the cause
  116. of failure.
  117. @see Pa_Initialize
  118. */
  119. PaError Pa_Terminate( void );
  120. /** The type used to refer to audio devices. Values of this type usually
  121. range from 0 to (Pa_DeviceCount-1), and may also take on the PaNoDevice
  122. and paUseHostApiSpecificDeviceSpecification values.
  123. @see Pa_DeviceCount, paNoDevice, paUseHostApiSpecificDeviceSpecification
  124. */
  125. typedef int PaDeviceIndex;
  126. /** A special PaDeviceIndex value indicating that no device is available,
  127. or should be used.
  128. @see PaDeviceIndex
  129. */
  130. #define paNoDevice ((PaDeviceIndex)-1)
  131. /** A special PaDeviceIndex value indicating that the device(s) to be used
  132. are specified in the host api specific stream info structure.
  133. @see PaDeviceIndex
  134. */
  135. #define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2)
  136. /* Host API enumeration mechanism */
  137. /** The type used to enumerate to host APIs at runtime. Values of this type
  138. range from 0 to (Pa_GetHostApiCount()-1).
  139. @see Pa_GetHostApiCount
  140. */
  141. typedef int PaHostApiIndex;
  142. /** Retrieve the number of available host APIs. Even if a host API is
  143. available it may have no devices available.
  144. @return A non-negative value indicating the number of available host APIs
  145. or, a PaErrorCode (which are always negative) if PortAudio is not initialized
  146. or an error is encountered.
  147. @see PaHostApiIndex
  148. */
  149. PaHostApiIndex Pa_GetHostApiCount( void );
  150. /** Retrieve the index of the default host API. The default host API will be
  151. the lowest common denominator host API on the current platform and is
  152. unlikely to provide the best performance.
  153. @return A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1)
  154. indicating the default host API index or, a PaErrorCode (which are always
  155. negative) if PortAudio is not initialized or an error is encountered.
  156. */
  157. PaHostApiIndex Pa_GetDefaultHostApi( void );
  158. /** Unchanging unique identifiers for each supported host API. This type
  159. is used in the PaHostApiInfo structure. The values are guaranteed to be
  160. unique and to never change, thus allowing code to be written that
  161. conditionally uses host API specific extensions.
  162. New type ids will be allocated when support for a host API reaches
  163. "public alpha" status, prior to that developers should use the
  164. paInDevelopment type id.
  165. @see PaHostApiInfo
  166. */
  167. typedef enum PaHostApiTypeId
  168. {
  169. paInDevelopment=0, /* use while developing support for a new host API */
  170. paDirectSound=1,
  171. paMME=2,
  172. paASIO=3,
  173. paSoundManager=4,
  174. paCoreAudio=5,
  175. paOSS=7,
  176. paALSA=8,
  177. paAL=9,
  178. paBeOS=10,
  179. paWDMKS=11,
  180. paJACK=12,
  181. paWASAPI=13,
  182. paAudioScienceHPI=14
  183. } PaHostApiTypeId;
  184. /** A structure containing information about a particular host API. */
  185. typedef struct PaHostApiInfo
  186. {
  187. /** this is struct version 1 */
  188. int structVersion;
  189. /** The well known unique identifier of this host API @see PaHostApiTypeId */
  190. PaHostApiTypeId type;
  191. /** A textual description of the host API for display on user interfaces. */
  192. const char *name;
  193. /** The number of devices belonging to this host API. This field may be
  194. used in conjunction with Pa_HostApiDeviceIndexToDeviceIndex() to enumerate
  195. all devices for this host API.
  196. @see Pa_HostApiDeviceIndexToDeviceIndex
  197. */
  198. int deviceCount;
  199. /** The default input device for this host API. The value will be a
  200. device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice
  201. if no default input device is available.
  202. */
  203. PaDeviceIndex defaultInputDevice;
  204. /** The default output device for this host API. The value will be a
  205. device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice
  206. if no default output device is available.
  207. */
  208. PaDeviceIndex defaultOutputDevice;
  209. } PaHostApiInfo;
  210. /** Retrieve a pointer to a structure containing information about a specific
  211. host Api.
  212. @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1)
  213. @return A pointer to an immutable PaHostApiInfo structure describing
  214. a specific host API. If the hostApi parameter is out of range or an error
  215. is encountered, the function returns NULL.
  216. The returned structure is owned by the PortAudio implementation and must not
  217. be manipulated or freed. The pointer is only guaranteed to be valid between
  218. calls to Pa_Initialize() and Pa_Terminate().
  219. */
  220. const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi );
  221. /** Convert a static host API unique identifier, into a runtime
  222. host API index.
  223. @param type A unique host API identifier belonging to the PaHostApiTypeId
  224. enumeration.
  225. @return A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or,
  226. a PaErrorCode (which are always negative) if PortAudio is not initialized
  227. or an error is encountered.
  228. The paHostApiNotFound error code indicates that the host API specified by the
  229. type parameter is not available.
  230. @see PaHostApiTypeId
  231. */
  232. PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type );
  233. /** Convert a host-API-specific device index to standard PortAudio device index.
  234. This function may be used in conjunction with the deviceCount field of
  235. PaHostApiInfo to enumerate all devices for the specified host API.
  236. @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1)
  237. @param hostApiDeviceIndex A valid per-host device index in the range
  238. 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1)
  239. @return A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1)
  240. or, a PaErrorCode (which are always negative) if PortAudio is not initialized
  241. or an error is encountered.
  242. A paInvalidHostApi error code indicates that the host API index specified by
  243. the hostApi parameter is out of range.
  244. A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter
  245. is out of range.
  246. @see PaHostApiInfo
  247. */
  248. PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi,
  249. int hostApiDeviceIndex );
  250. /** Structure used to return information about a host error condition.
  251. */
  252. typedef struct PaHostErrorInfo{
  253. PaHostApiTypeId hostApiType; /**< the host API which returned the error code */
  254. long errorCode; /**< the error code returned */
  255. const char *errorText; /**< a textual description of the error if available, otherwise a zero-length string */
  256. }PaHostErrorInfo;
  257. /** Return information about the last host error encountered. The error
  258. information returned by Pa_GetLastHostErrorInfo() will never be modified
  259. asyncronously by errors occurring in other PortAudio owned threads
  260. (such as the thread that manages the stream callback.)
  261. This function is provided as a last resort, primarily to enhance debugging
  262. by providing clients with access to all available error information.
  263. @return A pointer to an immutable structure constaining information about
  264. the host error. The values in this structure will only be valid if a
  265. PortAudio function has previously returned the paUnanticipatedHostError
  266. error code.
  267. */
  268. const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void );
  269. /* Device enumeration and capabilities */
  270. /** Retrieve the number of available devices. The number of available devices
  271. may be zero.
  272. @return A non-negative value indicating the number of available devices or,
  273. a PaErrorCode (which are always negative) if PortAudio is not initialized
  274. or an error is encountered.
  275. */
  276. PaDeviceIndex Pa_GetDeviceCount( void );
  277. /** Retrieve the index of the default input device. The result can be
  278. used in the inputDevice parameter to Pa_OpenStream().
  279. @return The default input device index for the default host API, or paNoDevice
  280. if no default input device is available or an error was encountered.
  281. */
  282. PaDeviceIndex Pa_GetDefaultInputDevice( void );
  283. /** Retrieve the index of the default output device. The result can be
  284. used in the outputDevice parameter to Pa_OpenStream().
  285. @return The default output device index for the defualt host API, or paNoDevice
  286. if no default output device is available or an error was encountered.
  287. @note
  288. On the PC, the user can specify a default device by
  289. setting an environment variable. For example, to use device #1.
  290. <pre>
  291. set PA_RECOMMENDED_OUTPUT_DEVICE=1
  292. </pre>
  293. The user should first determine the available device ids by using
  294. the supplied application "pa_devs".
  295. */
  296. PaDeviceIndex Pa_GetDefaultOutputDevice( void );
  297. /** The type used to represent monotonic time in seconds that can be used
  298. for syncronisation. The type is used for the outTime argument to the
  299. PaStreamCallback and as the result of Pa_GetStreamTime().
  300. @see PaStreamCallback, Pa_GetStreamTime
  301. */
  302. typedef double PaTime;
  303. /** A type used to specify one or more sample formats. Each value indicates
  304. a possible format for sound data passed to and from the stream callback,
  305. Pa_ReadStream and Pa_WriteStream.
  306. The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8
  307. and aUInt8 are usually implemented by all implementations.
  308. The floating point representation (paFloat32) uses +1.0 and -1.0 as the
  309. maximum and minimum respectively.
  310. paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
  311. The paNonInterleaved flag indicates that a multichannel buffer is passed
  312. as a set of non-interleaved pointers.
  313. @see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo
  314. @see paFloat32, paInt16, paInt32, paInt24, paInt8
  315. @see paUInt8, paCustomFormat, paNonInterleaved
  316. */
  317. typedef unsigned long PaSampleFormat;
  318. #define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */
  319. #define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */
  320. #define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */
  321. #define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */
  322. #define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */
  323. #define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */
  324. #define paCustomFormat ((PaSampleFormat) 0x00010000)/**< @see PaSampleFormat */
  325. #define paNonInterleaved ((PaSampleFormat) 0x80000000)
  326. /** A structure providing information and capabilities of PortAudio devices.
  327. Devices may support input, output or both input and output.
  328. */
  329. typedef struct PaDeviceInfo
  330. {
  331. int structVersion; /* this is struct version 2 */
  332. const char *name;
  333. PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/
  334. int maxInputChannels;
  335. int maxOutputChannels;
  336. /* Default latency values for interactive performance. */
  337. PaTime defaultLowInputLatency;
  338. PaTime defaultLowOutputLatency;
  339. /* Default latency values for robust non-interactive applications (eg. playing sound files). */
  340. PaTime defaultHighInputLatency;
  341. PaTime defaultHighOutputLatency;
  342. double defaultSampleRate;
  343. } PaDeviceInfo;
  344. /** Retrieve a pointer to a PaDeviceInfo structure containing information
  345. about the specified device.
  346. @return A pointer to an immutable PaDeviceInfo structure. If the device
  347. parameter is out of range the function returns NULL.
  348. @param device A valid device index in the range 0 to (Pa_GetDeviceCount()-1)
  349. @note PortAudio manages the memory referenced by the returned pointer,
  350. the client must not manipulate or free the memory. The pointer is only
  351. guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate().
  352. @see PaDeviceInfo, PaDeviceIndex
  353. */
  354. const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
  355. /** Parameters for one direction (input or output) of a stream.
  356. */
  357. typedef struct PaStreamParameters
  358. {
  359. /** A valid device index in the range 0 to (Pa_GetDeviceCount()-1)
  360. specifying the device to be used or the special constant
  361. paUseHostApiSpecificDeviceSpecification which indicates that the actual
  362. device(s) to use are specified in hostApiSpecificStreamInfo.
  363. This field must not be set to paNoDevice.
  364. */
  365. PaDeviceIndex device;
  366. /** The number of channels of sound to be delivered to the
  367. stream callback or accessed by Pa_ReadStream() or Pa_WriteStream().
  368. It can range from 1 to the value of maxInputChannels in the
  369. PaDeviceInfo record for the device specified by the device parameter.
  370. */
  371. int channelCount;
  372. /** The sample format of the buffer provided to the stream callback,
  373. a_ReadStream() or Pa_WriteStream(). It may be any of the formats described
  374. by the PaSampleFormat enumeration.
  375. */
  376. PaSampleFormat sampleFormat;
  377. /** The desired latency in seconds. Where practical, implementations should
  378. configure their latency based on these parameters, otherwise they may
  379. choose the closest viable latency instead. Unless the suggested latency
  380. is greater than the absolute upper limit for the device implementations
  381. should round the suggestedLatency up to the next practial value - ie to
  382. provide an equal or higher latency than suggestedLatency wherever possibe.
  383. Actual latency values for an open stream may be retrieved using the
  384. inputLatency and outputLatency fields of the PaStreamInfo structure
  385. returned by Pa_GetStreamInfo().
  386. @see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo
  387. */
  388. PaTime suggestedLatency;
  389. /** An optional pointer to a host api specific data structure
  390. containing additional information for device setup and/or stream processing.
  391. hostApiSpecificStreamInfo is never required for correct operation,
  392. if not used it should be set to NULL.
  393. */
  394. void *hostApiSpecificStreamInfo;
  395. } PaStreamParameters;
  396. /** Return code for Pa_IsFormatSupported indicating success. */
  397. #define paFormatIsSupported (0)
  398. /** Determine whether it would be possible to open a stream with the specified
  399. parameters.
  400. @param inputParameters A structure that describes the input parameters used to
  401. open a stream. The suggestedLatency field is ignored. See PaStreamParameters
  402. for a description of these parameters. inputParameters must be NULL for
  403. output-only streams.
  404. @param outputParameters A structure that describes the output parameters used
  405. to open a stream. The suggestedLatency field is ignored. See PaStreamParameters
  406. for a description of these parameters. outputParameters must be NULL for
  407. input-only streams.
  408. @param sampleRate The required sampleRate. For full-duplex streams it is the
  409. sample rate for both input and output
  410. @return Returns 0 if the format is supported, and an error code indicating why
  411. the format is not supported otherwise. The constant paFormatIsSupported is
  412. provided to compare with the return value for success.
  413. @see paFormatIsSupported, PaStreamParameters
  414. */
  415. PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
  416. const PaStreamParameters *outputParameters,
  417. double sampleRate );
  418. /* Streaming types and functions */
  419. /**
  420. A single PaStream can provide multiple channels of real-time
  421. streaming audio input and output to a client application. A stream
  422. provides access to audio hardware represented by one or more
  423. PaDevices. Depending on the underlying Host API, it may be possible
  424. to open multiple streams using the same device, however this behavior
  425. is implementation defined. Portable applications should assume that
  426. a PaDevice may be simultaneously used by at most one PaStream.
  427. Pointers to PaStream objects are passed between PortAudio functions that
  428. operate on streams.
  429. @see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream,
  430. Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive,
  431. Pa_GetStreamTime, Pa_GetStreamCpuLoad
  432. */
  433. typedef void PaStream;
  434. /** Can be passed as the framesPerBuffer parameter to Pa_OpenStream()
  435. or Pa_OpenDefaultStream() to indicate that the stream callback will
  436. accept buffers of any size.
  437. */
  438. #define paFramesPerBufferUnspecified (0)
  439. /** Flags used to control the behavior of a stream. They are passed as
  440. parameters to Pa_OpenStream or Pa_OpenDefaultStream. Multiple flags may be
  441. ORed together.
  442. @see Pa_OpenStream, Pa_OpenDefaultStream
  443. @see paNoFlag, paClipOff, paDitherOff, paNeverDropInput,
  444. paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags
  445. */
  446. typedef unsigned long PaStreamFlags;
  447. /** @see PaStreamFlags */
  448. #define paNoFlag ((PaStreamFlags) 0)
  449. /** Disable default clipping of out of range samples.
  450. @see PaStreamFlags
  451. */
  452. #define paClipOff ((PaStreamFlags) 0x00000001)
  453. /** Disable default dithering.
  454. @see PaStreamFlags
  455. */
  456. #define paDitherOff ((PaStreamFlags) 0x00000002)
  457. /** Flag requests that where possible a full duplex stream will not discard
  458. overflowed input samples without calling the stream callback. This flag is
  459. only valid for full duplex callback streams and only when used in combination
  460. with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using
  461. this flag incorrectly results in a paInvalidFlag error being returned from
  462. Pa_OpenStream and Pa_OpenDefaultStream.
  463. @see PaStreamFlags, paFramesPerBufferUnspecified
  464. */
  465. #define paNeverDropInput ((PaStreamFlags) 0x00000004)
  466. /** Call the stream callback to fill initial output buffers, rather than the
  467. default behavior of priming the buffers with zeros (silence). This flag has
  468. no effect for input-only and blocking read/write streams.
  469. @see PaStreamFlags
  470. */
  471. #define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008)
  472. /** A mask specifying the platform specific bits.
  473. @see PaStreamFlags
  474. */
  475. #define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000)
  476. /**
  477. Timing information for the buffers passed to the stream callback.
  478. */
  479. typedef struct PaStreamCallbackTimeInfo{
  480. PaTime inputBufferAdcTime;
  481. PaTime currentTime;
  482. PaTime outputBufferDacTime;
  483. } PaStreamCallbackTimeInfo;
  484. /**
  485. Flag bit constants for the statusFlags to PaStreamCallback.
  486. @see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow,
  487. paPrimingOutput
  488. */
  489. typedef unsigned long PaStreamCallbackFlags;
  490. /** In a stream opened with paFramesPerBufferUnspecified, indicates that
  491. input data is all silence (zeros) because no real data is available. In a
  492. stream opened without paFramesPerBufferUnspecified, it indicates that one or
  493. more zero samples have been inserted into the input buffer to compensate
  494. for an input underflow.
  495. @see PaStreamCallbackFlags
  496. */
  497. #define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001)
  498. /** In a stream opened with paFramesPerBufferUnspecified, indicates that data
  499. prior to the first sample of the input buffer was discarded due to an
  500. overflow, possibly because the stream callback is using too much CPU time.
  501. Otherwise indicates that data prior to one or more samples in the
  502. input buffer was discarded.
  503. @see PaStreamCallbackFlags
  504. */
  505. #define paInputOverflow ((PaStreamCallbackFlags) 0x00000002)
  506. /** Indicates that output data (or a gap) was inserted, possibly because the
  507. stream callback is using too much CPU time.
  508. @see PaStreamCallbackFlags
  509. */
  510. #define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004)
  511. /** Indicates that output data will be discarded because no room is available.
  512. @see PaStreamCallbackFlags
  513. */
  514. #define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008)
  515. /** Some of all of the output data will be used to prime the stream, input
  516. data may be zero.
  517. @see PaStreamCallbackFlags
  518. */
  519. #define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010)
  520. /**
  521. Allowable return values for the PaStreamCallback.
  522. @see PaStreamCallback
  523. */
  524. typedef enum PaStreamCallbackResult
  525. {
  526. paContinue=0,
  527. paComplete=1,
  528. paAbort=2
  529. } PaStreamCallbackResult;
  530. /**
  531. Functions of type PaStreamCallback are implemented by PortAudio clients.
  532. They consume, process or generate audio in response to requests from an
  533. active PortAudio stream.
  534. @param input and @param output are arrays of interleaved samples,
  535. the format, packing and number of channels used by the buffers are
  536. determined by parameters to Pa_OpenStream().
  537. @param frameCount The number of sample frames to be processed by
  538. the stream callback.
  539. @param timeInfo The time in seconds when the first sample of the input
  540. buffer was received at the audio input, the time in seconds when the first
  541. sample of the output buffer will begin being played at the audio output, and
  542. the time in seconds when the stream callback was called.
  543. See also Pa_GetStreamTime()
  544. @param statusFlags Flags indicating whether input and/or output buffers
  545. have been inserted or will be dropped to overcome underflow or overflow
  546. conditions.
  547. @param userData The value of a user supplied pointer passed to
  548. Pa_OpenStream() intended for storing synthesis data etc.
  549. @return
  550. The stream callback should return one of the values in the
  551. PaStreamCallbackResult enumeration. To ensure that the callback continues
  552. to be called, it should return paContinue (0). Either paComplete or paAbort
  553. can be returned to finish stream processing, after either of these values is
  554. returned the callback will not be called again. If paAbort is returned the
  555. stream will finish as soon as possible. If paComplete is returned, the stream
  556. will continue until all buffers generated by the callback have been played.
  557. This may be useful in applications such as soundfile players where a specific
  558. duration of output is required. However, it is not necessary to utilise this
  559. mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also
  560. be used to stop the stream. The callback must always fill the entire output
  561. buffer irrespective of its return value.
  562. @see Pa_OpenStream, Pa_OpenDefaultStream
  563. @note With the exception of Pa_GetStreamCpuLoad() it is not permissable to call
  564. PortAudio API functions from within the stream callback.
  565. */
  566. typedef int PaStreamCallback(
  567. const void *input, void *output,
  568. unsigned long frameCount,
  569. const PaStreamCallbackTimeInfo* timeInfo,
  570. PaStreamCallbackFlags statusFlags,
  571. void *userData );
  572. /** Opens a stream for either input, output or both.
  573. @param stream The address of a PaStream pointer which will receive
  574. a pointer to the newly opened stream.
  575. @param inputParameters A structure that describes the input parameters used by
  576. the opened stream. See PaStreamParameters for a description of these parameters.
  577. inputParameters must be NULL for output-only streams.
  578. @param outputParameters A structure that describes the output parameters used by
  579. the opened stream. See PaStreamParameters for a description of these parameters.
  580. outputParameters must be NULL for input-only streams.
  581. @param sampleRate The desired sampleRate. For full-duplex streams it is the
  582. sample rate for both input and output
  583. @param framesPerBuffer The number of frames passed to the stream callback
  584. function, or the preferred block granularity for a blocking read/write stream.
  585. The special value paFramesPerBufferUnspecified (0) may be used to request that
  586. the stream callback will recieve an optimal (and possibly varying) number of
  587. frames based on host requirements and the requested latency settings.
  588. Note: With some host APIs, the use of non-zero framesPerBuffer for a callback
  589. stream may introduce an additional layer of buffering which could introduce
  590. additional latency. PortAudio guarantees that the additional latency
  591. will be kept to the theoretical minimum however, it is strongly recommended
  592. that a non-zero framesPerBuffer value only be used when your algorithm
  593. requires a fixed number of frames per stream callback.
  594. @param streamFlags Flags which modify the behaviour of the streaming process.
  595. This parameter may contain a combination of flags ORed together. Some flags may
  596. only be relevant to certain buffer formats.
  597. @param streamCallback A pointer to a client supplied function that is responsible
  598. for processing and filling input and output buffers. If this parameter is NULL
  599. the stream will be opened in 'blocking read/write' mode. In blocking mode,
  600. the client can receive sample data using Pa_ReadStream and write sample data
  601. using Pa_WriteStream, the number of samples that may be read or written
  602. without blocking is returned by Pa_GetStreamReadAvailable and
  603. Pa_GetStreamWriteAvailable respectively.
  604. @param userData A client supplied pointer which is passed to the stream callback
  605. function. It could for example, contain a pointer to instance data necessary
  606. for processing the audio buffers. This parameter is ignored if streamCallback
  607. is NULL.
  608. @return
  609. Upon success Pa_OpenStream() returns paNoError and places a pointer to a
  610. valid PaStream in the stream argument. The stream is inactive (stopped).
  611. If a call to Pa_OpenStream() fails, a non-zero error code is returned (see
  612. PaError for possible error codes) and the value of stream is invalid.
  613. @see PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream,
  614. Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable
  615. */
  616. PaError Pa_OpenStream( PaStream** stream,
  617. const PaStreamParameters *inputParameters,
  618. const PaStreamParameters *outputParameters,
  619. double sampleRate,
  620. unsigned long framesPerBuffer,
  621. PaStreamFlags streamFlags,
  622. PaStreamCallback *streamCallback,
  623. void *userData );
  624. /** A simplified version of Pa_OpenStream() that opens the default input
  625. and/or output devices.
  626. @param stream The address of a PaStream pointer which will receive
  627. a pointer to the newly opened stream.
  628. @param numInputChannels The number of channels of sound that will be supplied
  629. to the stream callback or returned by Pa_ReadStream. It can range from 1 to
  630. the value of maxInputChannels in the PaDeviceInfo record for the default input
  631. device. If 0 the stream is opened as an output-only stream.
  632. @param numOutputChannels The number of channels of sound to be delivered to the
  633. stream callback or passed to Pa_WriteStream. It can range from 1 to the value
  634. of maxOutputChannels in the PaDeviceInfo record for the default output dvice.
  635. If 0 the stream is opened as an output-only stream.
  636. @param sampleFormat The sample format of both the input and output buffers
  637. provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream.
  638. sampleFormat may be any of the formats described by the PaSampleFormat
  639. enumeration.
  640. @param sampleRate Same as Pa_OpenStream parameter of the same name.
  641. @param framesPerBuffer Same as Pa_OpenStream parameter of the same name.
  642. @param streamCallback Same as Pa_OpenStream parameter of the same name.
  643. @param userData Same as Pa_OpenStream parameter of the same name.
  644. @return As for Pa_OpenStream
  645. @see Pa_OpenStream, PaStreamCallback
  646. */
  647. PaError Pa_OpenDefaultStream( PaStream** stream,
  648. int numInputChannels,
  649. int numOutputChannels,
  650. PaSampleFormat sampleFormat,
  651. double sampleRate,
  652. unsigned long framesPerBuffer,
  653. PaStreamCallback *streamCallback,
  654. void *userData );
  655. /** Closes an audio stream. If the audio stream is active it
  656. discards any pending buffers as if Pa_AbortStream() had been called.
  657. */
  658. PaError Pa_CloseStream( PaStream *stream );
  659. /** Functions of type PaStreamFinishedCallback are implemented by PortAudio
  660. clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback
  661. function. Once registered they are called when the stream becomes inactive
  662. (ie once a call to Pa_StopStream() will not block).
  663. A stream will become inactive after the stream callback returns non-zero,
  664. or when Pa_StopStream or Pa_AbortStream is called. For a stream providing audio
  665. output, if the stream callback returns paComplete, or Pa_StopStream is called,
  666. the stream finished callback will not be called until all generated sample data
  667. has been played.
  668. @param userData The userData parameter supplied to Pa_OpenStream()
  669. @see Pa_SetStreamFinishedCallback
  670. */
  671. typedef void PaStreamFinishedCallback( void *userData );
  672. /** Register a stream finished callback function which will be called when the
  673. stream becomes inactive. See the description of PaStreamFinishedCallback for
  674. further details about when the callback will be called.
  675. @param stream a pointer to a PaStream that is in the stopped state - if the
  676. stream is not stopped, the stream's finished callback will remain unchanged
  677. and an error code will be returned.
  678. @param streamFinishedCallback a pointer to a function with the same signature
  679. as PaStreamFinishedCallback, that will be called when the stream becomes
  680. inactive. Passing NULL for this parameter will un-register a previously
  681. registered stream finished callback function.
  682. @return on success returns paNoError, otherwise an error code indicating the cause
  683. of the error.
  684. @see PaStreamFinishedCallback
  685. */
  686. PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback );
  687. /** Commences audio processing.
  688. */
  689. PaError Pa_StartStream( PaStream *stream );
  690. /** Terminates audio processing. It waits until all pending
  691. audio buffers have been played before it returns.
  692. */
  693. PaError Pa_StopStream( PaStream *stream );
  694. /** Terminates audio processing immediately without waiting for pending
  695. buffers to complete.
  696. */
  697. PaError Pa_AbortStream( PaStream *stream );
  698. /** Determine whether the stream is stopped.
  699. A stream is considered to be stopped prior to a successful call to
  700. Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream.
  701. If a stream callback returns a value other than paContinue the stream is NOT
  702. considered to be stopped.
  703. @return Returns one (1) when the stream is stopped, zero (0) when
  704. the stream is running or, a PaErrorCode (which are always negative) if
  705. PortAudio is not initialized or an error is encountered.
  706. @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive
  707. */
  708. PaError Pa_IsStreamStopped( PaStream *stream );
  709. /** Determine whether the stream is active.
  710. A stream is active after a successful call to Pa_StartStream(), until it
  711. becomes inactive either as a result of a call to Pa_StopStream() or
  712. Pa_AbortStream(), or as a result of a return value other than paContinue from
  713. the stream callback. In the latter case, the stream is considered inactive
  714. after the last buffer has finished playing.
  715. @return Returns one (1) when the stream is active (ie playing or recording
  716. audio), zero (0) when not playing or, a PaErrorCode (which are always negative)
  717. if PortAudio is not initialized or an error is encountered.
  718. @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped
  719. */
  720. PaError Pa_IsStreamActive( PaStream *stream );
  721. /** A structure containing unchanging information about an open stream.
  722. @see Pa_GetStreamInfo
  723. */
  724. typedef struct PaStreamInfo
  725. {
  726. /** this is struct version 1 */
  727. int structVersion;
  728. /** The input latency of the stream in seconds. This value provides the most
  729. accurate estimate of input latency available to the implementation. It may
  730. differ significantly from the suggestedLatency value passed to Pa_OpenStream().
  731. The value of this field will be zero (0.) for output-only streams.
  732. @see PaTime
  733. */
  734. PaTime inputLatency;
  735. /** The output latency of the stream in seconds. This value provides the most
  736. accurate estimate of output latency available to the implementation. It may
  737. differ significantly from the suggestedLatency value passed to Pa_OpenStream().
  738. The value of this field will be zero (0.) for input-only streams.
  739. @see PaTime
  740. */
  741. PaTime outputLatency;
  742. /** The sample rate of the stream in Hertz (samples per second). In cases
  743. where the hardware sample rate is inaccurate and PortAudio is aware of it,
  744. the value of this field may be different from the sampleRate parameter
  745. passed to Pa_OpenStream(). If information about the actual hardware sample
  746. rate is not available, this field will have the same value as the sampleRate
  747. parameter passed to Pa_OpenStream().
  748. */
  749. double sampleRate;
  750. } PaStreamInfo;
  751. /** Retrieve a pointer to a PaStreamInfo structure containing information
  752. about the specified stream.
  753. @return A pointer to an immutable PaStreamInfo structure. If the stream
  754. parameter invalid, or an error is encountered, the function returns NULL.
  755. @param stream A pointer to an open stream previously created with Pa_OpenStream.
  756. @note PortAudio manages the memory referenced by the returned pointer,
  757. the client must not manipulate or free the memory. The pointer is only
  758. guaranteed to be valid until the specified stream is closed.
  759. @see PaStreamInfo
  760. */
  761. const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream );
  762. /** Determine the current time for the stream according to the same clock used
  763. to generate buffer timestamps. This time may be used for syncronising other
  764. events to the audio stream, for example synchronizing audio to MIDI.
  765. @return The stream's current time in seconds, or 0 if an error occurred.
  766. @see PaTime, PaStreamCallback
  767. */
  768. PaTime Pa_GetStreamTime( PaStream *stream );
  769. /** Retrieve CPU usage information for the specified stream.
  770. The "CPU Load" is a fraction of total CPU time consumed by a callback stream's
  771. audio processing routines including, but not limited to the client supplied
  772. stream callback. This function does not work with blocking read/write streams.
  773. This function may be called from the stream callback function or the
  774. application.
  775. @return
  776. A floating point value, typically between 0.0 and 1.0, where 1.0 indicates
  777. that the stream callback is consuming the maximum number of CPU cycles possible
  778. to maintain real-time operation. A value of 0.5 would imply that PortAudio and
  779. the stream callback was consuming roughly 50% of the available CPU time. The
  780. return value may exceed 1.0. A value of 0.0 will always be returned for a
  781. blocking read/write stream, or if an error occurrs.
  782. */
  783. double Pa_GetStreamCpuLoad( PaStream* stream );
  784. /** Read samples from an input stream. The function doesn't return until
  785. the entire buffer has been filled - this may involve waiting for the operating
  786. system to supply the data.
  787. @param stream A pointer to an open stream previously created with Pa_OpenStream.
  788. @param buffer A pointer to a buffer of sample frames. The buffer contains
  789. samples in the format specified by the inputParameters->sampleFormat field
  790. used to open the stream, and the number of channels specified by
  791. inputParameters->numChannels. If non-interleaved samples were requested,
  792. buffer is a pointer to the first element of an array of non-interleaved
  793. buffer pointers, one for each channel.
  794. @param frames The number of frames to be read into buffer. This parameter
  795. is not constrained to a specific range, however high performance applications
  796. will want to match this parameter to the framesPerBuffer parameter used
  797. when opening the stream.
  798. @return On success PaNoError will be returned, or PaInputOverflowed if input
  799. data was discarded by PortAudio after the previous call and before this call.
  800. */
  801. PaError Pa_ReadStream( PaStream* stream,
  802. void *buffer,
  803. unsigned long frames );
  804. /** Write samples to an output stream. This function doesn't return until the
  805. entire buffer has been consumed - this may involve waiting for the operating
  806. system to consume the data.
  807. @param stream A pointer to an open stream previously created with Pa_OpenStream.
  808. @param buffer A pointer to a buffer of sample frames. The buffer contains
  809. samples in the format specified by the outputParameters->sampleFormat field
  810. used to open the stream, and the number of channels specified by
  811. outputParameters->numChannels. If non-interleaved samples were requested,
  812. buffer is a pointer to the first element of an array of non-interleaved
  813. buffer pointers, one for each channel.
  814. @param frames The number of frames to be written from buffer. This parameter
  815. is not constrained to a specific range, however high performance applications
  816. will want to match this parameter to the framesPerBuffer parameter used
  817. when opening the stream.
  818. @return On success PaNoError will be returned, or paOutputUnderflowed if
  819. additional output data was inserted after the previous call and before this
  820. call.
  821. */
  822. PaError Pa_WriteStream( PaStream* stream,
  823. const void *buffer,
  824. unsigned long frames );
  825. /** Retrieve the number of frames that can be read from the stream without
  826. waiting.
  827. @return Returns a non-negative value representing the maximum number of frames
  828. that can be read from the stream without blocking or busy waiting or, a
  829. PaErrorCode (which are always negative) if PortAudio is not initialized or an
  830. error is encountered.
  831. */
  832. signed long Pa_GetStreamReadAvailable( PaStream* stream );
  833. /** Retrieve the number of frames that can be written to the stream without
  834. waiting.
  835. @return Returns a non-negative value representing the maximum number of frames
  836. that can be written to the stream without blocking or busy waiting or, a
  837. PaErrorCode (which are always negative) if PortAudio is not initialized or an
  838. error is encountered.
  839. */
  840. signed long Pa_GetStreamWriteAvailable( PaStream* stream );
  841. /* Miscellaneous utilities */
  842. /** Retrieve the size of a given sample format in bytes.
  843. @return The size in bytes of a single sample in the specified format,
  844. or paSampleFormatNotSupported if the format is not supported.
  845. */
  846. PaError Pa_GetSampleSize( PaSampleFormat format );
  847. /** Put the caller to sleep for at least 'msec' milliseconds. This function is
  848. provided only as a convenience for authors of portable code (such as the tests
  849. and examples in the PortAudio distribution.)
  850. The function may sleep longer than requested so don't rely on this for accurate
  851. musical timing.
  852. */
  853. void Pa_Sleep( long msec );
  854. #ifdef __cplusplus
  855. }
  856. #endif /* __cplusplus */
  857. #endif /* PORTAUDIO_H */