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.

202 lines
6.9 KiB

  1. /******************************************************************************
  2. * ReverbFX.h *
  3. *-------------*
  4. * This is the header file for the CReverbFX implementation.
  5. *------------------------------------------------------------------------------
  6. * Copyright (C) 1999 Microsoft Corporation Date: 03/01/99
  7. * All Rights Reserved
  8. *
  9. *********************************************************************** MC ****/
  10. #ifndef ReverbFX_H
  11. #define ReverbFX_H
  12. #ifndef __spttseng_h__
  13. #include "spttseng.h"
  14. #endif
  15. //-------------------------------------------------------------
  16. // Comment-out line below if you want
  17. // integer math instead of floating point.
  18. //
  19. // NOTE:
  20. // Bathtub preset probably won't work
  21. // using integer math (overflow)
  22. //-------------------------------------------------------------
  23. #define FLOAT_REVERB 1
  24. #ifdef FLOAT_REVERB
  25. #define REVERBT float
  26. #define REVERBL float
  27. #else
  28. #define REVERBT short
  29. #define REVERBL long
  30. #endif
  31. #ifdef FLOAT_REVERB
  32. static const float REVERB_VOL_OFF = 0.0;
  33. static const float REVERB_VOL_UNITY = 1.0f;
  34. static const float REVERB_MIN_MIX = 0.001f;
  35. #else
  36. static const long REVERB_VOL_SHIFT = (16);
  37. static const long REVERB_VOL_LEVELS = 65536;
  38. static const long REVERB_VOL_OFF = 0;
  39. static const long REVERB_VOL_UNITY = REVERB_VOL_LEVELS;
  40. #endif
  41. static const float REVERB_MIN_DB = (-110.0);
  42. static const long KMAXREVBMODS = 5;
  43. static const long KWORKBUFLEN = 1024;
  44. //-------------------------------------
  45. // Reverb preset parametrs
  46. //-------------------------------------
  47. struct REVERBCONFIG
  48. {
  49. float wetGain_dB; // WET gain (db)
  50. float dryGain_dB; // DRY gain (db)
  51. short numOfReflect; // Number of modules
  52. float *gain_ms_Array; // Array of delay values (ms)
  53. float *gain_dB_Array; // Array of gain values (db)
  54. float seqIndex; // "sequencer" fx
  55. };
  56. typedef struct REVERBCONFIG REVERBCONFIG, *LPREVERBCONFIG;
  57. struct Reverb_Mod
  58. {
  59. REVERBL lGain; // Gain of the amplifiers.
  60. long dwDelay; // Length of the delay line.
  61. long dwDelayBufferSize; // Size of the delay buffer.
  62. REVERBT *psDelayBuffer; // Circular delay buffer, length dwDelay.
  63. REVERBT *psDelayIn; // Current input position in the delay.
  64. REVERBT *psDelayOut; // Current output position in the delay.
  65. REVERBT *psDelayEnd; // Location immediately following the buffer.
  66. };
  67. typedef struct Reverb_Mod Reverb_Mod, *LP_Reverb_Mod;
  68. //----------------------------------
  69. // Reverb error codes
  70. //----------------------------------
  71. static const long KREVERB_NOERROR = 0;
  72. static const long KREVERB_MEMERROR = 1;
  73. static const long KREVERB_OFF = 2;
  74. //-----------------------------------------
  75. // ReverbFX Class
  76. //-----------------------------------------
  77. class CReverbFX
  78. {
  79. public:
  80. //----------------------------------
  81. // Initialization functions
  82. //----------------------------------
  83. CReverbFX( void );
  84. ~CReverbFX( void );
  85. short Reverb_Init
  86. (
  87. REVERBTYPE reverbPreset, // Configuration preset
  88. long nSamplesPerSec, // SampleRate
  89. long stereoOut // true = output is stero
  90. );
  91. private:
  92. REVERBL DecibelToPercent( float flDecibel );
  93. void ClearReverb( LP_Reverb_Mod mod );
  94. short AllocReverbModule
  95. (
  96. LP_Reverb_Mod mod,
  97. REVERBL lGain, // Gain of the amplifiers.
  98. long dwDelay, // Length of the delay line.
  99. long dwDelayBufferSize // Size of the delay buffer.
  100. );
  101. short CreateReverbModules
  102. (
  103. short wModules, // Number of modules to create.
  104. LP_Reverb_Mod *mods,
  105. float * pfltDelay, // Array of delay values for the modules.
  106. float * pfltDB, // Array of gain values for the modules.
  107. float fltSamplesPerMS // Number of samples per millisecond.
  108. );
  109. void DeleteReverbModules ();
  110. LPREVERBCONFIG GetReverbConfig( REVERBTYPE dwReverbConfig );
  111. //----------------------------------
  112. // Run-time
  113. //----------------------------------
  114. void CopyWithGain
  115. (
  116. REVERBT *psDest,
  117. REVERBT *psSource,
  118. long dwSamples,
  119. REVERBL gain
  120. );
  121. void MixWithGain_STEREO
  122. (
  123. REVERBT *pWet,
  124. REVERBT *pDry,
  125. short *pDest,
  126. long dwSamples,
  127. REVERBL gain
  128. );
  129. void MixWithGain_MONO
  130. (
  131. REVERBT *pWet,
  132. REVERBT *pDry,
  133. short *pDest,
  134. long dwSamples,
  135. REVERBL gain
  136. );
  137. void ProcessReverbModule
  138. (
  139. LP_Reverb_Mod mod,
  140. long dwDestSamples, // Number of samples to process.
  141. REVERBT *pSource, // Source sample buffer.
  142. REVERBT *pDestination // Destination sample buffer.
  143. );
  144. void ProcessReverbBuffer
  145. (
  146. REVERBT *psSample, // Samples to process (in/out).
  147. long wSamples, // Number of samples to process.
  148. LP_Reverb_Mod *mods // Array of modules to apply.
  149. );
  150. public:
  151. short Reverb_Process( float *sampleBuffer, long dwSamplesRemaining, float audioGain );
  152. private:
  153. //----------------------------------
  154. // Member Variables
  155. //----------------------------------
  156. long m_StereoOut;
  157. long m_dwWorkBufferSize;
  158. REVERBT *m_pWorkBuf;
  159. REVERBL m_wetVolGain;
  160. REVERBL m_dryVolGain;
  161. long m_numOfMods;
  162. LP_Reverb_Mod m_Reverb_Mods[KMAXREVBMODS];
  163. LPREVERBCONFIG m_pReverbConfig;
  164. float m_Count;
  165. float m_LenScale;
  166. };
  167. typedef CReverbFX *LP_CReverbFX;
  168. #endif //--- This must be the last line in the file