Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
5.4 KiB

  1. /**********************************************************************/
  2. /**********************************************************************/
  3. /********* Global constants used by silence detector *******/
  4. /**********************************************************************/
  5. /**********************************************************************/
  6. //BUFERSIZE is the size, in samples, of the speech encoder input buffer.
  7. //This should be set to the same value as MYCODEC_BUFFER_SAMPS in mycodec.h
  8. #define BUFFERSIZE 240
  9. //HIST_TIME is the time period, in seconds, represented by the number of past values of SD
  10. // parameters kept in memory. HIST_SIZE is the size of the history arrys and is set so
  11. // that the size of the history arrays correspond to HIST_TIME seconds of stored SD parameters.
  12. #define HIST_TIME 1.0
  13. #define HIST_SIZE (int)(HIST_TIME*8000/BUFFERSIZE)
  14. //ENERGY_TAU_HIST_TIME is the time period, in seconds, represented by the number of past
  15. // values of energy tau kept in memory. Energy tau is used only by the SD initializer.
  16. #define ENERGY_TAU_HIST_TIME 1.5
  17. #define ENERGY_TAU_HIST_SIZE (int)(ENERGY_TAU_HIST_TIME*8000/BUFFERSIZE)
  18. #define OFFSET 10
  19. #define MAX_SAMPLE 32768.0
  20. #define MASK_SILENCE_MARKED 0x01
  21. #define MASK_EARLY_EXIT 0x02
  22. #define MASK_SILENCE_CODED 0x04
  23. #define MASK_SQUELCH 0xF00
  24. //The following times (in seconds) are used by initializeSD to
  25. // decide when to stop initializing.
  26. //Initialization is not allowed to complete before the end of
  27. // MIN_STARTUP_TIME, in seconds.
  28. //If initialization fails before the end of MAX_STARTUP_TIME,
  29. // silence detection is disabled
  30. #define MIN_STARTUP_TIME 2
  31. #define MAX_STARTUP_TIME 20
  32. #define STOPPING_STDEV 3.0
  33. #define INITL_STOPPING_STDEV 10.0
  34. #define INITL_MIN_TAU 20.0
  35. #define INITL_STDEV 2.0
  36. //MAX_SPEECH_TIME time is the amount of time in seconds that the silence "off"
  37. // mode (no silent frames detected) is allowed to continue before
  38. // reinitialization is automatically invoked.
  39. #define MAX_SPEECH_TIME 4.0
  40. //SD_MIN_BUFFERSIZE is the smallest possible input buffersize
  41. // in bytes for silence detection (20 samples)
  42. #define SD_MIN_BUFFERSIZE 40
  43. //Initial threshold settings
  44. #define SLIDER_MAX 100.0f
  45. #define SLIDER_MIN 0.0f
  46. #define INITL_HANGTIME 0
  47. #define MIN_SPEECH_INTERVAL 6
  48. #define HANG_SLOPE 6.0f/14.0f
  49. #define INITL_ENERGY_ON 3.8f
  50. #define INITL_ENERGY_TX INITL_ENERGY_ON
  51. #define INITL_ZC_ON 2.0f
  52. #define INITL_ZC_TX INITL_ZC_ON
  53. #define ZC_SLOPE 0.045f
  54. #define INITL_ALPHA_ON 2.0f
  55. #define INITL_ENERGY_OFF 2.8f
  56. #define INITL_ZC_OFF INITL_ZC_ON
  57. #define INITL_ALPHA_OFF INITL_ALPHA_ON
  58. #define FALSE 0
  59. #define TRUE 1
  60. #define SPEECH 0
  61. #define SILENCE 1
  62. #define NONADAPT 3
  63. /**********************************************************************/
  64. /**********************************************************************/
  65. /********* Data structure for silence detector and prefilters *******/
  66. /**********************************************************************/
  67. /**********************************************************************/
  68. typedef struct {
  69. float Mean;
  70. float Stdev;
  71. float History[HIST_SIZE];
  72. } STATS;
  73. typedef struct {
  74. STATS Energy;
  75. STATS Alpha1;
  76. STATS ZC;
  77. int FrameCount;
  78. } MODE0;
  79. typedef struct {
  80. STATS Energy;
  81. int FrameCount;
  82. } MODE1;
  83. typedef struct {
  84. float TauMean;
  85. float TauStdev;
  86. float TauHistory[ENERGY_TAU_HIST_SIZE];
  87. } TAU_STATS;
  88. typedef struct {
  89. TAU_STATS TauEnergy;
  90. TAU_STATS TauAlpha1;
  91. TAU_STATS TauZC;
  92. } TAU_MODE;
  93. typedef struct {
  94. /*The following parameters are used to set thresholds for
  95. * changing from silence to speechmode designation in Silence_Detect.
  96. * These are factors which are used to multiply the standard deviation of
  97. * the energy, alpha1, & zero crossing, respectively.
  98. */
  99. float Energy_on;
  100. float ZC_on;
  101. float Alpha1_on;
  102. float Energy_tx;
  103. float ZC_tx;
  104. /*The following parameters are used to set thresholds for
  105. * changing from speech to silent mode designation in Silence_Detect.
  106. *These are factors which are used to multiply the standard deviation of
  107. * the energy & zero crossing, respectively.
  108. */
  109. float Energy_off;
  110. float ZC_off;
  111. float Alpha1_off;
  112. /* Tau is the distance between the Mode0 (silence) and the Mode1 (speech) energy means.
  113. If the distance between mode 0 and mode 1 energy means is less than MIN_TAU,
  114. silence detection is impossible.
  115. */
  116. float Energy_MinTau;
  117. /* Energy squelch level */
  118. float Squelch_set;
  119. int BufferSize;
  120. int HistSize;
  121. int TauHistSize;
  122. int MinStartupCount;
  123. int MaxStartupCount;
  124. int MaxSpeechFrameCount;
  125. } SETTINGS;
  126. typedef struct {
  127. float nBuffer[4];
  128. float dBuffer[3];
  129. float denom[6];
  130. float num[6];
  131. float sbuff[BUFFERSIZE];
  132. float storebuff[BUFFERSIZE];
  133. } FILTERS;
  134. typedef struct {
  135. MODE0 Mode0;
  136. MODE1 Mode1;
  137. MODE0 *Mode0Ptr;
  138. MODE1 *Mode1Ptr;
  139. TAU_MODE TauMode;
  140. int initFrameCount;
  141. int Class;
  142. int SD_enable;
  143. float FrameEnergy;
  144. float FrameLinPred;
  145. float FrameZCs;
  146. SETTINGS SDsettings;
  147. FILTERS Filt;
  148. int HangCntr;
  149. } SD_STATE_VALS;
  150. typedef struct {
  151. long SDFlags;
  152. //COMFORT_PARMS ComfortParms;
  153. SD_STATE_VALS SDstate;
  154. } INSTNCE, *SD_INST;