SndFx.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. #ifndef SNDFX_H
  19. #define SNDFX_H
  20. #include <stdio.h> // For FILE*
  21. #include "System.h"
  22. // If PATHS_IN_INCLUDES macro is defined, we can utilized relative
  23. // paths to a header file. In this case we generally go off of our
  24. // RSPiX root directory. System.h MUST be included before this macro
  25. // is evaluated. System.h is the header that, based on the current
  26. // platform (or more so in this case on the compiler), defines
  27. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  28. // instead.
  29. #ifdef PATHS_IN_INCLUDES
  30. #else
  31. #endif // PATHS_IN_INCLUDES
  32. //////////////////////////////////////////////////////////////////////////////
  33. // Macros.
  34. //////////////////////////////////////////////////////////////////////////////
  35. #define RSP_SNDFX_MAX_BITSPERSAMPLE 32 // Maximum bits per sample.
  36. #define RSP_SNDFX_NUM_FADE_INTERVALS 10 // Size of fades table.
  37. //////////////////////////////////////////////////////////////////////////////
  38. // Types.
  39. //////////////////////////////////////////////////////////////////////////////
  40. // Forward declare RSndFx for typedef.
  41. class RSndFx;
  42. // Handy-dandy typedef.
  43. typedef RSndFx* PSNDFX;
  44. class RSndFx
  45. {
  46. /////////////////////// Typedefs & Enums ///////////////////////////////////
  47. public:
  48. // Effects that can be active simulatneously.
  49. // GetCurrentFX() returns these combined by | for all active fx:
  50. typedef enum
  51. {
  52. NoFX = 0x0000, // No current FX.
  53. // FX that affect all channels.
  54. FadeIn = 0x0001, // Fade in all channels.
  55. FadeOut = 0x0002, // Fade out all channels.
  56. // FX that affect individual channels.
  57. DecimateLeft = 0x0004, // Decimate left channel. NYI.
  58. DecimateRight = 0x0008 // Decimate right channel. NYI.
  59. } FX;
  60. public:
  61. // Default constructor.
  62. RSndFx();
  63. // Destructor.
  64. ~RSndFx();
  65. ////////////////////////// Querries ///////////////////////////////////////
  66. public:
  67. // Returns the currently active fx as FX enums combined with |.
  68. FX GetCurrentFX(void) { return m_fx; }
  69. /////////////////////// Global Methods ////////////////////////////////////
  70. public:
  71. // Sets the fade accuracy (i.e., the number of steps to perform a fade).
  72. // This costs sNumStemps * 256 * bits per sample / 8 bytes of memory.
  73. // This function should only be called after the bits per sample have
  74. // been set via a call to SetDataType().
  75. static short SetFadeAccuracy( // Returns 0 on success.
  76. short sNumSteps); // Number of steps to fades; see above.
  77. // Release any dynamic memory referenced by static members.
  78. static void CleanUp(void);
  79. ////////////////////////// Methods ////////////////////////////////////////
  80. public:
  81. // Release any dynamic memory and reset variables.
  82. // Clears all effects.
  83. void Clear(void);
  84. // Reset effects to start.
  85. void Reset(void);
  86. // Set type of PCM data in use. This will reset all effects.
  87. static void SetDataType( // Returns nothing.
  88. long lSamplesPerSec, // Samples per second.
  89. long lBitsPerSample, // Bits per sample.
  90. long lNumChannels); // Number of channels.
  91. // Implements the effect on the provided buffer.
  92. void Do( // Returns nothing.
  93. UCHAR* pucSrcData, // Data to affect.
  94. long lBufSize, // Amount of data.
  95. UCHAR* pucDstData = NULL); // Destination for data, defaults to
  96. // same as source.
  97. /////////////////////////////////////////////////////////////////////////
  98. // Various FX.
  99. /////////////////////////////////////////////////////////////////////////
  100. /////////////////////// Fade In /////////////////////////////////////////
  101. // Set up a fade in.
  102. short SetUpFadeIn( // Returns 0 on success.
  103. long lDuration); // Duration until silence in milliseconds.
  104. // Activate/Deactivate fade in.
  105. void ActivateFadeIn( // Returns nothing.
  106. short sActivate); // TRUE to activate, FALSE to deactivate.
  107. /////////////////////// Fade Out ////////////////////////////////////////
  108. // Set up a fade out.
  109. short SetUpFadeOut( // Returns 0 on success.
  110. long lDuration); // Duration until full volume in milliseconds.
  111. // Activate/Deactivate fade out.
  112. void ActivateFadeOut( // Returns nothing.
  113. short sActivate); // TRUE to activate, FALSE to deactivate.
  114. ////////////////////////// Internal Methods ///////////////////////////////
  115. protected:
  116. // Initialize instantiable members.
  117. void Init(void);
  118. ////////////////////////// Member vars ////////////////////////////////////
  119. public:
  120. protected:
  121. FX m_fx; // Currently active effects.
  122. /////////////////////////////////////////////////////////////////////////
  123. // Various FX.
  124. /////////////////////////////////////////////////////////////////////////
  125. /////////////////////// Fade In /////////////////////////////////////////
  126. long m_lFadeInMillisecondsDuration; // Original duration.
  127. long m_lFadeInBytesDurationAffected; // Amount left to fade.
  128. long m_lFadeInBytesDuration; // Duration in bytes.
  129. long m_lFadeInRate;
  130. /////////////////////// Fade Out ////////////////////////////////////////
  131. long m_lFadeOutMillisecondsDuration; // Original duration.
  132. long m_lFadeOutBytesDurationRemaining; // Amount left to fade.
  133. long m_lFadeOutBytesDuration; // Duration in bytes.
  134. long m_lFadeOutRate;
  135. ///////////////////// Protected Typedefs ///////////////////////////////
  136. typedef struct // Stores info particular PCM type.
  137. {
  138. long lMin; // Mininum value (silence).
  139. long lMax; // Maximum value (saturation).
  140. } PCMINFO;
  141. /////////////////////// Static members /////////////////////////////////
  142. static long ms_lSamplesPerSec; // Samples per second.
  143. static long ms_lBitsPerSample; // Bits per sample.
  144. static long ms_lNumChannels; // Number of channels.
  145. static long ms_lBitsPerSec; // Number of bits per second.
  146. // Can be used to convert bytes to milliseconds
  147. // and convert milliseconds into bytes. See
  148. // macros BYTES2MS and MS2BYTES in SndFx.CPP.
  149. static PCMINFO ms_apcminfo[RSP_SNDFX_MAX_BITSPERSAMPLE + 1]; // Stores info
  150. // particular to each
  151. // PCM type.
  152. static U8* ms_pu8Fade; // Unsigned 8 bit output
  153. // fade table.
  154. static S16* ms_ps16Fade; // Signed 16 bit output
  155. // fade table.
  156. static short ms_sNumFadeSteps; // Number of fade steps.
  157. };
  158. #endif // SNDFX_H
  159. //////////////////////////////////////////////////////////////////////////////
  160. // EOF
  161. //////////////////////////////////////////////////////////////////////////////