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.

137 lines
4.1 KiB

  1. //
  2. //
  3. //
  4. #ifndef _CHORUSP_
  5. #define _CHORUSP_
  6. #include "dsdmobse.h"
  7. #include "dmocom.h"
  8. #include "dsdmo.h"
  9. #include "PropertyHelp.h"
  10. #include "param.h"
  11. #define cALLPASS ((float).61803398875) // 1-x^2=x.
  12. #define RVB_LP_COEF ((float).1)
  13. #define MAXALLPASS cALLPASS
  14. #define DelayLineSize (DefineDelayLineSize(40))
  15. class CDirectSoundChorusDMO :
  16. public CDirectSoundDMO,
  17. public CParamsManager,
  18. public ISpecifyPropertyPages,
  19. public IDirectSoundFXChorus,
  20. public CParamsManager::UpdateCallback,
  21. public CComBase
  22. {
  23. public:
  24. CDirectSoundChorusDMO( IUnknown * pUnk, HRESULT *phr );
  25. ~CDirectSoundChorusDMO();
  26. DECLARE_IUNKNOWN;
  27. STDMETHODIMP NDQueryInterface(REFIID riid, void **ppv);
  28. static CComBase* WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  29. // InitOnCreation is called by the class factory to give the object a chance to initialize
  30. // immediately after it is created. This is used to prepare the object's parameter information.
  31. HRESULT InitOnCreation();
  32. // Note that an Init function also exists in the CPCMDMO base class and it can be overridden
  33. // to provide initialization for the effect's actual audio processing.
  34. HRESULT Init();
  35. STDMETHOD(Clone) (THIS_ IMediaObjectInPlace **);
  36. /* IFilter */
  37. STDMETHOD(SetAllParameters) (THIS_ LPCDSFXChorus);
  38. STDMETHOD(GetAllParameters) (THIS_ LPDSFXChorus);
  39. // ISpecifyPropertyPages
  40. STDMETHOD(GetPages)(CAUUID * pPages) { return PropertyHelp::GetPages(CLSID_DirectSoundPropChorus, pPages); }
  41. // IPersist methods
  42. virtual HRESULT STDMETHODCALLTYPE GetClassID( CLSID *pClassID );
  43. // IPersistStream
  44. STDMETHOD(IsDirty)(void) { return m_fDirty ? S_OK : S_FALSE; }
  45. STDMETHOD(Load)(IStream *pStm) { return PropertyHelp::Load(this, DSFXChorus(), pStm); }
  46. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) { return PropertyHelp::Save(this, DSFXChorus(), pStm, fClearDirty); }
  47. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) { if (!pcbSize) return E_POINTER; pcbSize->QuadPart = sizeof(DSFXChorus); return S_OK; }
  48. // SetParam handling
  49. STDMETHODIMP SetParam(DWORD dwParamIndex,MP_DATA value) { return SetParamInternal(dwParamIndex, value, false); }
  50. HRESULT SetParamUpdate(DWORD dwParamIndex, MP_DATA value) { return SetParamInternal(dwParamIndex, value, true); }
  51. HRESULT SetParamInternal(DWORD dwParamIndex, MP_DATA value, bool fSkipPasssingToParamManager);
  52. // Overrides
  53. //
  54. HRESULT FBRProcess(DWORD cQuanta, BYTE *pIn, BYTE *pOut);
  55. HRESULT ProcessInPlace(ULONG ulQuanta, LPBYTE pcbData, REFERENCE_TIME rtStart, DWORD dwFlags);
  56. HRESULT Discontinuity();
  57. bool m_fDirty;
  58. protected:
  59. HRESULT CheckInputType(const DMO_MEDIA_TYPE *pmt);
  60. private:
  61. // { EAX
  62. __forceinline void DoOneSample(int *l, int *r);
  63. #define DECLARE_EAX_VARS(type, var) \
  64. type m_Eax ## var;
  65. DECLARE_EAX_VARS(float, Depth);
  66. DECLARE_EAX_VARS(float, WetLevel); // Ratio of original and mixed.
  67. DECLARE_EAX_VARS(float, DepthCoef); // Delay distance.
  68. DECLARE_EAX_VARS(float, LfoCoef);
  69. DECLARE_EAX_VARS(float, FbCoef); // User-set feed-back coef.
  70. DECLARE_EAX_VARS(float, Frequency); // User-set.
  71. DECLARE_EAX_VARS(float, Delay);
  72. DECLARE_EAX_VARS(float, DelayCoef); // User-set chorus delay.
  73. DECLARE_EAX_VARS(long, Waveform);
  74. DECLARE_EAX_VARS(long, Phase);
  75. #define m_EaxSamplesPerSec m_ulSamplingRate
  76. DelayBuffer2<float, DelayLineSize, 3> m_DelayLine;
  77. __forceinline int Saturate(float f) {
  78. int i;
  79. #ifdef DONTUSEi386
  80. _asm {
  81. fld f
  82. fistp i
  83. }
  84. #else
  85. i = (int)f;
  86. #endif
  87. if (i > 32767)
  88. i = 32767;
  89. else if ( i < -32768)
  90. i = -32768;
  91. return(i);
  92. }
  93. __forceinline float Interpolate(float a, float b, float percent)
  94. {
  95. percent = a + (b - a) * percent;
  96. return(percent);
  97. }
  98. float m_LfoState[2];
  99. DWORD m_DelayFixedPtr;
  100. DWORD m_DelayL;
  101. DWORD m_DelayL1;
  102. DWORD m_DelayR;
  103. DWORD m_DelayR1;
  104. // } EAX
  105. };
  106. EXT_STD_CREATE(Chorus);
  107. #endif//