AudioPlugIn.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // AudioPlugIn.cpp: implementation of the CAudioPlugIn class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "AudioPlugIn.h"
  6. // Note: see AudioPlugIn.h to redefine PROCESS_IN_PLACE
  7. #if PROCESS_IN_PLACE
  8. #pragma message("***** Compiling an IN-PLACE audio plug-in *****")
  9. #else
  10. #pragma message("***** Compiling an NON-IN-PLACE audio plug-in *****")
  11. #endif
  12. #include "resource.h"
  13. #include <commctrl.h>
  14. char g_path[MAX_PATH];
  15. #define SPS_CONFIGDLG_IMPL
  16. #define SPS_CONFIGDLG_ON_WM_CLOSE { ShowWindow(hwndDlg,SW_HIDE); /*g_config.visible=0;*/ }
  17. //#define SPS_CONFIGDLG_HIDEABLE_EDITOR 0
  18. #include "../sps_common.h"
  19. #include "../sps_configdlg.h"
  20. //////////////////////////////////////////////////////////////////////
  21. // Ctors
  22. CAudioPlugIn::CAudioPlugIn( HRESULT* phr )
  23. {
  24. // TODO: put all initialization code in Initialize(), below.
  25. }
  26. CAudioPlugIn::~CAudioPlugIn()
  27. {
  28. SPS_quitapp();
  29. }
  30. ////////////////////////////////////////////////////////////////////////////////
  31. HRESULT CAudioPlugIn::Initialize()
  32. {
  33. SPS_initapp();
  34. strcpy(g_path,"c:\\progra~1\\winamp\\plugins\\dsp_sps"); //FUCKO
  35. return S_OK;
  36. }
  37. ////////////////////////////////////////////////////////////////////////////////
  38. HRESULT CAudioPlugIn::IsValidInputFormat( const WAVEFORMATEX* pwfx ) const
  39. {
  40. // The plug-in base class will have already validated pwfx to ensure that
  41. // it is 16-bit PCM or 32-bit float, 1 or 2 channels.
  42. // TODO: Add any additional checks here, such as sample rate, etc.
  43. // By default, only 32-bit float buffers are supported.
  44. if (WAVE_FORMAT_IEEE_FLOAT != pwfx->wFormatTag)
  45. return VFW_E_TYPE_NOT_ACCEPTED;
  46. return S_OK;
  47. }
  48. ////////////////////////////////////////////////////////////////////////////////
  49. HRESULT CAudioPlugIn::IsValidOutputFormat( const WAVEFORMATEX* pwfx ) const
  50. {
  51. // The plug-in base class will have already validated pwfx to ensure that
  52. // it is 16-bit PCM or 32-bit float, 1 or 2 channels.
  53. // TODO: Add any additional checks here, such as sample rate, etc.
  54. // By default, only 32-bit float buffers are supported.
  55. if (WAVE_FORMAT_IEEE_FLOAT != pwfx->wFormatTag)
  56. return VFW_E_TYPE_NOT_ACCEPTED;
  57. return S_OK;
  58. }
  59. ////////////////////////////////////////////////////////////////////////////////
  60. HRESULT CAudioPlugIn::IsValidTransform( const WAVEFORMATEX* pwfxIn, const WAVEFORMATEX* pwfxOut ) const
  61. {
  62. // The plug-in base class will have already validated pwfxIn/pwfxOut to ensure that
  63. // it is 16-bit PCM or 32-bit float, 1 or 2 channels, and that both have the same
  64. // sample rate.
  65. // TODO: Add any additional checks here, such as sample rate, etc.
  66. // By default, only 32-bit float buffers are supported.
  67. if (WAVE_FORMAT_IEEE_FLOAT != pwfxIn->wFormatTag)
  68. return VFW_E_TYPE_NOT_ACCEPTED;
  69. if (WAVE_FORMAT_IEEE_FLOAT != pwfxOut->wFormatTag)
  70. return VFW_E_TYPE_NOT_ACCEPTED;
  71. return S_OK;
  72. }
  73. ////////////////////////////////////////////////////////////////////////////////
  74. HRESULT CAudioPlugIn::SuggestOutputFormat( WAVEFORMATEX* pwfx ) const
  75. {
  76. // The plug-in base class will have already validated pwfx to ensure that
  77. // it is 16-bit PCM or 32-bit float, 1 or 2 channels, and that both have the same
  78. // sample rate.
  79. // TODO: Add any additional checks here, such as sample rate, etc.
  80. // pwfx is initially set to the input format. If your plug-in doesn't need
  81. // to change the output format, simply return S_OK.
  82. // TODO: change pwfx if necessary.
  83. return S_OK;
  84. }
  85. ////////////////////////////////////////////////////////////////////////////////
  86. HRESULT CAudioPlugIn::Process( LONGLONG llSampAudioTimestamp,
  87. AudioBuffer* pbufIn,
  88. AudioBuffer* pbufOut )
  89. {
  90. BOOL const bGenerateTail = (NULL == pbufIn);
  91. BOOL const bIsInPlace = (pbufIn == pbufOut);
  92. // Note about deferred zero filling:
  93. //
  94. // AudioBuffer will automatically take advantage of IDeferZeroFill,
  95. // if the host app supports it. To avoid unnecessary and wasteful buffer
  96. // fills, always check the 'bZero' flag in AudioBuffer before calling
  97. // the GetPointer() method. This is because calling GetPointer() will
  98. // trigger a zero-fill if the underlying data buffer was marked as "defer
  99. // zero fill."
  100. //
  101. // Similarly, to allow downstream filters to benefit from deferred
  102. // zero filling, be sure to set the 'bZero' flag in an AudioBuffer, if
  103. // your DSP code is producing a completely silent buffer.
  104. if (bGenerateTail)
  105. {
  106. // TODO: Add code to generate a tail if required by your plug-in.
  107. // Return S_OK if more effect tail data remains. Return S_FALSE
  108. // if no more tail data remains.
  109. // Default implementation generates no tail
  110. return S_FALSE;
  111. }
  112. // TODO: Put your DSP code here
  113. float *in=pbufIn->GetPointer();
  114. float *out=pbufOut->GetPointer();
  115. int of=(int)pbufIn->lOffset;
  116. int size=(int)pbufIn->pms->GetSize();
  117. int nbsamp=size/sizeof(float);
  118. /* // If we're bypassed, copy input to output without processing
  119. float fEnabled = GetParamValue( PARAM_ENABLE );
  120. if (fEnabled < 0.5f)
  121. {
  122. memcpy (out, in, pbufIn->cSamp * m_wfxIn.nBlockAlign );
  123. return S_OK;
  124. }*/
  125. const WAVEFORMATEX *inpformat=GetInputFormat();
  126. int nch=inpformat->nChannels;
  127. int srate=inpformat->nSamplesPerSec;
  128. if(0)
  129. {
  130. char tmp[512];
  131. int size2=(int)pbufOut->pms->GetSize();
  132. wsprintf(tmp,"%d %d %d %d %d %d\n",of,size,size2,nbsamp,nch,srate);
  133. OutputDebugString(tmp);
  134. }
  135. memcpy(out,in,size);
  136. extern SPSEffectContext *g_fucko_ctx;
  137. SPS_process_samples(g_fucko_ctx,
  138. (void *)out, nbsamp/nch, 1, 32, nch, srate,
  139. nbsamp, nbsamp);
  140. return S_OK;
  141. }
  142. ////////////////////////////////////////////////////////////////////////////////
  143. HRESULT CAudioPlugIn::AllocateResources()
  144. {
  145. // TODO: add code to here to prepare the for the start of streaming
  146. return S_OK;
  147. }
  148. ////////////////////////////////////////////////////////////////////////////////
  149. HRESULT CAudioPlugIn::FreeResources()
  150. {
  151. // TODO: add code to here to clean up after streaming
  152. return S_OK;
  153. }
  154. ////////////////////////////////////////////////////////////////////////////////
  155. int CAudioPlugIn::PersistGetSize() const
  156. {
  157. int const cb
  158. = sizeof(DWORD) // # of persisted parameters
  159. + NUM_PARAMS * (sizeof(DWORD) + sizeof(float)); // (index,value), for each parameter
  160. return cb;
  161. }
  162. ////////////////////////////////////////////////////////////////////////////////
  163. HRESULT CAudioPlugIn::PersistLoad( IStream* pStream )
  164. {
  165. ULONG cb = 0;
  166. HRESULT hr = S_OK;
  167. // Get the number of persisted parameters
  168. DWORD cParams = 0;
  169. hr = pStream->Read( &cParams, sizeof(cParams), &cb );
  170. if (FAILED( hr ) || cb != sizeof(cParams))
  171. return E_FAIL;
  172. // Restore each parameter
  173. for (DWORD ix = 0; ix < cParams; ix++)
  174. {
  175. // Get the parameter index
  176. DWORD dwParam = 0;
  177. hr = pStream->Read( &dwParam, sizeof(dwParam), &cb );
  178. if (FAILED( hr ) || cb != sizeof(dwParam))
  179. return E_FAIL;
  180. // Get the parameter value
  181. float fValue = 0;
  182. hr = pStream->Read( &fValue, sizeof(fValue), &cb );
  183. if (FAILED( hr ) || cb != sizeof(fValue))
  184. return E_FAIL;
  185. // Set the parameter value
  186. if (m_pMediaParams)
  187. m_pMediaParams->SetParam( dwParam, fValue );
  188. }
  189. return S_OK;
  190. }
  191. ////////////////////////////////////////////////////////////////////////////////
  192. HRESULT CAudioPlugIn::PersistSave( IStream* pStream )
  193. {
  194. ULONG cb = 0;
  195. HRESULT hr = S_OK;
  196. // Put the number of persisted parameters
  197. DWORD cParams = NUM_PARAMS;
  198. hr = pStream->Write( &cParams, sizeof(cParams), &cb );
  199. if (FAILED( hr ) || cb != sizeof(cParams))
  200. return E_FAIL;
  201. // Save each parameter
  202. for (DWORD dwParam = 0; dwParam < cParams; dwParam++)
  203. {
  204. float fValue = 0;
  205. // Get the parameter value
  206. if (m_pMediaParams)
  207. m_pMediaParams->GetParam( dwParam, &fValue );
  208. // Write the parameter index
  209. hr = pStream->Write( &dwParam, sizeof(dwParam), &cb );
  210. if (FAILED( hr ) || cb != sizeof(dwParam))
  211. return E_FAIL;
  212. // Write the parameter value
  213. hr = pStream->Write( &fValue, sizeof(fValue), &cb );
  214. if (FAILED( hr ) || cb != sizeof(fValue))
  215. return E_FAIL;
  216. }
  217. return S_OK;
  218. }