portaudio.h 47 KB

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