speex_preprocess.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* Copyright (C) 2003 Epic Games
  2. Written by Jean-Marc Valin */
  3. /**
  4. * @file speex_preprocess.h
  5. * @brief Speex preprocessor. The preprocess can do noise suppression,
  6. * residual echo suppression (after using the echo canceller), automatic
  7. * gain control (AGC) and voice activity detection (VAD).
  8. */
  9. /*
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are
  12. met:
  13. 1. Redistributions of source code must retain the above copyright notice,
  14. this list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  18. 3. The name of the author may not be used to endorse or promote products
  19. derived from this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  24. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  28. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  29. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef SPEEX_PREPROCESS_H
  33. #define SPEEX_PREPROCESS_H
  34. /** @defgroup SpeexPreprocessState SpeexPreprocessState: The Speex preprocessor
  35. * This is the Speex preprocessor. The preprocess can do noise suppression,
  36. * residual echo suppression (after using the echo canceller), automatic
  37. * gain control (AGC) and voice activity detection (VAD).
  38. * @{
  39. */
  40. #include "speex/speex_types.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /** State of the preprocessor (one per channel). Should never be accessed directly. */
  45. struct SpeexPreprocessState_;
  46. /** State of the preprocessor (one per channel). Should never be accessed directly. */
  47. typedef struct SpeexPreprocessState_ SpeexPreprocessState;
  48. /** Creates a new preprocessing state. You MUST create one state per channel processed.
  49. * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms). Must be
  50. * the same value as that used for the echo canceller for residual echo cancellation to work.
  51. * @param sampling_rate Sampling rate used for the input.
  52. * @return Newly created preprocessor state
  53. */
  54. SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_rate);
  55. /** Destroys a preprocessor state
  56. * @param st Preprocessor state to destroy
  57. */
  58. void speex_preprocess_state_destroy(SpeexPreprocessState *st);
  59. /** Preprocess a frame
  60. * @param st Preprocessor state
  61. * @param x Audio sample vector (in and out). Must be same size as specified in speex_preprocess_state_init().
  62. * @return Bool value for voice activity (1 for speech, 0 for noise/silence), ONLY if VAD turned on.
  63. */
  64. int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x);
  65. /** Preprocess a frame (deprecated, use speex_preprocess_run() instead)*/
  66. int speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, spx_int32_t *echo);
  67. /** Update preprocessor state, but do not compute the output
  68. * @param st Preprocessor state
  69. * @param x Audio sample vector (in only). Must be same size as specified in speex_preprocess_state_init().
  70. */
  71. void speex_preprocess_estimate_update(SpeexPreprocessState *st, spx_int16_t *x);
  72. /** Used like the ioctl function to control the preprocessor parameters
  73. * @param st Preprocessor state
  74. * @param request ioctl-type request (one of the SPEEX_PREPROCESS_* macros)
  75. * @param ptr Data exchanged to-from function
  76. * @return 0 if no error, -1 if request in unknown
  77. */
  78. int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
  79. /** Set preprocessor denoiser state */
  80. #define SPEEX_PREPROCESS_SET_DENOISE 0
  81. /** Get preprocessor denoiser state */
  82. #define SPEEX_PREPROCESS_GET_DENOISE 1
  83. /** Set preprocessor Automatic Gain Control state */
  84. #define SPEEX_PREPROCESS_SET_AGC 2
  85. /** Get preprocessor Automatic Gain Control state */
  86. #define SPEEX_PREPROCESS_GET_AGC 3
  87. /** Set preprocessor Voice Activity Detection state */
  88. #define SPEEX_PREPROCESS_SET_VAD 4
  89. /** Get preprocessor Voice Activity Detection state */
  90. #define SPEEX_PREPROCESS_GET_VAD 5
  91. /** Set preprocessor Automatic Gain Control level (float) */
  92. #define SPEEX_PREPROCESS_SET_AGC_LEVEL 6
  93. /** Get preprocessor Automatic Gain Control level (float) */
  94. #define SPEEX_PREPROCESS_GET_AGC_LEVEL 7
  95. /** Set preprocessor dereverb state */
  96. #define SPEEX_PREPROCESS_SET_DEREVERB 8
  97. /** Get preprocessor dereverb state */
  98. #define SPEEX_PREPROCESS_GET_DEREVERB 9
  99. /** Set preprocessor dereverb level */
  100. #define SPEEX_PREPROCESS_SET_DEREVERB_LEVEL 10
  101. /** Get preprocessor dereverb level */
  102. #define SPEEX_PREPROCESS_GET_DEREVERB_LEVEL 11
  103. /** Set preprocessor dereverb decay */
  104. #define SPEEX_PREPROCESS_SET_DEREVERB_DECAY 12
  105. /** Get preprocessor dereverb decay */
  106. #define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13
  107. /** Set probability required for the VAD to go from silence to voice */
  108. #define SPEEX_PREPROCESS_SET_PROB_START 14
  109. /** Get probability required for the VAD to go from silence to voice */
  110. #define SPEEX_PREPROCESS_GET_PROB_START 15
  111. /** Set probability required for the VAD to stay in the voice state (integer percent) */
  112. #define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16
  113. /** Get probability required for the VAD to stay in the voice state (integer percent) */
  114. #define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17
  115. /** Set maximum attenuation of the noise in dB (negative number) */
  116. #define SPEEX_PREPROCESS_SET_NOISE_SUPPRESS 18
  117. /** Get maximum attenuation of the noise in dB (negative number) */
  118. #define SPEEX_PREPROCESS_GET_NOISE_SUPPRESS 19
  119. /** Set maximum attenuation of the residual echo in dB (negative number) */
  120. #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS 20
  121. /** Get maximum attenuation of the residual echo in dB (negative number) */
  122. #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS 21
  123. /** Set maximum attenuation of the residual echo in dB when near end is active (negative number) */
  124. #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22
  125. /** Get maximum attenuation of the residual echo in dB when near end is active (negative number) */
  126. #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23
  127. /** Set the corresponding echo canceller state so that residual echo suppression can be performed (NULL for no residual echo suppression) */
  128. #define SPEEX_PREPROCESS_SET_ECHO_STATE 24
  129. /** Get the corresponding echo canceller state */
  130. #define SPEEX_PREPROCESS_GET_ECHO_STATE 25
  131. /** Set maximal gain increase in dB/second (int32) */
  132. #define SPEEX_PREPROCESS_SET_AGC_INCREMENT 26
  133. /** Get maximal gain increase in dB/second (int32) */
  134. #define SPEEX_PREPROCESS_GET_AGC_INCREMENT 27
  135. /** Set maximal gain decrease in dB/second (int32) */
  136. #define SPEEX_PREPROCESS_SET_AGC_DECREMENT 28
  137. /** Get maximal gain decrease in dB/second (int32) */
  138. #define SPEEX_PREPROCESS_GET_AGC_DECREMENT 29
  139. /** Set maximal gain in dB (int32) */
  140. #define SPEEX_PREPROCESS_SET_AGC_MAX_GAIN 30
  141. /** Get maximal gain in dB (int32) */
  142. #define SPEEX_PREPROCESS_GET_AGC_MAX_GAIN 31
  143. /* Can't set loudness */
  144. /** Get loudness */
  145. #define SPEEX_PREPROCESS_GET_AGC_LOUDNESS 33
  146. /* Can't set gain */
  147. /** Get current gain (int32 percent) */
  148. #define SPEEX_PREPROCESS_GET_AGC_GAIN 35
  149. /* Can't set spectrum size */
  150. /** Get spectrum size for power spectrum (int32) */
  151. #define SPEEX_PREPROCESS_GET_PSD_SIZE 37
  152. /* Can't set power spectrum */
  153. /** Get power spectrum (int32[] of squared values) */
  154. #define SPEEX_PREPROCESS_GET_PSD 39
  155. /* Can't set noise size */
  156. /** Get spectrum size for noise estimate (int32) */
  157. #define SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE 41
  158. /* Can't set noise estimate */
  159. /** Get noise estimate (int32[] of squared values) */
  160. #define SPEEX_PREPROCESS_GET_NOISE_PSD 43
  161. /* Can't set speech probability */
  162. /** Get speech probability in last frame (int32). */
  163. #define SPEEX_PREPROCESS_GET_PROB 45
  164. /** Set preprocessor Automatic Gain Control level (int32) */
  165. #define SPEEX_PREPROCESS_SET_AGC_TARGET 46
  166. /** Get preprocessor Automatic Gain Control level (int32) */
  167. #define SPEEX_PREPROCESS_GET_AGC_TARGET 47
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. /** @}*/
  172. #endif