Browse Source

Add input device support

Add force sound rate option
master
Jeroen Vreeken 5 years ago
parent
commit
edf63f0987
4 changed files with 42 additions and 12 deletions
  1. +2
    -1
      Makefile
  2. +34
    -5
      analog_trx.c
  3. +5
    -5
      sound.c
  4. +1
    -1
      sound.h

+ 2
- 1
Makefile View File

@ -9,7 +9,8 @@ SRCS = \
interface.c \
sound.c \
alaw.c \
dsp.c
dsp.c \
input.c
OBJS = $(SRCS:.c=.o)


+ 34
- 5
analog_trx.c View File

@ -35,6 +35,7 @@
#include "sound.h"
#include "dtmf.h"
#include "alaw.h"
#include "input.h"
static bool verbose = false;
@ -62,17 +63,25 @@ int squelch_level_o = 100000;
int squelch_on_delay = 3;
int squelch_off_delay = 10;
bool squelch_input = false;
bool squelch(void)
{
dcd_t dcd;
if (dcd_type == RIG_DCD_NONE)
return false;
return squelch_input;
rig_get_dcd(rig, RIG_VFO_CURR, &dcd);
return dcd == RIG_DCD_ON;
}
void input_cb(bool state)
{
printf("DCD input: %d\n", state);
squelch_input = state;
}
bool soft_squelch(int16_t *samples, int nr)
{
double total = 0;
@ -405,6 +414,8 @@ static void usage(void)
printf("-p [dev]\tHAMlib PTT device file\n");
printf("-d [msec]\tTX delay\n");
printf("-t [msec]\tTX tail\n");
printf("-i [dev]\tUse input device instead of DCD\n");
printf("-r ]rate]\tSound rate\n");
}
int main(int argc, char **argv)
@ -412,23 +423,27 @@ int main(int argc, char **argv)
char *call = "pirate";
char *sounddev = "default";
char *netname = "analog";
char *inputdev = NULL;
int ssid = 0;
uint8_t mac[6];
int fd_int;
int fd_input = -1;
struct pollfd *fds;
int sound_fdc_tx;
int sound_fdc_rx;
int nfds;
int poll_int;
int poll_tty;
int poll_input;
int opt;
int mode = CODEC2_MODE_3200;
bool is_c2 = true;
bool tap = true;
int rate = 8000;
rig_model = 1; // set to dummy.
while ((opt = getopt(argc, argv, "vac:s:n:Sm:d:t:p:P:D:f")) != -1) {
while ((opt = getopt(argc, argv, "vac:i:s:n:Sm:d:t:p:P:D:fr:")) != -1) {
switch(opt) {
case 'v':
verbose = true;
@ -439,6 +454,9 @@ int main(int argc, char **argv)
case 'c':
call = optarg;
break;
case 'i':
inputdev = optarg;
break;
case 's':
sounddev = optarg;
break;
@ -495,6 +513,9 @@ int main(int argc, char **argv)
tx_tail = 1000000 * atoi(optarg);
tx_tail_ms = tx_tail / 1000000;
break;
case 'r':
rate = atoi(optarg);
break;
case 'f':
fullduplex = true;
break;
@ -519,9 +540,11 @@ int main(int argc, char **argv)
mod_silence = calloc(nr_samples, sizeof(mod_silence[0]));
fd_int = interface_init(netname, mac, tap);
sound_init(sounddev, cb_sound_in, nr_samples);
sound_init(sounddev, cb_sound_in, nr_samples, rate);
hl_init();
dtmf_init();
if (inputdev)
fd_input = input_init(inputdev);
prio();
@ -532,7 +555,7 @@ int main(int argc, char **argv)
sound_fdc_tx = sound_poll_count_tx();
sound_fdc_rx = sound_poll_count_rx();
nfds = sound_fdc_tx + sound_fdc_rx + 1 + 1;
nfds = sound_fdc_tx + sound_fdc_rx + 1 + 1 + 1;
fds = calloc(sizeof(struct pollfd), nfds);
sound_poll_fill_tx(fds, sound_fdc_tx);
@ -543,12 +566,15 @@ int main(int argc, char **argv)
poll_tty = poll_int + 1;
fds[poll_tty].fd = 0;
fds[poll_tty].events = POLLIN;
poll_input = poll_tty + 1;
fds[poll_input].fd = fd_input;
fds[poll_input].events = POLLIN;
do {
poll(fds, nfds, tx_state ? tx_tail_ms : -1);
if (fds[poll_int].revents & POLLIN) {
if (!tx_state && (!cdc || fullduplex)) {
if (!tx_state && (!cdc || fullduplex) && tx_delay) {
tx_delay_start();
} else {
interface_tx(cb_int_tx);
@ -558,6 +584,9 @@ int main(int argc, char **argv)
if (fds[poll_tty].revents & POLLIN) {
handle_tty();
}
if (fds[poll_input].revents & POLLIN) {
input_handle(fd_input, input_cb);
}
if (sound_poll_out_tx(fds, sound_fdc_tx)) {
sound_silence();
// sound_out(mod_silence, nr_samples);


+ 5
- 5
sound.c View File

@ -195,7 +195,7 @@ int sound_rx(void)
return 0;
}
int sound_param(snd_pcm_t *pcm_handle, bool is_tx)
int sound_param(snd_pcm_t *pcm_handle, bool is_tx, int force_rate)
{
int channels = 1;
snd_pcm_hw_params_t *hw_params;
@ -212,7 +212,7 @@ int sound_param(snd_pcm_t *pcm_handle, bool is_tx)
snd_pcm_hw_params_set_format (pcm_handle, hw_params, SND_PCM_FORMAT_S16_BE);
unsigned int rate = 8000;
unsigned int rrate = rate;
unsigned int rrate = force_rate;
if (snd_pcm_hw_params_set_rate_near (pcm_handle, hw_params, &rrate, NULL)) {
printf("Could not set rate %d\n", rrate);
@ -267,7 +267,7 @@ int sound_param(snd_pcm_t *pcm_handle, bool is_tx)
return 0;
}
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr)
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr, int rate)
{
int err;
@ -286,13 +286,13 @@ int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr)
if (err < 0)
return -1;
sound_param(pcm_handle_tx, true);
sound_param(pcm_handle_tx, true, rate);
err = snd_pcm_open (&pcm_handle_rx, device_name, SND_PCM_STREAM_CAPTURE, 0);
if (err < 0)
return -1;
sound_param(pcm_handle_rx, false);
sound_param(pcm_handle_rx, false, rate);
silence_nr = nr * ratio_out;
silence = calloc(silence_nr * 2, sizeof(int16_t));


+ 1
- 1
sound.h View File

@ -24,7 +24,7 @@
int sound_out(int16_t *samples, int nr);
int sound_silence(void);
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int nr);
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int nr, int rate);
int sound_poll_count_tx(void);
int sound_poll_fill_tx(struct pollfd *fds, int count);
bool sound_poll_out_tx(struct pollfd *fds, int count);


Loading…
Cancel
Save