Browse Source

Sync with freedv code.

master
Jeroen Vreeken 5 years ago
parent
commit
ca559da4eb
5 changed files with 28 additions and 24 deletions
  1. +9
    -6
      analog_trx.c
  2. +8
    -6
      interface.c
  3. +2
    -2
      interface.h
  4. +8
    -9
      sound.c
  5. +1
    -1
      sound.h

+ 9
- 6
analog_trx.c View File

@ -64,6 +64,9 @@ int squelch_level_o = 100000;
int squelch_on_delay = 3;
int squelch_off_delay = 10;
uint8_t mac[6];
uint8_t bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
bool squelch_input = false;
bool squelch(void)
@ -137,7 +140,7 @@ static void cb_control(char *ctrl)
printf("DTMF: %s\n", ctrl);
interface_rx(msg, strlen(ctrl), ETH_P_AR_CONTROL);
interface_rx(bcast, mac, ETH_P_AR_CONTROL, msg, strlen(ctrl));
}
void handle_tty(void)
@ -191,7 +194,7 @@ static void cb_sound_in(int16_t *samples, int nr)
codec2_encode(rx_codec, packed_codec_bits, samples_rx);
interface_rx(packed_codec_bits, bytes_per_codec_frame, rx_type);
interface_rx(bcast, mac, rx_type, packed_codec_bits, bytes_per_codec_frame);
}
nr_rx = 0;
}
@ -201,7 +204,7 @@ static void cb_sound_in(int16_t *samples, int nr)
alaw_encode(alaw, samples, nr);
interface_rx(alaw, nr, ETH_P_ALAW);
interface_rx(bcast, mac, ETH_P_ALAW, alaw, nr);
}
}
@ -211,7 +214,8 @@ static int tx_mode = -1;
static struct CODEC2 *tx_codec = NULL;
static int tx_bytes_per_codec_frame = 8;
static int cb_int_tx(uint8_t *data, size_t len, uint16_t eth_type)
static int cb_int_tx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len)
{
int newmode = 0;
bool is_c2 = true;
@ -425,7 +429,6 @@ int main(int argc, char **argv)
char *sounddev = "default";
char *netname = "analog";
char *inputdev = NULL;
uint8_t mac[6];
int fd_int;
int fd_input = -1;
struct pollfd *fds;
@ -588,7 +591,7 @@ 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, rate);
sound_init(sounddev, cb_sound_in, nr_samples, 8000, rate);
hl_init();
dtmf_init();
if (inputdev)


+ 8
- 6
interface.c View File

@ -33,12 +33,12 @@
static int fd;
static uint16_t eth_mac[6];
int interface_rx(uint8_t *data, size_t len, uint16_t eth_type)
int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len)
{
uint8_t packet[len + 14];
memset(packet, 0xff, 6);
memcpy(packet + 6, eth_mac, 6);
memcpy(packet, to, 6);
memcpy(packet + 6, from, 6);
packet[12] = eth_type >> 8;
packet[13] = eth_type & 0xff;
@ -49,7 +49,7 @@ int interface_rx(uint8_t *data, size_t len, uint16_t eth_type)
return 0;
}
int interface_tx(int (*cb)(uint8_t *data, size_t len, uint16_t eth_type))
int interface_tx(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len))
{
uint8_t data[2048];
size_t len;
@ -59,7 +59,7 @@ int interface_tx(int (*cb)(uint8_t *data, size_t len, uint16_t eth_type))
// int i;
uint16_t eth_type = (data[12] << 8) | data[13];
return cb(data + 14, len - 14, eth_type);
return cb(data, data + 6, eth_type, data + 14, len - 14);
}
return 0;
@ -137,7 +137,9 @@ static int tap_alloc(char *dev, uint8_t mac[6])
memcpy(ifr.ifr_hwaddr.sa_data, mac, 6);
if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
printf("Setting HWADDR failed\n");
printf("Setting HWADDR %02x:%02x:%02x:%02x:%02x:%02x failed\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
close(fd);
return -1;
}


+ 2
- 2
interface.h View File

@ -22,8 +22,8 @@
#include <stdint.h>
#include <stdbool.h>
int interface_rx(uint8_t *data, size_t len, uint16_t eth_type);
int interface_tx(int (*cb)(uint8_t *data, size_t len, uint16_t eth_type));
int interface_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len);
int interface_tx(int (*cb)(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len));
int interface_init(char *name, uint8_t mac[6], bool tap);
#endif /* _INCLUDE_INTERFACE_H_ */

+ 8
- 9
sound.c View File

@ -162,7 +162,6 @@ int sound_rx(void)
return -1;
}
if (src_in) {
int i;
int r_in = r * ratio_in;
@ -195,7 +194,7 @@ int sound_rx(void)
return 0;
}
int sound_param(snd_pcm_t *pcm_handle, bool is_tx, int force_rate)
int sound_param(snd_pcm_t *pcm_handle, bool is_tx, int sw_rate, int hw_rate)
{
int channels = 1;
snd_pcm_hw_params_t *hw_params;
@ -211,8 +210,8 @@ int sound_param(snd_pcm_t *pcm_handle, bool is_tx, int force_rate)
else
snd_pcm_hw_params_set_format (pcm_handle, hw_params, SND_PCM_FORMAT_S16_BE);
unsigned int rate = 8000;
unsigned int rrate = force_rate;
unsigned int rate = sw_rate;
unsigned int rrate = hw_rate;
if (snd_pcm_hw_params_set_rate_near (pcm_handle, hw_params, &rrate, NULL)) {
printf("Could not set rate %d\n", rrate);
@ -243,8 +242,8 @@ int sound_param(snd_pcm_t *pcm_handle, bool is_tx, int force_rate)
}
}
snd_pcm_uframes_t buffer_size = nr * 2 * 10;
snd_pcm_uframes_t period_size = nr * 2;
snd_pcm_uframes_t buffer_size = nr * ( is_tx ? 2 : 10);
snd_pcm_uframes_t period_size = nr * 1;
snd_pcm_hw_params_set_buffer_size_near (pcm_handle, hw_params, &buffer_size);
snd_pcm_hw_params_set_period_size_near (pcm_handle, hw_params, &period_size, NULL);
@ -267,7 +266,7 @@ int sound_param(snd_pcm_t *pcm_handle, bool is_tx, int force_rate)
return 0;
}
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr, int rate)
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr, int rate, int hw_rate)
{
int err;
@ -286,13 +285,13 @@ int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr, i
if (err < 0)
return -1;
sound_param(pcm_handle_tx, true, rate);
sound_param(pcm_handle_tx, true, rate, hw_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, rate);
sound_param(pcm_handle_rx, false, rate, hw_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 rate);
int sound_init(char *device, void (*in_cb)(int16_t *samples, int nr), int inr, int rate, int hw_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