Source code of Windows XP (NT5)
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.

146 lines
4.0 KiB

  1. //
  2. //
  3. //
  4. #ifndef _Echop_
  5. #define _Echop_
  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. class CDirectSoundEchoDMO :
  15. public CDirectSoundDMO,
  16. public CParamsManager,
  17. public ISpecifyPropertyPages,
  18. public IDirectSoundFXEcho,
  19. public CParamsManager::UpdateCallback,
  20. public CComBase
  21. {
  22. public:
  23. CDirectSoundEchoDMO( IUnknown *pUnk, HRESULT *phr );
  24. ~CDirectSoundEchoDMO();
  25. DECLARE_IUNKNOWN;
  26. STDMETHODIMP NDQueryInterface(REFIID riid, void **ppv);
  27. static CComBase* WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  28. // InitOnCreation is called by the class factory to give the object a chance to initialize
  29. // immediately after it is created. This is used to prepare the object's parameter information.
  30. HRESULT InitOnCreation();
  31. // Note that an Init function also exists in the CPCMDMO base class and it can be overridden
  32. // to provide initialization for the effect's actual audio processing.
  33. STDMETHOD(Clone) (THIS_ IMediaObjectInPlace **);
  34. HRESULT Init();
  35. /* IFilter */
  36. STDMETHOD(SetAllParameters) (THIS_ LPCDSFXEcho);
  37. STDMETHOD(GetAllParameters) (THIS_ LPDSFXEcho);
  38. // ISpecifyPropertyPages
  39. STDMETHOD(GetPages)(CAUUID * pPages) { return PropertyHelp::GetPages(CLSID_DirectSoundPropEcho, pPages); }
  40. // IPersist methods
  41. virtual HRESULT STDMETHODCALLTYPE GetClassID( CLSID *pClassID );
  42. // IPersistStream
  43. STDMETHOD(IsDirty)(void) { return m_fDirty ? S_OK : S_FALSE; }
  44. STDMETHOD(Load)(IStream *pStm) { return PropertyHelp::Load(this, DSFXEcho(), pStm); }
  45. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) { return PropertyHelp::Save(this, DSFXEcho(), pStm, fClearDirty); }
  46. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) { if (!pcbSize) return E_POINTER; pcbSize->QuadPart = sizeof(DSFXEcho); return S_OK; }
  47. // SetParam handling
  48. STDMETHODIMP SetParam(DWORD dwParamIndex,MP_DATA value) { return SetParamInternal(dwParamIndex, value, false); }
  49. HRESULT SetParamUpdate(DWORD dwParamIndex, MP_DATA value) { return SetParamInternal(dwParamIndex, value, true); }
  50. HRESULT SetParamInternal(DWORD dwParamIndex, MP_DATA value, bool fSkipPasssingToParamManager);
  51. // Overrides
  52. //
  53. HRESULT FBRProcess(DWORD cQuanta, BYTE *pIn, BYTE *pOut);
  54. HRESULT ProcessInPlace(ULONG ulQuanta, LPBYTE pcbData, REFERENCE_TIME rtStart, DWORD dwFlags);
  55. HRESULT Discontinuity();
  56. bool m_fDirty;
  57. protected:
  58. HRESULT CheckInputType(const DMO_MEDIA_TYPE *pmt) {
  59. HRESULT hr = CPCMDMO::CheckInputType(pmt);
  60. if (FAILED(hr)) return hr;
  61. WAVEFORMATEX *pWave = (WAVEFORMATEX*)pmt->pbFormat;
  62. if (pWave->wFormatTag != WAVE_FORMAT_PCM ||
  63. (pWave->wBitsPerSample != 8 && pWave->wBitsPerSample != 16) ||
  64. (pWave->nChannels != 1 && pWave->nChannels != 2)) {
  65. return DMO_E_TYPE_NOT_ACCEPTED;
  66. }
  67. return S_OK;
  68. }
  69. private:
  70. // { EAX
  71. __forceinline void DoOneSample(int *l, int *r);
  72. // Declare internal variables.
  73. #define DECLARE_EAX_VARS(type, var) \
  74. type m_Eax ## var;
  75. DECLARE_EAX_VARS(long, DelayLRead);
  76. DECLARE_EAX_VARS(long, DelayRRead);
  77. #define m_EaxSamplesPerSec m_ulSamplingRate
  78. __forceinline int Saturate(float f) {
  79. int i;
  80. #ifdef DONTUSEi386
  81. _asm {
  82. fld f
  83. fistp i
  84. }
  85. #else
  86. i = (int)f;
  87. #endif
  88. if (i > 32767)
  89. i = 32767;
  90. else if ( i < -32768)
  91. i = -32768;
  92. return(i);
  93. }
  94. float m_StateL, m_StateR;
  95. __forceinline float Interpolate(float a, float b, float percent)
  96. {
  97. percent = a + (b - a) * percent;
  98. return(percent);
  99. }
  100. DECLARE_EAX_VARS(float, Lpfb);
  101. DECLARE_EAX_VARS(float, Lpff);
  102. DECLARE_EAX_VARS(float, Wetlevel);
  103. DECLARE_EAX_VARS(long, Pan);
  104. void Bump(void);
  105. DelayBuffer2<float, 2000, 16> m_DelayL;
  106. DelayBuffer2<float, 2000, 16> m_DelayR;
  107. // } EAX
  108. };
  109. EXT_STD_CREATE(Echo);
  110. #endif//