FreeCalypso > hg > ice1-trau-tester
changeset 7:ca351324187a
pcm: implement Tx on the E1 timeslot
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 23 Jun 2024 19:21:00 +0000 |
parents | 631f2db08538 |
children | 70aa8cbdbde9 |
files | pcm/Makefile pcm/globals.h pcm/pcm_tx.c pcm/read_ts.c |
diffstat | 4 files changed, 60 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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);
--- /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 <stdint.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <osmocom/core/select.h> + +#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); +}