annotate libtwamr/spreproc.c @ 485:751f06541fbb

doc/Codec-utils: clarify lack of DHF in gsmfr-decode-rb
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 May 2024 01:47:22 +0000
parents 7e0aeab69b10
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
403
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : spreproc.c
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Subframe preprocessing
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "spreproc.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "oper_32b.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "weight_a.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "syn_filt.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "residu.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "memops.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "no_count.h"
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * PUBLIC PROGRAM CODE
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ********************************************************************************
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 int subframePreProc(
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 enum Mode mode, /* i : coder mode */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 const Word16 gamma1[], /* i : spectral exp. factor 1 */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 const Word16 gamma1_12k2[],/* i : spectral exp. factor 1 for EFR */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 const Word16 gamma2[], /* i : spectral exp. factor 2 */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 Word16 *A, /* i : A(z) unquantized for the 4 subframes */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 Word16 *speech, /* i : speech segment */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 Word16 *mem_err, /* i : pointer to error signal */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 Word16 *mem_w0, /* i : memory of weighting filter */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word16 *zero, /* i : pointer to zero vector */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 Word16 ai_zero[], /* o : history of weighted synth. filter */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 exc[], /* o : long term prediction residual */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Word16 h1[], /* o : impulse response */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 Word16 xn[], /* o : target vector for pitch search */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 Word16 res2[], /* o : long term prediction residual */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 error[] /* o : error of LPC synthesis filter */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 )
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word16 i;
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 Ap1[MP1]; /* A(z) with spectral expansion */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Word16 Ap2[MP1]; /* A(z) with spectral expansion */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 const Word16 *g1; /* Pointer to correct gammma1 vector */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /*---------------------------------------------------------------*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 * mode specific pointer to gamma1 values *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 *---------------------------------------------------------------*/
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 test (); test ();
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if ( sub(mode, MR122) == 0 || sub(mode, MR102) == 0 )
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 g1 = gamma1_12k2; move16 ();
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 else
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 {
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 g1 = gamma1; move16 ();
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 /*---------------------------------------------------------------*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 * Find the weighted LPC coefficients for the weighting filter. *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 *---------------------------------------------------------------*/
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 Weight_Ai(A, g1, Ap1);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 Weight_Ai(A, gamma2, Ap2);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 /*---------------------------------------------------------------*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 * Compute impulse response, h1[], of weighted synthesis filter *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *---------------------------------------------------------------*/
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 for (i = 0; i <= M; i++)
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 {
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 ai_zero[i] = Ap1[i]; move16 ();
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 Syn_filt(Aq, ai_zero, h1, L_SUBFR, zero, 0);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 Syn_filt(Ap2, h1, h1, L_SUBFR, zero, 0);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 /*------------------------------------------------------------------------*
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 * *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 * Find the target vector for pitch search: *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 * *
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 *------------------------------------------------------------------------*/
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 /* LPC residual */
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 Residu(Aq, speech, res2, L_SUBFR);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 Copy(res2, exc, L_SUBFR);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 Syn_filt(Aq, exc, error, L_SUBFR, mem_err, 0);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 Residu(Ap1, error, xn, L_SUBFR);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 /* target signal xn[]*/
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 Syn_filt(Ap2, xn, xn, L_SUBFR, mem_w0, 0);
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 return 0;
7e0aeab69b10 libtwamr: integrate spreproc.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }