Leaked source code of windows server 2003
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.

969 lines
30 KiB

  1. /*******************************************************************************
  2. * ReverbFX.cpp *
  3. *-------------*
  4. * Description:
  5. * This module is the implementation file for the CReverbFX class.
  6. *-------------------------------------------------------------------------------
  7. * Created By: mc Date: 03/12/99
  8. * Copyright (C) 1999 Microsoft Corporation
  9. * All Rights Reserved
  10. *
  11. *******************************************************************************/
  12. #include "stdafx.h"
  13. #ifndef __spttseng_h__
  14. #include "spttseng.h"
  15. #endif
  16. #ifndef SPDebug_h
  17. #include <spdebug.h>
  18. #endif
  19. #ifndef ReverbFX_H
  20. #include "ReverbFX.h"
  21. #endif
  22. /*****************************************************************************
  23. * CReverbFX::DecibelToPercent *
  24. *-----------------------------*
  25. * Description:
  26. * Converts Voltage percentage from dB
  27. * v = 10^(dB/20)
  28. *
  29. ********************************************************************** MC ***/
  30. REVERBL CReverbFX::DecibelToPercent( float flDecibel )
  31. {
  32. SPDBG_FUNC( "CReverbFX::DecibelToPercent" );
  33. float fltIntVol;
  34. if( flDecibel >= REVERB_MIN_DB )
  35. {
  36. fltIntVol = (float) pow( 10.0, (double)flDecibel / 20.0 );
  37. }
  38. else
  39. {
  40. fltIntVol = 0.0;
  41. }
  42. #ifdef FLOAT_REVERB
  43. return fltIntVol;
  44. #else
  45. fltIntVol = fltIntVol * REVERB_VOL_LEVELS;
  46. return (REVERBL)fltIntVol;
  47. #endif
  48. } /* CReverbFX::DecibelToPercent */
  49. /*****************************************************************************
  50. * CReverbFX::ClearReverb *
  51. *------------------------*
  52. * Description:
  53. * Fills the delay line with silence.
  54. *
  55. ********************************************************************** MC ***/
  56. void CReverbFX::ClearReverb( LP_Reverb_Mod mod )
  57. {
  58. SPDBG_FUNC( "CReverbFX::ClearReverb" );
  59. long i;
  60. REVERBT *dPtr;
  61. dPtr = mod->psDelayBuffer;
  62. for( i = 0; i < mod->dwDelayBufferSize; i++ )
  63. {
  64. *dPtr++ = 0;
  65. }
  66. } /* CReverbFX::ClearReverb */
  67. /*****************************************************************************
  68. * CReverbFX::AllocReverbModule *
  69. *------------------------------*
  70. * Description:
  71. *
  72. ********************************************************************** MC ***/
  73. short CReverbFX::AllocReverbModule
  74. (
  75. LP_Reverb_Mod mod,
  76. REVERBL lGain, // Gain of the amplifiers.
  77. long dwDelay, // Length of the delay line.
  78. long dwDelayBufferSize // Size of the delay buffer.
  79. )
  80. {
  81. SPDBG_FUNC( "CReverbFX::AllocReverbModule" );
  82. short result;
  83. result = KREVERB_NOERROR;
  84. mod->lGain = lGain;
  85. mod->dwDelay = dwDelay;
  86. mod->dwDelayBufferSize = dwDelayBufferSize;
  87. mod->psDelayBuffer = new REVERBT[mod->dwDelayBufferSize];
  88. if( mod->psDelayBuffer == NULL )
  89. {
  90. result = KREVERB_MEMERROR;
  91. }
  92. else
  93. {
  94. mod->psDelayEnd = mod->psDelayBuffer + mod->dwDelayBufferSize;
  95. mod->psDelayOut = mod->psDelayBuffer;
  96. if( mod->dwDelayBufferSize == mod->dwDelay )
  97. {
  98. mod->psDelayIn = mod->psDelayBuffer;
  99. }
  100. else
  101. {
  102. mod->psDelayIn = mod->psDelayBuffer + mod->dwDelay;
  103. }
  104. ClearReverb( mod );
  105. }
  106. return result;
  107. } /* CReverbFX::AllocReverbModule */
  108. /*****************************************************************************
  109. * CReverbFX::CreateReverbModules *
  110. *--------------------------------*
  111. * Description:
  112. * Creates an array of reverb modules.
  113. *
  114. ********************************************************************** MC ***/
  115. short CReverbFX::CreateReverbModules
  116. (
  117. short wModules, // Number of modules to create.
  118. LP_Reverb_Mod *mods,
  119. float * pfltDelay, // Array of delay values for the modules.
  120. float * pfltDB, // Array of gain values for the modules.
  121. float fltSamplesPerMS // Number of samples per millisecond.
  122. )
  123. {
  124. SPDBG_FUNC( "CReverbFX::CreateReverbModules" );
  125. long dwDelay, i;
  126. float tempF;
  127. REVERBL vol;
  128. short result = KREVERB_NOERROR;
  129. if( wModules > 0 )
  130. {
  131. for( i = 0; i < wModules; i++ )
  132. {
  133. mods[i] = new Reverb_Mod;
  134. if( !mods[i] )
  135. {
  136. //---------------------------------------
  137. // Not enough memory
  138. //---------------------------------------
  139. result = KREVERB_MEMERROR;
  140. break;
  141. }
  142. else
  143. {
  144. tempF = *pfltDelay++ * fltSamplesPerMS;
  145. dwDelay = (long) tempF;
  146. if( dwDelay < 2 )
  147. dwDelay = 2; // @@@@
  148. vol = DecibelToPercent( *pfltDB++ );
  149. result = AllocReverbModule( mods[i], vol, dwDelay, dwDelay );
  150. if( result != KREVERB_NOERROR )
  151. break;
  152. }
  153. }
  154. }
  155. return result;
  156. } /* CReverbFX::CreateReverbModules */
  157. /*****************************************************************************
  158. * CReverbFX::DeleteReverbModules *
  159. *--------------------------------*
  160. * Description:
  161. * Deletes an array of reverb modules.
  162. *
  163. ********************************************************************** MC ***/
  164. void CReverbFX::DeleteReverbModules( )
  165. {
  166. SPDBG_FUNC( "CReverbFX::DeleteReverbModules" );
  167. long i;
  168. for( i = 0; i < KMAXREVBMODS; i++ )
  169. {
  170. if( m_Reverb_Mods[i] != NULL )
  171. {
  172. if( m_Reverb_Mods[i]->psDelayBuffer != NULL )
  173. {
  174. delete m_Reverb_Mods[i]->psDelayBuffer;
  175. }
  176. delete m_Reverb_Mods[i];
  177. m_Reverb_Mods[i] = NULL;
  178. }
  179. }
  180. if( m_pWorkBuf != NULL )
  181. {
  182. delete m_pWorkBuf;
  183. m_pWorkBuf = NULL;
  184. }
  185. } /* CReverbFX::DeleteReverbModules */
  186. /*****************************************************************************
  187. * CReverbFX::GetReverbConfig *
  188. *----------------------------*
  189. * Description:
  190. *
  191. ********************************************************************** MC ***/
  192. LPREVERBCONFIG CReverbFX::GetReverbConfig( REVERBTYPE dwReverbConfig )
  193. {
  194. SPDBG_FUNC( "CReverbFX::GetReverbConfig" );
  195. LPREVERBCONFIG pReverbConfig = NULL;
  196. switch( dwReverbConfig )
  197. {
  198. //-----------------------------
  199. // Hall
  200. //-----------------------------
  201. case REVERB_TYPE_HALL:
  202. {
  203. static float afltLeftDelay[] = { (float)(float)(30.6), (float)(20.83), (float)(14.85), (float)(10.98) };
  204. static float afltLeftGain[] = { (float)(-2.498), (float)(-2.2533), (float)(-2.7551), (float)(-2.5828) };
  205. static REVERBCONFIG reverbConfig =
  206. {
  207. (-17.0), // Wet
  208. (-2.0), // Dry
  209. 4,
  210. afltLeftDelay,
  211. afltLeftGain,
  212. (float)0.0,
  213. };
  214. pReverbConfig = &reverbConfig;
  215. }
  216. break;
  217. //-----------------------------
  218. // Stadium
  219. //-----------------------------
  220. case REVERB_TYPE_STADIUM:
  221. {
  222. static float afltLeftDelay[] = { (float)(40.6*4), (float)(27.65*4), (float)(17.85*4), (float)(10.98*4) };
  223. static float afltLeftGain[] = { (float)(-2.498), (float)(-2.2533), (float)(-2.7551), (float)(-2.5828) };
  224. static REVERBCONFIG reverbConfig =
  225. {
  226. (-3.0), // Wet
  227. (-5.0), // Dry
  228. 4,
  229. afltLeftDelay,
  230. afltLeftGain,
  231. (float)0.0,
  232. };
  233. pReverbConfig = &reverbConfig;
  234. }
  235. break;
  236. //-----------------------------
  237. // Church
  238. //-----------------------------
  239. case REVERB_TYPE_CHURCH:
  240. {
  241. static float afltLeftDelay[] = { (float)(40.6*2), (float)(27.65*2), (float)(17.85*2), (float)(10.98*2) };
  242. static float afltLeftGain[] = { (float)(-2.498), (float)(-2.2533), (float)(-2.7551), (float)(-2.5828) };
  243. static REVERBCONFIG reverbConfig =
  244. {
  245. (-5.0), // Wet
  246. (-5.0), // Dry
  247. 4,
  248. afltLeftDelay,
  249. afltLeftGain,
  250. (float)0.0,
  251. };
  252. pReverbConfig = &reverbConfig;
  253. }
  254. break;
  255. //-----------------------------
  256. // Bathtub
  257. //-----------------------------
  258. case REVERB_TYPE_BATHTUB:
  259. {
  260. static float afltLeftDelay[] = { (float)(10.0) };
  261. static float afltLeftGain[] = { (float)(-0.5) };
  262. static REVERBCONFIG reverbConfig =
  263. {
  264. (7.0), // Wet
  265. (9.0), // Dry
  266. 1,
  267. afltLeftDelay,
  268. afltLeftGain,
  269. (float)0.0,
  270. };
  271. pReverbConfig = &reverbConfig;
  272. }
  273. break;
  274. //-----------------------------
  275. // Room
  276. //-----------------------------
  277. case REVERB_TYPE_ROOM:
  278. {
  279. static float afltLeftDelay[] = { (float)(10.6) };
  280. static float afltLeftGain[] = { (float)(-10.498) };
  281. static REVERBCONFIG reverbConfig =
  282. {
  283. (0.0), // Wet
  284. (0.0), // Dry
  285. 1,
  286. afltLeftDelay,
  287. afltLeftGain,
  288. (float)0.0,
  289. };
  290. pReverbConfig = &reverbConfig;
  291. }
  292. break;
  293. //-----------------------------
  294. // Echo
  295. //-----------------------------
  296. case REVERB_TYPE_ECHO:
  297. {
  298. static float afltLeftDelay[] = { (float)(400.6) };
  299. static float afltLeftGain[] = { (float)(-10.498) };
  300. static REVERBCONFIG reverbConfig =
  301. {
  302. (-10.0), // Wet
  303. (0.0), // Dry
  304. 1,
  305. afltLeftDelay,
  306. afltLeftGain,
  307. (float)0.0,
  308. };
  309. pReverbConfig = &reverbConfig;
  310. }
  311. break;
  312. //-----------------------------
  313. // Sequencer
  314. //-----------------------------
  315. case REVERB_TYPE_ROBOSEQ:
  316. {
  317. static float afltLeftDelay[] = { (float)(10.0) };
  318. static float afltLeftGain[] = { (float)(-0.5) };
  319. static REVERBCONFIG reverbConfig =
  320. {
  321. (6.5), // Wet
  322. (9.0), // Dry
  323. 1,
  324. afltLeftDelay,
  325. afltLeftGain,
  326. (float)0.05,
  327. };
  328. pReverbConfig = &reverbConfig;
  329. }
  330. break;
  331. }
  332. return pReverbConfig;
  333. } /* CReverbFX::GetReverbConfig */
  334. /*****************************************************************************
  335. * CReverbFX::Reverb_Init *
  336. *------------------------*
  337. * Description:
  338. * Initialize a reverberator array.
  339. *
  340. ********************************************************************** MC ***/
  341. short CReverbFX::Reverb_Init( REVERBTYPE reverbPreset, long nSamplesPerSec, long stereoOut )
  342. {
  343. SPDBG_FUNC( "CReverbFX::Reverb_Init" );
  344. short result = KREVERB_NOERROR;
  345. float fltSamplesPerMS;
  346. m_StereoOut = stereoOut;
  347. if( reverbPreset > REVERB_TYPE_OFF )
  348. {
  349. //----------------------------------------------
  350. // Get params from preset number
  351. //----------------------------------------------
  352. m_pReverbConfig = GetReverbConfig( reverbPreset );
  353. m_numOfMods = m_pReverbConfig->numOfReflect;
  354. //----------------------------------------------
  355. // Convert dB's to linear gain
  356. //----------------------------------------------
  357. m_wetVolGain = DecibelToPercent( m_pReverbConfig->wetGain_dB );
  358. m_dryVolGain = DecibelToPercent( m_pReverbConfig->dryGain_dB );
  359. fltSamplesPerMS = (float)nSamplesPerSec / (float)1000.0;
  360. result = CreateReverbModules
  361. (
  362. (short)m_numOfMods,
  363. (LP_Reverb_Mod*)&m_Reverb_Mods,
  364. m_pReverbConfig->gain_ms_Array,
  365. m_pReverbConfig->gain_dB_Array,
  366. fltSamplesPerMS
  367. );
  368. if( result != KREVERB_NOERROR )
  369. {
  370. //--------------------------------
  371. // Failure! Not enough memory
  372. //--------------------------------
  373. return result;
  374. }
  375. if( m_pWorkBuf == NULL )
  376. {
  377. m_pWorkBuf = new REVERBT[m_dwWorkBufferSize];
  378. if( m_pWorkBuf == NULL )
  379. {
  380. //--------------------------------
  381. // Failure! Not enough memory
  382. //--------------------------------
  383. result = KREVERB_MEMERROR;
  384. return result;
  385. }
  386. }
  387. }
  388. else
  389. {
  390. DeleteReverbModules( );
  391. result = KREVERB_OFF;
  392. }
  393. return result;
  394. } /* CReverbFX::Reverb_Init */
  395. /*****************************************************************************
  396. * CReverbFX::CReverbFX *
  397. *----------------------*
  398. * Description:
  399. *
  400. ********************************************************************** MC ***/
  401. CReverbFX::CReverbFX( void )
  402. {
  403. SPDBG_FUNC( "CReverbFX::CReverbFX" );
  404. long i;
  405. //--------------------------------
  406. // Initilize
  407. //--------------------------------
  408. m_dwWorkBufferSize = KWORKBUFLEN;
  409. m_pWorkBuf = NULL;
  410. m_wetVolGain = 0;
  411. m_dryVolGain = 0;
  412. m_numOfMods = 0;
  413. m_Count = 0;
  414. m_StereoOut = false;
  415. for( i = 0; i < KMAXREVBMODS; i++ )
  416. {
  417. m_Reverb_Mods[i] = NULL;
  418. }
  419. } /* CReverbFX::CReverbFX */
  420. /*****************************************************************************
  421. * CReverbFX::~CReverbFX *
  422. *-----------------------*
  423. * Description:
  424. *
  425. ********************************************************************** MC ***/
  426. CReverbFX::~CReverbFX( void )
  427. {
  428. SPDBG_FUNC( "CReverbFX::~CReverbFX" );
  429. DeleteReverbModules( );
  430. } /* CReverbFX::~CReverbFX */
  431. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  432. // Run-time
  433. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  434. /*****************************************************************************
  435. * CReverbFX::CopyWithGain *
  436. *-------------------------*
  437. * Description:
  438. * Copies audio buffer with gain
  439. *
  440. ********************************************************************** MC ***/
  441. void CReverbFX::CopyWithGain
  442. ( REVERBT *psDest,
  443. REVERBT *psSource,
  444. long dwSamples,
  445. REVERBL gain)
  446. {
  447. SPDBG_FUNC( "CReverbFX::CopyWithGain" );
  448. if( gain <= REVERB_VOL_OFF )
  449. {
  450. //----------------------------------------
  451. // Clear buffer, gain = 0
  452. //----------------------------------------
  453. memset( psDest, 0, sizeof(REVERBT) * dwSamples );
  454. }
  455. else if( gain == REVERB_VOL_UNITY )
  456. {
  457. //----------------------------------------
  458. // Copy buffer, gain = 1
  459. //----------------------------------------
  460. memcpy( psDest, psSource, sizeof(REVERBT) * dwSamples );
  461. }
  462. else
  463. {
  464. //----------------------------------------
  465. // Copy with gain
  466. //----------------------------------------
  467. while( dwSamples )
  468. {
  469. #ifdef FLOAT_REVERB
  470. *psDest++ = (*psSource++) * gain;
  471. #else
  472. *psDest++ = (short) (( (long)(*psSource++) * (long)gain) >> REVERB_VOL_SHIFT);
  473. #endif
  474. dwSamples--;
  475. }
  476. }
  477. } /* CReverbFX::CopyWithGain */
  478. /*****************************************************************************
  479. * CReverbFX::MixWithGain_MONO *
  480. *-----------------------------*
  481. * Description:
  482. * (psDest * gain) + psSource -> psDest
  483. * Clipping is performed.
  484. *
  485. ********************************************************************** MC ***/
  486. void CReverbFX::MixWithGain_MONO
  487. (
  488. REVERBT *pWet,
  489. REVERBT *pDry,
  490. short *pDest,
  491. long dwSamples,
  492. REVERBL gain
  493. )
  494. {
  495. SPDBG_FUNC( "CReverbFX::MixWithGain_MONO" );
  496. REVERBL lSample; // long or float
  497. if( gain <= REVERB_VOL_OFF )
  498. {
  499. //----------------------------------
  500. // Do nothing...I guess
  501. //----------------------------------
  502. }
  503. else if( gain == REVERB_VOL_UNITY )
  504. {
  505. //----------------------------------
  506. // Don't apply any gain (= 1.0)
  507. //----------------------------------
  508. while( dwSamples )
  509. {
  510. lSample = (REVERBL)(*pWet++) + *pDry;
  511. //------------------------------------
  512. // Clip signal if overflow
  513. //------------------------------------
  514. if( lSample < -32768 )
  515. {
  516. lSample = -32768;
  517. }
  518. else if( lSample > 32767 )
  519. {
  520. lSample = 32767;
  521. }
  522. *pDest++ = (short)lSample;
  523. pDry++;
  524. dwSamples--;
  525. }
  526. }
  527. else
  528. {
  529. while( dwSamples )
  530. {
  531. //----------------------------------
  532. // Mix with gain on source audio
  533. //----------------------------------
  534. #ifdef FLOAT_REVERB
  535. lSample = ((*pDry) * gain) + *pWet++;
  536. #else
  537. lSample = ((long)(*pDry * (long)(gain)) >> REVERB_VOL_SHIFT) + *pWet++;
  538. #endif
  539. //------------------------------------
  540. // Clip signal if overflow
  541. //------------------------------------
  542. if( lSample < -32768 )
  543. {
  544. lSample = -32768;
  545. }
  546. else if( lSample > 32767 )
  547. {
  548. lSample = 32767;
  549. }
  550. *pDest++ = (short)lSample;
  551. pDry++;
  552. dwSamples--;
  553. }
  554. }
  555. } /* CReverbFX::MixWithGain_MONO */
  556. /*****************************************************************************
  557. * CReverbFX::MixWithGain_STEREO *
  558. *-------------------------------*
  559. * Description:
  560. *
  561. ********************************************************************** MC ***/
  562. void CReverbFX::MixWithGain_STEREO
  563. (
  564. REVERBT *pWet,
  565. REVERBT *pDry,
  566. short *pDest,
  567. long dwSamples,
  568. REVERBL gain
  569. )
  570. {
  571. SPDBG_FUNC( "CReverbFX::MixWithGain_STEREO" );
  572. REVERBL lSample, hold; // long or float
  573. REVERBL lSample_B; // long or float
  574. if( gain <= REVERB_VOL_OFF )
  575. {
  576. //----------------------------------
  577. // Do nothing...I guess
  578. //----------------------------------
  579. }
  580. else if( gain == REVERB_VOL_UNITY )
  581. {
  582. //----------------------------------
  583. // Don't apply any gain (= 1.0)
  584. //----------------------------------
  585. while( dwSamples )
  586. {
  587. lSample = (REVERBL)(*pWet++) + (*pDry++);
  588. //------------------------------------
  589. // Clip signal if overflow
  590. //------------------------------------
  591. if( lSample < -32768 )
  592. {
  593. lSample = -32768;
  594. }
  595. else if( lSample > 32767 )
  596. {
  597. lSample = 32767;
  598. }
  599. *pDest++ = (short)lSample;
  600. *pDest++ = (short)(0 - (short)lSample);
  601. dwSamples--;
  602. }
  603. }
  604. else
  605. {
  606. while( dwSamples )
  607. {
  608. //----------------------------------
  609. // Mix with gain on source audio
  610. //----------------------------------
  611. #ifdef FLOAT_REVERB
  612. hold = ((*pDry) * gain);
  613. lSample = hold + *pWet;
  614. lSample_B = hold - *pWet++;
  615. //lSample_B = 0 - lSample_B;
  616. //lSample_B = (0 - hold) - *pWet++;
  617. #else
  618. lSample = ((long)(*pDry * (long)(gain)) >> REVERB_VOL_SHIFT) + *pWet;
  619. lSample_B = ((long)(*pDry * (long)(gain)) >> REVERB_VOL_SHIFT) - *pWet++;
  620. #endif
  621. //------------------------------------
  622. // Clip signal if overflow
  623. //------------------------------------
  624. if( lSample < -32768 )
  625. {
  626. lSample = -32768;
  627. }
  628. else if( lSample > 32767 )
  629. {
  630. lSample = 32767;
  631. }
  632. *pDest++ = (short)lSample;
  633. if( lSample < -32768 )
  634. {
  635. lSample = -32768;
  636. }
  637. else if( lSample > 32767 )
  638. {
  639. lSample = 32767;
  640. }
  641. *pDest++ = (short)lSample_B;
  642. pDry++;
  643. dwSamples--;
  644. }
  645. }
  646. } /* CReverbFX::MixWithGain_STEREO */
  647. /*****************************************************************************
  648. * CReverbFX::ProcessReverbModule *
  649. *-------------------*
  650. * Description:
  651. * Process one delay buffer
  652. *
  653. ********************************************************************** MC ***/
  654. void CReverbFX::ProcessReverbModule
  655. (
  656. LP_Reverb_Mod mod,
  657. long dwDestSamples, // Number of samples to process.
  658. REVERBT *pSource, // Source sample buffer.
  659. REVERBT *pDestination // Destination sample buffer.
  660. )
  661. {
  662. SPDBG_FUNC( "CReverbFX::ProcessReverbModule" );
  663. REVERBT sDelayOut;
  664. REVERBT sDelayIn;
  665. REVERBT *psDelayEnd;
  666. //(void) QueryPerformanceCounter (&g_StartTime );
  667. psDelayEnd = mod->psDelayBuffer + (long)((float)mod->dwDelayBufferSize * m_LenScale);
  668. dwDestSamples++;
  669. while( --dwDestSamples )
  670. {
  671. //----------------------------------------
  672. // Delay + current --> delay buffer
  673. //----------------------------------------
  674. sDelayOut = *mod->psDelayOut;
  675. #ifdef FLOAT_REVERB
  676. sDelayIn = (sDelayOut * mod->lGain) + *pSource;
  677. //------------------------------------------------------------
  678. // Take this test out and you'll die in about 10 sec...
  679. //------------------------------------------------------------
  680. if( sDelayIn > 0)
  681. {
  682. if( sDelayIn < 0.001 )
  683. sDelayIn = 0;
  684. }
  685. else if( sDelayIn > -0.001 )
  686. {
  687. sDelayIn = 0;
  688. }
  689. #else
  690. sDelayIn = ((sDelayOut * mod->lGain) >> REVERB_VOL_SHIFT) + *pSource;
  691. #endif
  692. *mod->psDelayIn++ = sDelayIn;
  693. //----------------------------------------
  694. // Delay - (Delay + current) --> current
  695. //----------------------------------------
  696. #ifdef FLOAT_REVERB
  697. *pDestination = sDelayOut - (sDelayIn * mod->lGain);
  698. #else
  699. *pDestination = sDelayOut - ((sDelayIn * mod->lGain) >> REVERB_VOL_SHIFT);
  700. #endif
  701. //---------------------------------------
  702. // Wrap circular buffer ptrs
  703. //---------------------------------------
  704. if( mod->psDelayIn >= psDelayEnd )
  705. {
  706. mod->psDelayIn = mod->psDelayBuffer;
  707. }
  708. mod->psDelayOut++;
  709. if( mod->psDelayOut >= psDelayEnd )
  710. {
  711. mod->psDelayOut = mod->psDelayBuffer;
  712. }
  713. pSource++;
  714. pDestination++;
  715. }
  716. //(void) QueryPerformanceCounter (&g_EndTime);
  717. //g_LapseTime.QuadPart = (g_EndTime.QuadPart - g_StartTime.QuadPart);
  718. } /* CReverbFX::ProcessReverbModule */
  719. //----------------------------------------------------------------------------
  720. // Applies an array of reverb modules to a block of samples.
  721. //----------------------------------------------------------------------------
  722. /*****************************************************************************
  723. * CReverbFX::ProcessReverbBuffer *
  724. *--------------------------------*
  725. * Description:
  726. * Applies an array of reverb modules to a block of samples.
  727. *
  728. ********************************************************************** MC ***/
  729. void CReverbFX::ProcessReverbBuffer
  730. ( REVERBT *psSample, // Samples to process (in/out).
  731. long dwSamples, // Number of samples to process.
  732. LP_Reverb_Mod *mods // Array of modules to apply.
  733. )
  734. {
  735. SPDBG_FUNC( "CReverbFX::ProcessReverbBuffer" );
  736. short i;
  737. for (i = 0; i < KMAXREVBMODS; i++)
  738. {
  739. if( mods[i] != NULL )
  740. {
  741. ProcessReverbModule( mods[i], dwSamples, psSample, psSample );
  742. }
  743. else
  744. break;
  745. }
  746. } /* CReverbFX::ProcessReverbBuffer */
  747. /*****************************************************************************
  748. * CReverbFX::Reverb_Process *
  749. *---------------------------*
  750. * Description:
  751. *
  752. ********************************************************************** MC ***/
  753. short CReverbFX::Reverb_Process( float *sampleBuffer,
  754. long dwSamplesRemaining, float audioGain )
  755. {
  756. SPDBG_FUNC( "CReverbFX::Reverb_Process" );
  757. long dwSamplesToProcess;
  758. short *pOutBuffer;
  759. REVERBL totalWetGain, totalDryGain;
  760. if( m_numOfMods )
  761. {
  762. #ifdef FLOAT_REVERB
  763. totalWetGain = m_wetVolGain * audioGain;
  764. if (totalWetGain < REVERB_MIN_MIX)
  765. totalWetGain = REVERB_MIN_MIX;
  766. totalDryGain = m_dryVolGain * audioGain;
  767. if (totalDryGain < REVERB_MIN_MIX)
  768. totalDryGain = REVERB_MIN_MIX;
  769. #else
  770. totalWetGain = (REVERBL)(m_wetVolGain * audioGain * (float)REVERB_VOL_LEVELS);
  771. totalDryGain = (REVERBL)(m_dryVolGain * audioGain * (float)REVERB_VOL_LEVELS);
  772. #endif
  773. pOutBuffer = (short*)sampleBuffer;
  774. m_LenScale = (float)1.0 - (m_Count * m_pReverbConfig->seqIndex);
  775. while( dwSamplesRemaining > 0 )
  776. {
  777. //----------------------------------------------------------------------------
  778. // Process client's buffer using 'work buffer' chunks
  779. //----------------------------------------------------------------------------
  780. if( dwSamplesRemaining < m_dwWorkBufferSize )
  781. {
  782. dwSamplesToProcess = dwSamplesRemaining;
  783. }
  784. else
  785. {
  786. dwSamplesToProcess = m_dwWorkBufferSize;
  787. }
  788. //-----------------------------------------------------------------
  789. // Copy audio into WET buffer with wet gain
  790. // sampleBuffer * totalWetGain --> m_pWorkBuf
  791. //-----------------------------------------------------------------
  792. CopyWithGain( m_pWorkBuf, sampleBuffer, dwSamplesToProcess, totalWetGain );
  793. //-----------------------------------------------------------------
  794. // Perform reverb processing on the work buffer
  795. //-----------------------------------------------------------------
  796. ProcessReverbBuffer
  797. (
  798. m_pWorkBuf,
  799. dwSamplesToProcess,
  800. (LP_Reverb_Mod*)&m_Reverb_Mods
  801. );
  802. //-----------------------------------------------------------------
  803. // Mix the dry with wet samples
  804. // (sampleBuffer * totalDryGain) + m_pWorkBuf --> sampleBuffer
  805. //-----------------------------------------------------------------
  806. if( m_StereoOut )
  807. {
  808. MixWithGain_STEREO( m_pWorkBuf, sampleBuffer, pOutBuffer, dwSamplesToProcess, totalDryGain );
  809. pOutBuffer += dwSamplesToProcess * 2;
  810. }
  811. else
  812. {
  813. MixWithGain_MONO( m_pWorkBuf, sampleBuffer, pOutBuffer, dwSamplesToProcess, totalDryGain );
  814. pOutBuffer += dwSamplesToProcess;
  815. }
  816. sampleBuffer += dwSamplesToProcess;
  817. dwSamplesRemaining -= dwSamplesToProcess;
  818. }
  819. }
  820. m_Count = (float)rand() / (float)4096; // 0 - 32K -> 0 - 8
  821. return 0;
  822. } /* CReverbFX::Reverb_Process */