2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Module: audio.h
|
|
|
|
*
|
2015-07-27 01:17:23 +00:00
|
|
|
* Purpose: Interface to audio device commonly called a "sound card"
|
|
|
|
* for historical reasons.
|
2015-07-27 00:35:07 +00:00
|
|
|
*
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef AUDIO_H
|
|
|
|
#define AUDIO_H 1
|
|
|
|
|
2015-10-27 16:31:02 +00:00
|
|
|
#ifdef USE_HAMLIB
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#endif
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
#include "direwolf.h" /* for MAX_CHANS used throughout the application. */
|
2015-07-27 01:17:23 +00:00
|
|
|
#include "ax25_pad.h" /* for AX25_MAX_ADDR_LEN */
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PTT control.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum ptt_method_e {
|
|
|
|
PTT_METHOD_NONE, /* VOX or no transmit. */
|
|
|
|
PTT_METHOD_SERIAL, /* Serial port RTS or DTR. */
|
2015-07-27 01:05:48 +00:00
|
|
|
PTT_METHOD_GPIO, /* General purpose I/O, Linux only. */
|
2015-10-27 16:31:02 +00:00
|
|
|
PTT_METHOD_LPT, /* Parallel printer port, Linux only. */
|
|
|
|
PTT_METHOD_HAMLIB }; /* HAMLib, Linux only. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
typedef enum ptt_method_e ptt_method_t;
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
enum ptt_line_e { PTT_LINE_NONE = 0, PTT_LINE_RTS = 1, PTT_LINE_DTR = 2 }; // Important: 0 for neither.
|
2015-07-27 00:35:07 +00:00
|
|
|
typedef enum ptt_line_e ptt_line_t;
|
|
|
|
|
|
|
|
enum audio_in_type_e {
|
|
|
|
AUDIO_IN_TYPE_SOUNDCARD,
|
|
|
|
AUDIO_IN_TYPE_SDR_UDP,
|
|
|
|
AUDIO_IN_TYPE_STDIN };
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
/* For option to try fixing frames with bad CRC. */
|
|
|
|
|
|
|
|
typedef enum retry_e {
|
|
|
|
RETRY_NONE=0,
|
|
|
|
RETRY_SWAP_SINGLE=1,
|
|
|
|
RETRY_SWAP_DOUBLE=2,
|
|
|
|
RETRY_SWAP_TRIPLE=3,
|
|
|
|
RETRY_REMOVE_SINGLE=4,
|
|
|
|
RETRY_REMOVE_DOUBLE=5,
|
|
|
|
RETRY_REMOVE_TRIPLE=6,
|
|
|
|
RETRY_INSERT_SINGLE=7,
|
|
|
|
RETRY_INSERT_DOUBLE=8,
|
|
|
|
RETRY_SWAP_TWO_SEP=9,
|
|
|
|
RETRY_SWAP_MANY=10,
|
|
|
|
RETRY_REMOVE_MANY=11,
|
|
|
|
RETRY_REMOVE_TWO_SEP=12,
|
|
|
|
RETRY_MAX = 13} retry_t;
|
|
|
|
|
|
|
|
typedef enum sanity_e { SANITY_APRS, SANITY_AX25, SANITY_NONE } sanity_t;
|
|
|
|
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
struct audio_s {
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
/* Previously we could handle only a single audio device. */
|
|
|
|
/* In version 1.2, we generalize this to handle multiple devices. */
|
|
|
|
/* This means we can now have more than 2 radio channels. */
|
|
|
|
|
|
|
|
struct adev_param_s {
|
|
|
|
|
|
|
|
/* Properites of the sound device. */
|
|
|
|
|
|
|
|
int defined; /* Was device defined? */
|
|
|
|
/* First one defaults to yes. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
char adevice_in[80]; /* Name of the audio input device (or file?). */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* TODO: Can be "-" to read from stdin. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
char adevice_out[80]; /* Name of the audio output device (or file?). */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int num_channels; /* Should be 1 for mono or 2 for stereo. */
|
|
|
|
int samples_per_sec; /* Audio sampling rate. Typically 11025, 22050, or 44100. */
|
|
|
|
int bits_per_sample; /* 8 (unsigned char) or 16 (signed short). */
|
|
|
|
|
|
|
|
} adev[MAX_ADEVS];
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Common to all channels. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
char tts_script[80]; /* Script for text to speech. */
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
/* Properties for each audio channel, common to receive and transmit. */
|
|
|
|
/* Can be different for each radio channel. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
|
|
|
|
struct achan_param_s {
|
|
|
|
|
|
|
|
int valid; /* Is this channel valid? */
|
|
|
|
|
|
|
|
char mycall[AX25_MAX_ADDR_LEN]; /* Call associated with this radio channel. */
|
|
|
|
/* Could all be the same or different. */
|
|
|
|
|
|
|
|
|
|
|
|
enum modem_t { MODEM_AFSK, MODEM_BASEBAND, MODEM_SCRAMBLE, MODEM_OFF } modem_type;
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
/* Usual AFSK. */
|
2015-07-27 01:17:23 +00:00
|
|
|
/* Baseband signal. Not used yet. */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* Scrambled http://www.amsat.org/amsat/articles/g3ruh/109/fig03.gif */
|
2015-07-27 01:17:23 +00:00
|
|
|
/* No modem. Might want this for DTMF only channel. */
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
enum dtmf_decode_t { DTMF_DECODE_OFF, DTMF_DECODE_ON } dtmf_decode;
|
|
|
|
|
|
|
|
/* Originally the DTMF ("Touch Tone") decoder was always */
|
|
|
|
/* enabled because it took a negligible amount of CPU. */
|
|
|
|
/* There were complaints about the false positives when */
|
|
|
|
/* hearing other modulation schemes on HF SSB so now it */
|
|
|
|
/* is enabled only when needed. */
|
|
|
|
|
|
|
|
/* "On" will send special "t" packet to attached applications */
|
|
|
|
/* and process as APRStt. Someday we might want to separate */
|
|
|
|
/* these but for now, we have a single off/on. */
|
|
|
|
|
|
|
|
int decimate; /* Reduce AFSK sample rate by this factor to */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* decrease computational requirements. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int mark_freq; /* Two tones for AFSK modulation, in Hz. */
|
|
|
|
int space_freq; /* Standard tones are 1200 and 2200 for 1200 baud. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int baud; /* Data bits (more accurately, symbols) per second. */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* Standard rates are 1200 for VHF and 300 for HF. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
/* Next 3 come from config file or command line. */
|
|
|
|
|
|
|
|
char profiles[16]; /* zero or more of ABC etc, optional + */
|
|
|
|
|
|
|
|
int num_freq; /* Number of different frequency pairs for decoders. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int offset; /* Spacing between filter frequencies. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
/* Next two are derived from 3 above by demod_init. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int num_demod; /* Number of different demodulators (filters). */
|
|
|
|
/* Previously this was same as num_subchan but we add */
|
|
|
|
/* a new variation in version 1.2 where a single modem */
|
|
|
|
/* can feed multiple slicers and HDLC decoders. */
|
|
|
|
|
|
|
|
/* num_slicers could be added to be more general but */
|
|
|
|
/* for the intial experiment, we can just examine profiles. */
|
|
|
|
|
|
|
|
int num_subchan; /* Total number of modems / hdlc decoders for each channel. */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* Potentially it could be product of strlen(profiles) * num_freq. */
|
|
|
|
/* Currently can't use both at once. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
/* These are for dealing with imperfect frames. */
|
|
|
|
|
|
|
|
enum retry_e fix_bits; /* Level of effort to recover from */
|
|
|
|
/* a bad FCS on the frame. */
|
|
|
|
/* 0 = no effort */
|
|
|
|
/* 1 = try fixing a single bit */
|
|
|
|
/* 2... = more techniques... */
|
|
|
|
|
|
|
|
enum sanity_e sanity_test; /* Sanity test to apply when finding a good */
|
|
|
|
/* CRC after making a change. */
|
|
|
|
/* Must look like APRS, AX.25, or anything. */
|
|
|
|
|
|
|
|
int passall; /* Allow thru even with bad CRC. */
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
/* Additional properties for transmit. */
|
2015-07-27 01:17:23 +00:00
|
|
|
|
|
|
|
/* Originally we had control outputs only for PTT. */
|
|
|
|
/* In version 1.2, we generalize this to allow others such as DCD. */
|
|
|
|
/* Index following structure by one of these: */
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
#define OCTYPE_PTT 0
|
|
|
|
#define OCTYPE_DCD 1
|
2015-10-27 16:31:02 +00:00
|
|
|
#define OCTYPE_RIG 2
|
|
|
|
#define OCTYPE_FUTURE 3
|
2015-07-27 01:17:23 +00:00
|
|
|
|
2015-10-27 16:31:02 +00:00
|
|
|
#define NUM_OCTYPES 4 /* number of values above */
|
2015-07-27 01:17:23 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
|
2015-10-27 16:31:02 +00:00
|
|
|
ptt_method_t ptt_method; /* none, serial port, GPIO, LPT, HAMLIB. */
|
2015-07-27 01:17:23 +00:00
|
|
|
|
|
|
|
char ptt_device[20]; /* Serial device name for PTT. e.g. COM1 or /dev/ttyS0 */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
ptt_line_t ptt_line; /* Control line when using serial port. PTT_LINE_RTS, PTT_LINE_DTR. */
|
|
|
|
ptt_line_t ptt_line2; /* Optional second one: PTT_LINE_NONE when not used. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int ptt_gpio; /* GPIO number. */
|
2015-07-27 01:05:48 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int ptt_lpt_bit; /* Bit number for parallel printer port. */
|
2015-07-27 01:05:48 +00:00
|
|
|
/* Bit 0 = pin 2, ..., bit 7 = pin 9. */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int ptt_invert; /* Invert the output. */
|
|
|
|
int ptt_invert2; /* Invert the secondary output. */
|
|
|
|
|
2015-10-27 16:31:02 +00:00
|
|
|
#ifdef USE_HAMLIB
|
|
|
|
int ptt_rig; /* HAMLib rig. */
|
|
|
|
#endif
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
} octrl[NUM_OCTYPES];
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
/* Transmit timing. */
|
|
|
|
|
|
|
|
int dwait; /* First wait extra time for receiver squelch. */
|
|
|
|
/* Default 0 units of 10 mS each . */
|
|
|
|
|
|
|
|
int slottime; /* Slot time in 10 mS units for persistance algorithm. */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* Typical value is 10 meaning 100 milliseconds. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int persist; /* Sets probability for transmitting after each */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* slot time delay. Transmit if a random number */
|
|
|
|
/* in range of 0 - 255 <= persist value. */
|
|
|
|
/* Otherwise wait another slot time and try again. */
|
|
|
|
/* Default value is 63 for 25% probability. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int txdelay; /* After turning on the transmitter, */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* send "flags" for txdelay * 10 mS. */
|
|
|
|
/* Default value is 30 meaning 300 milliseconds. */
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int txtail; /* Amount of time to keep transmitting after we */
|
2015-07-27 00:35:07 +00:00
|
|
|
/* are done sending the data. This is to avoid */
|
|
|
|
/* dropping PTT too soon and chopping off the end */
|
|
|
|
/* of the frame. Again 10 mS units. */
|
|
|
|
/* At this point, I'm thinking of 10 as the default. */
|
2015-07-27 01:17:23 +00:00
|
|
|
|
|
|
|
} achan[MAX_CHANS];
|
|
|
|
|
2015-10-27 16:31:02 +00:00
|
|
|
#ifdef USE_HAMLIB
|
|
|
|
int rigs; /* Total number of configured rigs */
|
|
|
|
RIG *rig[MAX_RIGS]; /* HAMLib rig instances */
|
|
|
|
#endif
|
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
};
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
|
2015-07-27 00:35:07 +00:00
|
|
|
#if __WIN32__
|
|
|
|
#define DEFAULT_ADEVICE "" /* Windows: Empty string = default audio device. */
|
|
|
|
#else
|
|
|
|
#if USE_ALSA
|
|
|
|
#define DEFAULT_ADEVICE "default" /* Use default device for ALSA. */
|
|
|
|
#else
|
|
|
|
#define DEFAULT_ADEVICE "/dev/dsp" /* First audio device for OSS. */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* UDP audio receiving port. Couldn't find any standard or usage precedent.
|
|
|
|
* Got the number from this example: http://gqrx.dk/doc/streaming-audio-over-udp
|
|
|
|
* Any better suggestions?
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_UDP_AUDIO_PORT 7355
|
|
|
|
|
|
|
|
|
|
|
|
// Maximum size of the UDP buffer (for allowing IP routing, udp packets are often limited to 1472 bytes)
|
|
|
|
|
|
|
|
#define SDR_UDP_BUF_MAXLEN 2000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_NUM_CHANNELS 1
|
|
|
|
#define DEFAULT_SAMPLES_PER_SEC 44100 /* Very early observations. Might no longer be valid. */
|
|
|
|
/* 22050 works a lot better than 11025. */
|
|
|
|
/* 44100 works a little better than 22050. */
|
|
|
|
/* If you have a reasonable machine, use the highest rate. */
|
|
|
|
#define MIN_SAMPLES_PER_SEC 8000
|
|
|
|
#define MAX_SAMPLES_PER_SEC 48000 /* Formerly 44100. */
|
|
|
|
/* Software defined radio often uses 48000. */
|
|
|
|
|
|
|
|
#define DEFAULT_BITS_PER_SAMPLE 16
|
|
|
|
|
2015-07-27 01:05:48 +00:00
|
|
|
#define DEFAULT_FIX_BITS RETRY_SWAP_SINGLE
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Standard for AFSK on VHF FM.
|
|
|
|
* Reversing mark and space makes no difference because
|
|
|
|
* NRZI encoding only cares about change or lack of change
|
|
|
|
* between the two tones.
|
|
|
|
*
|
|
|
|
* HF SSB uses 300 baud and 200 Hz shift.
|
|
|
|
* 1600 & 1800 Hz is a popular tone pair, sometimes
|
|
|
|
* called the KAM tones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_MARK_FREQ 1200
|
|
|
|
#define DEFAULT_SPACE_FREQ 2200
|
|
|
|
#define DEFAULT_BAUD 1200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Typical transmit timings for VHF.
|
|
|
|
*/
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
#define DEFAULT_DWAIT 0
|
2015-07-27 00:35:07 +00:00
|
|
|
#define DEFAULT_SLOTTIME 10
|
|
|
|
#define DEFAULT_PERSIST 63
|
|
|
|
#define DEFAULT_TXDELAY 30
|
2015-07-27 01:17:23 +00:00
|
|
|
#define DEFAULT_TXTAIL 10
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that we have two versions of these in audio.c and audio_win.c.
|
|
|
|
* Use one or the other depending on the platform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int audio_open (struct audio_s *pa);
|
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int audio_get (int a); /* a = audio device, 0 for first */
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int audio_put (int a, int c);
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
int audio_flush (int a);
|
2015-07-27 00:35:07 +00:00
|
|
|
|
2015-07-27 01:17:23 +00:00
|
|
|
void audio_wait (int a);
|
2015-07-27 00:35:07 +00:00
|
|
|
|
|
|
|
int audio_close (void);
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* ifdef AUDIO_H */
|
|
|
|
|
|
|
|
|
|
|
|
/* end audio.h */
|
|
|
|
|