FreeCalypso > hg > gsm-codec-lib
comparison libgsmfr2/prng.c @ 256:a33edf624061
libgsmfr2: start with API definition and port of libgsmfrp code
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Apr 2024 20:49:53 +0000 |
parents | libgsmfrp/prng.c@3b64f255689a |
children | 573afa985df6 |
comparison
equal
deleted
inserted
replaced
255:07f936338de1 | 256:a33edf624061 |
---|---|
1 /* | |
2 * We use a pseudorandom sequence generator function in two places: | |
3 * when generating comfort noise (GSM 06.12 section 6.1), and when | |
4 * randomizing grid position parameters as part of speech muting | |
5 * during error handling (GSM 06.11 section 6). | |
6 * | |
7 * Our PRNG is a copy of the pseudonoise() function from ETSI EFR code, | |
8 * where it is used for similar purposes. | |
9 */ | |
10 | |
11 #include <stdint.h> | |
12 #include "tw_gsmfr.h" | |
13 #include "pp_internal.h" | |
14 | |
15 uint16_t gsmfr_preproc_prng(struct gsmfr_preproc_state *st, uint16_t no_bits) | |
16 { | |
17 uint16_t noise_bits, Sn, i; | |
18 | |
19 noise_bits = 0; | |
20 for (i = 0; i < no_bits; i++) | |
21 { | |
22 /* State n == 31 */ | |
23 if ((st->cn_random_lfsr & 0x00000001L) != 0) | |
24 { | |
25 Sn = 1; | |
26 } | |
27 else | |
28 { | |
29 Sn = 0; | |
30 } | |
31 | |
32 /* State n == 3 */ | |
33 if ((st->cn_random_lfsr & 0x10000000L) != 0) | |
34 { | |
35 Sn = Sn ^ 1; | |
36 } | |
37 else | |
38 { | |
39 Sn = Sn ^ 0; | |
40 } | |
41 | |
42 noise_bits = noise_bits << 1; | |
43 noise_bits = noise_bits | st->cn_random_lfsr & 1; | |
44 | |
45 st->cn_random_lfsr >>= 1; | |
46 if (Sn & 1) | |
47 { | |
48 st->cn_random_lfsr |= 0x40000000L; | |
49 } | |
50 } | |
51 | |
52 return noise_bits; | |
53 } |