diff --git a/sw/ground_segment/multimon/Makefile b/sw/ground_segment/multimon/Makefile index 2021e38eba..a59e259fc3 100644 --- a/sw/ground_segment/multimon/Makefile +++ b/sw/ground_segment/multimon/Makefile @@ -1,15 +1,6 @@ DEBUG =n -OS =$(shell uname) CFLAGS =-Wall -Wstrict-prototypes -I/usr/X11R6/include -ifeq ($(OS),SunOS) -ifeq ($(DEBUG),y) -CFLAGS +=-g -O -DSUN_AUDIO -DARCH_SPARC -else -CFLAGS +=-O3 -DSUN_AUDIO -DARCH_SPARC -endif -LDFLAGSX =-lX11 -L/usr/X11R6/lib -R/usr/X11R6/lib -lsocket -lnsl -else ifeq ($(DEBUG),y) CFLAGS +=-g -O -march=i486 -falign-loops=2 -falign-jumps=2 \ -falign-functions=2 -DARCH_I386 @@ -18,7 +9,6 @@ CFLAGS +=-O3 -march=i486 -falign-loops=2 -falign-jumps=2 \ -falign-functions=2 -DARCH_I386 endif LDFLAGSX =-lX11 -L/usr/X11R6/lib -endif #BINDIR =bin-$(shell uname -m) @@ -51,14 +41,8 @@ $(BINDIR)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< SRC_L2 =hdlc.c pprz.c -# pocsag.c -# SRC_L1 =demod_afsk12.c demod_afsk24.c demod_afsk24_2.c demod_afsk48p.c demod_afsk48.c SRC_L1 = demod_afsk48p.c demod_display.c -#SRC_L1 +=demod_hapn48.c demod_fsk96.c -#SRC_L1 +=demod_poc5.c demod_poc12.c demod_poc24.c -#SRC_L1 +=demod_dtmf.c demod_zvei.c demod_display.c SRC_MISC = unixinput.c xdisplay.c -# costabf.c SRC_GEN =gen.c gen_dtmf.c gen_sin.c gen_zvei.c gen_hdlc.c costabi.c @@ -84,10 +68,10 @@ costabi.c costabf.c: $(BINDIR)/mkcostab $(BINDIR)/mkcostab clean: - $(RM) -f core `find . -name '*.[oas]' -print` - $(RM) -f core `find . -name 'core' -print` - $(RM) -f core costabi.c costabf.c *~ - + $(RM) -f core `find . -name '*.[oas]' -print` + $(RM) -f core `find . -name 'core' -print` + $(RM) -f core costabi.c costabf.c *~ + $(RM) $(BINDIR)/multimon depend dep: $(CPP) -M $(CFLAGS) $(SRC_MISC) $(SRC_L1) $(SRC_L2) $(SRC_GEN) mkcostab.c > $(BINDIR)/.depend diff --git a/sw/ground_segment/multimon/gen.h b/sw/ground_segment/multimon/gen.h deleted file mode 100644 index 95d5c15add..0000000000 --- a/sw/ground_segment/multimon/gen.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * gen.h -- generate different test signals - * - * Copyright (C) 1997 - * Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* ---------------------------------------------------------------------- */ - -#define SAMPLE_RATE 22050 -#define MS(x) ((float)(x)*SAMPLE_RATE/1000) - -extern const int costabi[0x400]; - -#define COS(x) costabi[(((x)>>6)&0x3ffu)] - -enum gen_type { gentype_dtmf, gentype_sine, gentype_zvei, gentype_hdlc }; - -struct gen_params { - enum gen_type type; - int ampl; - union { - struct { - int duration; - int pause; - char str[256]; - } dtmf; - struct { - int duration; - int freq; - } sine; - struct { - int duration; - int pause; - char str[256]; - } zvei; - struct { - int modulation; - int txdelay; - int pktlen; - unsigned char pkt[256]; - } hdlc; - } p; -}; - -struct gen_state { - union { - struct { - int ch_idx; - int ph_row, ph_col, phinc_row, phinc_col; - int time, time2; - } dtmf; - struct { - int ph, phinc; - int time; - } sine; - struct { - int ch_idx; - int ph, phinc; - int time, time2; - } zvei; - struct { - int lastb; - int ch_idx, bitmask; - unsigned int ph, phinc, bitph; - unsigned int datalen; - unsigned char data[512]; - } hdlc; - } s; -}; - -extern void gen_init_dtmf(struct gen_params *p, struct gen_state *s); -extern int gen_dtmf(signed short *buf, int buflen, struct gen_params *p, struct gen_state *s); - -extern void gen_init_sine(struct gen_params *p, struct gen_state *s); -extern int gen_sine(signed short *buf, int buflen, struct gen_params *p, struct gen_state *s); - -extern void gen_init_zvei(struct gen_params *p, struct gen_state *s); -extern int gen_zvei(signed short *buf, int buflen, struct gen_params *p, struct gen_state *s); - -extern void gen_init_hdlc(struct gen_params *p, struct gen_state *s); -extern int gen_hdlc(signed short *buf, int buflen, struct gen_params *p, struct gen_state *s); - diff --git a/sw/ground_segment/multimon/multimon.h b/sw/ground_segment/multimon/multimon.h index 47b030fbbc..911b447789 100644 --- a/sw/ground_segment/multimon/multimon.h +++ b/sw/ground_segment/multimon/multimon.h @@ -33,154 +33,56 @@ extern const float costabf[0x400]; /* ---------------------------------------------------------------------- */ struct demod_state { - const struct demod_param *dem_par; - union { - struct l2_state_hdlc { - unsigned char rxbuf[512]; - unsigned char *rxptr; - unsigned int rxstate; - unsigned int rxbitstream; - unsigned int rxbitbuf; - } hdlc; + const struct demod_param *dem_par; + union { + struct l2_state_hdlc { + unsigned char rxbuf[512]; + unsigned char *rxptr; + unsigned int rxstate; + unsigned int rxbitstream; + unsigned int rxbitbuf; + } hdlc; - struct l2_state_pocsag { - unsigned long rx_data; - struct l2_pocsag_rx { - unsigned char rx_sync; - unsigned char rx_word; - unsigned char rx_bit; - char func; - unsigned long adr; - unsigned char buffer[128]; - unsigned int numnibbles; - } rx[2]; - } pocsag; - - struct l2_state_pprz { - unsigned char rxbuf[512]; - unsigned char *rxptr; - unsigned int rxstate; - unsigned int rxbitstream; - unsigned int rxbitbuf; - char* pipe_path; - int pipe_fd; - } pprz; - } l2; - union { - struct l1_state_poc5 { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int subsamp; - } poc5; + struct l2_state_pprz { + unsigned char rxbuf[512]; + unsigned char *rxptr; + unsigned int rxstate; + unsigned int rxbitstream; + unsigned int rxbitbuf; + char* pipe_path; + int pipe_fd; + } pprz; + } l2; + union { + struct l1_state_afsk48p { + unsigned int dcd_shreg; + unsigned int sphase; + unsigned int lasts; + unsigned int dcd_count; + unsigned int sample_count; + } afsk48p; - struct l1_state_poc12 { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int subsamp; - } poc12; - - struct l1_state_poc24 { - unsigned int dcd_shreg; - unsigned int sphase; - } poc24; - - struct l1_state_afsk12 { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int lasts; - unsigned int subsamp; - } afsk12; - - struct l1_state_afsk24 { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int lasts; - } afsk24; - - struct l1_state_afsk48p { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int lasts; - unsigned int dcd_count; - unsigned int sample_count; - } afsk48p; - - struct l1_state_afsk48 { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int lasts; - unsigned int dcd_count; - unsigned int sample_count; - } afsk48; - - struct l1_state_hapn48 { - unsigned int shreg; - unsigned int sphase; - float lvllo, lvlhi; - } hapn48; - - struct l1_state_fsk96 { - unsigned int dcd_shreg; - unsigned int sphase; - unsigned int descram; - } fsk96; - - struct l1_state_dtmf { - unsigned int ph[8]; - float energy[4]; - float tenergy[4][16]; - int blkcount; - int lastch; - } dtmf; - - struct l1_state_zvei { - unsigned int ph[16]; - float energy[4]; - float tenergy[4][32]; - int blkcount; - int lastch; - } zvei; - - struct l1_state_scope { - int datalen; - int dispnum; - float data[512]; - } scope; - } l1; + struct l1_state_scope { + int datalen; + int dispnum; + float data[512]; + } scope; + } l1; }; struct demod_param { - const char *name; - unsigned int samplerate; - unsigned int overlap; - void (*init)(struct demod_state *s); - void (*demod)(struct demod_state *s, float *buffer, int length); + const char *name; + unsigned int samplerate; + unsigned int overlap; + void (*init)(struct demod_state *s); + void (*demod)(struct demod_state *s, float *buffer, int length); }; /* ---------------------------------------------------------------------- */ -extern const struct demod_param demod_poc5; -extern const struct demod_param demod_poc12; -extern const struct demod_param demod_poc24; - -extern const struct demod_param demod_afsk1200; -extern const struct demod_param demod_afsk2400; -extern const struct demod_param demod_afsk2400_2; extern const struct demod_param demod_afsk4800p; -extern const struct demod_param demod_afsk4800; - -extern const struct demod_param demod_hapn4800; -extern const struct demod_param demod_fsk9600; - -extern const struct demod_param demod_dtmf; -extern const struct demod_param demod_zvei; - extern const struct demod_param demod_scope; -/* #define ALL_DEMOD &demod_poc5, &demod_poc12, &demod_poc24, \ */ -/* &demod_afsk1200, &demod_afsk2400, &demod_afsk2400_2, &demod_afsk4800p, \ */ -/* &demod_afsk4800, &demod_hapn4800, &demod_fsk9600, &demod_dtmf, \ */ -/* &demod_zvei, &demod_scope */ #define ALL_DEMOD &demod_afsk4800p,&demod_scope /* ---------------------------------------------------------------------- */ @@ -190,9 +92,6 @@ void verbprintf(int verb_level, const char *fmt, ...); void hdlc_init(struct demod_state *s); void hdlc_rxbit(struct demod_state *s, int bit); -void pocsag_init(struct demod_state *s); -void pocsag_rxbit(struct demod_state *s, int bit); - void pprz_init(struct demod_state *s); void pprz_rxbit(struct demod_state *s, int bit); void pprz_status(struct demod_state *s); diff --git a/sw/ground_segment/multimon/unixinput.c b/sw/ground_segment/multimon/unixinput.c index 3c4e855e1f..5c55633b15 100644 --- a/sw/ground_segment/multimon/unixinput.c +++ b/sw/ground_segment/multimon/unixinput.c @@ -46,8 +46,8 @@ /* ---------------------------------------------------------------------- */ static const char *allowed_types[] = { - "raw", "aiff", "au", "hcom", "sf", "voc", "cdr", "dat", - "smp", "wav", "maud", "vwe", NULL + "raw", "aiff", "au", "hcom", "sf", "voc", "cdr", "dat", + "smp", "wav", "maud", "vwe", NULL }; /* ---------------------------------------------------------------------- */ @@ -71,23 +71,23 @@ static int verbose_level = 0; void verbprintf(int verb_level, const char *fmt, ...) { - va_list args; + va_list args; - va_start(args, fmt); - if (verb_level <= verbose_level) - vfprintf(stdout, fmt, args); - va_end(args); + va_start(args, fmt); + if (verb_level <= verbose_level) + vfprintf(stdout, fmt, args); + va_end(args); } /* ---------------------------------------------------------------------- */ static void process_buffer(float *buf, unsigned int len) { - int i; + int i; - for (i = 0; i < NUMDEMOD; i++) - if (MASK_ISSET(i) && dem[i]->demod) - dem[i]->demod(dem_st+i, buf, len); + for (i = 0; i < NUMDEMOD; i++) + if (MASK_ISSET(i) && dem[i]->demod) + dem[i]->demod(dem_st+i, buf, len); } /* ---------------------------------------------------------------------- */ @@ -96,68 +96,68 @@ static void process_buffer(float *buf, unsigned int len) static void input_sound(unsigned int sample_rate, unsigned int overlap, const char *ifname) { - audio_info_t audioinfo; - audio_info_t audioinfo2; - audio_device_t audiodev; - int fd; - short buffer[8192]; - float fbuf[16384]; - unsigned int fbuf_cnt = 0; - int i; - short *sp; + audio_info_t audioinfo; + audio_info_t audioinfo2; + audio_device_t audiodev; + int fd; + short buffer[8192]; + float fbuf[16384]; + unsigned int fbuf_cnt = 0; + int i; + short *sp; - if ((fd = open(ifname ? ifname : "/dev/audio", O_RDONLY)) < 0) { - perror("open"); - exit (10); - } - if (ioctl(fd, AUDIO_GETDEV, &audiodev) == -1) { - perror("ioctl: AUDIO_GETDEV"); - exit (10); - } - AUDIO_INITINFO(&audioinfo); - audioinfo.record.sample_rate = sample_rate; - audioinfo.record.channels = 1; - audioinfo.record.precision = 16; - audioinfo.record.encoding = AUDIO_ENCODING_LINEAR; - /*audioinfo.record.gain = 0x20; - audioinfo.record.port = AUDIO_LINE_IN; - audioinfo.monitor_gain = 0;*/ - if (ioctl(fd, AUDIO_SETINFO, &audioinfo) == -1) { - perror("ioctl: AUDIO_SETINFO"); - exit (10); - } - if (ioctl(fd, I_FLUSH, FLUSHR) == -1) { - perror("ioctl: I_FLUSH"); - exit (10); - } - if (ioctl(fd, AUDIO_GETINFO, &audioinfo2) == -1) { - perror("ioctl: AUDIO_GETINFO"); - exit (10); - } - fprintf(stdout, "Audio device: name %s, ver %s, config %s, " - "sampling rate %d\n", audiodev.name, audiodev.version, - audiodev.config, audioinfo.record.sample_rate); - for (;;) { - i = read(fd, sp = buffer, sizeof(buffer)); - if (i < 0 && errno != EAGAIN) { - perror("read"); - exit(4); - } - if (!i) - break; - if (i > 0) { - for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++) - fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); - if (i) - fprintf(stderr, "warning: noninteger number of samples read\n"); - if (fbuf_cnt > overlap) { - process_buffer(fbuf, fbuf_cnt-overlap); - memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); - fbuf_cnt = overlap; - } - } - } - close(fd); + if ((fd = open(ifname ? ifname : "/dev/audio", O_RDONLY)) < 0) { + perror("open"); + exit (10); + } + if (ioctl(fd, AUDIO_GETDEV, &audiodev) == -1) { + perror("ioctl: AUDIO_GETDEV"); + exit (10); + } + AUDIO_INITINFO(&audioinfo); + audioinfo.record.sample_rate = sample_rate; + audioinfo.record.channels = 1; + audioinfo.record.precision = 16; + audioinfo.record.encoding = AUDIO_ENCODING_LINEAR; + /*audioinfo.record.gain = 0x20; + audioinfo.record.port = AUDIO_LINE_IN; + audioinfo.monitor_gain = 0;*/ + if (ioctl(fd, AUDIO_SETINFO, &audioinfo) == -1) { + perror("ioctl: AUDIO_SETINFO"); + exit (10); + } + if (ioctl(fd, I_FLUSH, FLUSHR) == -1) { + perror("ioctl: I_FLUSH"); + exit (10); + } + if (ioctl(fd, AUDIO_GETINFO, &audioinfo2) == -1) { + perror("ioctl: AUDIO_GETINFO"); + exit (10); + } + fprintf(stdout, "Audio device: name %s, ver %s, config %s, " + "sampling rate %d\n", audiodev.name, audiodev.version, + audiodev.config, audioinfo.record.sample_rate); + for (;;) { + i = read(fd, sp = buffer, sizeof(buffer)); + if (i < 0 && errno != EAGAIN) { + perror("read"); + exit(4); + } + if (!i) + break; + if (i > 0) { + for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++) + fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); + if (i) + fprintf(stderr, "warning: noninteger number of samples read\n"); + if (fbuf_cnt > overlap) { + process_buffer(fbuf, fbuf_cnt-overlap); + memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); + fbuf_cnt = overlap; + } + } + } + close(fd); } #else /* SUN_AUDIO */ @@ -166,126 +166,126 @@ static void input_sound(unsigned int sample_rate, unsigned int overlap, static void input_sound(unsigned int sample_rate, unsigned int overlap, const char *ifname) { - int sndparam; - int fd; - union { - short s[8192]; - unsigned char b[8192]; - } b; - float fbuf[16384]; - unsigned int fbuf_cnt = 0; - int i; - short *sp; - unsigned char *bp; - int fmt = 0; - int stereo = 0; + int sndparam; + int fd; + union { + short s[8192]; + unsigned char b[8192]; + } b; + float fbuf[16384]; + unsigned int fbuf_cnt = 0; + int i; + short *sp; + unsigned char *bp; + int fmt = 0; + int stereo = 0; - if ((fd = open(ifname ? ifname : "/dev/dsp", O_RDONLY)) < 0) { - perror("open"); - exit (10); - } - sndparam = AFMT_S16_LE; /* we want 16 bits/sample signed */ - /* little endian; works only on little endian systems! */ - if (ioctl(fd, SNDCTL_DSP_SETFMT, &sndparam) == -1) { - perror("ioctl: SNDCTL_DSP_SETFMT"); - exit (10); - } - if (sndparam != AFMT_S16_LE) { - fmt = 1; - sndparam = AFMT_U8; - if (ioctl(fd, SNDCTL_DSP_SETFMT, &sndparam) == -1) { - perror("ioctl: SNDCTL_DSP_SETFMT"); - exit (10); - } - if (sndparam != AFMT_U8) { - perror("ioctl: SNDCTL_DSP_SETFMT"); - exit (10); - } - } - sndparam = 0; /* we want only 1 channel */ - if (ioctl(fd, SNDCTL_DSP_STEREO, &sndparam) == -1) { - perror("ioctl: SNDCTL_DSP_STEREO"); - exit (10); - } - if (sndparam == 1) { - fprintf(stderr, "soundif: Warning, cannot set the channel " - "number to 1, will use stereo\n"); - stereo=1; - } else - if (sndparam != 0) { - fprintf(stderr, "soundif: Error, cannot set the channel " - "number to 1\n"); - exit (10); - } - sndparam = sample_rate; - if (ioctl(fd, SNDCTL_DSP_SPEED, &sndparam) == -1) { - perror("ioctl: SNDCTL_DSP_SPEED"); - exit (10); - } - if ((10*abs(sndparam-sample_rate)) > sample_rate) { - perror("ioctl: SNDCTL_DSP_SPEED"); - exit (10); - } - if (sndparam != sample_rate) { - fprintf(stderr, "Warning: Sampling rate is %u, " - "requested %u\n", sndparam, sample_rate); - } + if ((fd = open(ifname ? ifname : "/dev/dsp", O_RDONLY)) < 0) { + perror("open"); + exit (10); + } + sndparam = AFMT_S16_LE; /* we want 16 bits/sample signed */ + /* little endian; works only on little endian systems! */ + if (ioctl(fd, SNDCTL_DSP_SETFMT, &sndparam) == -1) { + perror("ioctl: SNDCTL_DSP_SETFMT"); + exit (10); + } + if (sndparam != AFMT_S16_LE) { + fmt = 1; + sndparam = AFMT_U8; + if (ioctl(fd, SNDCTL_DSP_SETFMT, &sndparam) == -1) { + perror("ioctl: SNDCTL_DSP_SETFMT"); + exit (10); + } + if (sndparam != AFMT_U8) { + perror("ioctl: SNDCTL_DSP_SETFMT"); + exit (10); + } + } + sndparam = 0; /* we want only 1 channel */ + if (ioctl(fd, SNDCTL_DSP_STEREO, &sndparam) == -1) { + perror("ioctl: SNDCTL_DSP_STEREO"); + exit (10); + } + if (sndparam == 1) { + fprintf(stderr, "soundif: Warning, cannot set the channel " + "number to 1, will use stereo\n"); + stereo=1; + } else + if (sndparam != 0) { + fprintf(stderr, "soundif: Error, cannot set the channel " + "number to 1\n"); + exit (10); + } + sndparam = sample_rate; + if (ioctl(fd, SNDCTL_DSP_SPEED, &sndparam) == -1) { + perror("ioctl: SNDCTL_DSP_SPEED"); + exit (10); + } + if ((10*abs(sndparam-sample_rate)) > sample_rate) { + perror("ioctl: SNDCTL_DSP_SPEED"); + exit (10); + } + if (sndparam != sample_rate) { + fprintf(stderr, "Warning: Sampling rate is %u, " + "requested %u\n", sndparam, sample_rate); + } #if 0 - sndparam = 4; - if (ioctl(fd, SOUND_PCM_SUBDIVIDE, &sndparam) == -1) { - perror("ioctl: SOUND_PCM_SUBDIVIDE"); - } - if (sndparam != 4) { - perror("ioctl: SOUND_PCM_SUBDIVIDE"); - } + sndparam = 4; + if (ioctl(fd, SOUND_PCM_SUBDIVIDE, &sndparam) == -1) { + perror("ioctl: SOUND_PCM_SUBDIVIDE"); + } + if (sndparam != 4) { + perror("ioctl: SOUND_PCM_SUBDIVIDE"); + } #endif - for (;;) { - if (fmt) { - i = read(fd, bp = b.b, sizeof(b.b)); - if (i < 0 && errno != EAGAIN) { - perror("read"); - exit(4); - } - if (!i) - break; - if (i > 0) { - for (; i >= sizeof(b.b[0]); i -= sizeof(b.b[0]), sp++) - fbuf[fbuf_cnt++] = ((int)(*bp)-0x80) * (1.0/128.0); - if (i) - fprintf(stderr, "warning: noninteger number of samples read\n"); - if (fbuf_cnt > overlap) { - process_buffer(fbuf, fbuf_cnt-overlap); - memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); - fbuf_cnt = overlap; - } - } - } else { - i = read(fd, sp = b.s, sizeof(b.s)); - if (i < 0 && errno != EAGAIN) { - perror("read"); - exit(4); - } - if (!i) - break; - if (i > 0) { - if (stereo) { - for (; i >= sizeof(b.s[0]); i -= (sizeof(b.s[0])*2), sp+=2) - fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); - } else { - for (; i >= sizeof(b.s[0]); i -= sizeof(b.s[0]), sp++) - fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); - } - if (i) - fprintf(stderr, "warning: noninteger number of samples read\n"); - if (fbuf_cnt > overlap) { - process_buffer(fbuf, fbuf_cnt-overlap); - memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); - fbuf_cnt = overlap; - } - } - } + for (;;) { + if (fmt) { + i = read(fd, bp = b.b, sizeof(b.b)); + if (i < 0 && errno != EAGAIN) { + perror("read"); + exit(4); + } + if (!i) + break; + if (i > 0) { + for (; i >= sizeof(b.b[0]); i -= sizeof(b.b[0]), sp++) + fbuf[fbuf_cnt++] = ((int)(*bp)-0x80) * (1.0/128.0); + if (i) + fprintf(stderr, "warning: noninteger number of samples read\n"); + if (fbuf_cnt > overlap) { + process_buffer(fbuf, fbuf_cnt-overlap); + memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); + fbuf_cnt = overlap; } - close(fd); + } + } else { + i = read(fd, sp = b.s, sizeof(b.s)); + if (i < 0 && errno != EAGAIN) { + perror("read"); + exit(4); + } + if (!i) + break; + if (i > 0) { + if (stereo) { + for (; i >= sizeof(b.s[0]); i -= (sizeof(b.s[0])*2), sp+=2) + fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); + } else { + for (; i >= sizeof(b.s[0]); i -= sizeof(b.s[0]), sp++) + fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); + } + if (i) + fprintf(stderr, "warning: noninteger number of samples read\n"); + if (fbuf_cnt > overlap) { + process_buffer(fbuf, fbuf_cnt-overlap); + memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); + fbuf_cnt = overlap; + } + } + } + } + close(fd); } #endif /* SUN_AUDIO */ @@ -294,218 +294,218 @@ static void input_sound(unsigned int sample_rate, unsigned int overlap, static void input_file(unsigned int sample_rate, unsigned int overlap, const char *fname, const char *type) { - struct stat statbuf; - int pipedes[2]; - int pid = 0, soxstat; - int fd; - int i; - short buffer[8192]; - float fbuf[16384]; - unsigned int fbuf_cnt = 0; - short *sp; + struct stat statbuf; + int pipedes[2]; + int pid = 0, soxstat; + int fd; + int i; + short buffer[8192]; + float fbuf[16384]; + unsigned int fbuf_cnt = 0; + short *sp; - /* - * if the input type is not raw, sox is started to convert the - * samples to the requested format - */ - if (!type || !strcmp(type, "raw")) { - if ((fd = open(fname, O_RDONLY)) < 0) { - perror("open"); - exit(10); - } - } else { - if (stat(fname, &statbuf)) { - perror("stat"); - exit(10); - } - if (pipe(pipedes)) { - perror("pipe"); - exit(10); - } - if (!(pid = fork())) { - char srate[8]; - /* - * child starts here... first set up filedescriptors, - * then start sox... - */ - sprintf(srate, "%d", sample_rate); - close(pipedes[0]); /* close reading pipe end */ - close(1); /* close standard output */ - if (dup2(pipedes[1], 1) < 0) - perror("dup2"); - close(pipedes[1]); /* close writing pipe end */ - execlp("sox", "sox", - "-t", type, fname, - "-t", "raw", "-s", "-w", "-r", srate, "-", - NULL); - perror("execlp"); - exit(10); - } - if (pid < 0) { - perror("fork"); - exit(10); - } - close(pipedes[1]); /* close writing pipe end */ - fd = pipedes[0]; - } - /* - * demodulate - */ - for (;;) { - i = read(fd, sp = buffer, sizeof(buffer)); - if (i < 0 && errno != EAGAIN) { - perror("read"); - exit(4); - } - if (!i) - break; - if (i > 0) { - for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++) - fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); - if (i) - fprintf(stderr, "warning: noninteger number of samples read\n"); - if (fbuf_cnt > overlap) { - process_buffer(fbuf, fbuf_cnt-overlap); - memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); - fbuf_cnt = overlap; - } - } - } - close(fd); - waitpid(pid, &soxstat, 0); + /* + * if the input type is not raw, sox is started to convert the + * samples to the requested format + */ + if (!type || !strcmp(type, "raw")) { + if ((fd = open(fname, O_RDONLY)) < 0) { + perror("open"); + exit(10); + } + } else { + if (stat(fname, &statbuf)) { + perror("stat"); + exit(10); + } + if (pipe(pipedes)) { + perror("pipe"); + exit(10); + } + if (!(pid = fork())) { + char srate[8]; + /* + * child starts here... first set up filedescriptors, + * then start sox... + */ + sprintf(srate, "%d", sample_rate); + close(pipedes[0]); /* close reading pipe end */ + close(1); /* close standard output */ + if (dup2(pipedes[1], 1) < 0) + perror("dup2"); + close(pipedes[1]); /* close writing pipe end */ + execlp("sox", "sox", + "-t", type, fname, + "-t", "raw", "-s", "-w", "-r", srate, "-", + NULL); + perror("execlp"); + exit(10); + } + if (pid < 0) { + perror("fork"); + exit(10); + } + close(pipedes[1]); /* close writing pipe end */ + fd = pipedes[0]; + } + /* + * demodulate + */ + for (;;) { + i = read(fd, sp = buffer, sizeof(buffer)); + if (i < 0 && errno != EAGAIN) { + perror("read"); + exit(4); + } + if (!i) + break; + if (i > 0) { + for (; i >= sizeof(buffer[0]); i -= sizeof(buffer[0]), sp++) + fbuf[fbuf_cnt++] = (*sp) * (1.0/32768.0); + if (i) + fprintf(stderr, "warning: noninteger number of samples read\n"); + if (fbuf_cnt > overlap) { + process_buffer(fbuf, fbuf_cnt-overlap); + memmove(fbuf, fbuf+fbuf_cnt-overlap, overlap*sizeof(fbuf[0])); + fbuf_cnt = overlap; + } + } + } + close(fd); + waitpid(pid, &soxstat, 0); } /* ---------------------------------------------------------------------- */ static const char usage_str[] = "multimod\n" -"Demodulates many different radio transmission formats\n" -"(C) 1996 by Thomas Sailer HB9JNX/AE4WA\n" -" -t : input file type (any other type than raw requires sox)\n" -" -a : add demodulator\n" -" -p : output\n" -" -s : subtract demodulator\n"; + "Demodulates many different radio transmission formats\n" + "(C) 1996 by Thomas Sailer HB9JNX/AE4WA\n" + " -t : input file type (any other type than raw requires sox)\n" + " -a : add demodulator\n" + " -p : output\n" + " -s : subtract demodulator\n"; int main(int argc, char *argv[]) { - int c; - int errflg = 0; - int i; - char **itype; - int mask_first = 1; - int sample_rate = -1; - unsigned int overlap = 0; - char *input_type = "hw"; + int c; + int errflg = 0; + int i; + char **itype; + int mask_first = 1; + int sample_rate = -1; + unsigned int overlap = 0; + char *input_type = "hw"; - fprintf(stdout, "multimod (C) 1996/1997 by Tom Sailer HB9JNX/AE4WA\n" - "available demodulators:"); - for (i = 0; i < NUMDEMOD; i++) - fprintf(stdout, " %s", dem[i]->name); - fprintf(stdout, "\n"); - while ((c = getopt(argc, argv, "t:a:p:s:v:")) != EOF) { - switch (c) { - case '?': - errflg++; - break; + fprintf(stdout, "multimod (C) 1996/1997 by Tom Sailer HB9JNX/AE4WA\n" + "available demodulators:"); + for (i = 0; i < NUMDEMOD; i++) + fprintf(stdout, " %s", dem[i]->name); + fprintf(stdout, "\n"); + while ((c = getopt(argc, argv, "t:a:p:s:v:")) != EOF) { + switch (c) { + case '?': + errflg++; + break; - case 'v': - verbose_level = strtoul(optarg, 0, 0); - break; + case 'v': + verbose_level = strtoul(optarg, 0, 0); + break; - case 't': - for (itype = (char **)allowed_types; *itype; itype++) - if (!strcmp(*itype, optarg)) { - input_type = *itype; - goto intypefound; - } - fprintf(stderr, "invalid input type \"%s\"\n" - "allowed types: ", optarg); - for (itype = (char **)allowed_types; *itype; itype++) - fprintf(stderr, "%s ", *itype); - fprintf(stderr, "\n"); - errflg++; - intypefound: - break; + case 't': + for (itype = (char **)allowed_types; *itype; itype++) + if (!strcmp(*itype, optarg)) { + input_type = *itype; + goto intypefound; + } + fprintf(stderr, "invalid input type \"%s\"\n" + "allowed types: ", optarg); + for (itype = (char **)allowed_types; *itype; itype++) + fprintf(stderr, "%s ", *itype); + fprintf(stderr, "\n"); + errflg++; + intypefound: + break; - case 'a': - if (mask_first) - memset(dem_mask, 0, sizeof(dem_mask)); - mask_first = 0; - for (i = 0; i < NUMDEMOD; i++) - if (!strcasecmp(optarg, dem[i]->name)) { - MASK_SET(i); - break; - } - if (i >= NUMDEMOD) { - fprintf(stderr, "invalid mode \"%s\"\n", optarg); - errflg++; - } - break; + case 'a': + if (mask_first) + memset(dem_mask, 0, sizeof(dem_mask)); + mask_first = 0; + for (i = 0; i < NUMDEMOD; i++) + if (!strcasecmp(optarg, dem[i]->name)) { + MASK_SET(i); + break; + } + if (i >= NUMDEMOD) { + fprintf(stderr, "invalid mode \"%s\"\n", optarg); + errflg++; + } + break; - case 'p': - printf("pipe=%s\n", optarg); - strcpy(multimon_pipe_name, optarg); - break; + case 'p': + printf("pipe=%s\n", optarg); + strcpy(multimon_pipe_name, optarg); + break; - case 's': - if (mask_first) - memset(dem_mask, 0xff, sizeof(dem_mask)); - mask_first = 0; - for (i = 0; i < NUMDEMOD; i++) - if (!strcasecmp(optarg, dem[i]->name)) { - MASK_RESET(i); - break; - } - if (i >= NUMDEMOD) { - fprintf(stderr, "invalid mode \"%s\"\n", optarg); - errflg++; - } - break; + case 's': + if (mask_first) + memset(dem_mask, 0xff, sizeof(dem_mask)); + mask_first = 0; + for (i = 0; i < NUMDEMOD; i++) + if (!strcasecmp(optarg, dem[i]->name)) { + MASK_RESET(i); + break; + } + if (i >= NUMDEMOD) { + fprintf(stderr, "invalid mode \"%s\"\n", optarg); + errflg++; + } + break; - } - } - if (errflg) { - (void)fprintf(stderr, usage_str); - exit(2); - } - if (mask_first) - memset(dem_mask, 0xff, sizeof(dem_mask)); + } + } + if (errflg) { + (void)fprintf(stderr, usage_str); + exit(2); + } + if (mask_first) + memset(dem_mask, 0xff, sizeof(dem_mask)); - fprintf(stdout, "Enabled demodulators:"); - for (i = 0; i < NUMDEMOD; i++) - if (MASK_ISSET(i)) { - fprintf(stdout, " %s", dem[i]->name); - memset(dem_st+i, 0, sizeof(dem_st[i])); - dem_st[i].dem_par = dem[i]; - if (dem[i]->init) - dem[i]->init(dem_st+i); - if (sample_rate == -1) - sample_rate = dem[i]->samplerate; - else if (sample_rate != dem[i]->samplerate) { - fprintf(stdout, "\n"); - fprintf(stderr, "Error: Current sampling rate %d, " - " demodulator \"%s\" requires %d\n", - sample_rate, dem[i]->name, dem[i]->samplerate); - exit(3); - } - if (dem[i]->overlap > overlap) - overlap = dem[i]->overlap; - } + fprintf(stdout, "Enabled demodulators:"); + for (i = 0; i < NUMDEMOD; i++) + if (MASK_ISSET(i)) { + fprintf(stdout, " %s", dem[i]->name); + memset(dem_st+i, 0, sizeof(dem_st[i])); + dem_st[i].dem_par = dem[i]; + if (dem[i]->init) + dem[i]->init(dem_st+i); + if (sample_rate == -1) + sample_rate = dem[i]->samplerate; + else if (sample_rate != dem[i]->samplerate) { fprintf(stdout, "\n"); + fprintf(stderr, "Error: Current sampling rate %d, " + " demodulator \"%s\" requires %d\n", + sample_rate, dem[i]->name, dem[i]->samplerate); + exit(3); + } + if (dem[i]->overlap > overlap) + overlap = dem[i]->overlap; + } + fprintf(stdout, "\n"); - if (!strcmp(input_type, "hw")) { - if ((argc - optind) >= 1) - input_sound(sample_rate, overlap, argv[optind]); - else - input_sound(sample_rate, overlap, NULL); - exit(0); - } - if ((argc - optind) < 1) { - (void)fprintf(stderr, "no source files specified\n"); - exit(4); - } - for (i = optind; i < argc; i++) - input_file(sample_rate, overlap, argv[i], input_type); - exit(0); + if (!strcmp(input_type, "hw")) { + if ((argc - optind) >= 1) + input_sound(sample_rate, overlap, argv[optind]); + else + input_sound(sample_rate, overlap, NULL); + exit(0); + } + if ((argc - optind) < 1) { + (void)fprintf(stderr, "no source files specified\n"); + exit(4); + } + for (i = optind; i < argc; i++) + input_file(sample_rate, overlap, argv[i], input_type); + exit(0); } /* ---------------------------------------------------------------------- */