Debian Codegraph @

src/host/RtAudio/include/asio.h

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