Cleanup
[carla.git] / source / modules / rtaudio / include / asio.cpp
blobb241663b3d810c95e9a1544486cce47c7f26925a
1 /*
2 Steinberg Audio Stream I/O API
3 (c) 1996, Steinberg Soft- und Hardware GmbH
5 asio.cpp
7 asio functions entries which translate the
8 asio interface to the asiodrvr class methods
9 */
11 #include <string.h>
12 #include "asiosys.h" // platform definition
13 #include "asio.h"
15 #if MAC
16 #include "asiodrvr.h"
18 #pragma export on
20 AsioDriver *theAsioDriver = 0;
22 extern "C"
25 long main()
27 return 'ASIO';
30 #elif WINDOWS
32 #include "windows.h"
33 #include "iasiodrv.h"
34 #include "asiodrivers.h"
36 IASIO *theAsioDriver = 0;
37 extern AsioDrivers *asioDrivers;
39 #elif SGI || SUN || BEOS || LINUX
40 #include "asiodrvr.h"
41 static AsioDriver *theAsioDriver = 0;
42 #endif
44 //-----------------------------------------------------------------------------------------------------
45 ASIOError ASIOInit(ASIODriverInfo *info)
47 #if MAC || SGI || SUN || BEOS || LINUX
48 if(theAsioDriver)
50 delete theAsioDriver;
51 theAsioDriver = 0;
53 info->driverVersion = 0;
54 strcpy(info->name, "No ASIO Driver");
55 theAsioDriver = getDriver();
56 if(!theAsioDriver)
58 strcpy(info->errorMessage, "Not enough memory for the ASIO driver!");
59 return ASE_NotPresent;
61 if(!theAsioDriver->init(info->sysRef))
63 theAsioDriver->getErrorMessage(info->errorMessage);
64 delete theAsioDriver;
65 theAsioDriver = 0;
66 return ASE_NotPresent;
68 strcpy(info->errorMessage, "No ASIO Driver Error");
69 theAsioDriver->getDriverName(info->name);
70 info->driverVersion = theAsioDriver->getDriverVersion();
71 return ASE_OK;
73 #else
75 info->driverVersion = 0;
76 strcpy(info->name, "No ASIO Driver");
77 if(theAsioDriver) // must be loaded!
79 if(!theAsioDriver->init(info->sysRef))
81 theAsioDriver->getErrorMessage(info->errorMessage);
82 theAsioDriver = 0;
83 return ASE_NotPresent;
86 strcpy(info->errorMessage, "No ASIO Driver Error");
87 theAsioDriver->getDriverName(info->name);
88 info->driverVersion = theAsioDriver->getDriverVersion();
89 return ASE_OK;
91 return ASE_NotPresent;
93 #endif // !MAC
96 ASIOError ASIOExit(void)
98 if(theAsioDriver)
100 #if WINDOWS
101 asioDrivers->removeCurrentDriver();
102 #else
103 delete theAsioDriver;
104 #endif
106 theAsioDriver = 0;
107 return ASE_OK;
110 ASIOError ASIOStart(void)
112 if(!theAsioDriver)
113 return ASE_NotPresent;
114 return theAsioDriver->start();
117 ASIOError ASIOStop(void)
119 if(!theAsioDriver)
120 return ASE_NotPresent;
121 return theAsioDriver->stop();
124 ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels)
126 if(!theAsioDriver)
128 *numInputChannels = *numOutputChannels = 0;
129 return ASE_NotPresent;
131 return theAsioDriver->getChannels(numInputChannels, numOutputChannels);
134 ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency)
136 if(!theAsioDriver)
138 *inputLatency = *outputLatency = 0;
139 return ASE_NotPresent;
141 return theAsioDriver->getLatencies(inputLatency, outputLatency);
144 ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity)
146 if(!theAsioDriver)
148 *minSize = *maxSize = *preferredSize = *granularity = 0;
149 return ASE_NotPresent;
151 return theAsioDriver->getBufferSize(minSize, maxSize, preferredSize, granularity);
154 ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate)
156 if(!theAsioDriver)
157 return ASE_NotPresent;
158 return theAsioDriver->canSampleRate(sampleRate);
161 ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate)
163 if(!theAsioDriver)
164 return ASE_NotPresent;
165 return theAsioDriver->getSampleRate(currentRate);
168 ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate)
170 if(!theAsioDriver)
171 return ASE_NotPresent;
172 return theAsioDriver->setSampleRate(sampleRate);
175 ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources)
177 if(!theAsioDriver)
179 *numSources = 0;
180 return ASE_NotPresent;
182 return theAsioDriver->getClockSources(clocks, numSources);
185 ASIOError ASIOSetClockSource(long reference)
187 if(!theAsioDriver)
188 return ASE_NotPresent;
189 return theAsioDriver->setClockSource(reference);
192 ASIOError ASIOGetSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp)
194 if(!theAsioDriver)
195 return ASE_NotPresent;
196 return theAsioDriver->getSamplePosition(sPos, tStamp);
199 ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info)
201 if(!theAsioDriver)
203 info->channelGroup = -1;
204 info->type = ASIOSTInt16MSB;
205 strcpy(info->name, "None");
206 return ASE_NotPresent;
208 return theAsioDriver->getChannelInfo(info);
211 ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
212 long bufferSize, ASIOCallbacks *callbacks)
214 if(!theAsioDriver)
216 ASIOBufferInfo *info = bufferInfos;
217 for(long i = 0; i < numChannels; i++, info++)
218 info->buffers[0] = info->buffers[1] = 0;
219 return ASE_NotPresent;
221 return theAsioDriver->createBuffers(bufferInfos, numChannels, bufferSize, callbacks);
224 ASIOError ASIODisposeBuffers(void)
226 if(!theAsioDriver)
227 return ASE_NotPresent;
228 return theAsioDriver->disposeBuffers();
231 ASIOError ASIOControlPanel(void)
233 if(!theAsioDriver)
234 return ASE_NotPresent;
235 return theAsioDriver->controlPanel();
238 ASIOError ASIOFuture(long selector, void *opt)
240 if(!theAsioDriver)
241 return ASE_NotPresent;
242 return theAsioDriver->future(selector, opt);
245 ASIOError ASIOOutputReady(void)
247 if(!theAsioDriver)
248 return ASE_NotPresent;
249 return theAsioDriver->outputReady();
252 #if MAC
253 } // extern "C"
254 #pragma export off
255 #endif