lpcnet  1.0-207-g777aecd
Neural Vocoder.
lpcnet.h
1 /* Copyright (c) 2018 Mozilla */
2 /*
3  Redistribution and use in source and binary forms, with or without
4  modification, are permitted provided that the following conditions
5  are met:
6 
7  - Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 #ifndef _LPCNET_H_
28 #define _LPCNET_H_
29 
30 #ifndef LPCNET_EXPORT
31 # if defined(WIN32)
32 # if defined(LPCNET_BUILD) && defined(DLL_EXPORT)
33 # define LPCNET_EXPORT __declspec(dllexport)
34 # else
35 # define LPCNET_EXPORT
36 # endif
37 # elif defined(__GNUC__) && defined(LPCNET_BUILD)
38 # define LPCNET_EXPORT __attribute__ ((visibility ("default")))
39 # else
40 # define LPCNET_EXPORT
41 # endif
42 #endif
43 
44 
45 #define NB_FEATURES 20
46 #define NB_TOTAL_FEATURES 36
47 
49 #define LPCNET_COMPRESSED_SIZE 8
51 #define LPCNET_PACKET_SAMPLES (4*160)
53 #define LPCNET_FRAME_SIZE (160)
54 
55 typedef struct LPCNetState LPCNetState;
56 
57 typedef struct LPCNetDecState LPCNetDecState;
58 
59 typedef struct LPCNetEncState LPCNetEncState;
60 
61 typedef struct LPCNetPLCState LPCNetPLCState;
62 
63 
67 LPCNET_EXPORT int lpcnet_decoder_get_size(void);
68 
76 LPCNET_EXPORT int lpcnet_decoder_init(LPCNetDecState *st);
77 
78 LPCNET_EXPORT void lpcnet_reset(LPCNetState *lpcnet);
79 
83 LPCNET_EXPORT LPCNetDecState *lpcnet_decoder_create(void);
84 
88 LPCNET_EXPORT void lpcnet_decoder_destroy(LPCNetDecState *st);
89 
96 LPCNET_EXPORT int lpcnet_decode(LPCNetDecState *st, const unsigned char *buf, short *pcm);
97 
98 
99 
103 LPCNET_EXPORT int lpcnet_encoder_get_size(void);
104 
112 LPCNET_EXPORT int lpcnet_encoder_init(LPCNetEncState *st);
113 
117 LPCNET_EXPORT LPCNetEncState *lpcnet_encoder_create(void);
118 
122 LPCNET_EXPORT void lpcnet_encoder_destroy(LPCNetEncState *st);
123 
130 LPCNET_EXPORT int lpcnet_encode(LPCNetEncState *st, const short *pcm, unsigned char *buf);
131 
138 LPCNET_EXPORT int lpcnet_compute_features(LPCNetEncState *st, const short *pcm, float features[4][NB_TOTAL_FEATURES]);
139 
146 LPCNET_EXPORT int lpcnet_compute_single_frame_features(LPCNetEncState *st, const short *pcm, float features[NB_TOTAL_FEATURES]);
147 
148 
155 LPCNET_EXPORT int lpcnet_compute_single_frame_features_float(LPCNetEncState *st, const float *pcm, float features[NB_TOTAL_FEATURES]);
156 
160 LPCNET_EXPORT int lpcnet_get_size(void);
161 
169 LPCNET_EXPORT int lpcnet_init(LPCNetState *st);
170 
174 LPCNET_EXPORT LPCNetState *lpcnet_create(void);
175 
179 LPCNET_EXPORT void lpcnet_destroy(LPCNetState *st);
180 
188 LPCNET_EXPORT void lpcnet_synthesize(LPCNetState *st, const float *features, short *output, int N);
189 
190 
191 #define LPCNET_PLC_CAUSAL 0
192 #define LPCNET_PLC_NONCAUSAL 1
193 #define LPCNET_PLC_CODEC 2
194 
195 #define LPCNET_PLC_DC_FILTER 4
196 
197 LPCNET_EXPORT int lpcnet_plc_get_size(void);
198 
199 LPCNET_EXPORT int lpcnet_plc_init(LPCNetPLCState *st, int options);
200 LPCNET_EXPORT void lpcnet_plc_reset(LPCNetPLCState *st);
201 
202 LPCNET_EXPORT LPCNetPLCState *lpcnet_plc_create(int options);
203 
204 LPCNET_EXPORT void lpcnet_plc_destroy(LPCNetPLCState *st);
205 
206 LPCNET_EXPORT int lpcnet_plc_update(LPCNetPLCState *st, short *pcm);
207 
208 LPCNET_EXPORT int lpcnet_plc_conceal(LPCNetPLCState *st, short *pcm);
209 
210 LPCNET_EXPORT void lpcnet_plc_fec_add(LPCNetPLCState *st, const float *features);
211 
212 LPCNET_EXPORT void lpcnet_plc_fec_clear(LPCNetPLCState *st);
213 
214 LPCNET_EXPORT int lpcnet_load_model(LPCNetState *st, const unsigned char *data, int len);
215 LPCNET_EXPORT int lpcnet_plc_load_model(LPCNetPLCState *st, const unsigned char *data, int len);
216 
217 #endif