blob: b14c9783a8d23ce014d9731c448ffdda045e4440 [file] [log] [blame]
Philipp Maier898c9c62020-02-06 14:25:01 +01001/*
2 * (C) 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
3 * Author: Philipp Maier <pmaier@sysmocom.de>
4 * All Rights Reserved
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
Philipp Maier898c9c62020-02-06 14:25:01 +010018 */
19
20#include <string.h>
21#include <stdio.h>
22#include <stdint.h>
23#include <osmocom/core/utils.h>
24#include <osmocom/coding/gsm0503_amr_dtx.h>
25
26char sample_afs_sid_frame[] =
27 {
28"111111110000000011001100101010100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001111011100100010011111111001000100111011110011001001100111100110010011001"
29};
30
31char sample_afs_sid_update_frame[] =
32 {
33"111111110000000011001100101010100000010000001111111100101011011110001001000000110111110000001001011111101111010011001111100000101000011111001001111100110111110011111001001111101100010001001111000000100100011100111001100000111000110000111001010011101111010011111111010000101100011100111001111100110111110011111001110011101000010010001111110000100000011111001001011100110011110010111001101111100011010001111111001100100100011111111001000000110000110000001001"
34};
35
36char sample_afs_onset_frame[] =
37 {
38"111111110000000011001100101010100000111100000000111111000100101000111111100000000111110010001010001111110100000011111100111110100100111111000000110011001011101001001111011100001011110000001010010011111100000000111100111110101000111110110000111111000000101011111111010000001100110000111010111111111000000010111100000010100100111100110000100011001000101000111111101100001011110000111010011111110011000010111100101110101100111111000000010011001111101000001111"
39};
40
41char sample_ahs_sid_update_frame[] =
42 {
43"111100001100101010110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110000110110100011001000011010000000000000001111010010000000000001000000000010110000000011001000000000000000100000101000000000000000001010100000010010000000000010000111110001110110110011001101000000000100100011001000001010000100100000000011"
44};
45
46char sample_ahs_sid_first_p1_frame[] =
47 {
48"111100001100101001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001111001001001011010110001101100101001110001111001110100110010000111101110110110000100100011111001001110000011110110001010010101100001010100000111101110110001010000111110001110110110011001101001111000011101001010011100011000111010110000011"
49};
50
51char sample_ahs_sid_first_p2_frame[] =
52 {
53"111110100100000010100000110111001110101100000100101001011101100011101010010000001010010010001100101010100100010111110101110011011110101000010100111000001001110111101110010101001110000010001101101011110000000011100100110110011111100011001000001101100101001110001111001110100110010000111101110110110000100100011111001001110000011110110001010010101100001010100000111101110110001010000111110001110110110011001101001111000011101001010011100011000111010110000011"
54};
55
56char sample_ahs_onset_frame[] =
57 {
58"111101011000101001010000111001000111011110000000011110001110010011011111100000101101101001101110011111010000000001010010110001101101110100000010011110101100010001011101101010000111100011101100111101011010100011110010110001001111100011001000011010000000000000001010010010000000000001000000000000100000000011001000000000000000100000101000000000000000010010000101010010000000000010101100111110101000110110011001000000000100100011001000001010000100100000001100"
59};
60
61char sample_sid_first_inh_frame[] =
62 {
63"xBxBxBxBxBxBxBxBxBxBxBxBxBxBxBxBx1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0x0x0x0x1x1x0x1x1x0"
64};
65
66char sample_sid_update_inh_frame[] =
67 {
68"xBxBxBxBxBxBxBxBxBxBxBxBxBxBxBxBx0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1"
69};
70
71unsigned int string_to_ubit(ubit_t * ubits, char *string)
72{
73 unsigned int len;
74 unsigned int i;
75
76 len = strlen(string);
77
78 for (i = 0; i < len; i++) {
79 ubits[i] = string[i] & 1;
80 }
81
82 return len;
83}
84
85void test_gsm0503_detect_afs_dtx_frame(char *string)
86{
87 ubit_t ubits[512];
88 uint8_t dtx_frame_type;
89 int n_errors;
90 int n_bits_total;
91
92 string_to_ubit(ubits, string);
93 dtx_frame_type = gsm0503_detect_afs_dtx_frame(&n_errors, &n_bits_total, ubits);
94 printf(" ==> %s, n_errors=%i, n_bits_total=%i\n", gsm0503_amr_dtx_frame_name(dtx_frame_type),
95 n_errors, n_bits_total);
96}
97
98void test_gsm0503_detect_ahs_dtx_frame(char *string)
99{
100 ubit_t ubits[512];
101 uint8_t dtx_frame_type;
102 int n_errors;
103 int n_bits_total;
104
105 string_to_ubit(ubits, string);
106 dtx_frame_type = gsm0503_detect_ahs_dtx_frame(&n_errors, &n_bits_total, ubits);
107 printf(" ==> %s, n_errors=%i, n_bits_total=%i\n", gsm0503_amr_dtx_frame_name(dtx_frame_type),
108 n_errors, n_bits_total);
109}
110
111int main(int argc, char **argv)
112{
113 printf("FR AMR DTX FRAMES:\n");
114 test_gsm0503_detect_afs_dtx_frame(sample_afs_sid_frame);
115 test_gsm0503_detect_afs_dtx_frame(sample_afs_sid_update_frame);
116 test_gsm0503_detect_afs_dtx_frame(sample_afs_onset_frame);
117 printf("HR AMR DTX FRAMES:\n");
118 test_gsm0503_detect_ahs_dtx_frame(sample_ahs_sid_update_frame);
119 test_gsm0503_detect_ahs_dtx_frame(sample_ahs_sid_first_p1_frame);
120 test_gsm0503_detect_ahs_dtx_frame(sample_ahs_sid_first_p2_frame);
121 test_gsm0503_detect_ahs_dtx_frame(sample_ahs_onset_frame);
122 test_gsm0503_detect_ahs_dtx_frame(sample_sid_first_inh_frame);
123 test_gsm0503_detect_ahs_dtx_frame(sample_sid_update_inh_frame);
124
125 return EXIT_SUCCESS;
126}