diff options
author | erdgeist <erdgeist@erdgeist.org> | 2025-08-15 12:42:40 +0200 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2025-08-15 12:42:40 +0200 |
commit | 30325d24d107dbf133da39f7c96d1510fd1c9449 (patch) | |
tree | 932baa5b2a4475821f16dccf9e3e05011daa6d92 /codec2_internal.h | |
parent | 9022d768021bbe15c7815cc6f8b64218b46f0e10 (diff) |
Bump to codec2 version 1.2.0erdgeist-bump-to-1.2.0
Diffstat (limited to 'codec2_internal.h')
-rw-r--r-- | codec2_internal.h | 129 |
1 files changed, 62 insertions, 67 deletions
diff --git a/codec2_internal.h b/codec2_internal.h index b46e358..32cd7eb 100644 --- a/codec2_internal.h +++ b/codec2_internal.h | |||
@@ -28,81 +28,76 @@ | |||
28 | 28 | ||
29 | #ifndef __CODEC2_INTERNAL__ | 29 | #ifndef __CODEC2_INTERNAL__ |
30 | #define __CODEC2_INTERNAL__ | 30 | #define __CODEC2_INTERNAL__ |
31 | #include <stdbool.h> | ||
31 | 32 | ||
32 | #include "codec2_fft.h" | 33 | #include "codec2_fft.h" |
33 | #include "newamp1.h" | 34 | #include "newamp1.h" |
34 | #include "newamp2.h" | ||
35 | 35 | ||
36 | struct CODEC2 { | 36 | struct CODEC2 { |
37 | int mode; | 37 | int mode; |
38 | C2CONST c2const; | 38 | C2CONST c2const; |
39 | int Fs; | 39 | int Fs; |
40 | int n_samp; | 40 | int n_samp; |
41 | int m_pitch; | 41 | int m_pitch; |
42 | codec2_fft_cfg fft_fwd_cfg; /* forward FFT config */ | 42 | codec2_fft_cfg fft_fwd_cfg; /* forward FFT config */ |
43 | codec2_fftr_cfg fftr_fwd_cfg; /* forward real FFT config */ | 43 | codec2_fftr_cfg fftr_fwd_cfg; /* forward real FFT config */ |
44 | float *w; /* [m_pitch] time domain hamming window */ | 44 | float *w; /* [m_pitch] time domain hamming window */ |
45 | float W[FFT_ENC]; /* DFT of w[] */ | 45 | float W[FFT_ENC]; /* DFT of w[] */ |
46 | float *Pn; /* [2*n_samp] trapezoidal synthesis window */ | 46 | float *Pn; /* [2*n_samp] trapezoidal synthesis window */ |
47 | float *bpf_buf; /* buffer for band pass filter */ | 47 | float *bpf_buf; /* buffer for band pass filter */ |
48 | float *Sn; /* [m_pitch] input speech */ | 48 | float *Sn; /* [m_pitch] input speech */ |
49 | float hpf_states[2]; /* high pass filter states */ | 49 | float hpf_states[2]; /* high pass filter states */ |
50 | void *nlp; /* pitch predictor states */ | 50 | void *nlp; /* pitch predictor states */ |
51 | int gray; /* non-zero for gray encoding */ | 51 | int gray; /* non-zero for gray encoding */ |
52 | 52 | ||
53 | codec2_fftr_cfg fftr_inv_cfg; /* inverse FFT config */ | 53 | codec2_fftr_cfg fftr_inv_cfg; /* inverse FFT config */ |
54 | float *Sn_; /* [2*n_samp] synthesised output speech */ | 54 | float *Sn_; /* [2*n_samp] synthesised output speech */ |
55 | float ex_phase; /* excitation model phase track */ | 55 | float ex_phase; /* excitation model phase track */ |
56 | float bg_est; /* background noise estimate for post filter */ | 56 | float bg_est; /* background noise estimate for post filter */ |
57 | float prev_f0_enc; /* previous frame's f0 estimate */ | 57 | float prev_f0_enc; /* previous frame's f0 estimate */ |
58 | MODEL prev_model_dec; /* previous frame's model parameters */ | 58 | MODEL prev_model_dec; /* previous frame's model parameters */ |
59 | float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */ | 59 | float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */ |
60 | float prev_e_dec; /* previous frame's LPC energy */ | 60 | float prev_e_dec; /* previous frame's LPC energy */ |
61 | 61 | ||
62 | int lpc_pf; /* LPC post filter on */ | 62 | int lpc_pf; /* LPC post filter on */ |
63 | int bass_boost; /* LPC post filter bass boost */ | 63 | int bass_boost; /* LPC post filter bass boost */ |
64 | float beta; /* LPC post filter parameters */ | 64 | float beta; /* LPC post filter parameters */ |
65 | float gamma; | 65 | float gamma; |
66 | 66 | ||
67 | float xq_enc[2]; /* joint pitch and energy VQ states */ | 67 | float xq_enc[2]; /* joint pitch and energy VQ states */ |
68 | float xq_dec[2]; | 68 | float xq_dec[2]; |
69 | 69 | ||
70 | int smoothing; /* enable smoothing for channels with errors */ | 70 | int smoothing; /* enable smoothing for channels with errors */ |
71 | float *softdec; /* optional soft decn bits from demod */ | 71 | float *softdec; /* optional soft decn bits from demod */ |
72 | 72 | ||
73 | /* newamp1 states */ | 73 | /* newamp1 states */ |
74 | 74 | ||
75 | float rate_K_sample_freqs_kHz[NEWAMP1_K]; | 75 | float rate_K_sample_freqs_kHz[NEWAMP1_K]; |
76 | float prev_rate_K_vec_[NEWAMP1_K]; | 76 | float prev_rate_K_vec_[NEWAMP1_K]; |
77 | float Wo_left; | 77 | float Wo_left; |
78 | int voicing_left; | 78 | int voicing_left; |
79 | codec2_fft_cfg phase_fft_fwd_cfg; | 79 | codec2_fft_cfg phase_fft_fwd_cfg; |
80 | codec2_fft_cfg phase_fft_inv_cfg; | 80 | codec2_fft_cfg phase_fft_inv_cfg; |
81 | float se; /* running sum of squared error */ | 81 | float se; /* running sum of squared error */ |
82 | unsigned int nse; /* number of terms in sum */ | 82 | unsigned int nse; /* number of terms in sum */ |
83 | float *user_rate_K_vec_no_mean_; /* optional, user supplied vector for quantisation experiments */ | 83 | float *user_rate_K_vec_no_mean_; /* optional, user supplied vector for |
84 | int post_filter_en; | 84 | quantisation experiments */ |
85 | float eq[NEWAMP1_K]; /* optional equaliser */ | 85 | bool post_filter_en; |
86 | int eq_en; | 86 | float eq[NEWAMP1_K]; /* optional equaliser */ |
87 | 87 | bool eq_en; | |
88 | /*newamp2 states (also uses newamp1 states )*/ | 88 | |
89 | float energy_prev; | 89 | /* used to dump features for deep learning experiments */ |
90 | float n2_rate_K_sample_freqs_kHz[NEWAMP2_K]; | 90 | FILE *fmlfeat, *fmlmodel; |
91 | float n2_prev_rate_K_vec_[NEWAMP2_K]; | 91 | |
92 | float n2_pwb_rate_K_sample_freqs_kHz[NEWAMP2_16K_K]; | 92 | /* encode/decode function pointers for the selected mode */ |
93 | float n2_pwb_prev_rate_K_vec_[NEWAMP2_16K_K]; | 93 | void (*encode)(struct CODEC2 *c2, unsigned char *bits, short speech[]); |
94 | 94 | void (*decode)(struct CODEC2 *c2, short speech[], const unsigned char *bits); | |
95 | /* used to dump features for deep learning experiments */ | 95 | void (*decode_ber)(struct CODEC2 *c2, short speech[], |
96 | FILE *fmlfeat; | 96 | const unsigned char *bits, float ber_est); |
97 | |||
98 | /* encode/decode function pointers for the selected mode */ | ||
99 | void (*encode)(struct CODEC2 *c2, unsigned char * bits, short speech[]); | ||
100 | void (*decode)(struct CODEC2 *c2, short speech[], const unsigned char * bits); | ||
101 | void (*decode_ber)(struct CODEC2 *c2, short speech[], const unsigned char * bits, float ber_est); | ||
102 | }; | 97 | }; |
103 | 98 | ||
104 | // test and debug | 99 | // test and debug |
105 | void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]); | 100 | void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]); |
106 | void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, | 101 | void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, |
107 | COMP Aw[], float gain); | 102 | COMP Aw[], float gain); |
108 | #endif | 103 | #endif |