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.

426 lines
11 KiB

  1. #ifndef _DSDMO_H_
  2. #define _DSDMO_H_
  3. #include <mmsystem.h>
  4. #include <dsoundp.h> // For effect IID and ClassID declarations
  5. extern double LogNorm[32];
  6. extern float mylog( float finput, unsigned long maxexponent);
  7. extern DWORD g_amPlatform;
  8. extern long g_cComponent;
  9. extern HMODULE g_hModule;
  10. #define EXT_STD_CREATE(x) \
  11. extern HRESULT CreateCDirectSound ## x ## DMO(IUnknown **ppunk);
  12. #define EXT_STD_CAPTURE_CREATE(x) \
  13. extern HRESULT CreateCDirectSoundCapture ## x ## DMO(IUnknown **ppunk);
  14. // Exception warnings
  15. //
  16. #pragma warning(disable:4530)
  17. #define STD_CREATE(x) \
  18. HRESULT CreateCDirectSound ## x ## DMO(IUnknown **ppunk) \
  19. { \
  20. HRESULT hr = E_OUTOFMEMORY; \
  21. CDirectSound ## x ## DMO *p = NULL; \
  22. try { \
  23. p = new CDirectSound ## x ## DMO; \
  24. } catch (...) {}; \
  25. if (p) { \
  26. hr = p->InitOnCreation(); \
  27. if (FAILED(hr)) \
  28. { \
  29. p->Release(); \
  30. p = NULL; \
  31. } \
  32. } \
  33. *ppunk = static_cast<IPersist*>(p); \
  34. return hr; \
  35. }
  36. #define STD_CAPTURE_CREATE(x) \
  37. HRESULT CreateCDirectSoundCapture ## x ## DMO(IUnknown **ppunk) \
  38. { \
  39. HRESULT hr = E_OUTOFMEMORY; \
  40. CDirectSoundCapture ## x ## DMO *p = NULL; \
  41. try { \
  42. p = new CDirectSoundCapture ## x ## DMO; \
  43. } catch (...) {}; \
  44. if (p) { \
  45. hr = p->InitOnCreation(); \
  46. if (FAILED(hr)) \
  47. { \
  48. p->Release(); \
  49. p = NULL; \
  50. } \
  51. } \
  52. *ppunk = static_cast<IPersist*>(p); \
  53. return hr; \
  54. }
  55. // Common #define's and templates for all filters
  56. //
  57. #define MaxSamplesPerSec 96000
  58. #define PI 3.1415926535
  59. #define DefineMsecSize(y, x) ((int)(((x) * (y)) / 1000))
  60. #define DefineDelayLineSize(x) DefineMsecSize(MaxSamplesPerSec, x)
  61. //#define GetMsecPos(x) (DefineDelayLineSize(x))
  62. #define GetMsecPos(x) (DefineMsecSize(m_EaxSamplesPerSec, x))
  63. #define FractMask 0xfff
  64. #define FractMultiplier 0x1000
  65. template <int BufferSize> class DelayBuffer
  66. {
  67. int Buffer[BufferSize];
  68. int BufferPos;
  69. public:
  70. inline void Init(void)
  71. {
  72. BufferPos = 0;
  73. memset(Buffer, 0, sizeof(Buffer));
  74. }
  75. inline int Pos(int x)
  76. {
  77. x += BufferPos;
  78. while (x < 0)
  79. x += BufferSize * FractMultiplier;
  80. x /= FractMultiplier;
  81. while (x >= BufferSize)
  82. x -= BufferSize;
  83. return(x);
  84. }
  85. inline void Bump(void)
  86. {
  87. if (BufferPos == 0)
  88. BufferPos += BufferSize * FractMultiplier;
  89. if (BufferPos < 0)
  90. BufferPos += BufferSize * FractMultiplier;
  91. BufferPos -= FractMultiplier;
  92. }
  93. inline int& operator[] (int i)
  94. {
  95. return (Buffer[i]);
  96. }
  97. };
  98. template <class type, float Msec, int AdditionalPositions> class DelayBuffer2
  99. {
  100. union {
  101. type Buffer[DefineDelayLineSize(Msec) + AdditionalPositions];
  102. type BufferDisplay[DefineDelayLineSize(Msec/10) + AdditionalPositions];
  103. };
  104. int BufferPos;
  105. int BufferSize;
  106. public:
  107. inline void Init(int SamplesPerSec)
  108. {
  109. BufferPos = 0;
  110. BufferSize = DefineMsecSize(Msec, SamplesPerSec) + AdditionalPositions;
  111. memset(Buffer, 0, sizeof(Buffer));
  112. }
  113. inline int FractPos(int x)
  114. {
  115. x *= FractMultiplier;
  116. x += BufferPos;
  117. while (x < 0)
  118. x += BufferSize * FractMultiplier;
  119. x /= FractMultiplier;
  120. while (x >= BufferSize)
  121. x -= BufferSize;
  122. return(x);
  123. }
  124. inline int Pos(int x)
  125. {
  126. x += BufferPos;
  127. while (x < 0)
  128. x += BufferSize * FractMultiplier;
  129. x /= FractMultiplier;
  130. while (x >= BufferSize)
  131. x -= BufferSize;
  132. return(x);
  133. }
  134. inline int LastPos(int x)
  135. {
  136. x = Pos(x + BufferSize - 1);
  137. return(x);
  138. }
  139. inline void Bump(void)
  140. {
  141. if (BufferPos == 0)
  142. BufferPos += BufferSize * FractMultiplier;
  143. if (BufferPos < 0)
  144. BufferPos += BufferSize * FractMultiplier;
  145. BufferPos -= FractMultiplier;
  146. }
  147. inline type& operator[] (int i)
  148. {
  149. return (Buffer[i]);
  150. }
  151. };
  152. //
  153. //
  154. //
  155. // { EAX
  156. #ifndef _EAXDMO_
  157. #define _EAXDMO_
  158. #define CHECK_PARAM(lo, hi) \
  159. if (value < lo || value > hi) {return DSERR_INVALIDPARAM;} else;
  160. #define PUT_EAX_VALUE(var, val) \
  161. m_Eax ## var = val
  162. #define PUT_EAX_FVAL(var, val) \
  163. m_Eax ## var = (float)(val)
  164. #define PUT_EAX_LVAL(var, val) \
  165. m_Eax ## var = (long)(val)
  166. #define TOFRACTION(x) ((float)x)
  167. #define INTERPOLATE(x, y) PUT_EAX_FVAL(x, (y)) // ??? Smooth it out...
  168. #define SET_MPV_FLOAT(var) \
  169. MP_DATA mpv; \
  170. mpv = (MP_DATA)var;
  171. #define SET_MPV_LONG SET_MPV_FLOAT
  172. enum ChorusFilterParams
  173. {
  174. CFP_Wetdrymix = 0,
  175. CFP_Depth,
  176. CFP_Frequency,
  177. CFP_Waveform,
  178. CFP_Phase,
  179. CFP_Feedback,
  180. CFP_Delay,
  181. CFP_MAX
  182. };
  183. enum CompressorFilterParams
  184. {
  185. CPFP_Gain = 0,
  186. CPFP_Attack,
  187. CPFP_Release,
  188. CPFP_Threshold,
  189. CPFP_Ratio,
  190. CPFP_Predelay,
  191. CPFP_CompMeterReset,
  192. CPFP_CompInputMeter,
  193. CPFP_CompGainMeter,
  194. CPFP_MAX
  195. };
  196. enum DistortionFilterParams
  197. {
  198. DFP_Gain = 0,
  199. DFP_Edge,
  200. DFP_LpCutoff,
  201. DFP_EqCenter,
  202. DFP_EqWidth,
  203. DFP_MAX
  204. };
  205. enum EchoFilterParams
  206. {
  207. EFP_Wetdrymix = 0,
  208. EFP_Feedback,
  209. EFP_DelayLeft,
  210. EFP_DelayRight,
  211. EFP_PanDelay,
  212. EFP_MAX
  213. };
  214. enum FilterParams
  215. {
  216. FFP_Wetdrymix = 0,
  217. FFP_Waveform,
  218. FFP_Frequency,
  219. FFP_Depth,
  220. FFP_Phase,
  221. FFP_Feedback,
  222. FFP_Delay,
  223. FFP_MAX
  224. };
  225. enum ParamEqFilterParams
  226. {
  227. PFP_Center = 0,
  228. PFP_Bandwidth,
  229. PFP_Gain,
  230. PFP_MAX
  231. };
  232. enum GargleFilterParams
  233. {
  234. GFP_Rate = 0,
  235. GFP_Shape,
  236. GFP_MAX
  237. };
  238. enum SVerbParams
  239. {
  240. SVP_Gain = 0,
  241. SVP_Mix,
  242. SVP_ReverbTime,
  243. SVP_Ratio,
  244. SVP_MAX
  245. };
  246. enum AecParams
  247. {
  248. AECP_Enable = 0,
  249. AECP_MAX
  250. };
  251. enum NoiseSuppressParams
  252. {
  253. NSP_Enable = 0,
  254. NSP_MAX
  255. };
  256. enum AgcParams
  257. {
  258. AGCP_Enable = 0,
  259. AGCP_MAX
  260. };
  261. #define GET_PUT(x, type) \
  262. STDMETHOD(get_Eax ## x) \
  263. ( THIS_ \
  264. type *Eax ## x \
  265. ) PURE; \
  266. STDMETHOD(put_Eax ## x) \
  267. ( THIS_ \
  268. type Eax ## x \
  269. ) PURE
  270. interface IChorus : public IUnknown
  271. {
  272. public:
  273. GET_PUT(Wetdrymix, float);
  274. GET_PUT(Depth, float);
  275. GET_PUT(Frequency, float);
  276. GET_PUT(Waveform, long);
  277. GET_PUT(Phase, long);
  278. GET_PUT(Feedback, float);
  279. GET_PUT(Delay, float);
  280. };
  281. interface ICompressor : public IUnknown
  282. {
  283. public:
  284. GET_PUT(Gain, float);
  285. GET_PUT(Attack, float);
  286. GET_PUT(Release, float);
  287. GET_PUT(Threshold, float);
  288. GET_PUT(Ratio, float);
  289. GET_PUT(Predelay, float);
  290. GET_PUT(CompMeterReset, float);
  291. GET_PUT(CompInputMeter, float);
  292. GET_PUT(CompGainMeter, float);
  293. };
  294. interface IDistortion : public IUnknown
  295. {
  296. public:
  297. GET_PUT(Gain, float);
  298. GET_PUT(Edge, float);
  299. GET_PUT(LpCutoff, float);
  300. GET_PUT(EqCenter, float);
  301. GET_PUT(EqWidth, float);
  302. };
  303. interface IEcho : public IUnknown
  304. {
  305. public:
  306. GET_PUT(Wetdrymix, float);
  307. GET_PUT(Feedback, float);
  308. GET_PUT(DelayLeft, float);
  309. GET_PUT(DelayRight, float);
  310. GET_PUT(PanDelay, long);
  311. };
  312. interface IFlanger : public IUnknown
  313. {
  314. public:
  315. GET_PUT(Wetdrymix, float);
  316. GET_PUT(Waveform, long);
  317. GET_PUT(Frequency, float);
  318. GET_PUT(Depth, float);
  319. GET_PUT(Phase, long);
  320. GET_PUT(Feedback, float);
  321. GET_PUT(Delay, float);
  322. };
  323. interface IParamEq : public IUnknown
  324. {
  325. public:
  326. GET_PUT(Center, float);
  327. GET_PUT(Bandwidth, float);
  328. GET_PUT(Gain, float);
  329. };
  330. #undef GET_PUT
  331. #if 0
  332. // Replaced these with the GUIDs from dsound.x; e.g. for chorus, the interface
  333. // ID is IID_IDirectSoundFXChorus and the ClassId is GUID_DSFX_STANDARD_CHORUS.
  334. DEFINE_GUID(IID_IChorus, 0x514b6fb2,0x0611,0x4714,0x80,0x02,0x0e,0x06,0x29,0x92,0x7d,0x8e);
  335. DEFINE_GUID(IID_ICompressor, 0x514b6fc0,0x0611,0x4714,0x80,0x02,0x0e,0x06,0x29,0x92,0x7d,0x8e);
  336. DEFINE_GUID(IID_IDistortion, 0x514b6fb8,0x0611,0x4714,0x80,0x02,0x0e,0x06,0x29,0x92,0x7d,0x8e);
  337. DEFINE_GUID(IID_IEcho,0x514b6fb3,0x0611,0x4714,0x80,0x02,0x0e,0x06,0x29,0x92,0x7d,0x8e);
  338. DEFINE_GUID(IID_IFlanger,0x514b6fb4,0x0611,0x4714,0x80,0x02,0x0e,0x06,0x29,0x92,0x7d,0x8e);
  339. DEFINE_GUID(IID_IParamEq,0x514b6fb7,0x0611,0x4714,0x80,0x02,0x0e,0x06,0x29,0x92,0x7d,0x8e);
  340. DEFINE_GUID(CLSID_DirectSoundChorusDMO, 0x120ced86,0x3bf4,0x4173,0xa1,0x32,0x3c,0xb4,0x06,0xcf,0x32,0x31);
  341. DEFINE_GUID(CLSID_DirectSoundCompressorDMO,0x120ced92,0x3bf4,0x4173,0xa1,0x32,0x3c,0xb4,0x06,0xcf,0x32,0x31);
  342. DEFINE_GUID(CLSID_DirectSoundDistortionDMO,0x120ced90,0x3bf4,0x4173,0xa1,0x32,0x3c,0xb4,0x06,0xcf,0x32,0x31);
  343. DEFINE_GUID(CLSID_DirectSoundEchoDMO,0x120ced87,0x3bf4,0x4173,0xa1,0x32,0x3c,0xb4,0x06,0xcf,0x32,0x31);
  344. DEFINE_GUID(CLSID_DirectSoundFlangerDMO,0x120ced88,0x3bf4,0x4173,0xa1,0x32,0x3c,0xb4,0x06,0xcf,0x32,0x31);
  345. DEFINE_GUID(CLSID_DirectSoundParamEqDMO,0x120ced89,0x3bf4,0x4173,0xa1,0x32,0x3c,0xb4,0x06,0xcf,0x32,0x31);
  346. #endif
  347. DEFINE_GUID(IID_IGargle, 0xd616f352, 0xd622, 0x11ce, 0xaa, 0xc5, 0x00, 0x20, 0xaf, 0x0b, 0x99, 0xa3);
  348. DEFINE_GUID(CLSID_GargleDMO, 0xdafd8210,0x5711,0x4b91,0x9f,0xe3,0xf7,0x5b,0x7a,0xe2,0x79,0xbf);
  349. DEFINE_GUID(CLSID_DirectSoundPropGargle,0x794885CC,0x5EB7,0x46E3,0xA9,0x37,0xAD,0x89,0x0A,0x6C,0x66,0x77);
  350. DEFINE_GUID(CLSID_DirectSoundPropChorus,0x60129CFD,0x2E9B,0x4098,0xAA,0x4B,0xD6,0xCF,0xAD,0xA2,0x65,0xC3);
  351. DEFINE_GUID(CLSID_DirectSoundPropFlanger,0x22AF00DF,0x46B4,0x4F51,0xA3,0x63,0x68,0x54,0xD5,0x2E,0x13,0xA0);
  352. DEFINE_GUID(CLSID_DirectSoundPropDistortion,0x5858107D,0x11EA,0x47B1,0x96,0x94,0x3F,0x29,0xF7,0x68,0x0F,0xB8);
  353. DEFINE_GUID(CLSID_DirectSoundPropEcho,0xD45CF2C7,0x48CF,0x4234,0x86,0xE2,0x45,0x59,0xC3,0x2F,0xAD,0x1A);
  354. DEFINE_GUID(CLSID_DirectSoundPropCompressor,0xED3DC730,0x31E5,0x4108,0xAD,0x8A,0x39,0x62,0xC9,0x30,0x42,0x5E);
  355. DEFINE_GUID(CLSID_DirectSoundPropParamEq,0xAE86C36D,0x808E,0x4B07,0xB7,0x99,0x56,0xD7,0x36,0x1C,0x38,0x35);
  356. DEFINE_GUID(CLSID_DirectSoundPropWavesReverb,0x6A879859,0x3858,0x4322,0x97,0x1A,0xB7,0x05,0xF3,0x49,0xF1,0x24);
  357. DEFINE_GUID(CLSID_DirectSoundPropI3DL2Reverb,0xD3952B77,0x2D22,0x4B72,0x8D,0xF4,0xBA,0x26,0x7A,0x9C,0x12,0xD0);
  358. DEFINE_GUID(CLSID_DirectSoundPropI3DL2Source,0x3DC26D0C,0xBEFF,0x406C,0x89,0xB0,0xCA,0x13,0xE2,0xBD,0x91,0x72);
  359. // } EAX
  360. #endif
  361. #endif // _DSDMO_H_