Audio plugin host https://kx.studio/carla
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.

1068 lines
43KB

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