annotate libtest/wavrdhelp.c @ 242:f081a6850fb5

libgsmfrp: new refined implementation The previous implementation exhibited the following defects, which are now fixed: 1) The last received valid SID was cached forever for the purpose of handling future invalid SIDs - we could have received some valid SID ages ago, then lots of speech or NO_DATA, and if we then get an invalid SID, we would resurrect the last valid SID from ancient history - a bad design. In our new design, we handle invalid SID based on the current state, much like BFI. 2) GSM 06.11 spec says clearly that after the second lost SID (received BFI=1 && TAF=1 in CN state) we need to gradually decrease the output level, rather than jump directly to emitting silence frames - we previously failed to implement such logic. 3) Per GSM 06.12 section 5.2, Xmaxc should be the same in all 4 subframes in a SID frame. What should we do if we receive an otherwise valid SID frame with different Xmaxc? Our previous approach would replicate this Xmaxc oddity in every subsequent generated CN frame, which is rather bad. In our new design, the very first CN frame (which can be seen as a transformation of the SID frame itself) retains the original 4 distinct Xmaxc, but all subsequent CN frames are based on the Xmaxc from the last subframe of the most recent SID.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 09 May 2023 05:16:31 +0000
parents 30d1d0a705c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our helper functions
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * on top of the basic WAV reader.
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "wavreader.h"
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "wavrdhelp.h"
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 int wavrd_check_header(void *wav, const char *filename)
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int format, sampleRate, channels, bitsPerSample;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 if (!wav_get_header(wav, &format, &channels, &sampleRate,
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 &bitsPerSample, NULL)) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 fprintf(stderr, "error: %s is not a valid WAV file\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 filename);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (format != 1) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 fprintf(stderr, "error: %s has unsupported WAV format %d\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 filename, format);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (bitsPerSample != 16) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fprintf(stderr,
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 "error: %s has unsupported WAV sample depth %d\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 filename, bitsPerSample);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (channels != 1) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr, "error: %s has %d channels, need 1\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 filename, channels);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (sampleRate != 8000) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 fprintf(stderr,
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 "error: %s has %d Hz sample rate, need 8000 Hz\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 filename, sampleRate);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return 0;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 int wavrd_get_pcm_block(void *wav, int16_t *pcm)
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 uint8_t bytes[320], *dp;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 int cc, i;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 cc = wav_read_data(wav, bytes, 320);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 cc >>= 1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 dp = bytes;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (i = 0; i < cc; i++) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 pcm[i] = dp[0] | (dp[1] << 8);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 dp += 2;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 while (i < 160)
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 pcm[i++] = 0;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return cc;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }