# HG changeset patch # User Mychaela Falconia # Date 1719170460 0 # Node ID ca351324187a7c794a7693a8583b519aac5e5e5a # Parent 631f2db08538145a6fbb4961c4d7e77074c3df6b pcm: implement Tx on the E1 timeslot diff -r 631f2db08538 -r ca351324187a pcm/Makefile --- a/pcm/Makefile Sun Jun 23 18:53:01 2024 +0000 +++ b/pcm/Makefile Sun Jun 23 19:21:00 2024 +0000 @@ -1,5 +1,5 @@ PROG= itt-pcm-one -OBJS= main.o read_ts.o record_ctrl.o user_cmd.o +OBJS= main.o pcm_tx.o read_ts.o record_ctrl.o user_cmd.o LIBUTIL=../libutil/libutil.a include ../config.defs diff -r 631f2db08538 -r ca351324187a pcm/globals.h --- a/pcm/globals.h Sun Jun 23 18:53:01 2024 +0000 +++ b/pcm/globals.h Sun Jun 23 19:21:00 2024 +0000 @@ -8,6 +8,8 @@ extern FILE *record_file; int ts_fd_cb(struct osmo_fd *ofd, unsigned int what); +void transmit_pcm_20ms(void); + void handle_user_cmd(int argc, char **argv); void cmd_record_start(int argc, char **argv); void cmd_record_stop(int argc, char **argv); diff -r 631f2db08538 -r ca351324187a pcm/pcm_tx.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm/pcm_tx.c Sun Jun 23 19:21:00 2024 +0000 @@ -0,0 +1,56 @@ +/* + * In this module we implement PCM Tx toward the TRAU. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "globals.h" + +static const uint8_t dmw_alaw[8] = + {0x34, 0x21, 0x21, 0x34, 0xB4, 0xA1, 0xA1, 0xB4}; + +static uint8_t pcm_fill_octet = 0x54; +static bool dmw_active; +static uint8_t *play_buffer; +static unsigned play_buf_nframes, play_buf_ptr; + +static void fill_with_dmw(uint8_t *buf) +{ + unsigned n; + + for (n = 0; n < 20; n++) { + memcpy(buf, dmw_alaw, 8); + buf += 8; + } +} + +static void fill_with_play(uint8_t *outbuf) +{ + memcpy(outbuf, play_buffer + play_buf_ptr * 160, 160); + play_buf_ptr++; + if (play_buf_ptr < play_buf_nframes) + return; + free(play_buffer); + play_buffer = 0; + printf("file play finished\n"); +} + +void transmit_pcm_20ms(void) +{ + uint8_t buf[160]; + + if (play_buffer) + fill_with_play(buf); + else if (dmw_active) + fill_with_dmw(buf); + else + memset(buf, pcm_fill_octet, 160); + write(ts_fd, buf, 160); +} diff -r 631f2db08538 -r ca351324187a pcm/read_ts.c --- a/pcm/read_ts.c Sun Jun 23 18:53:01 2024 +0000 +++ b/pcm/read_ts.c Sun Jun 23 19:21:00 2024 +0000 @@ -29,5 +29,6 @@ } if (record_file) fwrite(readbuf, 1, 160, record_file); + transmit_pcm_20ms(); return 0; }