ham radio OSS duplex realtime mmap program.
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 ([email protected])
* 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: [email protected]
*/
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
[email protected]
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 7 lines
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,=20select(),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.
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
Quoted 15 lines · Paul Davis
Quoted 7 lines
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,=20select(),mmap(), and runs in 3 threads.=20
It was made in 1996 for OSS; I am trying to get it running with ALSA.=20JACK 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.
Quoted 6 lines
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
Quoted 18 lines · James Courtier-Dutton
Quoted 17 lines · Paul Davis
Quoted 7 lines
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,=20select(),mmap(), and runs in 3 threads.=20
It was made in 1996 for OSS; I am trying to get it running with ALSA.=20JACK 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.
Quoted 7 lines
Quoted 4 lines
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 <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 3 lines
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
Paul Davis ha scritto:
Quoted 7 lines
Quoted 3 lines
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.
Signature · 12 lines
Abramo Bagnara mailto:[email protected] 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
Quoted 11 lines
Paul Davis ha scritto:
Quoted 7 lines
Quoted 3 lines
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
Quoted 5 lines · Paul Davis
Quoted 2 lines
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
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
[email protected]
-------------------------------------------------------
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
Re: bugs found in ham program
In reply to Paul DavisThanks 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 ([email protected])
* 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: [email protected]
*/
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
[email protected]
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 25 lines · 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/pcm0petc...
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)" ?
Quoted 3 lines
The prog is at https//projects.sourceforge.net/hfterm. Here is one of the important functions out of
l1/user/oss.cmy prog:
Thanks for Your ideas!
Try 0.9.7 release, it comes with some OSS emulation fixes.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Quoted 14 lines · Dr. med. Günther Montag
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/pcm0petc... 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)" ?
Quoted 4 lines
The prog is at https//projects.sourceforge.net/hfterm. Here is one of the important functions out of
l1/user/oss.cmy 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
Am Freitag 26 September 2003 16:51 schrieb James Courtier-Dutton:
Quoted 11 lines
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.
Quoted 2 lines
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
-------------------------------------------------------
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