asio.h 43 KB

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