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