API.h 7.3 KB

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