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.

159 lines
4.5 KiB

  1. //
  2. //
  3. //
  4. #ifndef _DirectSoundSampleDMO_p_
  5. #define _DirectSoundSampleDMO_p_
  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 CDirectSoundDistortionDMO :
  15. public CDirectSoundDMO,
  16. public CParamsManager,
  17. public ISpecifyPropertyPages,
  18. public IDirectSoundFXDistortion,
  19. public CParamsManager::UpdateCallback,
  20. public CComBase
  21. {
  22. public:
  23. CDirectSoundDistortionDMO( IUnknown *pUnk, HRESULT *phr );
  24. ~CDirectSoundDistortionDMO();
  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. // Init is called by the DMO base class when both input and output media
  32. // types have been set up.
  33. //
  34. HRESULT Init();
  35. // Note that an Init function also exists in the CPCMDMO base class and it can be overridden
  36. // to provide initialization for the effect's actual audio processing.
  37. STDMETHOD(Clone) (THIS_ IMediaObjectInPlace **);
  38. /* IFilter */
  39. STDMETHOD(SetAllParameters) (THIS_ LPCDSFXDistortion);
  40. STDMETHOD(GetAllParameters) (THIS_ LPDSFXDistortion);
  41. // ISpecifyPropertyPages
  42. STDMETHOD(GetPages)(CAUUID * pPages) { return PropertyHelp::GetPages(CLSID_DirectSoundPropDistortion, pPages); }
  43. // IPersist methods
  44. virtual HRESULT STDMETHODCALLTYPE GetClassID( CLSID *pClassID );
  45. // IPersistStream
  46. STDMETHOD(IsDirty)(void) { return m_fDirty ? S_OK : S_FALSE; }
  47. STDMETHOD(Load)(IStream *pStm) { return PropertyHelp::Load(this, DSFXDistortion(), pStm); }
  48. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) { return PropertyHelp::Save(this, DSFXDistortion(), pStm, fClearDirty); }
  49. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) { if (!pcbSize) return E_POINTER; pcbSize->QuadPart = sizeof(DSFXDistortion); return S_OK; }
  50. // SetParam handling
  51. STDMETHODIMP SetParam(DWORD dwParamIndex,MP_DATA value) { return SetParamInternal(dwParamIndex, value, false); }
  52. HRESULT SetParamUpdate(DWORD dwParamIndex, MP_DATA value) { return SetParamInternal(dwParamIndex, value, true); }
  53. HRESULT SetParamInternal(DWORD dwParamIndex, MP_DATA value, bool fSkipPasssingToParamManager);
  54. // Overrides
  55. //
  56. HRESULT FBRProcess(DWORD cQuanta, BYTE *pIn, BYTE *pOut);
  57. HRESULT ProcessInPlace(ULONG ulQuanta, LPBYTE pcbData, REFERENCE_TIME rtStart, DWORD dwFlags);
  58. HRESULT Discontinuity();
  59. DWORD ParamCount();
  60. bool m_fDirty;
  61. protected:
  62. HRESULT CheckInputType(const DMO_MEDIA_TYPE *pmt) {
  63. HRESULT hr = CPCMDMO::CheckInputType(pmt);
  64. if (FAILED(hr)) return hr;
  65. WAVEFORMATEX *pWave = (WAVEFORMATEX*)pmt->pbFormat;
  66. if (pWave->wFormatTag != WAVE_FORMAT_PCM ||
  67. (pWave->wBitsPerSample != 8 && pWave->wBitsPerSample != 16) ||
  68. (pWave->nChannels != 1 && pWave->nChannels != 2)) {
  69. return DMO_E_TYPE_NOT_ACCEPTED;
  70. }
  71. return S_OK;
  72. }
  73. private:
  74. // { EAX
  75. __forceinline void DoOneSample(int *l, int *r);
  76. __forceinline void DoOneSampleMono(int *l);
  77. // Declare internal variables.
  78. #define DECLARE_EAX_VARS(type, var) \
  79. type m_Eax ## var;
  80. DECLARE_EAX_VARS(long, Exp_range);
  81. DECLARE_EAX_VARS(float, InScale);
  82. DECLARE_EAX_VARS(float, Lpfb);
  83. DECLARE_EAX_VARS(float, Lpff);
  84. DECLARE_EAX_VARS(float, K1);
  85. DECLARE_EAX_VARS(float, K2);
  86. DECLARE_EAX_VARS(float, Edge);
  87. DECLARE_EAX_VARS(float, Gain);
  88. DECLARE_EAX_VARS(float, Scale);
  89. DECLARE_EAX_VARS(float, Center);
  90. DECLARE_EAX_VARS(float, Bandwidth);
  91. // DECLARE_EAX_VARS(float, SamplesPerSec);
  92. #define m_EaxSamplesPerSec m_ulSamplingRate
  93. __forceinline int Saturate(float f) {
  94. int i;
  95. #ifdef DONTUSEi386
  96. _asm {
  97. fld f
  98. fistp i
  99. }
  100. #else
  101. i = (int)f;
  102. #endif
  103. if (i > 32767)
  104. i = 32767;
  105. else if ( i < -32768)
  106. i = -32768;
  107. return(i);
  108. }
  109. __forceinline float Interpolate(float a, float b, float percent)
  110. {
  111. percent = a + (b - a) * percent;
  112. return(percent);
  113. }
  114. void Bump(void);
  115. float m_ls0;
  116. float m_rs0;
  117. float m_delayL1;
  118. float m_delayL2;
  119. float m_delayR1;
  120. float m_delayR2;
  121. // } EAX
  122. };
  123. EXT_STD_CREATE(Distortion);
  124. #endif//