summaryrefslogtreecommitdiff
path: root/codec2_internal.h
blob: 32cd7eb72a43ec5796929f8f6f6fbafcb701a18a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*---------------------------------------------------------------------------*\

  FILE........: codec2_internal.h
  AUTHOR......: David Rowe
  DATE CREATED: April 16 2012

  Header file for Codec2 internal states, exposed via this header
  file to assist in testing.

\*---------------------------------------------------------------------------*/

/*
  Copyright (C) 2012 David Rowe

  All rights reserved.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License version 2.1, as
  published by the Free Software Foundation.  This program is
  distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CODEC2_INTERNAL__
#define __CODEC2_INTERNAL__
#include <stdbool.h>

#include "codec2_fft.h"
#include "newamp1.h"

struct CODEC2 {
  int mode;
  C2CONST c2const;
  int Fs;
  int n_samp;
  int m_pitch;
  codec2_fft_cfg fft_fwd_cfg;   /* forward FFT config                        */
  codec2_fftr_cfg fftr_fwd_cfg; /* forward real FFT config                   */
  float *w;                     /* [m_pitch] time domain hamming window      */
  float W[FFT_ENC];             /* DFT of w[]                                */
  float *Pn;                    /* [2*n_samp] trapezoidal synthesis window   */
  float *bpf_buf;               /* buffer for band pass filter               */
  float *Sn;                    /* [m_pitch] input speech                    */
  float hpf_states[2];          /* high pass filter states                   */
  void *nlp;                    /* pitch predictor states                    */
  int gray;                     /* non-zero for gray encoding                */

  codec2_fftr_cfg fftr_inv_cfg; /* inverse FFT config                        */
  float *Sn_;                   /* [2*n_samp] synthesised output speech      */
  float ex_phase;               /* excitation model phase track              */
  float bg_est;                 /* background noise estimate for post filter */
  float prev_f0_enc;            /* previous frame's f0    estimate           */
  MODEL prev_model_dec;         /* previous frame's model parameters         */
  float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs                     */
  float prev_e_dec;             /* previous frame's LPC energy               */

  int lpc_pf;     /* LPC post filter on                        */
  int bass_boost; /* LPC post filter bass boost                */
  float beta;     /* LPC post filter parameters                */
  float gamma;

  float xq_enc[2]; /* joint pitch and energy VQ states          */
  float xq_dec[2];

  int smoothing;  /* enable smoothing for channels with errors */
  float *softdec; /* optional soft decn bits from demod        */

  /* newamp1 states */

  float rate_K_sample_freqs_kHz[NEWAMP1_K];
  float prev_rate_K_vec_[NEWAMP1_K];
  float Wo_left;
  int voicing_left;
  codec2_fft_cfg phase_fft_fwd_cfg;
  codec2_fft_cfg phase_fft_inv_cfg;
  float se;                        /* running sum of squared error */
  unsigned int nse;                /* number of terms in sum       */
  float *user_rate_K_vec_no_mean_; /* optional, user supplied vector for
                                      quantisation experiments */
  bool post_filter_en;
  float eq[NEWAMP1_K]; /* optional equaliser */
  bool eq_en;

  /* used to dump features for deep learning experiments */
  FILE *fmlfeat, *fmlmodel;

  /* encode/decode function pointers for the selected mode */
  void (*encode)(struct CODEC2 *c2, unsigned char *bits, short speech[]);
  void (*decode)(struct CODEC2 *c2, short speech[], const unsigned char *bits);
  void (*decode_ber)(struct CODEC2 *c2, short speech[],
                     const unsigned char *bits, float ber_est);
};

// test and debug
void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]);
void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model,
                          COMP Aw[], float gain);
#endif