Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

asio.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. Steinberg Audio Stream I/O API
  3. (c) 1996, Steinberg Soft- und Hardware GmbH
  4. asio.cpp
  5. asio functions entries which translate the
  6. asio interface to the asiodrvr class methods
  7. */
  8. #include <string.h>
  9. #include "asiosys.h" // platform definition
  10. #include "asio.h"
  11. #if MAC
  12. #include "asiodrvr.h"
  13. #pragma export on
  14. AsioDriver *theAsioDriver = 0;
  15. extern "C"
  16. {
  17. long main()
  18. {
  19. return 'ASIO';
  20. }
  21. #elif WINDOWS
  22. #include "windows.h"
  23. #include "iasiodrv.h"
  24. #include "asiodrivers.h"
  25. IASIO *theAsioDriver = 0;
  26. extern AsioDrivers *asioDrivers;
  27. #elif SGI || SUN || BEOS || LINUX
  28. #include "asiodrvr.h"
  29. static AsioDriver *theAsioDriver = 0;
  30. #endif
  31. //-----------------------------------------------------------------------------------------------------
  32. ASIOError ASIOInit(ASIODriverInfo *info)
  33. {
  34. #if MAC || SGI || SUN || BEOS || LINUX
  35. if(theAsioDriver)
  36. {
  37. delete theAsioDriver;
  38. theAsioDriver = 0;
  39. }
  40. info->driverVersion = 0;
  41. strcpy(info->name, "No ASIO Driver");
  42. theAsioDriver = getDriver();
  43. if(!theAsioDriver)
  44. {
  45. strcpy(info->errorMessage, "Not enough memory for the ASIO driver!");
  46. return ASE_NotPresent;
  47. }
  48. if(!theAsioDriver->init(info->sysRef))
  49. {
  50. theAsioDriver->getErrorMessage(info->errorMessage);
  51. delete theAsioDriver;
  52. theAsioDriver = 0;
  53. return ASE_NotPresent;
  54. }
  55. strcpy(info->errorMessage, "No ASIO Driver Error");
  56. theAsioDriver->getDriverName(info->name);
  57. info->driverVersion = theAsioDriver->getDriverVersion();
  58. return ASE_OK;
  59. #else
  60. info->driverVersion = 0;
  61. strcpy(info->name, "No ASIO Driver");
  62. if(theAsioDriver) // must be loaded!
  63. {
  64. if(!theAsioDriver->init(info->sysRef))
  65. {
  66. theAsioDriver->getErrorMessage(info->errorMessage);
  67. theAsioDriver = 0;
  68. return ASE_NotPresent;
  69. }
  70. strcpy(info->errorMessage, "No ASIO Driver Error");
  71. theAsioDriver->getDriverName(info->name);
  72. info->driverVersion = theAsioDriver->getDriverVersion();
  73. return ASE_OK;
  74. }
  75. return ASE_NotPresent;
  76. #endif // !MAC
  77. }
  78. ASIOError ASIOExit(void)
  79. {
  80. if(theAsioDriver)
  81. {
  82. #if WINDOWS
  83. asioDrivers->removeCurrentDriver();
  84. #else
  85. delete theAsioDriver;
  86. #endif
  87. }
  88. theAsioDriver = 0;
  89. return ASE_OK;
  90. }
  91. ASIOError ASIOStart(void)
  92. {
  93. if(!theAsioDriver)
  94. return ASE_NotPresent;
  95. return theAsioDriver->start();
  96. }
  97. ASIOError ASIOStop(void)
  98. {
  99. if(!theAsioDriver)
  100. return ASE_NotPresent;
  101. return theAsioDriver->stop();
  102. }
  103. ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels)
  104. {
  105. if(!theAsioDriver)
  106. {
  107. *numInputChannels = *numOutputChannels = 0;
  108. return ASE_NotPresent;
  109. }
  110. return theAsioDriver->getChannels(numInputChannels, numOutputChannels);
  111. }
  112. ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency)
  113. {
  114. if(!theAsioDriver)
  115. {
  116. *inputLatency = *outputLatency = 0;
  117. return ASE_NotPresent;
  118. }
  119. return theAsioDriver->getLatencies(inputLatency, outputLatency);
  120. }
  121. ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity)
  122. {
  123. if(!theAsioDriver)
  124. {
  125. *minSize = *maxSize = *preferredSize = *granularity = 0;
  126. return ASE_NotPresent;
  127. }
  128. return theAsioDriver->getBufferSize(minSize, maxSize, preferredSize, granularity);
  129. }
  130. ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate)
  131. {
  132. if(!theAsioDriver)
  133. return ASE_NotPresent;
  134. return theAsioDriver->canSampleRate(sampleRate);
  135. }
  136. ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate)
  137. {
  138. if(!theAsioDriver)
  139. return ASE_NotPresent;
  140. return theAsioDriver->getSampleRate(currentRate);
  141. }
  142. ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate)
  143. {
  144. if(!theAsioDriver)
  145. return ASE_NotPresent;
  146. return theAsioDriver->setSampleRate(sampleRate);
  147. }
  148. ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources)
  149. {
  150. if(!theAsioDriver)
  151. {
  152. *numSources = 0;
  153. return ASE_NotPresent;
  154. }
  155. return theAsioDriver->getClockSources(clocks, numSources);
  156. }
  157. ASIOError ASIOSetClockSource(long reference)
  158. {
  159. if(!theAsioDriver)
  160. return ASE_NotPresent;
  161. return theAsioDriver->setClockSource(reference);
  162. }
  163. ASIOError ASIOGetSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp)
  164. {
  165. if(!theAsioDriver)
  166. return ASE_NotPresent;
  167. return theAsioDriver->getSamplePosition(sPos, tStamp);
  168. }
  169. ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info)
  170. {
  171. if(!theAsioDriver)
  172. {
  173. info->channelGroup = -1;
  174. info->type = ASIOSTInt16MSB;
  175. strcpy(info->name, "None");
  176. return ASE_NotPresent;
  177. }
  178. return theAsioDriver->getChannelInfo(info);
  179. }
  180. ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
  181. long bufferSize, ASIOCallbacks *callbacks)
  182. {
  183. if(!theAsioDriver)
  184. {
  185. ASIOBufferInfo *info = bufferInfos;
  186. for(long i = 0; i < numChannels; i++, info++)
  187. info->buffers[0] = info->buffers[1] = 0;
  188. return ASE_NotPresent;
  189. }
  190. return theAsioDriver->createBuffers(bufferInfos, numChannels, bufferSize, callbacks);
  191. }
  192. ASIOError ASIODisposeBuffers(void)
  193. {
  194. if(!theAsioDriver)
  195. return ASE_NotPresent;
  196. return theAsioDriver->disposeBuffers();
  197. }
  198. ASIOError ASIOControlPanel(void)
  199. {
  200. if(!theAsioDriver)
  201. return ASE_NotPresent;
  202. return theAsioDriver->controlPanel();
  203. }
  204. ASIOError ASIOFuture(long selector, void *opt)
  205. {
  206. if(!theAsioDriver)
  207. return ASE_NotPresent;
  208. return theAsioDriver->future(selector, opt);
  209. }
  210. ASIOError ASIOOutputReady(void)
  211. {
  212. if(!theAsioDriver)
  213. return ASE_NotPresent;
  214. return theAsioDriver->outputReady();
  215. }
  216. #if MAC
  217. } // extern "C"
  218. #pragma export off
  219. #endif