summaryrefslogtreecommitdiff
path: root/codec2.h
diff options
context:
space:
mode:
Diffstat (limited to 'codec2.h')
-rw-r--r--codec2.h102
1 files changed, 46 insertions, 56 deletions
diff --git a/codec2.h b/codec2.h
index 709b462..97e9262 100644
--- a/codec2.h
+++ b/codec2.h
@@ -26,26 +26,22 @@
26 along with this program; if not, see <http://www.gnu.org/licenses/>. 26 along with this program; if not, see <http://www.gnu.org/licenses/>.
27*/ 27*/
28 28
29#ifndef __CODEC2__
30#define __CODEC2__
31#include "version.h"
32#include <stdbool.h>
33
29#ifdef __cplusplus 34#ifdef __cplusplus
30 extern "C" { 35extern "C" {
31#endif 36#endif
32 37
33#ifndef __CODEC2__ 38#define CODEC2_MODE_3200 0
34#define __CODEC2__ 39#define CODEC2_MODE_2400 1
35 40#define CODEC2_MODE_1600 2
36#include <version.h> 41#define CODEC2_MODE_1400 3
37 42#define CODEC2_MODE_1300 4
38#define CODEC2_MODE_3200 0 43#define CODEC2_MODE_1200 5
39#define CODEC2_MODE_2400 1 44#define CODEC2_MODE_700C 8
40#define CODEC2_MODE_1600 2
41#define CODEC2_MODE_1400 3
42#define CODEC2_MODE_1300 4
43#define CODEC2_MODE_1200 5
44#define CODEC2_MODE_700 6
45#define CODEC2_MODE_700B 7
46#define CODEC2_MODE_700C 8
47#define CODEC2_MODE_450 10
48#define CODEC2_MODE_450PWB 11
49 45
50#ifndef CODEC2_MODE_EN_DEFAULT 46#ifndef CODEC2_MODE_EN_DEFAULT
51#define CODEC2_MODE_EN_DEFAULT 1 47#define CODEC2_MODE_EN_DEFAULT 1
@@ -55,76 +51,70 @@
55// disable during compile time with -DCODEC2_MODE_1600_EN=0 51// disable during compile time with -DCODEC2_MODE_1600_EN=0
56// all but CODEC2 1600 are enabled then 52// all but CODEC2 1600 are enabled then
57 53
58//or the other way round 54// or the other way round
59// -DCODEC2_MODE_EN_DEFAULT=0 -DCODEC2_MODE_1600_EN=1 55// -DCODEC2_MODE_EN_DEFAULT=0 -DCODEC2_MODE_1600_EN=1
60// only CODEC2 Mode 1600 56// only CODEC2 Mode 1600
61 57
62#if !defined(CODEC2_MODE_3200_EN) 58#if !defined(CODEC2_MODE_3200_EN)
63 #define CODEC2_MODE_3200_EN CODEC2_MODE_EN_DEFAULT 59#define CODEC2_MODE_3200_EN CODEC2_MODE_EN_DEFAULT
64#endif 60#endif
65#if !defined(CODEC2_MODE_2400_EN) 61#if !defined(CODEC2_MODE_2400_EN)
66 #define CODEC2_MODE_2400_EN CODEC2_MODE_EN_DEFAULT 62#define CODEC2_MODE_2400_EN CODEC2_MODE_EN_DEFAULT
67#endif 63#endif
68#if !defined(CODEC2_MODE_1600_EN) 64#if !defined(CODEC2_MODE_1600_EN)
69 #define CODEC2_MODE_1600_EN CODEC2_MODE_EN_DEFAULT 65#define CODEC2_MODE_1600_EN CODEC2_MODE_EN_DEFAULT
70#endif 66#endif
71#if !defined(CODEC2_MODE_1400_EN) 67#if !defined(CODEC2_MODE_1400_EN)
72 #define CODEC2_MODE_1400_EN CODEC2_MODE_EN_DEFAULT 68#define CODEC2_MODE_1400_EN CODEC2_MODE_EN_DEFAULT
73#endif 69#endif
74#if !defined(CODEC2_MODE_1300_EN) 70#if !defined(CODEC2_MODE_1300_EN)
75 #define CODEC2_MODE_1300_EN CODEC2_MODE_EN_DEFAULT 71#define CODEC2_MODE_1300_EN CODEC2_MODE_EN_DEFAULT
76#endif 72#endif
77#if !defined(CODEC2_MODE_1200_EN) 73#if !defined(CODEC2_MODE_1200_EN)
78 #define CODEC2_MODE_1200_EN CODEC2_MODE_EN_DEFAULT 74#define CODEC2_MODE_1200_EN CODEC2_MODE_EN_DEFAULT
79#endif
80#if !defined(CODEC2_MODE_700_EN)
81 #define CODEC2_MODE_700_EN CODEC2_MODE_EN_DEFAULT
82#endif
83#if !defined(CODEC2_MODE_700B_EN)
84 #define CODEC2_MODE_700B_EN CODEC2_MODE_EN_DEFAULT
85#endif 75#endif
86#if !defined(CODEC2_MODE_700C_EN) 76#if !defined(CODEC2_MODE_700C_EN)
87 #define CODEC2_MODE_700C_EN CODEC2_MODE_EN_DEFAULT 77#define CODEC2_MODE_700C_EN CODEC2_MODE_EN_DEFAULT
88#endif
89#if !defined(CODEC2_MODE_450_EN)
90 #define CODEC2_MODE_450_EN CODEC2_MODE_EN_DEFAULT
91#endif
92#if !defined(CODEC2_MODE_450PWB_EN)
93 #define CODEC2_MODE_450PWB_EN CODEC2_MODE_EN_DEFAULT
94#endif 78#endif
95 79
96#define CODEC2_MODE_ACTIVE(mode_name, var) ((mode_name##_EN) == 0 ? 0: (var) == mode_name) 80#define CODEC2_MODE_ACTIVE(mode_name, var) \
81 ((mode_name##_EN) == 0 ? 0 : (var) == mode_name)
97 82
98struct CODEC2; 83struct CODEC2;
99 84
100struct CODEC2 * codec2_create(int mode); 85struct CODEC2 *codec2_create(int mode);
101void codec2_destroy(struct CODEC2 *codec2_state); 86void codec2_destroy(struct CODEC2 *codec2_state);
102void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]); 87void codec2_encode(struct CODEC2 *codec2_state, unsigned char bytes[],
103void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits); 88 short speech_in[]);
104void codec2_decode_ber(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits, float ber_est); 89void codec2_decode(struct CODEC2 *codec2_state, short speech_out[],
105int codec2_samples_per_frame(struct CODEC2 *codec2_state); 90 const unsigned char bytes[]);
106int codec2_bits_per_frame(struct CODEC2 *codec2_state); 91void codec2_decode_ber(struct CODEC2 *codec2_state, short speech_out[],
107 92 const unsigned char *bytes, float ber_est);
108void codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma); 93int codec2_samples_per_frame(struct CODEC2 *codec2_state);
109int codec2_get_spare_bit_index(struct CODEC2 *codec2_state); 94int codec2_bits_per_frame(struct CODEC2 *codec2_state);
110int codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, int unpacked_bits[]); 95int codec2_bytes_per_frame(struct CODEC2 *codec2_state);
96
97void codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable,
98 int bass_boost, float beta, float gamma);
99int codec2_get_spare_bit_index(struct CODEC2 *codec2_state);
100int codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, char unpacked_bits[]);
111void codec2_set_natural_or_gray(struct CODEC2 *codec2_state, int gray); 101void codec2_set_natural_or_gray(struct CODEC2 *codec2_state, int gray);
112void codec2_set_softdec(struct CODEC2 *c2, float *softdec); 102void codec2_set_softdec(struct CODEC2 *c2, float *softdec);
113float codec2_get_energy(struct CODEC2 *codec2_state, const unsigned char *bits); 103float codec2_get_energy(struct CODEC2 *codec2_state, const unsigned char *bits);
114 104
115// support for ML and VQ experiments 105// support for ML and VQ experiments
116void codec2_open_mlfeat(struct CODEC2 *codec2_state, char *filename); 106void codec2_open_mlfeat(struct CODEC2 *codec2_state, char *feat_filename,
107 char *model_filename);
117void codec2_load_codebook(struct CODEC2 *codec2_state, int num, char *filename); 108void codec2_load_codebook(struct CODEC2 *codec2_state, int num, char *filename);
118float codec2_get_var(struct CODEC2 *codec2_state); 109float codec2_get_var(struct CODEC2 *codec2_state);
119float *codec2_enable_user_ratek(struct CODEC2 *codec2_state, int *K); 110float *codec2_enable_user_ratek(struct CODEC2 *codec2_state, int *K);
120 111
121// 700C post filter and equaliser 112// 700C post filter and equaliser
122void codec2_700c_post_filter(struct CODEC2 *codec2_state, int en); 113void codec2_700c_post_filter(struct CODEC2 *codec2_state, bool en);
123void codec2_700c_eq(struct CODEC2 *codec2_state, int en); 114void codec2_700c_eq(struct CODEC2 *codec2_state, bool en);
124
125#endif
126 115
127#ifdef __cplusplus 116#ifdef __cplusplus
128} 117}
129#endif 118#endif
130 119
120#endif