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.

151 lines
4.8 KiB

  1. //
  2. //
  3. //
  4. #ifndef _COMPRESSP_
  5. #define _COMPRESSP_
  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 Delay_len DefineDelayLineSize(8)
  15. class CDirectSoundCompressorDMO :
  16. public CDirectSoundDMO,
  17. public CParamsManager,
  18. public ISpecifyPropertyPages,
  19. public IDirectSoundFXCompressor,
  20. public CParamsManager::UpdateCallback,
  21. public CComBase
  22. {
  23. public:
  24. CDirectSoundCompressorDMO( IUnknown *pUnk, HRESULT *phr );
  25. ~CDirectSoundCompressorDMO();
  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. HRESULT Init();
  33. // Note that an Init function also exists in the CPCMDMO base class and it can be overridden
  34. // to provide initialization for the effect's actual audio processing.
  35. STDMETHOD(Clone) (THIS_ IMediaObjectInPlace **);
  36. /* IFilter */
  37. STDMETHOD(SetAllParameters) (THIS_ LPCDSFXCompressor);
  38. STDMETHOD(GetAllParameters) (THIS_ LPDSFXCompressor);
  39. // ISpecifyPropertyPages
  40. STDMETHOD(GetPages)(CAUUID * pPages) { return PropertyHelp::GetPages(CLSID_DirectSoundPropCompressor, 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, DSFXCompressor(), pStm); }
  46. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) { return PropertyHelp::Save(this, DSFXCompressor(), pStm, fClearDirty); }
  47. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) { if (!pcbSize) return E_POINTER; pcbSize->QuadPart = sizeof(DSFXCompressor); 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. HRESULT hr = CPCMDMO::CheckInputType(pmt);
  61. if (FAILED(hr)) return hr;
  62. WAVEFORMATEX *pWave = (WAVEFORMATEX*)pmt->pbFormat;
  63. if (pWave->wFormatTag != WAVE_FORMAT_PCM ||
  64. (pWave->wBitsPerSample != 8 && pWave->wBitsPerSample != 16) ||
  65. (pWave->nChannels != 1 && pWave->nChannels != 2)) {
  66. return DMO_E_TYPE_NOT_ACCEPTED;
  67. }
  68. return S_OK;
  69. }
  70. private:
  71. // { EAX
  72. __forceinline void DoOneSample(int *l, int *r);
  73. __forceinline void DoOneSampleMono(int *l);
  74. // Declare internal variables.
  75. #define DECLARE_EAX_VARS(type, var) \
  76. type m_Eax ## var;
  77. DECLARE_EAX_VARS(float, AttackCoef);
  78. DECLARE_EAX_VARS(float, ReleaseCoef);
  79. DECLARE_EAX_VARS(float, CompThresh);
  80. DECLARE_EAX_VARS(float, CompressionRatio);
  81. DECLARE_EAX_VARS(float, GainBiasIP);
  82. DECLARE_EAX_VARS(float, GainBiasFP);
  83. DECLARE_EAX_VARS(float, CompInputPeak);
  84. DECLARE_EAX_VARS(float, CompGainMin);
  85. DECLARE_EAX_VARS(long , LeftPoint);
  86. DECLARE_EAX_VARS(long , RightPoint);
  87. // DECLARE_EAX_VARS(SamplesPerSec);
  88. float m_Envelope;
  89. float m_CompGain;
  90. #define m_EaxSamplesPerSec m_ulSamplingRate
  91. __forceinline int Saturate(float f) {
  92. int i;
  93. #ifdef DONTUSEi386
  94. _asm {
  95. fld f
  96. fistp i
  97. }
  98. #else
  99. i = (int)f;
  100. #endif
  101. if (i > 32767)
  102. i = 32767;
  103. else if ( i < -32768)
  104. i = -32768;
  105. return(i);
  106. }
  107. __forceinline float Interpolate(float a, float b, float percent)
  108. {
  109. percent = a + (b - a) * percent;
  110. return(percent);
  111. }
  112. void Bump(void);
  113. DelayBuffer2<float, 200, 0> m_LeftDelay;
  114. DelayBuffer2<float, 200, 0> m_RightDelay;
  115. // } EAX
  116. };
  117. EXT_STD_CREATE(Compressor);
  118. #endif//