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.

asio.h 42KB

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