xref: /aosp_15_r20/external/libopus/silk/API.h (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
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 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
12 names of specific contributors, may be used to endorse or promote
13 products derived from this software without specific prior written
14 permission.
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27 
28 #ifndef SILK_API_H
29 #define SILK_API_H
30 
31 #include "control.h"
32 #include "typedef.h"
33 #include "errors.h"
34 #include "entenc.h"
35 #include "entdec.h"
36 
37 #ifdef ENABLE_DEEP_PLC
38 #include "lpcnet_private.h"
39 #endif
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45 
46 #define SILK_MAX_FRAMES_PER_PACKET  3
47 
48 /* Struct for TOC (Table of Contents) */
49 typedef struct {
50     opus_int    VADFlag;                                /* Voice activity for packet                            */
51     opus_int    VADFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Voice activity for each frame in packet              */
52     opus_int    inbandFECFlag;                          /* Flag indicating if packet contains in-band FEC       */
53 } silk_TOC_struct;
54 
55 /****************************************/
56 /* Encoder functions                    */
57 /****************************************/
58 
59 /***********************************************/
60 /* Get size in bytes of the Silk encoder state */
61 /***********************************************/
62 opus_int silk_Get_Encoder_Size(                         /* O    Returns error code                              */
63     opus_int                        *encSizeBytes       /* O    Number of bytes in SILK encoder state           */
64 );
65 
66 /*************************/
67 /* Init or reset encoder */
68 /*************************/
69 opus_int silk_InitEncoder(                              /* O    Returns error code                              */
70     void                            *encState,          /* I/O  State                                           */
71     int                              arch,              /* I    Run-time architecture                           */
72     silk_EncControlStruct           *encStatus          /* O    Encoder Status                                  */
73 );
74 
75 /**************************/
76 /* Encode frame with Silk */
77 /**************************/
78 /* Note: if prefillFlag is set, the input must contain 10 ms of audio, irrespective of what                     */
79 /* encControl->payloadSize_ms is set to                                                                         */
80 opus_int silk_Encode(                                   /* O    Returns error code                              */
81     void                            *encState,          /* I/O  State                                           */
82     silk_EncControlStruct           *encControl,        /* I    Control status                                  */
83     const opus_int16                *samplesIn,         /* I    Speech sample input vector                      */
84     opus_int                        nSamplesIn,         /* I    Number of samples in input vector               */
85     ec_enc                          *psRangeEnc,        /* I/O  Compressor data structure                       */
86     opus_int32                      *nBytesOut,         /* I/O  Number of bytes in payload (input: Max bytes)   */
87     const opus_int                  prefillFlag,        /* I    Flag to indicate prefilling buffers no coding   */
88     int                             activity            /* I    Decision of Opus voice activity detector        */
89 );
90 
91 /****************************************/
92 /* Decoder functions                    */
93 /****************************************/
94 
95 
96 /***********************************************/
97 /* Load OSCE models from external data pointer */
98 /***********************************************/
99 opus_int silk_LoadOSCEModels(
100     void *decState,                                     /* O    I/O State                                       */
101     const unsigned char *data,                          /* I    pointer to binary blob                          */
102     int len                                             /* I    length of binary blob data                      */
103 );
104 
105 /***********************************************/
106 /* Get size in bytes of the Silk decoder state */
107 /***********************************************/
108 opus_int silk_Get_Decoder_Size(                         /* O    Returns error code                              */
109     opus_int                        *decSizeBytes       /* O    Number of bytes in SILK decoder state           */
110 );
111 
112 /*************************/
113 /* Init and Reset decoder */
114 /*************************/
115 opus_int silk_ResetDecoder(                              /* O    Returns error code                              */
116     void                            *decState            /* I/O  State                                           */
117 );
118 
119 opus_int silk_InitDecoder(                              /* O    Returns error code                              */
120     void                            *decState           /* I/O  State                                           */
121 );
122 
123 /******************/
124 /* Decode a frame */
125 /******************/
126 opus_int silk_Decode(                                   /* O    Returns error code                              */
127     void*                           decState,           /* I/O  State                                           */
128     silk_DecControlStruct*          decControl,         /* I/O  Control Structure                               */
129     opus_int                        lostFlag,           /* I    0: no loss, 1 loss, 2 decode fec                */
130     opus_int                        newPacketFlag,      /* I    Indicates first decoder call for this packet    */
131     ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                       */
132     opus_int16                      *samplesOut,        /* O    Decoded output speech vector                    */
133     opus_int32                      *nSamplesOut,       /* O    Number of samples decoded                       */
134 #ifdef ENABLE_DEEP_PLC
135     LPCNetPLCState                  *lpcnet,
136 #endif
137     int                             arch                /* I    Run-time architecture                           */
138 );
139 
140 #if 0
141 /**************************************/
142 /* Get table of contents for a packet */
143 /**************************************/
144 opus_int silk_get_TOC(
145     const opus_uint8                *payload,           /* I    Payload data                                */
146     const opus_int                  nBytesIn,           /* I    Number of input bytes                       */
147     const opus_int                  nFramesPerPayload,  /* I    Number of SILK frames per payload           */
148     silk_TOC_struct                 *Silk_TOC           /* O    Type of content                             */
149 );
150 #endif
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif
157