FreeCalypso > hg > vband-misc
comparison efr-sid/mk-sid-test2.c @ 48:3e632126e099
efr-sid: generate efr-sid-test2.gsmx for OS#6538
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 11 Aug 2024 22:17:37 +0000 |
| parents | efr-sid/mk-sid-test.c@8bfc517fda3b |
| children | 2daadef1e70d |
comparison
equal
deleted
inserted
replaced
| 47:ee54b9748c09 | 48:3e632126e099 |
|---|---|
| 1 /* | |
| 2 * This program generates a set of EFR codec frames based on a single input | |
| 3 * frame (in ETSI cod format) that is expected to be a perfect SID. | |
| 4 * The output frame set is intended to serve as a unit test for the | |
| 5 * bit-counting SID classification function; it will contain different | |
| 6 * extents of bit clearing to produce valid SID, invalid SID and non-SID | |
| 7 * speech classifications. | |
| 8 */ | |
| 9 | |
| 10 #include <stdio.h> | |
| 11 #include <stdint.h> | |
| 12 #include <stdlib.h> | |
| 13 #include <string.h> | |
| 14 #include <strings.h> | |
| 15 #include <gsm_efr.h> | |
| 16 #include "etsi.h" | |
| 17 | |
| 18 #define TOTAL_BITS 244 | |
| 19 | |
| 20 extern const uint8_t SID_codeword_bit_idx[95]; | |
| 21 | |
| 22 static uint8_t input_frame[ETSI_ENC_NWORDS]; | |
| 23 static FILE *outf; | |
| 24 | |
| 25 static void | |
| 26 read_input_file(filename) | |
| 27 char *filename; | |
| 28 { | |
| 29 FILE *inf; | |
| 30 | |
| 31 inf = fopen(filename, "r"); | |
| 32 if (!inf) { | |
| 33 perror(filename); | |
| 34 exit(1); | |
| 35 } | |
| 36 read_etsi_bits(inf, 0, input_frame, ETSI_ENC_NWORDS, filename); | |
| 37 fclose(inf); | |
| 38 } | |
| 39 | |
| 40 static void | |
| 41 emit_out_frame(bits) | |
| 42 uint8_t *bits; | |
| 43 { | |
| 44 uint8_t packed_frame[EFR_RTP_FRAME_LEN]; | |
| 45 | |
| 46 bits2frame(bits, packed_frame, "input", 0); | |
| 47 fwrite(packed_frame, 1, EFR_RTP_FRAME_LEN, outf); | |
| 48 } | |
| 49 | |
| 50 static void | |
| 51 emit_1bit_errors() | |
| 52 { | |
| 53 uint8_t frame_bits[TOTAL_BITS]; | |
| 54 unsigned n; | |
| 55 | |
| 56 for (n = 0; n < 95; n++) { | |
| 57 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 58 frame_bits[SID_codeword_bit_idx[n]] = 0; | |
| 59 emit_out_frame(frame_bits); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 static void | |
| 64 emit_2bit_errors() | |
| 65 { | |
| 66 uint8_t frame_bits[TOTAL_BITS]; | |
| 67 | |
| 68 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 69 frame_bits[SID_codeword_bit_idx[3]] = 0; | |
| 70 frame_bits[SID_codeword_bit_idx[14]] = 0; | |
| 71 emit_out_frame(frame_bits); | |
| 72 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 73 frame_bits[SID_codeword_bit_idx[15]] = 0; | |
| 74 frame_bits[SID_codeword_bit_idx[92]] = 0; | |
| 75 emit_out_frame(frame_bits); | |
| 76 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 77 frame_bits[SID_codeword_bit_idx[65]] = 0; | |
| 78 frame_bits[SID_codeword_bit_idx[35]] = 0; | |
| 79 emit_out_frame(frame_bits); | |
| 80 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 81 frame_bits[SID_codeword_bit_idx[89]] = 0; | |
| 82 frame_bits[SID_codeword_bit_idx[79]] = 0; | |
| 83 emit_out_frame(frame_bits); | |
| 84 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 85 frame_bits[SID_codeword_bit_idx[32]] = 0; | |
| 86 frame_bits[SID_codeword_bit_idx[38]] = 0; | |
| 87 emit_out_frame(frame_bits); | |
| 88 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 89 frame_bits[SID_codeword_bit_idx[46]] = 0; | |
| 90 frame_bits[SID_codeword_bit_idx[26]] = 0; | |
| 91 emit_out_frame(frame_bits); | |
| 92 } | |
| 93 | |
| 94 static void | |
| 95 emit_15bit_errors() | |
| 96 { | |
| 97 uint8_t frame_bits[TOTAL_BITS]; | |
| 98 unsigned i, j; | |
| 99 | |
| 100 for (i = 0; i < 6; i++) { | |
| 101 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 102 for (j = 0; j < 15; j++) | |
| 103 frame_bits[SID_codeword_bit_idx[j * 6 + i]] = 0; | |
| 104 emit_out_frame(frame_bits); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 static void | |
| 109 emit_16bit_errors() | |
| 110 { | |
| 111 uint8_t frame_bits[TOTAL_BITS]; | |
| 112 unsigned i, j; | |
| 113 | |
| 114 for (i = 0; i < 6; i++) { | |
| 115 bcopy(input_frame, frame_bits, TOTAL_BITS); | |
| 116 for (j = 0; j < 16; j++) | |
| 117 frame_bits[SID_codeword_bit_idx[j * 6 + i]] = 0; | |
| 118 emit_out_frame(frame_bits); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 main(argc, argv) | |
| 123 char **argv; | |
| 124 { | |
| 125 if (argc != 3) { | |
| 126 fprintf(stderr, "usage: %s input.cod output.gsmx\n", argv[0]); | |
| 127 exit(1); | |
| 128 } | |
| 129 read_input_file(argv[1]); | |
| 130 outf = fopen(argv[2], "w"); | |
| 131 if (!outf) { | |
| 132 perror(argv[2]); | |
| 133 exit(1); | |
| 134 } | |
| 135 /* emit the perfect, error-free SID first */ | |
| 136 emit_out_frame(input_frame); | |
| 137 /* now different bit-error possibilities */ | |
| 138 emit_1bit_errors(); | |
| 139 emit_2bit_errors(); | |
| 140 emit_15bit_errors(); | |
| 141 emit_16bit_errors(); | |
| 142 /* all done */ | |
| 143 fclose(outf); | |
| 144 exit(0); | |
| 145 } |
