patch-src_psk31-transmitter_C 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. $OpenBSD: patch-src_psk31-transmitter_C,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
  2. --- src/psk31-transmitter.C.orig Fri Aug 5 09:03:20 2005
  3. +++ src/psk31-transmitter.C Wed Jun 30 17:33:04 2010
  4. @@ -11,8 +11,7 @@
  5. #include <errno.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. -#include <sys/soundcard.h>
  9. -#include <sys/ioctl.h>
  10. +#include <poll.h>
  11. #include "psk31-coder.h"
  12. #include "psk31-transmitter.h"
  13. #include <assert.h>
  14. @@ -22,6 +21,8 @@ extern int full_duplex; // from psk31-main.C
  15. extern int chans; // from server-main.C
  16. extern int bits;
  17. +extern long long realpos, playpos; // from server-main.C
  18. +
  19. /* Morse code encoding table */
  20. /* 0=space, 1=dot; from msb to lsb; lowest 1 = end of code */
  21. unsigned int psk31_transmitter::cwtab[58] =
  22. @@ -432,64 +433,22 @@ int psk31_transmitter::processor()
  23. {
  24. static int wcnt = 0;
  25. - int res, odelay;
  26. + int res;
  27. + long long odelay;
  28. static int write_pending;
  29. static int len, buflen;
  30. static int odd = 0;
  31. static short val, obuf[BLOCKSIZE];
  32. - count_info cinfo;
  33. - audio_buf_info ospace;
  34. + struct pollfd pfd;
  35. + int events = 0, revents, n;
  36. - // Get free space in write buffer....
  37. - res=ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &ospace);
  38. - if(res)
  39. - {
  40. - if(errno==EBUSY)
  41. - {
  42. - // simplex card in read mode
  43. - // assume that there is enough space!
  44. - // (i.e. avoid check...)
  45. - // set odelay (this is not the real value, this
  46. - // echo will be too fast, but thats better than
  47. - // nothing...
  48. - odelay = 0;
  49. - }
  50. - else
  51. - {
  52. - perror("ERROR: GETOSPACE failed");
  53. - return TX_ERROR;
  54. - }
  55. - }
  56. - else
  57. - {
  58. - // ToDo: adjustable buffer limit --- a small buffer increases the
  59. - // possibility of buffer underruns, but reduces the delay between
  60. - // typing and actual transmission
  61. - if(ospace.fragments<ospace.fragstotal-32)
  62. - {
  63. - usleep(5000); // avoid 100% load!
  64. - return TX_BUSY;
  65. - }
  66. -#if 1
  67. - // Emulation of GETODELAY via GETOSPACE value...
  68. - // odelay value obtained this way might be larger than the
  69. - // real ODELAY by up to one fragment size....
  70. - odelay = (ospace.fragstotal*ospace.fragsize-ospace.bytes);
  71. -#endif
  72. - }
  73. + n = sio_pollfd(hdl, &pfd, events);
  74. + res = poll(&pfd, n, 0);
  75. + revents = sio_revents(hdl, &pfd);
  76. -#if 0
  77. - // Using GETODELAY.....
  78. - // does not work on all (esp. older) systems... -- requires OSS!
  79. - res=ioctl(audiofd, SNDCTL_DSP_GETODELAY, &odelay);
  80. - if(res)
  81. - {
  82. - perror("ERROR: GETODELAY failed");
  83. - return TX_ERROR;
  84. - }
  85. -#endif
  86. - // odelay is set above
  87. - ioctl(audiofd, SNDCTL_DSP_GETOPTR, &cinfo);
  88. + odelay = 0;
  89. + if (playpos > realpos)
  90. + odelay = playpos - realpos;
  91. if(!write_pending)
  92. {
  93. @@ -515,7 +474,7 @@ int psk31_transmitter::processor()
  94. }
  95. if(echo_char)
  96. {
  97. - add_echo_char(echo_char, cinfo.bytes+odelay+len*sizeof(short));
  98. + add_echo_char(echo_char, playpos+len*sizeof(short));
  99. echo_char=0;
  100. }
  101. @@ -568,32 +527,20 @@ int psk31_transmitter::processor()
  102. }
  103. }
  104. - res=write(audiofd, &obuf, len*sizeof(short));
  105. + res=sio_write(hdl, &obuf, len*sizeof(short));
  106. + playpos += res;
  107. if(res>0)
  108. wcnt+=res;
  109. if(res!=(int)(len*sizeof(short)))
  110. {
  111. - if(res<0 && (errno==EINTR||errno==EAGAIN))
  112. - {
  113. - write_pending=1; return TX_BUSY;
  114. - }
  115. - if(res==0 || (res<0 && (errno==EBUSY)))
  116. - {
  117. - write_pending=1; return TX_BUSY;
  118. - }
  119. - if(res<0)
  120. - {
  121. - fprintf(stderr,"tx: write error... res=%d\n",res);
  122. - return TX_ERROR;
  123. - }
  124. fprintf(stderr,"tx: partial write (%d/%d)...\n",
  125. res,BLOCKSIZE*sizeof(short));
  126. return TX_ERROR;
  127. }
  128. write_pending=0;
  129. - res = get_echo_char( cinfo.bytes );
  130. + res = get_echo_char( realpos );
  131. #if 0
  132. if(res!=TX_BUSY)