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.

172 lines
6.4 KiB

  1. /******************************************************************************
  2. * Backend.h *
  3. *-----------*
  4. * This is the header file for the CBackend implementation.
  5. *------------------------------------------------------------------------------
  6. * Copyright (C) 1999 Microsoft Corporation Date: 03/01/99
  7. * All Rights Reserved
  8. *
  9. *********************************************************************** MC ****/
  10. #ifndef Backend_H
  11. #define Backend_H
  12. #ifndef ReverbFX_H
  13. #include "ReverbFX.h"
  14. #endif
  15. #ifndef FeedChain_H
  16. #include "FeedChain.h"
  17. #endif
  18. #ifndef __spttseng_h__
  19. #include "spttseng.h"
  20. #endif
  21. #ifndef SPDebug_h
  22. #include <spdebug.h>
  23. #endif
  24. #ifndef SPCollec_h
  25. #include <SPCollec.h>
  26. #endif
  27. #include "SpTtsEngDebug.h"
  28. static const short MAX_TARGETS_PER_UNIT = 3; // Max number of knots allowed
  29. static const short MIN_VOICE_PITCH = 10; // Lowest voiced pitch (hertz)
  30. static const short UNIT_SIL = 0; // Silence phon
  31. static const short SPEECH_FRAME_SIZE = 5000; // Output audio uffer...
  32. static const short SPEECH_FRAME_OVER = 1000; // ...plus pad
  33. //----------------------------------------------------------
  34. // find a yn corresponding to xn,
  35. // given (x0, y0), (x1, y1), x0 <= xn <= x1
  36. //----------------------------------------------------------
  37. inline float LinInterp( float x0, float xn, float x1, float y0, float y1 )
  38. {
  39. return y0 + (y1-y0)*(xn-x0)/(x1-x0);
  40. }
  41. // Math marcos
  42. #define ABS(x) ((x) >= 0 ? (x) : -(x))
  43. #define MAX(x,y) (((x) >= (y)) ? (x) : (y))
  44. #define MIN(x,y) (((x) <= (y)) ? (x) : (y))
  45. static const float LINEAR_BKPT = 0.1f;
  46. static const float LOG_RANGE = (-25.0f);
  47. //********************************************************************
  48. //
  49. // CBackend keeps track of all the state information for the
  50. // synthesis process.
  51. //
  52. //********************************************************************
  53. class CBackend
  54. {
  55. public:
  56. /*--- Constructors/Destructors ---*/
  57. CBackend ();
  58. ~CBackend ();
  59. /*=== Methods =======*/
  60. HRESULT Init( IMSVoiceData* pVoiceDataObj,
  61. CFeedChain *pSrcObj,
  62. MSVOICEINFO* pVoiceInfo );
  63. SPEECH_STATE GetSpeechState() {return m_SpeechState;}
  64. void PrepareSpeech( ISpTTSEngineSite* outputSite );
  65. HRESULT RenderFrame( );
  66. private:
  67. HRESULT StartNewUnit();
  68. long ProsodyMod( UNITINFO *pCurUnit,
  69. long cInEpochs,
  70. float durationMpy,
  71. long cMaxOutEpochs);
  72. void CleanUpSynth();
  73. void ResRecons( float *pInRes,
  74. long InSize,
  75. float *pOutRes,
  76. long OutSize,
  77. float scale );
  78. void LPCFilter( float *pCurLPC, float *pCurRes, long len, float gain );
  79. void FreeSynth( MSUNITDATA* pSynth );
  80. void PSOLA_Stretch( float *pInRes, long InSize,
  81. float *pOutRes, long OutSize,
  82. float *pWindow,
  83. long cWindowSize );
  84. void CvtToShort( float *pSrc, long blocksize, long stereoOut, float audioGain );
  85. void Release( );
  86. /*=== Member Data ===*/
  87. CFeedChain *m_pSrcObj; // Backend gets its input from here
  88. MSUNITDATA m_Synth; // Unit data from 'Voicedataobj'
  89. float *m_pHistory; // LPC delays
  90. unsigned long m_fModifiers;
  91. float *m_pHistory2; // IIR delays
  92. float *m_pFilter; // IIR/FIR coefficients
  93. long m_cNumTaps; // Coefficient count
  94. LP_CReverbFX m_pReverb; // Reverb object
  95. long *m_pMap; // in/out epoch map
  96. float *m_pOutEpoch; // epoch sizes
  97. short *m_pRevFlag; // true = rev unvoiced
  98. float *m_pInRes; // m_pSynth.pRes
  99. float *m_pInEpoch; // m_pSynth.pEpoch
  100. float *m_pLPC; // m_pSynth->pLPC
  101. long m_cOutSamples_Phon; // sample count
  102. long m_durationTarget; // target sample total
  103. long m_silMode;
  104. float *m_pSynthTime; // pCurUnit->pTime
  105. float *m_pSynthAmp; // pCurUnit->pAmp
  106. long m_nKnots; // pCurUnit->nKnots
  107. SPEECH_STATE m_SpeechState; // Either continue or done
  108. long m_cOutSamples_Frame; // Audio output sample count for frame
  109. float *m_pSpeechBuf; // Audio output sample buffer
  110. ULONG m_cOutSamples_Total; // Audio output sample count for Speak
  111. long m_EpochIndex; // Index for render
  112. long m_cOutEpochs; // Count for render
  113. long m_vibrato_Phase1; // Current vibrato phase index
  114. float m_VibratoDepth; // Vibrato gain
  115. float m_VibratoFreq; // Vibrato speed
  116. long m_StereoOut; // TRUE = stereo output
  117. long m_BytesPerSample; // 2 = mono, 4 = stereo
  118. IMSVoiceData* m_pVoiceDataObj; // Voice object
  119. ULONG m_cOrder; // LPC filter order
  120. float m_SampleRate; // I/O rate
  121. float* m_pWindow; // Hanning Window
  122. long m_FFTSize; // FFT length
  123. // User Controls
  124. float m_UnitVolume; // 0 - 1.0 (linear)
  125. long m_MasterVolume; // 0 - 100 (linear)
  126. float m_linearScale; // Linear taper region scale
  127. // SAPI audio sink
  128. ISpTTSEngineSite* m_pOutputSite;
  129. bool m_HasSpeech;
  130. };
  131. //--------------------------------
  132. // Unimplemented
  133. //--------------------------------
  134. static const long BACKEND_BITFLAG_WHISPER = (1 << 0);
  135. static const long BACKEND_BITFLAG_FIR = (1 << 1);
  136. static const long BACKEND_BITFLAG_IIR = (1 << 2);
  137. static const long BACKEND_BITFLAG_REVERB = (1 << 3);
  138. static const float VIBRATO_DEFAULT_DEPTH = 0.05f;
  139. static const float VIBRATO_DEFAULT_FREQ = 3.0f; // hz
  140. #endif //--- This must be the last line in the file