FreeCalypso > hg > ice1-trau-tester
comparison pcm/pcm_tx.c @ 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 | |
children | 70aa8cbdbde9 |
comparison
equal
deleted
inserted
replaced
6:631f2db08538 | 7:ca351324187a |
---|---|
1 /* | |
2 * In this module we implement PCM Tx toward the TRAU. | |
3 */ | |
4 | |
5 #include <stdint.h> | |
6 #include <stdbool.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <unistd.h> | |
11 | |
12 #include <osmocom/core/select.h> | |
13 | |
14 #include "globals.h" | |
15 | |
16 static const uint8_t dmw_alaw[8] = | |
17 {0x34, 0x21, 0x21, 0x34, 0xB4, 0xA1, 0xA1, 0xB4}; | |
18 | |
19 static uint8_t pcm_fill_octet = 0x54; | |
20 static bool dmw_active; | |
21 static uint8_t *play_buffer; | |
22 static unsigned play_buf_nframes, play_buf_ptr; | |
23 | |
24 static void fill_with_dmw(uint8_t *buf) | |
25 { | |
26 unsigned n; | |
27 | |
28 for (n = 0; n < 20; n++) { | |
29 memcpy(buf, dmw_alaw, 8); | |
30 buf += 8; | |
31 } | |
32 } | |
33 | |
34 static void fill_with_play(uint8_t *outbuf) | |
35 { | |
36 memcpy(outbuf, play_buffer + play_buf_ptr * 160, 160); | |
37 play_buf_ptr++; | |
38 if (play_buf_ptr < play_buf_nframes) | |
39 return; | |
40 free(play_buffer); | |
41 play_buffer = 0; | |
42 printf("file play finished\n"); | |
43 } | |
44 | |
45 void transmit_pcm_20ms(void) | |
46 { | |
47 uint8_t buf[160]; | |
48 | |
49 if (play_buffer) | |
50 fill_with_play(buf); | |
51 else if (dmw_active) | |
52 fill_with_dmw(buf); | |
53 else | |
54 memset(buf, pcm_fill_octet, 160); | |
55 write(ts_fd, buf, 160); | |
56 } |