patch-xa_audio_c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. $OpenBSD: patch-xa_audio_c,v 1.2 2015/06/29 23:07:07 ratchov Exp $
  2. --- xa_audio.c.orig Sun Mar 21 23:36:25 1999
  3. +++ xa_audio.c Tue Jun 30 01:04:19 2015
  4. @@ -114,6 +114,7 @@
  5. * 21Feb99 - Added routine *_Audio_Prep to hide initialization delays
  6. * when starting audio.
  7. * 02Mar99 - Linux: Change XA_LINUX_NEWER_SND TO OLDER_SND to avoid confusion.
  8. + * 18Mar99 - OpenBSD: newer configuration, solves a few problems.
  9. *
  10. ****************************************************************************/
  11. @@ -4936,6 +4937,278 @@ xaULONG volume;
  12. /******************* END OF NetBSD SPECIFIC ROUTINES ************************/
  13. /****************************************************************************/
  14. +/****************************************************************************/
  15. +/**************** OpenBSD SPECIFIC ROUTINES *********************************/
  16. +/****************************************************************************/
  17. +
  18. +/*
  19. + * Based on the NetBSD port initially,
  20. + * contributed by Marc Espie <espie@cvs.openbsd.org>
  21. + * This code may actually work on NetBSD, but this is not my place to
  22. + * change this.
  23. + *
  24. + * This code tries not to abuse AUDIO_SETINFO, as this can be an expensive
  25. + * ioctl on some arches. Also, it is able to deal with weirder audio
  26. + * devices, such as those found on amiga or sparcs.
  27. + */
  28. +
  29. +#ifdef XA_OpenBSD_AUDIO
  30. +
  31. +void OpenBSD_Audio_Init();
  32. +void OpenBSD_Audio_Kill();
  33. +void OpenBSD_Audio_Off();
  34. +void OpenBSD_Audio_Prep();
  35. +void OpenBSD_Audio_On();
  36. +void OpenBSD_Adjust_Volume();
  37. +xaULONG OpenBSD_Closest_Freq();
  38. +void OpenBSD_Set_Output_Port();
  39. +void OpenBSD_Speaker_Toggle();
  40. +void OpenBSD_Headphone_Toggle();
  41. +
  42. +static struct sio_hdl *hdl = NULL;
  43. +
  44. +/********** XA_Audio_Setup **********************
  45. + *
  46. + * Also defines OpenBSD Specific variables.
  47. + *
  48. + *****/
  49. +void XA_Audio_Setup()
  50. +{
  51. + XA_Audio_Init = OpenBSD_Audio_Init;
  52. + XA_Audio_Kill = OpenBSD_Audio_Kill;
  53. + XA_Audio_Off = OpenBSD_Audio_Off;
  54. + XA_Audio_Prep = OpenBSD_Audio_Prep;
  55. + XA_Audio_On = OpenBSD_Audio_On;
  56. + XA_Closest_Freq = OpenBSD_Closest_Freq;
  57. + XA_Set_Output_Port = OpenBSD_Set_Output_Port;
  58. + XA_Speaker_Tog = OpenBSD_Speaker_Toggle;
  59. + XA_Headphone_Tog = OpenBSD_Headphone_Toggle;
  60. + XA_LineOut_Tog = OpenBSD_Headphone_Toggle;
  61. + XA_Adjust_Volume = OpenBSD_Adjust_Volume;
  62. +
  63. + xa_snd_cur = 0;
  64. + xa_audio_present = XA_AUDIO_UNK;
  65. + xa_audio_status = XA_AUDIO_STOPPED;
  66. + xa_audio_ring_size = 8;
  67. +}
  68. +
  69. +/********** OpenBSD_Audio_Init **********************
  70. + * Open /dev/audio and OpenBSD.
  71. + *
  72. + *****/
  73. +
  74. +void OpenBSD_Audio_Init()
  75. +{
  76. + struct sio_par par;
  77. +
  78. + if (xa_audio_present != XA_AUDIO_UNK) return;
  79. + hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
  80. + if (hdl == NULL)
  81. + {
  82. + fprintf(stderr,"Audio_Init: Error opening audio device. - ");
  83. + fprintf(stderr,"Will continue without audio\n");
  84. + xa_audio_present = XA_AUDIO_ERR;
  85. + return;
  86. + }
  87. +
  88. + DEBUG_LEVEL1 fprintf(stderr,"OpenBSD AUDIO\n");
  89. +
  90. + sio_initpar(&par);
  91. + par.appbufsz = 1024;
  92. + par.rate = 11025; /* this is changed later */
  93. + par.pchan = 1;
  94. + par.bits = 16;
  95. + par.le = SIO_LE_NATIVE;
  96. + par.sig = 1;
  97. + if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
  98. + fprintf(stderr,"Audio_Init: Error setting audio parameters\n");
  99. + xa_audio_present = XA_AUDIO_ERR;
  100. + return;
  101. + }
  102. + if ((par.pchan != 1 && par.pchan != 2) ||
  103. + (par.bits != 8 && par.bits != 16)) {
  104. + fprintf(stderr,"Audio_Init: Unsupported audio parameters\n");
  105. + xa_audio_present = XA_AUDIO_ERR;
  106. + return;
  107. + }
  108. + if (par.pchan == 1) {
  109. + if (par.bits == 8) {
  110. + xa_audio_hard_type = par.sig ? XA_AUDIO_SIGNED_1M : XA_AUDIO_LINEAR_1M;
  111. + } else {
  112. + if (par.le)
  113. + xa_audio_hard_type = par.sig ? XA_AUDIO_SIGNED_2ML : XA_AUDIO_LINEAR_2ML;
  114. + else
  115. + xa_audio_hard_type = par.sig ? XA_AUDIO_SIGNED_2MB : XA_AUDIO_LINEAR_2MB;
  116. + }
  117. + } else {
  118. + if (par.bits == 8) {
  119. + xa_audio_hard_type = par.sig ? XA_AUDIO_SIGNED_1S : XA_AUDIO_LINEAR_1S;
  120. + } else {
  121. + if (par.le)
  122. + xa_audio_hard_type = par.sig ? XA_AUDIO_SIGNED_2SL : XA_AUDIO_LINEAR_2SL;
  123. + else
  124. + xa_audio_hard_type = par.sig ? XA_AUDIO_SIGNED_2SB : XA_AUDIO_LINEAR_2SB;
  125. + }
  126. + }
  127. + xa_audio_hard_freq = par.rate;
  128. + xa_audio_hard_buff = par.appbufsz;
  129. + xa_audio_hard_bps = par.bps;
  130. + xa_audio_hard_chans = par.pchan;
  131. + xa_interval_id = 0;
  132. + xa_audio_present = XA_AUDIO_OK;
  133. + DEBUG_LEVEL2 fprintf(stderr," success \n");
  134. + Init_Audio_Ring(xa_audio_ring_size,
  135. + (XA_AUDIO_MAX_RING_BUFF * xa_audio_hard_bps) );
  136. +}
  137. +
  138. +/********** OpenBSD_Audio_Kill **********************
  139. + * Close /dev/audio.
  140. + *
  141. + *****/
  142. +void OpenBSD_Audio_Kill()
  143. +{
  144. + OpenBSD_Audio_Off(0);
  145. + xa_audio_present = XA_AUDIO_UNK;
  146. + sio_close(hdl);
  147. + Kill_Audio_Ring();
  148. +}
  149. +
  150. +/********** OpenBSD_Audio_Off **********************
  151. + * Stop Audio Stream
  152. + *
  153. + *****/
  154. +void OpenBSD_Audio_Off(flag)
  155. +xaULONG flag;
  156. +{ /* long ret; */
  157. +
  158. + if (xa_audio_status != XA_AUDIO_STARTED) return;
  159. +
  160. + /* SET FLAG TO STOP OUTPUT ROUTINE */
  161. + xa_audio_status = XA_AUDIO_STOPPED;
  162. +
  163. + if (!sio_stop(hdl)) {
  164. + fprintf(stderr,"Audio_Off: Error stopping device\n");
  165. + xa_audio_present = XA_AUDIO_ERR;
  166. + return;
  167. + }
  168. +
  169. + xa_time_audio = -1;
  170. + xa_audio_flushed = 0;
  171. +}
  172. +
  173. +/********** OpenBSD_Audio_Prep **********************
  174. + * Turn On Audio Stream.
  175. + *
  176. + *****/
  177. +void OpenBSD_Audio_Prep()
  178. +{
  179. + struct sio_par par;
  180. +
  181. + if (xa_audio_status == XA_AUDIO_STARTED) return;
  182. + else if (xa_audio_present != XA_AUDIO_OK) return;
  183. +
  184. + else if (xa_snd_cur)
  185. + {
  186. + sio_initpar(&par);
  187. + par.rate = xa_snd_cur->hfreq;
  188. + if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
  189. + fprintf(stderr,"Audio_Init: Error setting audio parameters\n");
  190. + xa_audio_present = XA_AUDIO_ERR;
  191. + return;
  192. + }
  193. + xa_audio_hard_freq = par.rate;
  194. +
  195. + /* xa_snd_cur gets changes in Update_Ring() */
  196. + xa_out_time = 100; /* keep audio fed 500ms ahead of video */ /* was 500, changed it to 100 - rcd */
  197. + xa_out_init = xa_audio_ring_size - 1;
  198. + xa_interval_time = xa_snd_cur->ch_time / XAAUD->divtest;
  199. + if (xa_interval_time == 0) xa_interval_time = 1;
  200. +
  201. + XA_Flush_Ring();
  202. + XA_Update_Ring(1000);
  203. + xa_audio_status = XA_AUDIO_PREPPED;
  204. + }
  205. +}
  206. +
  207. +/****-------------------------------------------------------------------****
  208. + *
  209. + ****-------------------------------------------------------------------****/
  210. +void OpenBSD_Audio_On()
  211. +{
  212. + if ( (xa_snd_cur)
  213. + && (xa_audio_present == XA_AUDIO_OK)
  214. + && (xa_audio_status == XA_AUDIO_PREPPED) )
  215. + {
  216. + xa_audio_status = XA_AUDIO_STARTED;
  217. + if (!sio_start(hdl)) {
  218. + fprintf(stderr,"Audio_Init: Error starting audio device\n");
  219. + xa_audio_present = XA_AUDIO_ERR;
  220. + return;
  221. + }
  222. + xa_time_now = XA_Read_AV_Time(); /* get new time */
  223. + New_Merged_Audio_Output();
  224. + }
  225. +}
  226. +
  227. +/********** OpenBSD_Closest_Freq **********************************************
  228. + *
  229. + * Global Variable Affect:
  230. + * xaULONG xa_audio_hard_buff must set but not larger than
  231. + * XA_AUDIO_MAX_RING_BUF size
  232. + ****************************************************************************/
  233. +xaULONG OpenBSD_Closest_Freq(ifreq)
  234. +xaLONG ifreq;
  235. +{
  236. + return ifreq;
  237. +}
  238. +
  239. +/* Eventually merge everything to one */
  240. +void OpenBSD_Set_Output_Port(aud_ports)
  241. +xaULONG aud_ports;
  242. +{
  243. +}
  244. +
  245. +/************* OpenBSD_Speaker_Toggle *****************************************
  246. + *
  247. + * flag = 0 turn speaker off
  248. + * flag = 1 turn speaker on
  249. + * flag = 2 toggle speaker
  250. + ****************************************************************************/
  251. +void OpenBSD_Speaker_Toggle(flag)
  252. +xaULONG flag;
  253. +{
  254. +}
  255. +
  256. +/************* OpenBSD_Headphone_Toggle *****************************************
  257. + *
  258. + * flag = 0 turn headphones off
  259. + * flag = 1 turn headphones on
  260. + * flag = 2 toggle headphones
  261. + ****************************************************************************/
  262. +void OpenBSD_Headphone_Toggle(flag)
  263. +xaULONG flag;
  264. +{
  265. +}
  266. +
  267. +/********** OpenBSD_Adjust_Volume **********************
  268. + * Routine for Adjusting Volume on OpenBSD
  269. + *
  270. + * Volume is in the range [0,XA_AUDIO_MAXVOL]
  271. + ****************************************************************************/
  272. +void OpenBSD_Adjust_Volume(volume)
  273. +xaULONG volume;
  274. +{
  275. +#if 0 /* not_yet, xanim sets initial volume too low */
  276. + if (hdl)
  277. + sio_setvol(hdl, volume * SIO_MAXVOL / XA_AUDIO_MAXVOL);
  278. +#endif
  279. +}
  280. +#endif
  281. +
  282. +/****************************************************************************/
  283. +/******************* END OF OpenBSD SPECIFIC ROUTINES ************************/
  284. +/****************************************************************************/
  285. +
  286. /****************************************************************************/
  287. /**************** TOWNS SPECIFIC ROUTINES ***********************************/
  288. /****************************************************************************/
  289. @@ -5828,29 +6101,19 @@ void New_Merged_Audio_Output()
  290. /*---------------- Now for the Write Segments -------------------------------*/
  291. -#ifdef XA_SPARC_AUDIO
  292. +#ifdef XA_NORMAL_AUDIO_WRITES
  293. write(devAudio,xa_audio_ring->buf,xa_audio_ring->len);
  294. #endif
  295. -#ifdef XA_NetBSD_AUDIO
  296. - write(devAudio,xa_audio_ring->buf,xa_audio_ring->len);
  297. +#ifdef XA_OpenBSD_AUDIO
  298. + sio_write(hdl, xa_audio_ring->buf, xa_audio_ring->len);
  299. #endif
  300. -#ifdef XA_AIX_AUDIO
  301. - { int rc;
  302. - rc = write ( devAudio, xa_audio_ring->buf, xa_audio_ring->len );
  303. - }
  304. -#endif
  305. -
  306. #ifdef XA_SGI_AUDIO
  307. /* # of Samples, not Bytes. Note: assume 16 bit samples. */
  308. ALwritesamps(port,xa_audio_ring->buf, (xa_audio_ring->len >> 1) );
  309. #endif
  310. -#ifdef XA_LINUX_AUDIO
  311. - write(devAudio,xa_audio_ring->buf,xa_audio_ring->len);
  312. -#endif
  313. -
  314. #ifdef XA_NAS_AUDIO
  315. NAS_Write_Data(xa_audio_ring->buf, xa_audio_ring->len);
  316. #endif
  317. @@ -5864,10 +6127,6 @@ void New_Merged_Audio_Output()
  318. }
  319. #endif
  320. -#ifdef XA_EWS_AUDIO
  321. - write(devAudio,xa_audio_ring->buf,xa_audio_ring->len);
  322. -#endif
  323. -
  324. #ifdef XA_AF_AUDIO
  325. { ATime act, atd = AFtime0;
  326. if (XAAUD->mute != xaTRUE)
  327. @@ -5883,10 +6142,6 @@ void New_Merged_Audio_Output()
  328. /* Some way to flush streamsocket???? */
  329. #endif
  330. -#ifdef XA_HPDEV_AUDIO
  331. - write (devAudio, xa_audio_ring->buf, xa_audio_ring->len);
  332. -#endif
  333. -
  334. #ifdef XA_MMS_AUDIO
  335. /* As currently implemented, this copies the audio data into a separate
  336. shared memory buffer for communication with the multimedia server. We
  337. @@ -5921,10 +6176,6 @@ void New_Merged_Audio_Output()
  338. else { mms_buffers_outstanding++; }
  339. }
  340. }
  341. -#endif
  342. -
  343. -#ifdef XA_TOWNS_AUDIO
  344. - write(devAudio,xa_audio_ring->buf,xa_audio_ring->len);
  345. #endif
  346. #ifdef XA_TOWNS8_AUDIO