All of lore.kernel.org
 help / color / mirror / Atom feed
* ham radio OSS duplex realtime mmap program.
@ 2003-09-26 11:26 Dr. med. Günther Montag
  2003-09-26 11:47 ` Paul Davis
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Dr. med. Günther Montag @ 2003-09-26 11:26 UTC (permalink / raw)
  To: alsa-devel; +Cc: hfterm-hackers

Hello
I work at "hfkernel" by Tom Sailer, a program for pactor/rtty (soundcard ham 
radio digimodes). It seems complicated, because it uses realtime scheduling, 
select(), mmap(), and runs in 3 threads. 
It was made in 1996 for OSS; I am trying to get it running with ALSA. 

It is unique thing because it can do 
Pactor without the expensive PTC (something like a radio modem), 
may be of interest for many hams outside Europe /USA.

I and friends see messages like
" 512 fragments passed since last wakeup", in endless loop, leading to 
crashes, seems to be xruns, not able to ctrl-alt-del, have to switch off 
machine.
.
What do You think, how can ALSA support it, or Do I have to rewrite it for 
ALSA.
I tried already with no success to say "Direct" and "non-block" in all 
combinations to /proc/asound/card0/pcm0p etc... 
If to rewrite, what function / ioctl matches
SNDCTL_DSP_GETISPACE...SNDCTL_DSP_GETOSPACE...
" ioctl(fd_audio, SNDCTL_DSP_GETIPTR, &cinfo) "
and 
" ioctl(fd_audio, SNDCTL_DSP_GETOPTR, &cinfo) " ?

The prog is at https//projects.sourceforge.net/hfterm.
Here is one of the important functions out of l1/user/oss.c my prog:
Thanks for Your ideas!

*****************************************************************************/

/*
 *      oss.c  --  Linux sound I/O.
 *
 *      Copyright (C) 1997  Thomas Sailer (sailer@ife.ee.ethz.ch)
 *        Swiss Federal Institute of Technology (ETH), Electronics Lab
 *
...
 *  This is the Linux realtime sound output driver
      
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <asm/byteorder.h>
#include <sys/soundcard.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <signal.h>
#include <endian.h>
#include <pthread.h>
#include "os.h"
#include "l1.h"
#include "l1user.h"

static int samples_remain = 0;
static int samples_count = 0;
static short *samples_ptr = NULL;

static int invert_ptt = 0;

static pthread_t thr_l1;

static float snd_corr;

#if __BYTE_ORDER == __BIG_ENDIAN
#define AUDIO_FMT AFMT_S16_BE
#else
#define AUDIO_FMT AFMT_S16_LE
#endif


static void *fdx_driver(void *name_audio)
{
        size_t pagesize = getpagesize();
        int apar, fd_audio, i;
	union {
		caddr_t v;
		short *s;
	} ibuf;
	caddr_t ibuf_ext;
	union {
		caddr_t v;
		short *s;
	} obuf;
	struct audio_buf_info iinfo, oinfo;
	unsigned int isize, osize;
	unsigned int ifragptr, ofragptr;
	fd_set rmask, wmask;
	struct count_info cinfo;
	unsigned int curfrag, lastfrag, nfrags;
	unsigned long long itime, otime, inc_fragment;
	l1_time_t inc_sample;
	int ptt_frames;
	short *s;
	
        if ((fd_audio = open(name_audio, O_RDWR, 0)) < 0)
                errstr(SEV_FATAL, "open");
        /*
         * configure audio
         */
        apar = AUDIO_FMT;
        if (ioctl(fd_audio, SNDCTL_DSP_SETFMT, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETFMT");
        if (apar != AUDIO_FMT) 
		errprintf(SEV_FATAL, "audio driver does not support the S16 format\n");
        apar = 0;
        if (ioctl(fd_audio, SNDCTL_DSP_STEREO, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_STEREO");
        if (apar != 0)
		errprintf(SEV_FATAL, "audio driver does not support mono\n");
        apar = SAMPLE_RATE;
        if (ioctl(fd_audio, SNDCTL_DSP_SPEED, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SPEED");
	if (apar != SAMPLE_RATE) {
		if (abs(apar-SAMPLE_RATE) >= SAMPLE_RATE/100)
			errprintf(SEV_FATAL, "audio driver does not support 8kHz sampling 
frequency\n");
	}
	inc_sample = 1000000.0*snd_corr/apar;
	inc_fragment = 64*1000000.0*snd_corr/apar*(1<<24);
        ifragptr = 0;
	itime = 0;
	ofragptr = 1;
	otime = ofragptr * inc_fragment;
	ptt_frames = 0;
	lastfrag = 0;
        /*
         * set fragment sizes
         */
        apar = 0xffff0007U;
        if (ioctl(fd_audio, SNDCTL_DSP_SETFRAGMENT, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETFRAGMENT");
	if (ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &oinfo) == -1)
		errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETOSPACE");
	osize = oinfo.fragstotal * oinfo.fragsize;
	if (ioctl(fd_audio, SNDCTL_DSP_GETISPACE, &iinfo) == -1)
		errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETISPACE");
	isize = iinfo.fragstotal * iinfo.fragsize;
	if (EXCESS_FRAGS * iinfo.fragsize > pagesize)
		errprintf(SEV_FATAL, "OSS: input: fragment size %d times excess frags > page 
size %d\n",
			  iinfo.fragsize, pagesize);
	/*
         * mmap buffers
         *
	 * BSD people attention: you may need to uncomment the PROT_READ
	 * feedback welcome: sailer@ife.ee.ethz.ch
	 */
	if ((ibuf.v = mmap(NULL, pagesize+isize, PROT_READ | PROT_WRITE, 
			   MAP_ANON | MAP_PRIVATE, -1, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: MAP_ANONYMOUS");
	ibuf_ext = ibuf.v + isize;
	if (munmap(ibuf.v, isize))
		errstr(SEV_FATAL, "munmap: MAP_ANONYMOUS");
/* following line: '| PROT_WRITE ' helps against abort in my machine. Guenther 
*/
	if ((ibuf.v = mmap(ibuf.v, isize, PROT_READ | PROT_WRITE, MAP_FILE 
			  | MAP_SHARED | MAP_FIXED, 
			  fd_audio, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: PROT_READ");
	if ((obuf.v = mmap(NULL, osize, PROT_WRITE /* | PROT_READ*/, 
			   MAP_FILE | MAP_SHARED, fd_audio, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: PROT_WRITE");
	errprintf(SEV_INFO, "OSS: output: #frag: %d  fragsz: %d  totbuf: %d  bufaddr: 
%p\n"
		  "OSS: input: #frag: %d  fragsz: %d  totbuf: %d  bufaddr: %p  mempage: 
%p\n"
		  "OSS: sample time increment: %u  fragment time increment: %u\n",
		  oinfo.fragstotal, oinfo.fragsize, osize, obuf.s,
		  iinfo.fragstotal, iinfo.fragsize, isize, ibuf.s, ibuf_ext, 
		  (unsigned int)inc_sample, (unsigned int)(inc_fragment >> 24));
        /*
         * start playback/recording
         */
        apar = 0;
        if (ioctl(fd_audio, SNDCTL_DSP_SETTRIGGER, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETTRIGGER");
	apar = PCM_ENABLE_OUTPUT | PCM_ENABLE_INPUT;
        if (ioctl(fd_audio, SNDCTL_DSP_SETTRIGGER, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETTRIGGER");
	/*
	 * loop
	 */
	for (;;) {
		FD_ZERO(&rmask);
		FD_ZERO(&wmask);
		FD_SET(fd_audio, &rmask);
		FD_SET(fd_audio, &wmask);
		i = select(fd_audio+1, &rmask, &wmask, NULL, NULL);
		if (i < 0) 
			errstr(SEV_FATAL, "select");
		if (!FD_ISSET(fd_audio, &rmask) && !FD_ISSET(fd_audio, &wmask))
			continue;
		/*
		 * process input
		 */
		if (ioctl(fd_audio, SNDCTL_DSP_GETIPTR, &cinfo) == -1)
			errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETIPTR");
		curfrag = cinfo.ptr / iinfo.fragsize;
		if (cinfo.blocks > 2)
			errprintf(SEV_WARNING, "%d fragments passed since last wakeup\n", 
cinfo.blocks);
		while (ifragptr != curfrag) {
			if (!ifragptr) {
				s = (short *)(ibuf.v + isize + iinfo.fragsize * ifragptr);
				memcpy(s, ibuf.v + iinfo.fragsize * ifragptr, iinfo.fragsize);
			} else
				s = (short *)(ibuf.v + iinfo.fragsize * ifragptr);
			if (samples_remain > 0) {
				i = 2*samples_remain;
				if (i > iinfo.fragsize)
					i = iinfo.fragsize;
				memcpy(samples_ptr, s, i);
				samples_ptr += i/2;
				samples_remain -= i/2;
			}
			l1_input_samples(itime >> 24, inc_sample, s, iinfo.fragsize/2);
			itime += inc_fragment;			
			ifragptr++;
			if (ifragptr >= iinfo.fragstotal)
				ifragptr = 0;
		}
		/*
		 * process output
		 */
		if (ioctl(fd_audio, SNDCTL_DSP_GETOPTR, &cinfo) == -1)
			errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETOPTR");
		curfrag = cinfo.ptr / oinfo.fragsize;
		nfrags = oinfo.fragstotal + curfrag - lastfrag;
		lastfrag = curfrag;
		if (nfrags >= oinfo.fragstotal)
			nfrags -= oinfo.fragstotal;
		if (nfrags != cinfo.blocks)
			errprintf(SEV_WARNING, "OSS sound driver lost interrupt!\n");
		if (nfrags > 2)
			errprintf(SEV_WARNING, "%d fragments passed since last wakeup\n", nfrags);
		ptt_frames -= nfrags;
		if (ptt_frames < 0) {
			otime += (-ptt_frames) * inc_fragment;
			ofragptr -= ptt_frames;
			while (ofragptr >= oinfo.fragstotal)
				ofragptr -= oinfo.fragstotal;
			ptt_frames = 0;
			memset(obuf.s, 0, oinfo.fragsize * oinfo.fragstotal);
		}
		/* sanity check */
		if (!ptt_frames && ofragptr != (curfrag + 1) % oinfo.fragstotal)
			errprintf(SEV_FATAL, "output pointers inconsistent %u %u %lu\n",
				  ofragptr, curfrag, (unsigned long)(otime >> 24));
		while (ptt_frames < oinfo.fragstotal && ptt_frames <= 4 && 
		       l1_output_samples(otime >> 24, inc_sample, (short *)(obuf.v + 
oinfo.fragsize * ofragptr), 
					 oinfo.fragsize/2)) {
			ofragptr++;
			if (ofragptr >= oinfo.fragstotal)
				ofragptr = 0;
			ptt_frames++;
			otime += inc_fragment;
		}
		output_ptt(ptt_frames > 0);
	}
}

/* --------------------------------------------------------------------- */

Günther 
Safari.Doktor@addcom.de


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 11:26 ham radio OSS duplex realtime mmap program Dr. med. Günther Montag
@ 2003-09-26 11:47 ` Paul Davis
  2003-09-26 13:52   ` James Courtier-Dutton
  2003-09-26 14:23 ` ham radio OSS duplex realtime mmap program Jaroslav Kysela
  2003-09-26 14:51 ` James Courtier-Dutton
  2 siblings, 1 reply; 13+ messages in thread
From: Paul Davis @ 2003-09-26 11:47 UTC (permalink / raw)
  To: Dr. med. Günther Montag; +Cc: alsa-devel, hfterm-hackers

>Hello
>I work at "hfkernel" by Tom Sailer, a program for pactor/rtty (soundcard =
>ham=20
>radio digimodes). It seems complicated, because it uses realtime scheduli=
>ng,=20
>select(), mmap(), and runs in 3 threads.=20
>It was made in 1996 for OSS; I am trying to get it running with ALSA.=20

JACK already does this kind of stuff. You'd save yourself major
headaches by starting off doing it as a JACK client. Alternatively,
use the JACK source as a guide, although its very complex because it
is intended to handle many channels in a very robust way, with
complete xrun detection.

http://jackit.sf.net/

another alternative source of ideas would be ecasound's own ALSA code.

--p


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 11:47 ` Paul Davis
@ 2003-09-26 13:52   ` James Courtier-Dutton
  2003-09-26 14:33     ` Jaroslav Kysela
  0 siblings, 1 reply; 13+ messages in thread
From: James Courtier-Dutton @ 2003-09-26 13:52 UTC (permalink / raw)
  To: Paul Davis
  Cc: "Dr. med. Günther Montag", alsa-devel,
	hfterm-hackers

Paul Davis wrote:
>>Hello
>>I work at "hfkernel" by Tom Sailer, a program for pactor/rtty (soundcard =
>>ham=20
>>radio digimodes). It seems complicated, because it uses realtime scheduli=
>>ng,=20
>>select(), mmap(), and runs in 3 threads.=20
>>It was made in 1996 for OSS; I am trying to get it running with ALSA.=20
> 
> 
> JACK already does this kind of stuff. You'd save yourself major
> headaches by starting off doing it as a JACK client. Alternatively,
> use the JACK source as a guide, although its very complex because it
> is intended to handle many channels in a very robust way, with
> complete xrun detection.
> 
> http://jackit.sf.net/
> 
> another alternative source of ideas would be ecasound's own ALSA code.
> 
> --p
> 
I agree with Paul, that JACK would be a good place to work from, because 
it already deals with all the complicated realtime full duplex details, 
and leaves a relatively simple interface for the user application.

Cheers
James



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 11:26 ham radio OSS duplex realtime mmap program Dr. med. Günther Montag
  2003-09-26 11:47 ` Paul Davis
@ 2003-09-26 14:23 ` Jaroslav Kysela
  2003-09-26 14:51 ` James Courtier-Dutton
  2 siblings, 0 replies; 13+ messages in thread
From: Jaroslav Kysela @ 2003-09-26 14:23 UTC (permalink / raw)
  To: Dr. med. Günther Montag; +Cc: alsa-devel, hfterm-hackers

On Fri, 26 Sep 2003, Dr. med. [iso-8859-15] Günther Montag wrote:

> Hello
> I work at "hfkernel" by Tom Sailer, a program for pactor/rtty (soundcard ham
> radio digimodes). It seems complicated, because it uses realtime scheduling,
> select(), mmap(), and runs in 3 threads.
> It was made in 1996 for OSS; I am trying to get it running with ALSA.
>
> It is unique thing because it can do
> Pactor without the expensive PTC (something like a radio modem),
> may be of interest for many hams outside Europe /USA.
>
> I and friends see messages like
> " 512 fragments passed since last wakeup", in endless loop, leading to
> crashes, seems to be xruns, not able to ctrl-alt-del, have to switch off
> machine.
> .
> What do You think, how can ALSA support it, or Do I have to rewrite it for
> ALSA.
> I tried already with no success to say "Direct" and "non-block" in all
> combinations to /proc/asound/card0/pcm0p etc...
> If to rewrite, what function / ioctl matches
> SNDCTL_DSP_GETISPACE...SNDCTL_DSP_GETOSPACE...
> " ioctl(fd_audio, SNDCTL_DSP_GETIPTR, &cinfo) "
> and
> " ioctl(fd_audio, SNDCTL_DSP_GETOPTR, &cinfo) " ?
>
> The prog is at https//projects.sourceforge.net/hfterm.
> Here is one of the important functions out of l1/user/oss.c my prog:
> Thanks for Your ideas!

Try 0.9.7 release, it comes with some OSS emulation fixes.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 13:52   ` James Courtier-Dutton
@ 2003-09-26 14:33     ` Jaroslav Kysela
  2003-09-26 14:50       ` Paul Davis
  0 siblings, 1 reply; 13+ messages in thread
From: Jaroslav Kysela @ 2003-09-26 14:33 UTC (permalink / raw)
  To: James Courtier-Dutton
  Cc: Paul Davis, "Dr. med. Günther Montag", alsa-devel,
	hfterm-hackers

On Fri, 26 Sep 2003, James Courtier-Dutton wrote:

> Paul Davis wrote:
> >>Hello
> >>I work at "hfkernel" by Tom Sailer, a program for pactor/rtty (soundcard =
> >>ham=20
> >>radio digimodes). It seems complicated, because it uses realtime scheduli=
> >>ng,=20
> >>select(), mmap(), and runs in 3 threads.=20
> >>It was made in 1996 for OSS; I am trying to get it running with ALSA.=20
> >
> >
> > JACK already does this kind of stuff. You'd save yourself major
> > headaches by starting off doing it as a JACK client. Alternatively,
> > use the JACK source as a guide, although its very complex because it
> > is intended to handle many channels in a very robust way, with
> > complete xrun detection.
> >
> > http://jackit.sf.net/
> >
> > another alternative source of ideas would be ecasound's own ALSA code.
> >
> > --p
> >
> I agree with Paul, that JACK would be a good place to work from, because
> it already deals with all the complicated realtime full duplex details,
> and leaves a relatively simple interface for the user application.

By the way, does JACK still rely on the float samples internally? Then it
is not a good solution for the soft-modem application (driver) where
everything should be highly optimized.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 14:33     ` Jaroslav Kysela
@ 2003-09-26 14:50       ` Paul Davis
  2003-09-26 16:08         ` Abramo Bagnara
  0 siblings, 1 reply; 13+ messages in thread
From: Paul Davis @ 2003-09-26 14:50 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: James Courtier-Dutton, "Dr. med. Günther Montag",
	alsa-devel, hfterm-hackers

>By the way, does JACK still rely on the float samples internally? Then it
>is not a good solution for the soft-modem application (driver) where
>everything should be highly optimized.

it does. on most modern CPUs, the FPU is as fast or faster than the
integer unit for arithmetic. the optimized float<->int/short
conversion we use consumes an infinitesimal number of cycles. and
besides, the fact that you'd probably have a context switch is a far
greater cost (though internal clients avoid this).

anyway, i don't advocate JACK for all uses - it was designed for
pro-audio primarily - but its basic design does demonstrate how to do
certain things that most people find really hard to do.

--p


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 11:26 ham radio OSS duplex realtime mmap program Dr. med. Günther Montag
  2003-09-26 11:47 ` Paul Davis
  2003-09-26 14:23 ` ham radio OSS duplex realtime mmap program Jaroslav Kysela
@ 2003-09-26 14:51 ` James Courtier-Dutton
  2003-09-30 11:35   ` [Hfterm-hackers] " Dr. med. Günther Montag
  2 siblings, 1 reply; 13+ messages in thread
From: James Courtier-Dutton @ 2003-09-26 14:51 UTC (permalink / raw)
  To: "Dr. med. Günther Montag"; +Cc: alsa-devel, hfterm-hackers

Dr. med. Günther Montag wrote:
> Hello
> I work at "hfkernel" by Tom Sailer, a program for pactor/rtty (soundcard ham 
> radio digimodes). It seems complicated, because it uses realtime scheduling, 
> select(), mmap(), and runs in 3 threads. 
> It was made in 1996 for OSS; I am trying to get it running with ALSA. 
> 
> It is unique thing because it can do 
> Pactor without the expensive PTC (something like a radio modem), 
> may be of interest for many hams outside Europe /USA.
> 
> I and friends see messages like
> " 512 fragments passed since last wakeup", in endless loop, leading to 
> crashes, seems to be xruns, not able to ctrl-alt-del, have to switch off 
> machine.
> .
> What do You think, how can ALSA support it, or Do I have to rewrite it for 
> ALSA.
> I tried already with no success to say "Direct" and "non-block" in all 
> combinations to /proc/asound/card0/pcm0p etc... 
> If to rewrite, what function / ioctl matches
> SNDCTL_DSP_GETISPACE...SNDCTL_DSP_GETOSPACE...
> " ioctl(fd_audio, SNDCTL_DSP_GETIPTR, &cinfo) "
> and 
> " ioctl(fd_audio, SNDCTL_DSP_GETOPTR, &cinfo) " ?
> 
> The prog is at https//projects.sourceforge.net/hfterm.
> Here is one of the important functions out of l1/user/oss.c my prog:
> Thanks for Your ideas!
> 
I thought all ham radio was half duplex. i.e. You listen and decode, and 
then transmit if needed. i did not think the listen and transmit worked 
at the same time.
So, in theory, one could have 2 threads.
One receiving audio data, one decoding it, and if the decoder needs to 
transmit anything it stops the receiving thread, and starts a transmit 
thread. There is enough time to close and then open the sound device 
between receive and transmit, so the sound card should never have to 
work in full duplex mode.

Cheers
James




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 14:50       ` Paul Davis
@ 2003-09-26 16:08         ` Abramo Bagnara
  2003-09-26 16:14           ` Paul Davis
  0 siblings, 1 reply; 13+ messages in thread
From: Abramo Bagnara @ 2003-09-26 16:08 UTC (permalink / raw)
  To: Paul Davis
  Cc: Jaroslav Kysela, James Courtier-Dutton,
	"Dr. med. Günther Montag", alsa-devel,
	hfterm-hackers

Paul Davis ha scritto:
>>By the way, does JACK still rely on the float samples internally? Then it
>>is not a good solution for the soft-modem application (driver) where
>>everything should be highly optimized.
> 
> 
> it does. on most modern CPUs, the FPU is as fast or faster than the
> integer unit for arithmetic. the optimized float<->int/short

According to my measurement your belief is definitely false for add/sub, 
sometimes true for mul and very likely true for div.


-- 
Abramo Bagnara                       mailto:abramo.bagnara@libero.it

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 16:08         ` Abramo Bagnara
@ 2003-09-26 16:14           ` Paul Davis
  2003-09-26 18:36             ` Steve Harris
                               ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Paul Davis @ 2003-09-26 16:14 UTC (permalink / raw)
  To: Abramo Bagnara
  Cc: Jaroslav Kysela, James Courtier-Dutton,
	"Dr. med. Günther Montag", alsa-devel,
	hfterm-hackers

>Paul Davis ha scritto:
>>>By the way, does JACK still rely on the float samples internally? Then it
>>>is not a good solution for the soft-modem application (driver) where
>>>everything should be highly optimized.
>> 
>> 
>> it does. on most modern CPUs, the FPU is as fast or faster than the
>> integer unit for arithmetic. the optimized float<->int/short
>
>According to my measurement your belief is definitely false for add/sub, 
>sometimes true for mul and very likely true for div.

my belief is based on measurements done by tomshardware, arstechnica
and others. that doesn't mean it can't be wrong.


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 16:14           ` Paul Davis
@ 2003-09-26 18:36             ` Steve Harris
  2003-09-30 11:39             ` Dr. med. Günther Montag
  2003-10-03 11:55             ` bugs found in ham program Günther Montag
  2 siblings, 0 replies; 13+ messages in thread
From: Steve Harris @ 2003-09-26 18:36 UTC (permalink / raw)
  To: alsa-devel

On Fri, Sep 26, 2003 at 12:14:26 -0400, Paul Davis wrote:
> >According to my measurement your belief is definitely false for add/sub, 
> >sometimes true for mul and very likely true for div.
> 
> my belief is based on measurements done by tomshardware, arstechnica
> and others. that doesn't mean it can't be wrong.

My belief is that its much more complex than that :)

It realy depends how much parellelism there is in your algorithm, PIV /
Athlon class cpus can perform more FP operations in parrallel that integer,
so, although each float operation can take longer than the equivalent
integer operation to execute, the whole inner loop may run in less cycles.

That before you even get into SIMD operations.

- Steve


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Hfterm-hackers] Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 14:51 ` James Courtier-Dutton
@ 2003-09-30 11:35   ` Dr. med. Günther Montag
  0 siblings, 0 replies; 13+ messages in thread
From: Dr. med. Günther Montag @ 2003-09-30 11:35 UTC (permalink / raw)
  To: James Courtier-Dutton, alsa-devel, hfterm-hackers

Am Freitag 26 September 2003 16:51 schrieb James Courtier-Dutton:
>
> I thought all ham radio was half duplex. i.e. You listen and decode, and
> then transmit if needed. i did not think the listen and transmit worked
> at the same time.
> So, in theory, one could have 2 threads.
> One receiving audio data, one decoding it, and if the decoder needs to
> transmit anything it stops the receiving thread, and starts a transmit
> thread. There is enough time to close and then open the sound device
> between receive and transmit, so the sound card should never have to
> work in full duplex mode.
>
> Cheers
> James
Hello James,
Yes, mostly it is so, but this program has 2 functions in it, one 
"hdx_driver", halfduplex, like You say above, for soundcards that can only do 
half duplex. It measures time for switching, with my soundblaster 16 about 32 
milliseconds, and tells me to make my tx delay a bit bigger.
The other, I posted it, does not switsch the soundcard, but keeps it open 
always, thus saving time for txdelay, which may be good for pactor in case of 
long distance if we have to calculate light speed (the window between 2 
packets is about 125 ms).

cheers

Safari.Doktor@addcom.de


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ham radio OSS duplex realtime mmap program.
  2003-09-26 16:14           ` Paul Davis
  2003-09-26 18:36             ` Steve Harris
@ 2003-09-30 11:39             ` Dr. med. Günther Montag
  2003-10-03 11:55             ` bugs found in ham program Günther Montag
  2 siblings, 0 replies; 13+ messages in thread
From: Dr. med. Günther Montag @ 2003-09-30 11:39 UTC (permalink / raw)
  To: Paul Davis, Abramo Bagnara
  Cc: Jaroslav Kysela, James Courtier-Dutton, alsa-devel,
	hfterm-hackers

Hello all!
Much thanks for the interesting suggestion & discussion, it has encouraged me 
that my prog also makes headache to You gurus. 
And also much thanks to the alsa developers that make a great job.
So I will look forward to alsa 0.9.7. and in between have a look on jack.
See you!

Günther 
Safari.Doktor@addcom.de


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: bugs found in ham program
  2003-09-26 16:14           ` Paul Davis
  2003-09-26 18:36             ` Steve Harris
  2003-09-30 11:39             ` Dr. med. Günther Montag
@ 2003-10-03 11:55             ` Günther Montag
  2 siblings, 0 replies; 13+ messages in thread
From: Günther Montag @ 2003-10-03 11:55 UTC (permalink / raw)
  To: Paul Davis, Ralf-Axel Krause, alsa-devel@lists.sourceforge.net,
	Ana Maria Grilo Moreira, Christopher Svenstedt, dh8wr,
	hfterm-hackers, sailer, wgiovan

Thanks all once more for help
I found 2 bugs, the one I had made myself:
I had changed mmap for input to PROT_READ | PROT_WRITE  (W R O N G !!)
which made endless loop system crash.
The other, after removing the first:
"memcpy" gave a segfault
I do not know why - it seems to have worked in old oss times
(I never tested it because I have half duplex card only,
this is in the full duplex driver)
if i look on it it must give a segfault!
Tom what do you think?
I put in a malloc for this memcpy -> now it runs
I append the new code.
please tell me what You think about it

/*****************************************************************************/

/*
 *      oss.c  --  Linux sound I/O.
 *
 *      Copyright (C) 1997  Thomas Sailer (sailer@ife.ee.ethz.ch)
 *        Swiss Federal Institute of Technology (ETH), Electronics Lab
 *
......

/* --------------------------------------------------------------------- */

#define EXCESS_FRAGS 3

static void *fdx_driver(void *name_audio)
{
        size_t pagesize = getpagesize();
        int apar, fd_audio, i, brake, brakepoint = 7;
	union {
		caddr_t v;
		short *s;
	} ibuf;
	caddr_t ibuf_ext;
	union {
		caddr_t v;
		short *s;
	} obuf;
	struct audio_buf_info iinfo, oinfo;
	unsigned int isize, osize;
	unsigned int ifragptr, ofragptr;
	fd_set rmask, wmask;
	struct count_info cinfo;
	unsigned int curfrag, lastfrag, nfrags;
	unsigned long long itime, otime, inc_fragment;
	l1_time_t inc_sample;
	int ptt_frames;
	short *s;
	void * m;
	
        if ((fd_audio = open(name_audio, O_RDWR, 0)) < 0)
                errstr(SEV_FATAL, "open");
        /*
         * configure audio
         */
        apar = AUDIO_FMT;
        if (ioctl(fd_audio, SNDCTL_DSP_SETFMT, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETFMT");
        if (apar != AUDIO_FMT) 
		errprintf(SEV_FATAL, "audio driver does not support the S16 format\n");
        apar = 0;
        if (ioctl(fd_audio, SNDCTL_DSP_STEREO, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_STEREO");
        if (apar != 0)
		errprintf(SEV_FATAL, "audio driver does not support mono\n");
        apar = SAMPLE_RATE;
        if (ioctl(fd_audio, SNDCTL_DSP_SPEED, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SPEED");
	if (apar != SAMPLE_RATE) {
		if (abs(apar-SAMPLE_RATE) >= SAMPLE_RATE/100)
			errprintf(SEV_FATAL, "audio driver does not support 8kHz sampling frequency\n");
	}
	inc_sample = 1000000.0*snd_corr/apar;
	inc_fragment = 64*1000000.0*snd_corr/apar*(1<<24);
        ifragptr = 0;
	itime = 0;
	ofragptr = 1;
	otime = ofragptr * inc_fragment;
	ptt_frames = 0;
	lastfrag = 0;
        /*
         * set fragment sizes
         */
        apar = 0xffff0007U;
        if (ioctl(fd_audio, SNDCTL_DSP_SETFRAGMENT, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETFRAGMENT");
	if (ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &oinfo) == -1)
		errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETOSPACE");
	osize = oinfo.fragstotal * oinfo.fragsize;
	if (ioctl(fd_audio, SNDCTL_DSP_GETISPACE, &iinfo) == -1)
		errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETISPACE");
	isize = iinfo.fragstotal * iinfo.fragsize;
	if (EXCESS_FRAGS * iinfo.fragsize > pagesize)
		errprintf(SEV_FATAL, "OSS: input: fragment size %d times excess frags > page size %d\n",
			  iinfo.fragsize, pagesize);
	/*
         * mmap buffers
         *
	 * BSD people attention: you may need to uncomment the PROT_READ
	 * feedback welcome: sailer@ife.ee.ethz.ch
	 */
	if ((ibuf.v = mmap(NULL, pagesize + isize, PROT_READ, 
			   MAP_ANON | MAP_PRIVATE, -1, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: MAP_ANONYMOUS");
	ibuf_ext = ibuf.v + isize;
	if (munmap(ibuf.v, isize))
		errstr(SEV_FATAL, "munmap: MAP_ANONYMOUS");
	if ((ibuf.v = mmap(ibuf.v, isize , PROT_READ , 
			    MAP_FILE  | MAP_SHARED | MAP_FIXED, 
			  fd_audio, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: PROT_READ");
		
/* orig
	if ((obuf.v = mmap(NULL, osize, PROT_WRITE -comment- | PROT_READ -comment, 
			   MAP_FILE | MAP_SHARED, fd_audio, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: PROT_WRITE");
*/

	if ((obuf.v = mmap(NULL, pagesize+osize, PROT_WRITE, 
			    MAP_ANON | MAP_PRIVATE, -1, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: obuf: MAP_ANONYMOUS");
//	ibuf_ext = ibuf.v + isize;
	if (munmap(obuf.v, osize))
		errstr(SEV_FATAL, "munmap: obuf: MAP_ANONYMOUS");
	if ((obuf.v = mmap(obuf.v, osize, PROT_WRITE /*| PROT_READ*/, 
			    MAP_FILE  | MAP_SHARED | MAP_FIXED, 
			    fd_audio, 0)) == MAP_FAILED)
		errstr(SEV_FATAL, "mmap: obuf: PROT_WRITE");


	errprintf(SEV_INFO, 
		    "\nOSS:  input: #frag: %d  fragsz: %d  totbuf: %d  bufaddr: %p  mempage: %p\n"
		    "OSS: output: #frag: %d  fragsz: %d  totbuf: %d  bufaddr: %p\n"
		    "OSS: sample time increment: %u  fragment time increment: %u\n",
		    iinfo.fragstotal, iinfo.fragsize, isize, ibuf.s, ibuf_ext, 
		    oinfo.fragstotal, oinfo.fragsize, osize, obuf.s,
		    (unsigned int)inc_sample, (unsigned int)(inc_fragment >> 24));
        /*
         * start playback/recording
         */
        apar = 0;
        if (ioctl(fd_audio, SNDCTL_DSP_SETTRIGGER, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETTRIGGER");
	apar = PCM_ENABLE_OUTPUT | PCM_ENABLE_INPUT;
        if (ioctl(fd_audio, SNDCTL_DSP_SETTRIGGER, &apar) == -1)
                errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_SETTRIGGER");
	/*
	 * loop
	 */

	for (;;) {
		FD_ZERO(&rmask);
		FD_ZERO(&wmask);
		FD_SET(fd_audio, &rmask);
		FD_SET(fd_audio, &wmask);
		i = select(fd_audio+1, &rmask, &wmask, NULL, NULL);
		if (i < 0) 
			errstr(SEV_FATAL, "select");
		if (!FD_ISSET(fd_audio, &rmask) && !FD_ISSET(fd_audio, &wmask))
			continue;
		/*
		 * process input
		 */
		if (ioctl(fd_audio, SNDCTL_DSP_GETIPTR, &cinfo) == -1)
			errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETIPTR");
		curfrag = cinfo.ptr / iinfo.fragsize;
//		printf( "fdx in:  count info: bytes = %d, blocks = %d, ptr = %d\n", cinfo.bytes, cinfo.blocks, cinfo.ptr );
		if (cinfo.blocks > 2) {
			errprintf(SEV_WARNING, "in:  %d fragments passed since last wakeup\n", cinfo.blocks);
			brake ++;
			}
		if (brake >= brakepoint) {
			errprintf(SEV_FATAL, "%d xruns. Exiting.\n", brake);
			exit (1);
			}
		
		while (ifragptr != curfrag) {

			if (!ifragptr) 
			
			{
				m = malloc(pagesize);
				if (m == NULL)
	   			    errstr(SEV_FATAL, "fdx_driver: malloc failed");
				//	s = (short *)(ibuf.v + isize );
				s = (short *) m;
		//		printf("\nifragptr: %d, curfrag %d, ibuf.v: %p, s: %p \n",
		//		ifragptr, curfrag, ibuf.v, s);  			 
		//		printf ("shift mem malloced in %p\n", m);
				memcpy(s, ibuf.v, iinfo.fragsize);
			} 
			
			else
				s = (short *)(ibuf.v + iinfo.fragsize * ifragptr);
		//	printf("=\nifragptr: %d, curfrag %d, ibuf.v: %p, s: %p \n", 
		//	        ifragptr, curfrag, ibuf.v, s);  			
			
			if (samples_remain > 0) {
				i = 2*samples_remain;
				if (i > iinfo.fragsize)
					i = iinfo.fragsize;
				memcpy(samples_ptr, s, i);
		
		//		printf("\nsamples_remain: %d, samples_ptr: %p, i: %d", samples_remain, samples_ptr, i);  			
								
				samples_ptr += i/2;
				samples_remain -= i/2;
			}
			
			l1_input_samples(itime >> 24, inc_sample, s, iinfo.fragsize/2);
			itime += inc_fragment;			
			if (!ifragptr) free(m);
			ifragptr++;
			if (ifragptr >= iinfo.fragstotal)
				ifragptr = 0;
		}
		/*
		 * process output
		 */
		if (ioctl(fd_audio, SNDCTL_DSP_GETOPTR, &cinfo) == -1)
			errstr(SEV_FATAL, "ioctl: SNDCTL_DSP_GETOPTR");
		curfrag = cinfo.ptr / oinfo.fragsize;
//		printf( "fdx out: count info: bytes = %d, blocks = %d, ptr = %d\n", cinfo.bytes, cinfo.blocks, cinfo.ptr );
		nfrags = oinfo.fragstotal + curfrag - lastfrag;
		lastfrag = curfrag;
		if (nfrags >= oinfo.fragstotal)
			nfrags -= oinfo.fragstotal;
		if (nfrags != cinfo.blocks)
			errprintf(SEV_WARNING, "OSS sound driver lost interrupt!\n");
		if (nfrags > 2) {
			errprintf(SEV_WARNING, "out: %d fragments passed since last wakeup\n", nfrags);
			brake ++;
			}
		ptt_frames -= nfrags;
		if (ptt_frames < 0) {
			otime += (-ptt_frames) * inc_fragment;
			ofragptr -= ptt_frames;
			while (ofragptr >= oinfo.fragstotal)
				ofragptr -= oinfo.fragstotal;
			ptt_frames = 0;
			memset(obuf.s, 0, oinfo.fragsize * oinfo.fragstotal);
		}
		/* sanity check */
		if (!ptt_frames && ofragptr != (curfrag + 1) % oinfo.fragstotal)
			errprintf(SEV_FATAL, "output pointers inconsistent %u %u %lu\n",
				  ofragptr, curfrag, (unsigned long)(otime >> 24));
		while (ptt_frames < oinfo.fragstotal && ptt_frames <= 4 && 
		       l1_output_samples(otime >> 24, inc_sample, (short *)(obuf.v + oinfo.fragsize * ofragptr), 
					 oinfo.fragsize/2)) {
			ofragptr++;
			if (ofragptr >= oinfo.fragstotal)
				ofragptr = 0;
			ptt_frames++;
			otime += inc_fragment;
		}
		output_ptt(ptt_frames > 0);
	}
}

/* --------------------------------------------------------------------- */

static void *hdx_driver(void *name_audio)
.....

cheers
Safari.Doktor@addcom.de


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2003-10-03 11:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-26 11:26 ham radio OSS duplex realtime mmap program Dr. med. Günther Montag
2003-09-26 11:47 ` Paul Davis
2003-09-26 13:52   ` James Courtier-Dutton
2003-09-26 14:33     ` Jaroslav Kysela
2003-09-26 14:50       ` Paul Davis
2003-09-26 16:08         ` Abramo Bagnara
2003-09-26 16:14           ` Paul Davis
2003-09-26 18:36             ` Steve Harris
2003-09-30 11:39             ` Dr. med. Günther Montag
2003-10-03 11:55             ` bugs found in ham program Günther Montag
2003-09-26 14:23 ` ham radio OSS duplex realtime mmap program Jaroslav Kysela
2003-09-26 14:51 ` James Courtier-Dutton
2003-09-30 11:35   ` [Hfterm-hackers] " Dr. med. Günther Montag

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.