1 /*---------------------------------------------------------------------------*\
2 
3   FILE........: codec2.h
4   AUTHOR......: David Rowe
5   DATE CREATED: 21 August 2010
6 
7   Codec 2 fully quantised encoder and decoder functions.  If you want use
8   Codec 2, these are the functions you need to call.
9 
10 \*---------------------------------------------------------------------------*/
11 
12 /*
13   Copyright (C) 2010 David Rowe
14 
15   All rights reserved.
16 
17   This program is free software; you can redistribute it and/or modify
18   it under the terms of the GNU Lesser General Public License version 2.1, as
19   published by the Free Software Foundation.  This program is
20   distributed in the hope that it will be useful, but WITHOUT ANY
21   WARRANTY; without even the implied warranty of MERCHANTABILITY or
22   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
23   License for more details.
24 
25   You should have received a copy of the GNU Lesser General Public License
26   along with this program; if not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 #ifndef __CODEC2__
30 #define  __CODEC2__
31 
32 #include <codec2/version.h>
33 
34 #ifdef __cplusplus
35   extern "C" {
36 #endif
37 
38 #define CODEC2_MODE_3200 	0
39 #define CODEC2_MODE_2400 	1
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_700C 	8
45 #define CODEC2_MODE_450 	10
46 #define CODEC2_MODE_450PWB 	11
47 
48 #ifndef CODEC2_MODE_EN_DEFAULT
49 #define CODEC2_MODE_EN_DEFAULT 1
50 #endif
51 
52 // by default we enable all modes
53 // disable during compile time with -DCODEC2_MODE_1600_EN=0
54 // all but CODEC2 1600 are enabled then
55 
56 //or the other way round
57 // -DCODEC2_MODE_EN_DEFAULT=0 -DCODEC2_MODE_1600_EN=1
58 // only CODEC2 Mode 1600
59 
60 #if !defined(CODEC2_MODE_3200_EN)
61         #define CODEC2_MODE_3200_EN CODEC2_MODE_EN_DEFAULT
62 #endif
63 #if !defined(CODEC2_MODE_2400_EN)
64         #define CODEC2_MODE_2400_EN CODEC2_MODE_EN_DEFAULT
65 #endif
66 #if !defined(CODEC2_MODE_1600_EN)
67         #define CODEC2_MODE_1600_EN CODEC2_MODE_EN_DEFAULT
68 #endif
69 #if !defined(CODEC2_MODE_1400_EN)
70         #define CODEC2_MODE_1400_EN CODEC2_MODE_EN_DEFAULT
71 #endif
72 #if !defined(CODEC2_MODE_1300_EN)
73         #define CODEC2_MODE_1300_EN CODEC2_MODE_EN_DEFAULT
74 #endif
75 #if !defined(CODEC2_MODE_1200_EN)
76         #define CODEC2_MODE_1200_EN CODEC2_MODE_EN_DEFAULT
77 #endif
78 #if !defined(CODEC2_MODE_700C_EN)
79         #define CODEC2_MODE_700C_EN CODEC2_MODE_EN_DEFAULT
80 #endif
81 #if !defined(CODEC2_MODE_450_EN)
82         #define CODEC2_MODE_450_EN CODEC2_MODE_EN_DEFAULT
83 #endif
84 #if !defined(CODEC2_MODE_450PWB_EN)
85         #define CODEC2_MODE_450PWB_EN CODEC2_MODE_EN_DEFAULT
86 #endif
87 
88 #define CODEC2_MODE_ACTIVE(mode_name, var)  ((mode_name##_EN) == 0 ? 0: (var) == mode_name)
89 
90 struct CODEC2;
91 
92 struct CODEC2 *codec2_create(int mode);
93 void codec2_destroy(struct CODEC2 *codec2_state);
94 void codec2_encode(struct CODEC2 *codec2_state, unsigned char bytes[], short speech_in[]);
95 void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char bytes[]);
96 void codec2_decode_ber(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bytes, float ber_est);
97 int  codec2_samples_per_frame(struct CODEC2 *codec2_state);
98 int  codec2_bits_per_frame(struct CODEC2 *codec2_state);
99 int  codec2_bytes_per_frame(struct CODEC2 *codec2_state);
100 
101 void codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma);
102 int  codec2_get_spare_bit_index(struct CODEC2 *codec2_state);
103 int  codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, char unpacked_bits[]);
104 void codec2_set_natural_or_gray(struct CODEC2 *codec2_state, int gray);
105 void codec2_set_softdec(struct CODEC2 *c2, float *softdec);
106 float codec2_get_energy(struct CODEC2 *codec2_state, const unsigned char *bits);
107 
108 // support for ML and VQ experiments
109 void codec2_open_mlfeat(struct CODEC2 *codec2_state, char *feat_filename, char *model_filename);
110 void codec2_load_codebook(struct CODEC2 *codec2_state, int num, char *filename);
111 float codec2_get_var(struct CODEC2 *codec2_state);
112 float *codec2_enable_user_ratek(struct CODEC2 *codec2_state, int *K);
113 
114 // 700C post filter and equaliser
115 void codec2_700c_post_filter(struct CODEC2 *codec2_state, int en);
116 void codec2_700c_eq(struct CODEC2 *codec2_state, int en);
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif
123 
124