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.

956 lines
38KB

  1. //---------------------------------------------------------------------------------------------------
  2. //---------------------------------------------------------------------------------------------------
  3. /*
  4. Steinberg Audio Stream I/O API
  5. (c) 1997 - 1999, Steinberg Soft- und Hardware GmbH
  6. ASIO Interface Specification v 2.0
  7. basic concept is an i/o synchronous double-buffer scheme:
  8. on bufferSwitch(index == 0), host will read/write:
  9. after ASIOStart(), the
  10. read first input buffer A (index 0)
  11. | will be invalid (empty)
  12. * ------------------------
  13. |------------------------|-----------------------|
  14. | | |
  15. | Input Buffer A (0) | Input Buffer B (1) |
  16. | | |
  17. |------------------------|-----------------------|
  18. | | |
  19. | Output Buffer A (0) | Output Buffer B (1) |
  20. | | |
  21. |------------------------|-----------------------|
  22. * -------------------------
  23. | before calling ASIOStart(),
  24. write host will have filled output
  25. buffer B (index 1) already
  26. *please* take special care of proper statement of input
  27. and output latencies (see ASIOGetLatencies()), these
  28. control sequencer sync accuracy
  29. */
  30. //---------------------------------------------------------------------------------------------------
  31. //---------------------------------------------------------------------------------------------------
  32. /*
  33. prototypes summary:
  34. ASIOError ASIOInit(ASIODriverInfo *info);
  35. ASIOError ASIOExit(void);
  36. ASIOError ASIOStart(void);
  37. ASIOError ASIOStop(void);
  38. ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels);
  39. ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency);
  40. ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);
  41. ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate);
  42. ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate);
  43. ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate);
  44. ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources);
  45. ASIOError ASIOSetClockSource(long reference);
  46. ASIOError ASIOGetSamplePosition (ASIOSamples *sPos, ASIOTimeStamp *tStamp);
  47. ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info);
  48. ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
  49. long bufferSize, ASIOCallbacks *callbacks);
  50. ASIOError ASIODisposeBuffers(void);
  51. ASIOError ASIOControlPanel(void);
  52. void *ASIOFuture(long selector, void *params);
  53. ASIOError ASIOOutputReady(void);
  54. */
  55. //---------------------------------------------------------------------------------------------------
  56. //---------------------------------------------------------------------------------------------------
  57. #ifndef __ASIO_H
  58. #define __ASIO_H
  59. // force 4 byte alignment
  60. #if defined(_MSC_VER) && !defined(__MWERKS__)
  61. #pragma pack(push,4)
  62. #elif PRAGMA_ALIGN_SUPPORTED
  63. #pragma options align = native
  64. #endif
  65. //- - - - - - - - - - - - - - - - - - - - - - - - -
  66. // Type definitions
  67. //- - - - - - - - - - - - - - - - - - - - - - - - -
  68. // number of samples data type is 64 bit integer
  69. #if NATIVE_INT64
  70. typedef long long int ASIOSamples;
  71. #else
  72. typedef struct ASIOSamples {
  73. unsigned long hi;
  74. unsigned long lo;
  75. } ASIOSamples;
  76. #endif
  77. // Timestamp data type is 64 bit integer,
  78. // Time format is Nanoseconds.
  79. #if NATIVE_INT64
  80. typedef long long int ASIOTimeStamp ;
  81. #else
  82. typedef struct ASIOTimeStamp {
  83. unsigned long hi;
  84. unsigned long lo;
  85. } ASIOTimeStamp;
  86. #endif
  87. // Samplerates are expressed in IEEE 754 64 bit double float,
  88. // native format as host computer
  89. #if IEEE754_64FLOAT
  90. typedef double ASIOSampleRate;
  91. #else
  92. typedef struct ASIOSampleRate {
  93. char ieee[8];
  94. } ASIOSampleRate;
  95. #endif
  96. // Boolean values are expressed as long
  97. typedef long ASIOBool;
  98. enum {
  99. ASIOFalse = 0,
  100. ASIOTrue = 1
  101. };
  102. // Sample Types are expressed as long
  103. typedef long ASIOSampleType;
  104. enum {
  105. ASIOSTInt16MSB = 0,
  106. ASIOSTInt24MSB = 1, // used for 20 bits as well
  107. ASIOSTInt32MSB = 2,
  108. ASIOSTFloat32MSB = 3, // IEEE 754 32 bit float
  109. ASIOSTFloat64MSB = 4, // IEEE 754 64 bit double float
  110. // these are used for 32 bit data buffer, with different alignment of the data inside
  111. // 32 bit PCI bus systems can be more easily used with these
  112. ASIOSTInt32MSB16 = 8, // 32 bit data with 18 bit alignment
  113. ASIOSTInt32MSB18 = 9, // 32 bit data with 18 bit alignment
  114. ASIOSTInt32MSB20 = 10, // 32 bit data with 20 bit alignment
  115. ASIOSTInt32MSB24 = 11, // 32 bit data with 24 bit alignment
  116. ASIOSTInt16LSB = 16,
  117. ASIOSTInt24LSB = 17, // used for 20 bits as well
  118. ASIOSTInt32LSB = 18,
  119. ASIOSTFloat32LSB = 19, // IEEE 754 32 bit float, as found on Intel x86 architecture
  120. ASIOSTFloat64LSB = 20, // IEEE 754 64 bit double float, as found on Intel x86 architecture
  121. // these are used for 32 bit data buffer, with different alignment of the data inside
  122. // 32 bit PCI bus systems can more easily used with these
  123. ASIOSTInt32LSB16 = 24, // 32 bit data with 18 bit alignment
  124. ASIOSTInt32LSB18 = 25, // 32 bit data with 18 bit alignment
  125. ASIOSTInt32LSB20 = 26, // 32 bit data with 20 bit alignment
  126. ASIOSTInt32LSB24 = 27 // 32 bit data with 24 bit alignment
  127. };
  128. //- - - - - - - - - - - - - - - - - - - - - - - - -
  129. // Error codes
  130. //- - - - - - - - - - - - - - - - - - - - - - - - -
  131. typedef long ASIOError;
  132. enum {
  133. ASE_OK = 0, // This value will be returned whenever the call succeeded
  134. ASE_SUCCESS = 0x3f4847a0, // unique success return value for ASIOFuture calls
  135. ASE_NotPresent = -1000, // hardware input or output is not present or available
  136. ASE_HWMalfunction, // hardware is malfunctioning (can be returned by any ASIO function)
  137. ASE_InvalidParameter, // input parameter invalid
  138. ASE_InvalidMode, // hardware is in a bad mode or used in a bad mode
  139. ASE_SPNotAdvancing, // hardware is not running when sample position is inquired
  140. ASE_NoClock, // sample clock or rate cannot be determined or is not present
  141. ASE_NoMemory // not enough memory for completing the request
  142. };
  143. //---------------------------------------------------------------------------------------------------
  144. //---------------------------------------------------------------------------------------------------
  145. //- - - - - - - - - - - - - - - - - - - - - - - - -
  146. // Time Info support
  147. //- - - - - - - - - - - - - - - - - - - - - - - - -
  148. typedef struct ASIOTimeCode
  149. {
  150. double speed; // speed relation (fraction of nominal speed)
  151. // optional; set to 0. or 1. if not supported
  152. ASIOSamples timeCodeSamples; // time in samples
  153. unsigned long flags; // some information flags (see below)
  154. char future[64];
  155. } ASIOTimeCode;
  156. typedef enum ASIOTimeCodeFlags
  157. {
  158. kTcValid = 1,
  159. kTcRunning = 1 << 1,
  160. kTcReverse = 1 << 2,
  161. kTcOnspeed = 1 << 3,
  162. kTcStill = 1 << 4,
  163. kTcSpeedValid = 1 << 8
  164. } ASIOTimeCodeFlags;
  165. typedef struct AsioTimeInfo
  166. {
  167. double speed; // absolute speed (1. = nominal)
  168. ASIOTimeStamp systemTime; // system time related to samplePosition, in nanoseconds
  169. // on mac, must be derived from Microseconds() (not UpTime()!)
  170. // on windows, must be derived from timeGetTime()
  171. ASIOSamples samplePosition;
  172. ASIOSampleRate sampleRate; // current rate
  173. unsigned long flags; // (see below)
  174. char reserved[12];
  175. } AsioTimeInfo;
  176. typedef enum AsioTimeInfoFlags
  177. {
  178. kSystemTimeValid = 1, // must always be valid
  179. kSamplePositionValid = 1 << 1, // must always be valid
  180. kSampleRateValid = 1 << 2,
  181. kSpeedValid = 1 << 3,
  182. kSampleRateChanged = 1 << 4,
  183. kClockSourceChanged = 1 << 5
  184. } AsioTimeInfoFlags;
  185. typedef struct ASIOTime // both input/output
  186. {
  187. long reserved[4]; // must be 0
  188. struct AsioTimeInfo timeInfo; // required
  189. struct ASIOTimeCode timeCode; // optional, evaluated if (timeCode.flags & kTcValid)
  190. } ASIOTime;
  191. /*
  192. using time info:
  193. it is recommended to use the new method with time info even if the asio
  194. device does not support timecode; continuous calls to ASIOGetSamplePosition
  195. and ASIOGetSampleRate are avoided, and there is a more defined relationship
  196. between callback time and the time info.
  197. see the example below.
  198. to initiate time info mode, after you have received the callbacks pointer in
  199. ASIOCreateBuffers, you will call the asioMessage callback with kAsioSupportsTimeInfo
  200. as the argument. if this returns 1, host has accepted time info mode.
  201. now host expects the new callback bufferSwitchTimeInfo to be used instead
  202. of the old bufferSwitch method. the ASIOTime structure is assumed to be valid
  203. and accessible until the callback returns.
  204. using time code:
  205. if the device supports reading time code, it will call host's asioMessage callback
  206. with kAsioSupportsTimeCode as the selector. it may then fill the according
  207. fields and set the kTcValid flag.
  208. host will call the future method with the kAsioEnableTimeCodeRead selector when
  209. it wants to enable or disable tc reading by the device. you should also support
  210. the kAsioCanTimeInfo and kAsioCanTimeCode selectors in ASIOFuture (see example).
  211. note:
  212. the AsioTimeInfo/ASIOTimeCode pair is supposed to work in both directions.
  213. as a matter of convention, the relationship between the sample
  214. position counter and the time code at buffer switch time is
  215. (ignoring offset between tc and sample pos when tc is running):
  216. on input: sample 0 -> input buffer sample 0 -> time code 0
  217. on output: sample 0 -> output buffer sample 0 -> time code 0
  218. this means that for 'real' calculations, one has to take into account
  219. the according latencies.
  220. example:
  221. ASIOTime asioTime;
  222. in createBuffers()
  223. {
  224. memset(&asioTime, 0, sizeof(ASIOTime));
  225. AsioTimeInfo* ti = &asioTime.timeInfo;
  226. ti->sampleRate = theSampleRate;
  227. ASIOTimeCode* tc = &asioTime.timeCode;
  228. tc->speed = 1.;
  229. timeInfoMode = false;
  230. canTimeCode = false;
  231. if(callbacks->asioMessage(kAsioSupportsTimeInfo, 0, 0, 0) == 1)
  232. {
  233. timeInfoMode = true;
  234. #if kCanTimeCode
  235. if(callbacks->asioMessage(kAsioSupportsTimeCode, 0, 0, 0) == 1)
  236. canTimeCode = true;
  237. #endif
  238. }
  239. }
  240. void switchBuffers(long doubleBufferIndex, bool processNow)
  241. {
  242. if(timeInfoMode)
  243. {
  244. AsioTimeInfo* ti = &asioTime.timeInfo;
  245. ti->flags = kSystemTimeValid | kSamplePositionValid | kSampleRateValid;
  246. ti->systemTime = theNanoSeconds;
  247. ti->samplePosition = theSamplePosition;
  248. if(ti->sampleRate != theSampleRate)
  249. ti->flags |= kSampleRateChanged;
  250. ti->sampleRate = theSampleRate;
  251. #if kCanTimeCode
  252. if(canTimeCode && timeCodeEnabled)
  253. {
  254. ASIOTimeCode* tc = &asioTime.timeCode;
  255. tc->timeCodeSamples = tcSamples; // tc in samples
  256. tc->flags = kTcValid | kTcRunning | kTcOnspeed; // if so...
  257. }
  258. ASIOTime* bb = callbacks->bufferSwitchTimeInfo(&asioTime, doubleBufferIndex, processNow ? ASIOTrue : ASIOFalse);
  259. #else
  260. callbacks->bufferSwitchTimeInfo(&asioTime, doubleBufferIndex, processNow ? ASIOTrue : ASIOFalse);
  261. #endif
  262. }
  263. else
  264. callbacks->bufferSwitch(doubleBufferIndex, ASIOFalse);
  265. }
  266. ASIOError ASIOFuture(long selector, void *params)
  267. {
  268. switch(selector)
  269. {
  270. case kAsioEnableTimeCodeRead:
  271. timeCodeEnabled = true;
  272. return ASE_SUCCESS;
  273. case kAsioDisableTimeCodeRead:
  274. timeCodeEnabled = false;
  275. return ASE_SUCCESS;
  276. case kAsioCanTimeInfo:
  277. return ASE_SUCCESS;
  278. #if kCanTimeCode
  279. case kAsioCanTimeCode:
  280. return ASE_SUCCESS;
  281. #endif
  282. }
  283. return ASE_NotPresent;
  284. };
  285. */
  286. //- - - - - - - - - - - - - - - - - - - - - - - - -
  287. // application's audio stream handler callbacks
  288. //- - - - - - - - - - - - - - - - - - - - - - - - -
  289. typedef struct ASIOCallbacks
  290. {
  291. void (*bufferSwitch) (long doubleBufferIndex, ASIOBool directProcess);
  292. // bufferSwitch indicates that both input and output are to be processed.
  293. // the current buffer half index (0 for A, 1 for B) determines
  294. // - the output buffer that the host should start to fill. the other buffer
  295. // will be passed to output hardware regardless of whether it got filled
  296. // in time or not.
  297. // - the input buffer that is now filled with incoming data. Note that
  298. // because of the synchronicity of i/o, the input always has at
  299. // least one buffer latency in relation to the output.
  300. // directProcess suggests to the host whether it should immedeately
  301. // start processing (directProcess == ASIOTrue), or whether its process
  302. // should be deferred because the call comes from a very low level
  303. // (for instance, a high level priority interrupt), and direct processing
  304. // would cause timing instabilities for the rest of the system. If in doubt,
  305. // directProcess should be set to ASIOFalse.
  306. // Note: bufferSwitch may be called at interrupt time for highest efficiency.
  307. void (*sampleRateDidChange) (ASIOSampleRate sRate);
  308. // gets called when the AudioStreamIO detects a sample rate change
  309. // If sample rate is unknown, 0 is passed (for instance, clock loss
  310. // when externally synchronized).
  311. long (*asioMessage) (long selector, long value, void* message, double* opt);
  312. // generic callback for various purposes, see selectors below.
  313. // note this is only present if the asio version is 2 or higher
  314. ASIOTime* (*bufferSwitchTimeInfo) (ASIOTime* params, long doubleBufferIndex, ASIOBool directProcess);
  315. // new callback with time info. makes ASIOGetSamplePosition() and various
  316. // calls to ASIOGetSampleRate obsolete,
  317. // and allows for timecode sync etc. to be preferred; will be used if
  318. // the driver calls asioMessage with selector kAsioSupportsTimeInfo.
  319. } ASIOCallbacks;
  320. // asioMessage selectors
  321. enum
  322. {
  323. kAsioSelectorSupported = 1, // selector in <value>, returns 1L if supported,
  324. // 0 otherwise
  325. kAsioEngineVersion, // returns engine (host) asio implementation version,
  326. // 2 or higher
  327. kAsioResetRequest, // request driver reset. if accepted, this
  328. // will close the driver (ASIO_Exit() ) and
  329. // re-open it again (ASIO_Init() etc). some
  330. // drivers need to reconfigure for instance
  331. // when the sample rate changes, or some basic
  332. // changes have been made in ASIO_ControlPanel().
  333. // returns 1L; note the request is merely passed
  334. // to the application, there is no way to determine
  335. // if it gets accepted at this time (but it usually
  336. // will be).
  337. kAsioBufferSizeChange, // not yet supported, will currently always return 0L.
  338. // for now, use kAsioResetRequest instead.
  339. // once implemented, the new buffer size is expected
  340. // in <value>, and on success returns 1L
  341. kAsioResyncRequest, // the driver went out of sync, such that
  342. // the timestamp is no longer valid. this
  343. // is a request to re-start the engine and
  344. // slave devices (sequencer). returns 1 for ok,
  345. // 0 if not supported.
  346. kAsioLatenciesChanged, // the drivers latencies have changed. The engine
  347. // will refetch the latencies.
  348. kAsioSupportsTimeInfo, // if host returns true here, it will expect the
  349. // callback bufferSwitchTimeInfo to be called instead
  350. // of bufferSwitch
  351. kAsioSupportsTimeCode, // supports time code reading/writing
  352. kAsioSupportsInputMonitor, // supports input monitoring
  353. kAsioNumMessageSelectors
  354. };
  355. //---------------------------------------------------------------------------------------------------
  356. //---------------------------------------------------------------------------------------------------
  357. //- - - - - - - - - - - - - - - - - - - - - - - - -
  358. // (De-)Construction
  359. //- - - - - - - - - - - - - - - - - - - - - - - - -
  360. typedef struct ASIODriverInfo
  361. {
  362. long asioVersion; // currently, 2
  363. long driverVersion; // driver specific
  364. char name[32];
  365. char errorMessage[124];
  366. void *sysRef; // on input: system reference
  367. // (Windows: application main window handle, Mac & SGI: 0)
  368. } ASIODriverInfo;
  369. ASIOError ASIOInit(ASIODriverInfo *info);
  370. /* Purpose:
  371. Initialize the AudioStreamIO.
  372. Parameter:
  373. info: pointer to an ASIODriver structure:
  374. - asioVersion:
  375. - on input, the host version. *** Note *** this is 0 for earlier asio
  376. implementations, and the asioMessage callback is implemeted
  377. only if asioVersion is 2 or greater. sorry but due to a design fault
  378. the driver doesn't have access to the host version in ASIOInit :-(
  379. added selector for host (engine) version in the asioMessage callback
  380. so we're ok from now on.
  381. - on return, asio implementation version.
  382. older versions are 1
  383. if you support this version (namely, ASIO_outputReady() )
  384. this should be 2 or higher. also see the note in
  385. ASIO_getTimeStamp() !
  386. - version: on return, the driver version (format is driver specific)
  387. - name: on return, a null-terminated string containing the driver's name
  388. - error message: on return, should contain a user message describing
  389. the type of error that occured during ASIOInit(), if any.
  390. - sysRef: platform specific
  391. Returns:
  392. If neither input nor output is present ASE_NotPresent
  393. will be returned.
  394. ASE_NoMemory, ASE_HWMalfunction are other possible error conditions
  395. */
  396. ASIOError ASIOExit(void);
  397. /* Purpose:
  398. Terminates the AudioStreamIO.
  399. Parameter:
  400. None.
  401. Returns:
  402. If neither input nor output is present ASE_NotPresent
  403. will be returned.
  404. Notes: this implies ASIOStop() and ASIODisposeBuffers(),
  405. meaning that no host callbacks must be accessed after ASIOExit().
  406. */
  407. //- - - - - - - - - - - - - - - - - - - - - - - - -
  408. // Start/Stop
  409. //- - - - - - - - - - - - - - - - - - - - - - - - -
  410. ASIOError ASIOStart(void);
  411. /* Purpose:
  412. Start input and output processing synchronously.
  413. This will
  414. - reset the sample counter to zero
  415. - start the hardware (both input and output)
  416. The first call to the hosts' bufferSwitch(index == 0) then tells
  417. the host to read from input buffer A (index 0), and start
  418. processing to output buffer A while output buffer B (which
  419. has been filled by the host prior to calling ASIOStart())
  420. is possibly sounding (see also ASIOGetLatencies())
  421. Parameter:
  422. None.
  423. Returns:
  424. If neither input nor output is present, ASE_NotPresent
  425. will be returned.
  426. If the hardware fails to start, ASE_HWMalfunction will be returned.
  427. Notes:
  428. There is no restriction on the time that ASIOStart() takes
  429. to perform (that is, it is not considered a realtime trigger).
  430. */
  431. ASIOError ASIOStop(void);
  432. /* Purpose:
  433. Stops input and output processing altogether.
  434. Parameter:
  435. None.
  436. Returns:
  437. If neither input nor output is present ASE_NotPresent
  438. will be returned.
  439. Notes:
  440. On return from ASIOStop(), the driver must in no
  441. case call the hosts' bufferSwitch() routine.
  442. */
  443. //- - - - - - - - - - - - - - - - - - - - - - - - -
  444. // Inquiry methods and sample rate
  445. //- - - - - - - - - - - - - - - - - - - - - - - - -
  446. ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels);
  447. /* Purpose:
  448. Returns number of individual input/output channels.
  449. Parameter:
  450. numInputChannels will hold the number of available input channels
  451. numOutputChannels will hold the number of available output channels
  452. Returns:
  453. If no input/output is present ASE_NotPresent will be returned.
  454. If only inputs, or only outputs are available, the according
  455. other parameter will be zero, and ASE_OK is returned.
  456. */
  457. ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency);
  458. /* Purpose:
  459. Returns the input and output latencies. This includes
  460. device specific delays, like FIFOs etc.
  461. Parameter:
  462. inputLatency will hold the 'age' of the first sample frame
  463. in the input buffer when the hosts reads it in bufferSwitch()
  464. (this is theoretical, meaning it does not include the overhead
  465. and delay between the actual physical switch, and the time
  466. when bufferSitch() enters).
  467. This will usually be the size of one block in sample frames, plus
  468. device specific latencies.
  469. outputLatency will specify the time between the buffer switch,
  470. and the time when the next play buffer will start to sound.
  471. The next play buffer is defined as the one the host starts
  472. processing after (or at) bufferSwitch(), indicated by the
  473. index parameter (0 for buffer A, 1 for buffer B).
  474. It will usually be either one block, if the host writes directly
  475. to a dma buffer, or two or more blocks if the buffer is 'latched' by
  476. the driver. As an example, on ASIOStart(), the host will have filled
  477. the play buffer at index 1 already; when it gets the callback (with
  478. the parameter index == 0), this tells it to read from the input
  479. buffer 0, and start to fill the play buffer 0 (assuming that now
  480. play buffer 1 is already sounding). In this case, the output
  481. latency is one block. If the driver decides to copy buffer 1
  482. at that time, and pass it to the hardware at the next slot (which
  483. is most commonly done, but should be avoided), the output latency
  484. becomes two blocks instead, resulting in a total i/o latency of at least
  485. 3 blocks. As memory access is the main bottleneck in native dsp processing,
  486. and to acheive less latency, it is highly recommended to try to avoid
  487. copying (this is also why the driver is the owner of the buffers). To
  488. summarize, the minimum i/o latency can be acheived if the input buffer
  489. is processed by the host into the output buffer which will physically
  490. start to sound on the next time slice. Also note that the host expects
  491. the bufferSwitch() callback to be accessed for each time slice in order
  492. to retain sync, possibly recursively; if it fails to process a block in
  493. time, it will suspend its operation for some time in order to recover.
  494. Returns:
  495. If no input/output is present ASE_NotPresent will be returned.
  496. */
  497. ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);
  498. /* Purpose:
  499. Returns min, max, and preferred buffer sizes for input/output
  500. Parameter:
  501. minSize will hold the minimum buffer size
  502. maxSize will hold the maxium possible buffer size
  503. preferredSize will hold the preferred buffer size (a size which
  504. best fits performance and hardware requirements)
  505. granularity will hold the granularity at which buffer sizes
  506. may differ. Usually, the buffer size will be a power of 2;
  507. in this case, granularity will hold -1 on return, signalling
  508. possible buffer sizes starting from minSize, increased in
  509. powers of 2 up to maxSize.
  510. Returns:
  511. If no input/output is present ASE_NotPresent will be returned.
  512. Notes:
  513. When minimum and maximum buffer size are equal,
  514. the preferred buffer size has to be the same value as well; granularity
  515. should be 0 in this case.
  516. */
  517. ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate);
  518. /* Purpose:
  519. Inquires the hardware for the available sample rates.
  520. Parameter:
  521. sampleRate is the rate in question.
  522. Returns:
  523. If the inquired sample rate is not supported, ASE_NoClock will be returned.
  524. If no input/output is present ASE_NotPresent will be returned.
  525. */
  526. ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate);
  527. /* Purpose:
  528. Get the current sample Rate.
  529. Parameter:
  530. currentRate will hold the current sample rate on return.
  531. Returns:
  532. If sample rate is unknown, sampleRate will be 0 and ASE_NoClock will be returned.
  533. If no input/output is present ASE_NotPresent will be returned.
  534. Notes:
  535. */
  536. ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate);
  537. /* Purpose:
  538. Set the hardware to the requested sample Rate. If sampleRate == 0,
  539. enable external sync.
  540. Parameter:
  541. sampleRate: on input, the requested rate
  542. Returns:
  543. If sampleRate is unknown ASE_NoClock will be returned.
  544. If the current clock is external, and sampleRate is != 0,
  545. ASE_InvalidMode will be returned
  546. If no input/output is present ASE_NotPresent will be returned.
  547. Notes:
  548. */
  549. typedef struct ASIOClockSource
  550. {
  551. long index; // as used for ASIOSetClockSource()
  552. long associatedChannel; // for instance, S/PDIF or AES/EBU
  553. long associatedGroup; // see channel groups (ASIOGetChannelInfo())
  554. ASIOBool isCurrentSource; // ASIOTrue if this is the current clock source
  555. char name[32]; // for user selection
  556. } ASIOClockSource;
  557. ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources);
  558. /* Purpose:
  559. Get the available external audio clock sources
  560. Parameter:
  561. clocks points to an array of ASIOClockSource structures:
  562. - index: this is used to identify the clock source
  563. when ASIOSetClockSource() is accessed, should be
  564. an index counting from zero
  565. - associatedInputChannel: the first channel of an associated
  566. input group, if any.
  567. - associatedGroup: the group index of that channel.
  568. groups of channels are defined to seperate for
  569. instance analog, S/PDIF, AES/EBU, ADAT connectors etc,
  570. when present simultaniously. Note that associated channel
  571. is enumerated according to numInputs/numOutputs, means it
  572. is independant from a group (see also ASIOGetChannelInfo())
  573. inputs are associated to a clock if the physical connection
  574. transfers both data and clock (like S/PDIF, AES/EBU, or
  575. ADAT inputs). if there is no input channel associated with
  576. the clock source (like Word Clock, or internal oscillator), both
  577. associatedChannel and associatedGroup should be set to -1.
  578. - isCurrentSource: on exit, ASIOTrue if this is the current clock
  579. source, ASIOFalse else
  580. - name: a null-terminated string for user selection of the available sources.
  581. numSources:
  582. on input: the number of allocated array members
  583. on output: the number of available clock sources, at least
  584. 1 (internal clock generator).
  585. Returns:
  586. If no input/output is present ASE_NotPresent will be returned.
  587. Notes:
  588. */
  589. ASIOError ASIOSetClockSource(long index);
  590. /* Purpose:
  591. Set the audio clock source
  592. Parameter:
  593. index as obtained from an inquiry to ASIOGetClockSources()
  594. Returns:
  595. If no input/output is present ASE_NotPresent will be returned.
  596. If the clock can not be selected because an input channel which
  597. carries the current clock source is active, ASE_InvalidMode
  598. *may* be returned (this depends on the properties of the driver
  599. and/or hardware).
  600. Notes:
  601. Should *not* return ASE_NoClock if there is no clock signal present
  602. at the selected source; this will be inquired via ASIOGetSampleRate().
  603. It should call the host callback procedure sampleRateHasChanged(),
  604. if the switch causes a sample rate change, or if no external clock
  605. is present at the selected source.
  606. */
  607. ASIOError ASIOGetSamplePosition (ASIOSamples *sPos, ASIOTimeStamp *tStamp);
  608. /* Purpose:
  609. Inquires the sample position/time stamp pair.
  610. Parameter:
  611. sPos will hold the sample position on return. The sample
  612. position is reset to zero when ASIOStart() gets called.
  613. tStamp will hold the system time when the sample position
  614. was latched.
  615. Returns:
  616. If no input/output is present, ASE_NotPresent will be returned.
  617. If there is no clock, ASE_SPNotAdvancing will be returned.
  618. Notes:
  619. in order to be able to synchronise properly,
  620. the sample position / time stamp pair must refer to the current block,
  621. that is, the engine will call ASIOGetSamplePosition() in its bufferSwitch()
  622. callback and expect the time for the current block. thus, when requested
  623. in the very first bufferSwitch after ASIO_Start(), the sample position
  624. should be zero, and the time stamp should refer to the very time where
  625. the stream was started. it also means that the sample position must be
  626. block aligned. the driver must ensure proper interpolation if the system
  627. time can not be determined for the block position. the driver is responsible
  628. for precise time stamps as it usually has most direct access to lower
  629. level resources. proper behaviour of ASIO_GetSamplePosition() and ASIO_GetLatencies()
  630. are essential for precise media synchronization!
  631. */
  632. typedef struct ASIOChannelInfo
  633. {
  634. long channel; // on input, channel index
  635. ASIOBool isInput; // on input
  636. ASIOBool isActive; // on exit
  637. long channelGroup; // dto
  638. ASIOSampleType type; // dto
  639. char name[32]; // dto
  640. } ASIOChannelInfo;
  641. ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info);
  642. /* Purpose:
  643. retreive information about the nature of a channel
  644. Parameter:
  645. info: pointer to a ASIOChannelInfo structure with
  646. - channel: on input, the channel index of the channel in question.
  647. - isInput: on input, ASIOTrue if info for an input channel is
  648. requested, else output
  649. - channelGroup: on return, the channel group that the channel
  650. belongs to. For drivers which support different types of
  651. channels, like analog, S/PDIF, AES/EBU, ADAT etc interfaces,
  652. there should be a reasonable grouping of these types. Groups
  653. are always independant form a channel index, that is, a channel
  654. index always counts from 0 to numInputs/numOutputs regardless
  655. of the group it may belong to.
  656. There will always be at least one group (group 0). Please
  657. also note that by default, the host may decide to activate
  658. channels 0 and 1; thus, these should belong to the most
  659. useful type (analog i/o, if present).
  660. - type: on return, contains the sample type of the channel
  661. - isActive: on return, ASIOTrue if channel is active as it was
  662. installed by ASIOCreateBuffers(), ASIOFalse else
  663. - name: describing the type of channel in question. Used to allow
  664. for user selection, and enabling of specific channels. examples:
  665. "Analog In", "SPDIF Out" etc
  666. Returns:
  667. If no input/output is present ASE_NotPresent will be returned.
  668. Notes:
  669. If possible, the string should be organised such that the first
  670. characters are most significantly describing the nature of the
  671. port, to allow for identification even if the view showing the
  672. port name is too small to display more than 8 characters, for
  673. instance.
  674. */
  675. //- - - - - - - - - - - - - - - - - - - - - - - - -
  676. // Buffer preparation
  677. //- - - - - - - - - - - - - - - - - - - - - - - - -
  678. typedef struct ASIOBufferInfo
  679. {
  680. ASIOBool isInput; // on input: ASIOTrue: input, else output
  681. long channelNum; // on input: channel index
  682. void *buffers[2]; // on output: double buffer addresses
  683. } ASIOBufferInfo;
  684. ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
  685. long bufferSize, ASIOCallbacks *callbacks);
  686. /* Purpose:
  687. Allocates input/output buffers for all input and output channels to be activated.
  688. Parameter:
  689. bufferInfos is a pointer to an array of ASIOBufferInfo structures:
  690. - isInput: on input, ASIOTrue if the buffer is to be allocated
  691. for an input, output buffer else
  692. - channelNum: on input, the index of the channel in question
  693. (counting from 0)
  694. - buffers: on exit, 2 pointers to the halves of the channels' double-buffer.
  695. the size of the buffer(s) of course depend on both the ASIOSampleType
  696. as obtained from ASIOGetChannelInfo(), and bufferSize
  697. numChannels is the sum of all input and output channels to be created;
  698. thus bufferInfos is a pointer to an array of numChannels ASIOBufferInfo
  699. structures.
  700. bufferSize selects one of the possible buffer sizes as obtained from
  701. ASIOGetBufferSizes().
  702. callbacks is a pointer to an ASIOCallbacks structure.
  703. Returns:
  704. If not enough memory is available ASE_NoMemory will be returned.
  705. If no input/output is present ASE_NotPresent will be returned.
  706. If bufferSize is not supported, or one or more of the bufferInfos elements
  707. contain invalid settings, ASE_InvalidMode will be returned.
  708. Notes:
  709. If individual channel selection is not possible but requested,
  710. the driver has to handle this. namely, bufferSwitch() will only
  711. have filled buffers of enabled outputs. If possible, processing
  712. and buss activities overhead should be avoided for channels which
  713. were not enabled here.
  714. */
  715. ASIOError ASIODisposeBuffers(void);
  716. /* Purpose:
  717. Releases all buffers for the device.
  718. Parameter:
  719. None.
  720. Returns:
  721. If no buffer were ever prepared, ASE_InvalidMode will be returned.
  722. If no input/output is present ASE_NotPresent will be returned.
  723. Notes:
  724. This implies ASIOStop().
  725. */
  726. ASIOError ASIOControlPanel(void);
  727. /* Purpose:
  728. request the driver to start a control panel component
  729. for device specific user settings. This will not be
  730. accessed on some platforms (where the component is accessed
  731. instead).
  732. Parameter:
  733. None.
  734. Returns:
  735. If no panel is available ASE_NotPresent will be returned.
  736. Actually, the return code is ignored.
  737. Notes:
  738. if the user applied settings which require a re-configuration
  739. of parts or all of the enigine and/or driver (such as a change of
  740. the block size), the asioMessage callback can be used (see
  741. ASIO_Callbacks).
  742. */
  743. ASIOError ASIOFuture(long selector, void *params);
  744. /* Purpose:
  745. various
  746. Parameter:
  747. selector: operation Code as to be defined. zero is reserved for
  748. testing purposes.
  749. params: depends on the selector; usually pointer to a structure
  750. for passing and retreiving any type and amount of parameters.
  751. Returns:
  752. the return value is also selector dependant. if the selector
  753. is unknown, ASE_InvalidParameter should be returned to prevent
  754. further calls with this selector. on success, ASE_SUCCESS
  755. must be returned (note: ASE_OK is *not* sufficient!)
  756. Notes:
  757. see selectors defined below.
  758. */
  759. enum
  760. {
  761. kAsioEnableTimeCodeRead = 1, // no arguments
  762. kAsioDisableTimeCodeRead, // no arguments
  763. kAsioSetInputMonitor, // ASIOInputMonitor* in params
  764. kAsioTransport, // ASIOTransportParameters* in params
  765. kAsioSetInputGain, // ASIOChannelControls* in params, apply gain
  766. kAsioGetInputMeter, // ASIOChannelControls* in params, fill meter
  767. kAsioSetOutputGain, // ASIOChannelControls* in params, apply gain
  768. kAsioGetOutputMeter, // ASIOChannelControls* in params, fill meter
  769. kAsioCanInputMonitor, // no arguments for kAsioCanXXX selectors
  770. kAsioCanTimeInfo,
  771. kAsioCanTimeCode,
  772. kAsioCanTransport,
  773. kAsioCanInputGain,
  774. kAsioCanInputMeter,
  775. kAsioCanOutputGain,
  776. kAsioCanOutputMeter
  777. };
  778. typedef struct ASIOInputMonitor
  779. {
  780. long input; // this input was set to monitor (or off), -1: all
  781. long output; // suggested output for monitoring the input (if so)
  782. long gain; // suggested gain, ranging 0 - 0x7fffffffL (-inf to +12 dB)
  783. ASIOBool state; // ASIOTrue => on, ASIOFalse => off
  784. long pan; // suggested pan, 0 => all left, 0x7fffffff => right
  785. } ASIOInputMonitor;
  786. typedef struct ASIOChannelControls
  787. {
  788. long channel; // on input, channel index
  789. ASIOBool isInput; // on input
  790. long gain; // on input, ranges 0 thru 0x7fffffff
  791. long meter; // on return, ranges 0 thru 0x7fffffff
  792. char future[32];
  793. } ASIOChannelControls;
  794. typedef struct ASIOTransportParameters
  795. {
  796. long command; // see enum below
  797. ASIOSamples samplePosition;
  798. long track;
  799. long trackSwitches[16]; // 512 tracks on/off
  800. char future[64];
  801. } ASIOTransportParameters;
  802. enum
  803. {
  804. kTransStart = 1,
  805. kTransStop,
  806. kTransLocate, // to samplePosition
  807. kTransPunchIn,
  808. kTransPunchOut,
  809. kTransArmOn, // track
  810. kTransArmOff, // track
  811. kTransMonitorOn, // track
  812. kTransMonitorOff, // track
  813. kTransArm, // trackSwitches
  814. kTransMonitor // trackSwitches
  815. };
  816. ASIOError ASIOOutputReady(void);
  817. /* Purpose:
  818. this tells the driver that the host has completed processing
  819. the output buffers. if the data format required by the hardware
  820. differs from the supported asio formats, but the hardware
  821. buffers are DMA buffers, the driver will have to convert
  822. the audio stream data; as the bufferSwitch callback is
  823. usually issued at dma block switch time, the driver will
  824. have to convert the *previous* host buffer, which increases
  825. the output latency by one block.
  826. when the host finds out that ASIOOutputReady() returns
  827. true, it will issue this call whenever it completed
  828. output processing. then the driver can convert the
  829. host data directly to the dma buffer to be played next,
  830. reducing output latency by one block.
  831. another way to look at it is, that the buffer switch is called
  832. in order to pass the *input* stream to the host, so that it can
  833. process the input into the output, and the output stream is passed
  834. to the driver when the host has completed its process.
  835. Parameter:
  836. None
  837. Returns:
  838. only if the above mentioned scenario is given, and a reduction
  839. of output latency can be acheived by this mechanism, should
  840. ASE_OK be returned. otherwise (and usually), ASE_NotPresent
  841. should be returned in order to prevent further calls to this
  842. function. note that the host may want to determine if it is
  843. to use this when the system is not yet fully initialized, so
  844. ASE_OK should always be returned if the mechanism makes sense.
  845. Notes:
  846. please remeber to adjust ASIOGetLatencies() according to
  847. whether ASIOOutputReady() was ever called or not, if your
  848. driver supports this scenario.
  849. also note that the engine may fail to call ASIO_OutputReady()
  850. in time in overload cases. as already mentioned, bufferSwitch
  851. should be called for every block regardless of whether a block
  852. could be processed in time.
  853. */
  854. // restore old alignment
  855. #if defined(_MSC_VER) && !defined(__MWERKS__)
  856. #pragma pack(pop)
  857. #elif PRAGMA_ALIGN_SUPPORTED
  858. #pragma options align = reset
  859. #endif
  860. #endif