convert to sndio(7), fixing some bugs along the way with

help from ratchov@
This commit is contained in:
jakemsr 2010-07-01 01:57:33 +00:00
parent 3d37d40774
commit 923488792d
10 changed files with 733 additions and 51 deletions

View File

@ -1,9 +1,9 @@
# $OpenBSD: Makefile,v 1.11 2010/01/23 10:29:45 landry Exp $
# $OpenBSD: Makefile,v 1.12 2010/07/01 01:57:33 jakemsr Exp $
COMMENT= gtk PSK31 send and receive
DISTNAME= gpsk31-0.3
PKGNAME= $(DISTNAME)p7
PKGNAME= $(DISTNAME)p8
CATEGORIES= comms hamradio
HOMEPAGE= http://www.qsl.net/pg4i/linux/gpsk31.html
@ -18,9 +18,10 @@ LIB_DEPENDS= gtk-x11-2.0,gdk_pixbuf-2.0,gdk-x11-2.0::x11/gtk+2
WANTLIB += X11 Xau Xcomposite Xcursor Xdamage Xdmcp Xext Xfixes
WANTLIB += Xi Xinerama Xrandr Xrender atk-1.0 c cairo expat fontconfig
WANTLIB += freetype gio-2.0 glib-2.0 glitz gmodule-2.0 gobject-2.0
WANTLIB += iconv intl m ossaudio pango-1.0 pangocairo-1.0 pangoft2-1.0
WANTLIB += pixman-1 png pthread pthread-stubs stdc++ xcb z
WANTLIB += freetype gio-2.0 glib-2.0 glitz gmodule-2.0 gthread-2.0
WANTLIB += gobject-2.0 iconv intl m pango-1.0 pangocairo-1.0 pangoft2-1.0
WANTLIB += pixman-1 png pthread pthread-stubs sndio stdc++ xcb xcb-render
WANTLIB += xcb-render-util z
MASTER_SITES= http://www.qsl.net/pg4i/download/

View File

@ -1,11 +1,11 @@
$OpenBSD: patch-configure_in,v 1.1.1.1 2007/05/30 05:27:44 jason Exp $
--- configure.in.orig Tue May 29 23:01:56 2007
+++ configure.in Tue May 29 23:02:18 2007
$OpenBSD: patch-configure_in,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
--- configure.in.orig Tue Nov 15 01:40:02 2005
+++ configure.in Thu May 6 02:55:49 2010
@@ -11,6 +11,7 @@ AC_CHECK_PROGS(RPMBUILD, rpmbuild, rpm)
dnl Checks for libraries.
AC_CHECK_LIB(m, main)
AC_CHECK_LIB(pthread, main)
+AC_CHECK_LIB(ossaudio, _oss_ioctl)
+AC_CHECK_LIB(sndio, sio_open)
AC_DEFINE(USE_PTHREAD, 1)
if test "${ac_cv_c_compiler_gnu}" = "yes"; then

View File

@ -1,12 +1,13 @@
$OpenBSD: patch-gpsk_conf,v 1.1.1.1 2007/05/30 05:27:44 jason Exp $
--- gpsk.conf.orig Tue May 29 23:20:30 2007
+++ gpsk.conf Tue May 29 23:20:36 2007
@@ -39,7 +39,7 @@ freq = 1000
$OpenBSD: patch-gpsk_conf,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
--- gpsk.conf.orig Tue Nov 15 02:19:56 2005
+++ gpsk.conf Wed Jun 30 17:56:29 2010
@@ -39,7 +39,8 @@ freq = 1000
dcd_level = 13
lsb = 0
ptt_device = "/dev/ttyS1"
-audio_device = "/dev/dsp"
+audio_device = "/dev/audio"
+# audio_device isn't actually used. use AUDIODEVICE env var.
+audio_device = "default"
#
# Use new demodulator/rx filter?
#

View File

@ -0,0 +1,13 @@
$OpenBSD: patch-src_callback_C,v 1.1 2010/07/01 01:57:33 jakemsr Exp $
--- src/callback.C.orig Wed Jun 30 17:47:33 2010
+++ src/callback.C Wed Jun 30 17:48:12 2010
@@ -29,9 +29,6 @@ int shift_key_down = 0; /* is shift-key pressed? */
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

View File

@ -1,12 +1,12 @@
$OpenBSD: patch-src_main_C,v 1.1.1.1 2007/05/30 05:27:44 jason Exp $
--- src/main.C.orig Tue May 29 22:57:54 2007
+++ src/main.C Tue May 29 22:58:00 2007
@@ -27,7 +27,7 @@
$OpenBSD: patch-src_main_C,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
--- src/main.C.orig Tue Nov 15 02:20:31 2005
+++ src/main.C Wed Jun 30 17:24:16 2010
@@ -27,8 +27,6 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
-#include <sys/soundcard.h>
+#include <soundcard.h>
#include <sys/ioctl.h>
-#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

View File

@ -1,12 +1,142 @@
$OpenBSD: patch-src_psk31-transmitter_C,v 1.1.1.1 2007/05/30 05:27:44 jason Exp $
--- src/psk31-transmitter.C.orig Tue May 29 22:56:14 2007
+++ src/psk31-transmitter.C Tue May 29 22:56:29 2007
@@ -11,7 +11,7 @@
$OpenBSD: patch-src_psk31-transmitter_C,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
--- src/psk31-transmitter.C.orig Fri Aug 5 09:03:20 2005
+++ src/psk31-transmitter.C Wed Jun 30 17:33:04 2010
@@ -11,8 +11,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/soundcard.h>
+#include <soundcard.h>
#include <sys/ioctl.h>
-#include <sys/ioctl.h>
+#include <poll.h>
#include "psk31-coder.h"
#include "psk31-transmitter.h"
#include <assert.h>
@@ -22,6 +21,8 @@ extern int full_duplex; // from psk31-main.C
extern int chans; // from server-main.C
extern int bits;
+extern long long realpos, playpos; // from server-main.C
+
/* Morse code encoding table */
/* 0=space, 1=dot; from msb to lsb; lowest 1 = end of code */
unsigned int psk31_transmitter::cwtab[58] =
@@ -432,64 +433,22 @@ int psk31_transmitter::processor()
{
static int wcnt = 0;
- int res, odelay;
+ int res;
+ long long odelay;
static int write_pending;
static int len, buflen;
static int odd = 0;
static short val, obuf[BLOCKSIZE];
- count_info cinfo;
- audio_buf_info ospace;
+ struct pollfd pfd;
+ int events = 0, revents, n;
- // Get free space in write buffer....
- res=ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &ospace);
- if(res)
- {
- if(errno==EBUSY)
- {
- // simplex card in read mode
- // assume that there is enough space!
- // (i.e. avoid check...)
- // set odelay (this is not the real value, this
- // echo will be too fast, but thats better than
- // nothing...
- odelay = 0;
- }
- else
- {
- perror("ERROR: GETOSPACE failed");
- return TX_ERROR;
- }
- }
- else
- {
- // ToDo: adjustable buffer limit --- a small buffer increases the
- // possibility of buffer underruns, but reduces the delay between
- // typing and actual transmission
- if(ospace.fragments<ospace.fragstotal-32)
- {
- usleep(5000); // avoid 100% load!
- return TX_BUSY;
- }
-#if 1
- // Emulation of GETODELAY via GETOSPACE value...
- // odelay value obtained this way might be larger than the
- // real ODELAY by up to one fragment size....
- odelay = (ospace.fragstotal*ospace.fragsize-ospace.bytes);
-#endif
- }
+ n = sio_pollfd(hdl, &pfd, events);
+ res = poll(&pfd, n, 0);
+ revents = sio_revents(hdl, &pfd);
-#if 0
- // Using GETODELAY.....
- // does not work on all (esp. older) systems... -- requires OSS!
- res=ioctl(audiofd, SNDCTL_DSP_GETODELAY, &odelay);
- if(res)
- {
- perror("ERROR: GETODELAY failed");
- return TX_ERROR;
- }
-#endif
- // odelay is set above
- ioctl(audiofd, SNDCTL_DSP_GETOPTR, &cinfo);
+ odelay = 0;
+ if (playpos > realpos)
+ odelay = playpos - realpos;
if(!write_pending)
{
@@ -515,7 +474,7 @@ int psk31_transmitter::processor()
}
if(echo_char)
{
- add_echo_char(echo_char, cinfo.bytes+odelay+len*sizeof(short));
+ add_echo_char(echo_char, playpos+len*sizeof(short));
echo_char=0;
}
@@ -568,32 +527,20 @@ int psk31_transmitter::processor()
}
}
- res=write(audiofd, &obuf, len*sizeof(short));
+ res=sio_write(hdl, &obuf, len*sizeof(short));
+ playpos += res;
if(res>0)
wcnt+=res;
if(res!=(int)(len*sizeof(short)))
{
- if(res<0 && (errno==EINTR||errno==EAGAIN))
- {
- write_pending=1; return TX_BUSY;
- }
- if(res==0 || (res<0 && (errno==EBUSY)))
- {
- write_pending=1; return TX_BUSY;
- }
- if(res<0)
- {
- fprintf(stderr,"tx: write error... res=%d\n",res);
- return TX_ERROR;
- }
fprintf(stderr,"tx: partial write (%d/%d)...\n",
res,BLOCKSIZE*sizeof(short));
return TX_ERROR;
}
write_pending=0;
- res = get_echo_char( cinfo.bytes );
+ res = get_echo_char( realpos );
#if 0
if(res!=TX_BUSY)

View File

@ -0,0 +1,30 @@
$OpenBSD: patch-src_psk31-transmitter_h,v 1.1 2010/07/01 01:57:33 jakemsr Exp $
--- src/psk31-transmitter.h.orig Tue Aug 2 09:50:58 2005
+++ src/psk31-transmitter.h Thu May 6 16:19:11 2010
@@ -5,6 +5,8 @@
#ifndef __PSK31_TRANSMITTER_INCLUDED
#define __PSK31_TRANSMITTER_INCLUDED
+#include <sndio.h>
+
#include "psk31-coder.h"
#define DMA_BUF_BITS 10
@@ -18,7 +20,7 @@ class psk31_transmitter { (private)
int transmit_state;
//int saved_echo_char;
//int saved_echo_timestamp;
- int audiofd;
+ struct sio_hdl *hdl;
int cwmode;
int qpsk;
int lsb;
@@ -85,7 +87,7 @@ class psk31_transmitter { (private)
if(q) *q=qpsk; if(l) *l=lsb; if(f) *f=_txfreq;
if(cw) *cw=cwmode;
}
- void set_audiofd(int fd) { audiofd=fd; }
+ void set_audiofd(struct sio_hdl *h) { hdl=h; }
int send_char(int c);
int send_string(char *str);
int send_cw_string(int need_postamble, char *str);

View File

@ -1,30 +1,537 @@
$OpenBSD: patch-src_server-main_C,v 1.1.1.1 2007/05/30 05:27:44 jason Exp $
--- src/server-main.C.orig Wed Nov 2 01:54:12 2005
+++ src/server-main.C Tue May 29 23:15:53 2007
@@ -19,7 +19,7 @@
* thread and from user interface thread (==interface functions)
$OpenBSD: patch-src_server-main_C,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
--- src/server-main.C.orig Wed Jun 30 17:19:24 2010
+++ src/server-main.C Wed Jun 30 17:35:40 2010
@@ -20,21 +20,14 @@
*/
-
+#include <sys/types.h>
#include <sys/mman.h>
-#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,7 +33,7 @@
#include <netinet/in.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <sys/time.h>
#include <fcntl.h>
-#include <sys/soundcard.h>
+#include <soundcard.h>
#include <sys/ioctl.h>
+#include <poll.h>
#include "psk31-receiver.h"
#include "psk31-transmitter.h"
@@ -60,7 +60,7 @@ int full_duplex;
#include "psk31-fft.h"
@@ -56,13 +49,15 @@
#define RX 0
// receive / transmit state information
-int full_duplex;
+int full_duplex = 0;
int chans;
int size;
int bits;
-static char *audio_path="/dev/dsp";
+static char *audio_path="/dev/audio";
+static char *audio_path=NULL;
static char *ptt_path=NULL;
static int audiofd=-1, pttfd=-1;
-static int audiofd=-1, pttfd=-1;
+static int pttfd=-1;
+static struct sio_hdl *hdl;
+static struct sio_par par;
static int ptt_invert=0;
static int ctl_ptt(int onoff);
int scconfig[2]; /* [0]=8bit/16bit [1]=mono/stereo */
@@ -125,7 +120,16 @@ typedef struct
#define N_BUFFERS 6
static buffer_t buffers[N_BUFFERS];
+long long realpos, playpos;
+static void onmove(void *addr, int delta)
+{
+ struct sio_par *par = (struct sio_par *)addr;
+
+ realpos += delta * par->bps * par->pchan;
+}
+
+
static void init_buffer()
{
int i;
@@ -203,216 +207,177 @@ buffer_t *b = buffers+bufnr;
*/
int init_audio ()
{
- int val;
- int speed = 8000;
+ uint speed = 8000;
int frags;
+ int want_bits, want_chans, retval = 0;
pthread_mutex_lock(&mutex_fd); //get the mutex for soundcard fd
- if (audiofd > 2)
+ if (hdl != NULL)
{
- close (audiofd);
- usleep (50000); //strange
- audiofd = -1;
+ sio_close(hdl);
+ hdl = NULL;
}
/* Open the soundcard */
- if (audiofd < 0)
+ if (hdl == NULL)
{
if (trDir == RX)
{
- audiofd = open(audio_path, O_RDONLY|O_NONBLOCK);
+ /* audio_path */
+ hdl = sio_open(NULL, SIO_REC, 0);
}
else
{
- audiofd = open(audio_path, O_WRONLY|O_NONBLOCK);
+ hdl = sio_open(NULL, SIO_PLAY, 0);
}
}
- if (audiofd < 0)
+ if (hdl == NULL)
{
- fprintf (stderr, "init_audio: can't open %s\n", audio_path);
+ fprintf (stderr, "init_audio: can't open ");
+ if (audio_path == NULL)
+ fprintf (stderr, "default sndio device\n");
+ else
+ fprintf (stderr, "%s\n", audio_path);
return -1;
}
+ sio_initpar(&par);
+
/* check parameter to see if 8 or 16 bits was requested */
/* return 1 or 2 if set 8 or 16 bits format failed */
- switch (scconfig[0])
+ want_bits = scconfig[0];
+ switch (want_bits)
{
case 0: /* 8 bits requested */
- val=AFMT_U8;
- if (ioctl(audiofd, SNDCTL_DSP_SETFMT, &val) <0)
- {
- /* ioctl failed */
- fprintf (stderr, "init_audio: ioctl SETFMT 8 failed\n");
- return -1;
- }
-
- /* see if 8 bit worked */
- if (val == AFMT_U8)
- {
- /* we can use 8 bit */
- size = 1;
- bits = 8;
- // fprintf (stderr, "init_audio: trying 8 bit ");
- }
- else /* 8 bit failed */
- {
- fprintf (stderr, "init_audio: failed to set to 8 bits\n");
- return 1;
- }
+ par.bits = 8;
+ par.sig = 0;
break;
-
case 1: /* 16 bits requested */
- val=AFMT_S16_NE;
- if (ioctl(audiofd, SNDCTL_DSP_SETFMT, &val) <0)
- {
- /* ioctl failed */
- fprintf (stderr, "init_audio: ioctl SETFMT 16 failed\n");
- return -1;
- }
-
- /* see if 16 bit worked */
- if (val == AFMT_S16_NE)
- {
- /* we can use 16 bit */
- size = 2;
- bits = 16;
- // fprintf (stderr, "init_audio: trying 16 bit ");
- }
- else /* set 16 bit failed */
- {
- fprintf (stderr, "init_audio: failed to set to 16 bits\n");
- return 2;
- }
+ par.bits = 16;
+ par.sig = 1;
break;
-
- default: /* Invalid request */
- fprintf (stderr, "\ninit_audio: invalid 8 or 16 bit request\n");
+ default:
+ fprintf (stderr, "\ninit_audio: invalid bit-depth request\n");
return -1;
}
/* check parameter to see if MONO or STEREO was requested */
/* return 3 or 4 if set mono or stereo format failed */
+ want_chans = scconfig[1];
switch (scconfig[1])
{
case 0: /* mono requested */
- val=MONO;
- if( ioctl(audiofd, SNDCTL_DSP_STEREO, &val)<0 )
- {
- /* ioctl failed */
- fprintf (stderr,"\ninit_audio: ioctl failed - MONO\n");
- return -1;
- }
- /* see if mono worked */
- if (val == MONO)
- {
- /* we can use mono */
- fprintf (stderr, "mono format\n");
- chans = MONO;
- }
+ if (trDir == RX)
+ par.rchan = 1;
else
- {
- /* set mono failed */
- fprintf (stderr, "\ninit_audio: request for mono failed\n");
- return 3;
- }
+ par.pchan = 1;
break;
-
case 1: /* stereo request */
- val = STEREO;
- if( ioctl(audiofd, SNDCTL_DSP_STEREO, &val)<0 )
- {
- fprintf (stderr, "\ninit_audio: ioctl failed - STEREO\n");
- return -1;
- }
- /* see if stereo worked */
- if (val == STEREO)
- {
- /* we can use stereo */
- fprintf (stderr, "stereo format\n");
- size = size * 2;
- chans = STEREO;
- }
+ if (trDir == RX)
+ par.rchan = 2;
else
- {
- /* set stereo failed */
- fprintf (stderr, "\ninit_audio: request for stereo failed\n");
- return 4;
- }
+ par.pchan = 2;
break;
-
default:
- fprintf (stderr, "\ninit_audio: invalid mono or stereo request\n");
- return -1;
+ fprintf (stderr, "\ninit_audio: invalid mono or stereo request\n");
+ return -1;
}
- /* setup the rest */
- val = speed;
- if (ioctl(audiofd, SNDCTL_DSP_SPEED, &val) < 0)
+ if (want_bits == 0)
+ frags = 8;
+ else
+ frags = 10;
+
+ if (want_chans == 1)
+ frags++;
+
+ par.appbufsz = 1 << frags;
+
+ par.rate = speed;
+
+ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par))
{
- fprintf (stderr, "init_audio: ioctl SPEED failed\n");
+ fprintf (stderr, "init_audio: error setting parameters\n");
return -1;
}
- if (val == speed)
+ if (want_bits == 0 && (par.bits != 8 || par.sig != 0))
{
- fprintf (stderr,"init_audio: using %d sample rate\n", val);
+ fprintf (stderr, "init_audio: could not set 8-bit mode\n");
+ retval = 1;
}
- else
+ else if (want_bits == 1 && (par.bits != 16 || par.sig != 1))
{
- fprintf(stderr,"inexact sampling rate: "
- "request for %d resulted in %d\n",speed,val);
+ fprintf (stderr, "init_audio: could not set 16-bit mode\n");
+ retval = 2;
}
- if (bits == 8)
- frags = 0x00020008;
+ if (par.bits == 8 && par.sig == 0)
+ {
+ size = 1;
+ bits = 8;
+ }
+ else if (par.bits == 16 && par.sig == 1)
+ {
+ size = 2;
+ bits = 16;
+ }
else
- frags = 0x0002000A;
+ {
+ fprintf (stderr, "init_audio: could not get usable format\n");
+ return -1;
+ }
- if (chans == STEREO)
- frags++;
+ if (want_chans == 0 &&
+ ((trDir == RX && par.rchan != 1) || (trDir == TX && par.pchan != 1)))
+ {
+ fprintf (stderr, "\ninit_audio: request for mono failed\n");
+ retval = 3;
+ }
+ else if (want_chans == 1 &&
+ ((trDir == RX && par.rchan != 2) || (trDir == TX && par.pchan != 2)))
+ {
+ fprintf (stderr, "\ninit_audio: request for stereo failed\n");
+ retval = 4;
+ }
- val = frags;
- ioctl(audiofd, SNDCTL_DSP_SETFRAGMENT, &val);
+ if ((trDir == RX && par.rchan == 1) || (trDir == TX && par.pchan == 1))
+ {
+ fprintf (stderr, "mono format\n");
+ chans = MONO;
+ }
+ else if ((trDir == RX && par.rchan == 2) || (trDir == TX && par.pchan == 2))
+ {
+ fprintf (stderr, "stereo format\n");
+ size = size * 2;
+ chans = STEREO;
+ }
-/*****************************************************/
-#if 0
- audio_buf_info inInfo, outInfo;
- if (ioctl(audiofd, SNDCTL_DSP_GETISPACE, &inInfo))
- perror ("init_audio: SNDCTL_DSP_GETOSPACE");
- if (ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &outInfo))
- perror ("init_audio: SNDCTL_DSP_GETOSPACE");
-
-printf ("In fragments=0x%08x fragstotal=0x%08x fragsize=0x%08x\n",
- inInfo.fragments, inInfo.fragstotal, inInfo.fragsize);
-printf ("Out fragments=0x%08x fragstotal=0x%08x fragsize=0x%08x\n",
- outInfo.fragments, outInfo.fragstotal, outInfo.fragsize);
-#endif
-/*****************************************************/
-
- // Check if the device is operating in full duplex mode
- if( ioctl(audiofd, SNDCTL_DSP_GETCAPS, &val)<0 )
- perror("Warning: GETCAPS on audio device failed");
+ if (abs(par.rate - speed) < speed * 1.03)
+ {
+ fprintf (stderr, "init_audio: using %d sample rate\n", speed);
+ }
else
- if(val&DSP_CAP_DUPLEX)
- full_duplex=1;
- fprintf(stderr,"init_audio: using %s duplex mode\n",
- full_duplex ? "full" : "half");
+ {
+ fprintf(stderr, "could not set sampling rate: "
+ "request for %d resulted in %d\n", speed, par.rate);
+ return -1;
+ }
-/*****************************************************/
-#if 0
- val = 0;
- if (ioctl(audiofd, SNDCTL_DSP_SETTRIGGER, &val) == -1)
- perror("ioctl: SNDCTL_DSP_SETTRIGGER");
- val = PCM_ENABLE_INPUT;
- if (ioctl(audiofd, SNDCTL_DSP_SETTRIGGER, &val) == -1)
- perror("ioctl: SNDCTL_DSP_SETTRIGGER");
-#endif
-/*****************************************************/
+ realpos = playpos = 0;
+ if (trDir == TX)
+ sio_onmove(hdl, onmove, &par);
+ if (!sio_start(hdl))
+ {
+ fprintf (stderr, "init_audio: could not start audio\n");
+ return -1;
+ }
+
// fprintf (stderr, "init_audio: size=%d\n", size);
pthread_mutex_unlock(&mutex_fd);
- return 0;
+ return retval;
}
@@ -461,10 +426,7 @@ static void *master_thr_func(void *dummy)
void master_handler(void)
{
int res;
- fd_set rset, wset, eset;
- struct timeval tm;
int dcd;
- static short odd;
buffers[COMM_RXCH].psk31rx->get_info(NULL,NULL,NULL,NULL,
NULL,&dcd,NULL,NULL);
@@ -487,13 +449,6 @@ void master_handler(void)
lastMode = trDir;
}
- FD_ZERO(&rset); FD_ZERO(&wset); FD_ZERO(&eset);
- FD_SET(audiofd, &rset);
- FD_SET(audiofd, &eset);
- if (trDir == TX)
- FD_SET(audiofd, &wset);
- tm.tv_sec=0; tm.tv_usec=50000; /* 50ms */
- res=select(audiofd+1, &rset, &wset, &eset, &tm);
/* In my older version I had the problem, that there exist
* sound drivers which do not support select correctly. So this
* code tries to read/write from/to the audiodevice without
@@ -502,61 +457,54 @@ void master_handler(void)
if (trDir == RX)
{
- short sample[2], save;
+ short buf[128];
+ int s = 0, todo;
+ char *p, *end;
- for (;;)
- {
- pthread_mutex_lock (&mutex_fd); // grab the mutex for the fd
- odd++;
- res = read(audiofd, &sample, size);
- if (res == 0)
- {
- break;
- }
- else if (res != size)
- {
- // fprintf(stderr,"%d %d\n",res,errno);
- if (errno == EINTR)
- {
- break;
- }
- if (errno == EAGAIN || errno == EBUSY)
- {
- break;
- }
- perror ("Audio read failed");
+ pthread_mutex_lock (&mutex_fd); // grab the mutex for the fd
+ p = (char *)buf;
+ todo = sizeof(buf);
+ while (todo > 0) {
+ res = sio_read(hdl, p, todo);
+ if (res == 0)
+ {
+ fprintf (stderr, "Audio read failed");
exit (1);
- }
- pthread_mutex_unlock (&mutex_fd); // release mutex for fd
+ }
+ todo -= res;
+ p += res;
+ }
+ pthread_mutex_unlock (&mutex_fd); // release mutex for fd
+ for (p = (char *)buf, end = p + sizeof(buf); p < end;)
+ {
/******* for S16_NE stereo *******/
if (chans == STEREO && bits == 16)
{
/* two signed 16 bits to one signed short */
- sample[0] = sample[0] | sample[1];
+ s = (((short *)p)[0] + ((short *)p)[1]) / 2;
+ p += 2 * sizeof(short);
}
/******* for S16_NE mono *******/
if (chans == MONO && bits == 16)
{
- /* nothing to do for this one */
+ s = ((short *)p)[0];
+ p += sizeof(short);
}
/******* for U8 stereo *******/
if (chans==STEREO && bits == 8)
{
- /* two unsigned 8 bit to a signed short */
- save = (((sample[0]>>8)&0xFF) - 128) * 128; //low
- sample[0] = ((sample[0]&0xFF) - 128) * 128; //high
- sample[0] = sample[0] | save; //mixed
+ s = 128 * (p[0] ^ 0x80) + (p[1] ^ 0x80);
+ p += 2;
}
/******* for U8 mono *******/
if (chans == MONO && bits == 8)
- {
- /* unsigned 8 bit to signed short */
- sample[0] = ((sample[0]&0xFF) - 128) * 128;
-
+ {
+ s = 256 * (p[0] ^ 0x80);
+ p++;
}
/*****************************/
@@ -569,7 +517,7 @@ void master_handler(void)
pthread_mutex_unlock(&mutex_rx);
continue;
}
- res = rx->process_rx_sample (sample[0]);
+ res = rx->process_rx_sample (s);
pthread_mutex_unlock(&mutex_rx);
if(res!=NO_CHAR)
{
@@ -597,13 +545,14 @@ void master_handler(void)
char buffer[128];
for(;;)
{
- res=read(audiofd, buffer, 128);
+ res=sio_read(hdl, buffer, 128);
if(res!=128) break;
}
}
pthread_mutex_lock (&mutex_fd);
pthread_mutex_lock(&mutex_tx);
+ psk31tx->set_audiofd(hdl);
res=psk31tx->processor();
pthread_mutex_unlock(&mutex_tx);
pthread_mutex_unlock (&mutex_fd);
@@ -742,7 +691,7 @@ int server_main(char *audio, char *ptt, char *datadir)
psk31fft->set_parameters(1024, 1024, psk31_fft::MODE_RXDATA);
buffers[COMM_RXCH].psk31rx = new psk31_receiver(psk31fft);
psk31tx = new psk31_transmitter();
- psk31tx->set_audiofd(audiofd);
+ psk31tx->set_audiofd(hdl);
#ifdef USE_PTHREAD

View File

@ -1,12 +1,13 @@
$OpenBSD: patch-src_spectrum_C,v 1.1.1.1 2007/05/30 05:27:44 jason Exp $
--- src/spectrum.C.orig Tue May 29 22:58:21 2007
+++ src/spectrum.C Tue May 29 22:58:28 2007
@@ -27,7 +27,7 @@
$OpenBSD: patch-src_spectrum_C,v 1.2 2010/07/01 01:57:33 jakemsr Exp $
--- src/spectrum.C.orig Fri Aug 5 09:03:20 2005
+++ src/spectrum.C Wed Jun 30 17:46:17 2010
@@ -25,9 +25,6 @@
#include <sys/stat.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/soundcard.h>
+#include <soundcard.h>
#include <gtk/gtk.h>
#include <stdio.h>

View File

@ -1,7 +1,6 @@
@comment $OpenBSD: PLIST,v 1.4 2009/12/21 18:11:02 ajacoutot Exp $
bin/gpsk31
@comment $OpenBSD: PLIST,v 1.5 2010/07/01 01:57:33 jakemsr Exp $
@bin bin/gpsk31
@man man/man1/gpsk31.1
share/applications/
share/applications/gpsk31.desktop
share/gpsk31/
share/gpsk31/README