SuperpoweredSimple.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #ifndef Header_SuperpoweredSimple
  2. #define Header_SuperpoweredSimple
  3. /**
  4. @file SuperpoweredSimple.h
  5. @brief Simple fast utility functions for transforming audio.
  6. */
  7. /**
  8. @fn SuperpoweredVolume(float *input, float *output, float volumeStart, float volumeEnd, unsigned int numberOfSamples);
  9. @brief Applies volume on a single stereo interleaved buffer.
  10. @param input Input buffer.
  11. @param output Output buffer. Can be equal to input (in-place processing).
  12. @param volumeStart Volume for the first sample.
  13. @param volumeEnd Volume for the last sample. Volume will be smoothly calculated between start end end.
  14. @param numberOfSamples The number of samples to process.
  15. */
  16. void SuperpoweredVolume(float *input, float *output, float volumeStart, float volumeEnd, unsigned int numberOfSamples);
  17. /**
  18. @fn SuperpoweredChangeVolume(float *input, float *output, float volumeStart, float volumeChange, unsigned int numberOfSamples);
  19. @brief Applies volume on a single stereo interleaved buffer.
  20. @param input Input buffer.
  21. @param output Output buffer. Can be equal to input (in-place processing).
  22. @param volumeStart Voume for the first sample.
  23. @param volumeChange Change volume by this amount for every sample.
  24. @param numberOfSamples The number of samples to process.
  25. */
  26. void SuperpoweredChangeVolume(float *input, float *output, float volumeStart, float volumeChange, unsigned int numberOfSamples);
  27. /**
  28. @fn SuperpoweredVolumeAdd(float *input, float *output, float volumeStart, float volumeEnd, unsigned int numberOfSamples);
  29. @brief Applies volume on a single stereo interleaved buffer and adds it to the audio in the output buffer.
  30. @param input Input buffer.
  31. @param output Output buffer.
  32. @param volumeStart Volume for the first sample.
  33. @param volumeEnd Volume for the last sample. Volume will be smoothly calculated between start end end.
  34. @param numberOfSamples The number of samples to process.
  35. */
  36. void SuperpoweredVolumeAdd(float *input, float *output, float volumeStart, float volumeEnd, unsigned int numberOfSamples);
  37. /**
  38. @fn SuperpoweredChangeVolumeAdd(float *input, float *output, float volumeStart, float volumeChange, unsigned int numberOfSamples);
  39. @brief Applies volume on a single stereo interleaved buffer and adds it to the audio in the output buffer.
  40. @param input Input buffer.
  41. @param output Output buffer.
  42. @param volumeStart Volume for the first sample.
  43. @param volumeChange Change volume by this amount for every sample.
  44. @param numberOfSamples The number of samples to process.
  45. */
  46. void SuperpoweredChangeVolumeAdd(float *input, float *output, float volumeStart, float volumeChange, unsigned int numberOfSamples);
  47. /**
  48. @fn SuperpoweredPeak(float *input, unsigned int numberOfValues);
  49. @return Returns with the peak value.
  50. @param input An array of floating point values.
  51. @param numberOfValues The number of values to process. (2 * numberOfSamples for stereo input) Must be a multiply of 8.
  52. */
  53. float SuperpoweredPeak(float *input, unsigned int numberOfValues);
  54. /**
  55. @fn SuperpoweredFloatToShortInt(float *input, short int *output, unsigned int numberOfSamples);
  56. @brief Converts a stereo interleaved 32-bit float input to stereo interleaved 16-bit signed integer output.
  57. @param input Stereo interleaved 32-bit input. Should be numberOfSamples * 2 + 16 big minimum.
  58. @param output Stereo interleaved 16-bit output. Should be numberOfSamples * 2 + 16 big minimum.
  59. @param numberOfSamples The number of samples to process.
  60. */
  61. void SuperpoweredFloatToShortInt(float *input, short int *output, unsigned int numberOfSamples);
  62. /**
  63. @fn SuperpoweredFloatToShortInt(float *inputLeft, float *inputRight, short int *output, unsigned int numberOfSamples);
  64. @brief Converts two 32-bit float input channels to stereo interleaved 16-bit signed integer output.
  65. @param inputLeft 32-bit input for the left side. Should be numberOfSamples + 8 big minimum.
  66. @param inputRight 32-bit input for the right side. Should be numberOfSamples + 8 big minimum.
  67. @param output Stereo interleaved 16-bit output. Should be numberOfSamples * 2 + 16 big minimum.
  68. @param numberOfSamples The number of samples to process.
  69. */
  70. void SuperpoweredFloatToShortInt(float *inputLeft, float *inputRight, short int *output, unsigned int numberOfSamples);
  71. /**
  72. @fn SuperpoweredShortIntToFloat(short int *input, float *output, unsigned int numberOfSamples, float *peaks);
  73. @brief Converts a stereo interleaved 16-bit signed integer input to stereo interleaved 32-bit float output.
  74. @param input Stereo interleaved 16-bit input. Should be numberOfSamples + 8 big minimum.
  75. @param output Stereo interleaved 32-bit output. Should be numberOfSamples + 8 big minimum.
  76. @param numberOfSamples The number of samples to process.
  77. @param peaks Peak value result (2 floats: left peak, right peak). Can be NULL if you are not interested.
  78. */
  79. void SuperpoweredShortIntToFloat(short int *input, float *output, unsigned int numberOfSamples, float *peaks = 0);
  80. /**
  81. @fn SuperpoweredInterleave(float *left, float *right, float *output, unsigned int numberOfSamples);
  82. @brief Makes an interleaved output from two input channels.
  83. @param left Input for left channel.
  84. @param right Input for right channel.
  85. @param output Interleaved output.
  86. @param numberOfSamples The number of samples to process.
  87. */
  88. void SuperpoweredInterleave(float *left, float *right, float *output, unsigned int numberOfSamples);
  89. /**
  90. @fn SuperpoweredInterleaveAndGetPeaks(float *left, float *right, float *output, unsigned int numberOfSamples, float *peaks);
  91. @brief Makes an interleaved output from two input channels, and measures the input volume.
  92. @param left Input for left channel.
  93. @param right Input for right channel.
  94. @param output Interleaved output.
  95. @param numberOfSamples The number of samples to process.
  96. @param peaks Peak value result (2 floats: left peak, right peak).
  97. */
  98. void SuperpoweredInterleaveAndGetPeaks(float *left, float *right, float *output, unsigned int numberOfSamples, float *peaks);
  99. /**
  100. @fn SuperpoweredDeInterleave(float *input, float *left, float *right, unsigned int numberOfSamples);
  101. @brief Deinterleaves an interleaved input.
  102. @param input Interleaved input.
  103. @param left Output for left channel.
  104. @param right Output for right channel.
  105. @param numberOfSamples The number of samples to process.
  106. */
  107. void SuperpoweredDeInterleave(float *input, float *left, float *right, unsigned int numberOfSamples);
  108. /**
  109. @fn SuperpoweredDeInterleaveAdd(float *input, float *left, float *right, unsigned int numberOfSamples);
  110. @brief Deinterleaves an interleaved input and adds the results to the output channels.
  111. @param input Interleaved input.
  112. @param left Output for left channel.
  113. @param right Output for right channel.
  114. @param numberOfSamples The number of samples to process.
  115. */
  116. void SuperpoweredDeInterleaveAdd(float *input, float *left, float *right, unsigned int numberOfSamples);
  117. /**
  118. @fn SuperpoweredHasNonFinite(float *buffer, unsigned int numberOfValues);
  119. @brief Checks if the samples has non-valid samples, such as infinity or NaN (not a number).
  120. @param buffer The buffer to check.
  121. @param numberOfValues Number of values in buffer. For stereo buffers, multiply by two!
  122. */
  123. bool SuperpoweredHasNonFinite(float *buffer, unsigned int numberOfValues);
  124. /**
  125. @fn SuperpoweredStereoToMono(float *input, float *output, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  126. @brief Makes mono output from stereo input.
  127. @param input Stereo interleaved input.
  128. @param output Output.
  129. @param leftGainStart Gain of the first sample on the left channel.
  130. @param leftGainEnd Gain for the last sample on the left channel. Gain will be smoothly calculated between start end end.
  131. @param rightGainStart Gain of the first sample on the right channel.
  132. @param rightGainEnd Gain for the last sample on the right channel. Gain will be smoothly calculated between start end end.
  133. @param numberOfSamples The number of samples to process.
  134. */
  135. void SuperpoweredStereoToMono(float *input, float *output, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  136. /**
  137. @fn SuperpoweredStereoToMono2(float *input, float *output0, float *output1, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  138. @brief Makes two mono outputs from stereo input.
  139. @param input Stereo interleaved input.
  140. @param output0 Output.
  141. @param output1 Output.
  142. @param leftGainStart Gain of the first sample on the left channel.
  143. @param leftGainEnd Gain for the last sample on the left channel. Gain will be smoothly calculated between start end end.
  144. @param rightGainStart Gain of the first sample on the right channel.
  145. @param rightGainEnd Gain for the last sample on the right channel. Gain will be smoothly calculated between start end end.
  146. @param numberOfSamples The number of samples to process.
  147. */
  148. void SuperpoweredStereoToMono2(float *input, float *output0, float *output1, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  149. /**
  150. @fn SuperpoweredCrossMono(float *left, float *right, float *output, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  151. @brief Makes mono output from two separate input channels.
  152. @param left Input for left channel.
  153. @param right Input for right channel.
  154. @param output Output.
  155. @param leftGainStart Gain of the first sample on the left channel.
  156. @param leftGainEnd Gain for the last sample on the left channel. Gain will be smoothly calculated between start end end.
  157. @param rightGainStart Gain of the first sample on the right channel.
  158. @param rightGainEnd Gain for the last sample on the right channel. Gain will be smoothly calculated between start end end.
  159. @param numberOfSamples The number of samples to process.
  160. */
  161. void SuperpoweredCrossMono(float *left, float *right, float *output, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  162. /**
  163. @fn SuperpoweredCrossMono2(float *left, float *right, float *output0, float *output1, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  164. @brief Makes two mono outputs from two separate input channels.
  165. @param left Input for left channel.
  166. @param right Input for right channel.
  167. @param output0 Output.
  168. @param output1 Output.
  169. @param leftGainStart Gain of the first sample on the left channel.
  170. @param leftGainEnd Gain for the last sample on the left channel. Gain will be smoothly calculated between start end end.
  171. @param rightGainStart Gain of the first sample on the right channel.
  172. @param rightGainEnd Gain for the last sample on the right channel. Gain will be smoothly calculated between start end end.
  173. @param numberOfSamples The number of samples to process.
  174. */
  175. void SuperpoweredCrossMono2(float *left, float *right, float *output0, float *output1, float leftGainStart, float leftGainEnd, float rightGainStart, float rightGainEnd, unsigned int numberOfSamples);
  176. /**
  177. @fn SuperpoweredCrossStereo(float *inputA, float *inputB, float *output, float gainStart[4], float gainEnd[4], unsigned int numberOfSamples);
  178. @brief Crossfades two separate input channels.
  179. @param inputA Interleaved stereo input (first).
  180. @param inputB Interleaved stereo input (second).
  181. @param output Interleaved stereo output.
  182. @param gainStart Gain of the first sample (first left, first right, second left, second right).
  183. @param gainEnd Gain for the last sample (first left, first right, second left, second right). Gain will be smoothly calculated between start end end.
  184. @param numberOfSamples The number of samples to process.
  185. */
  186. void SuperpoweredCrossStereo(float *inputA, float *inputB, float *output, float gainStart[4], float gainEnd[4], unsigned int numberOfSamples);
  187. /**
  188. @fn SuperpoweredVersion()
  189. @return Returns with the current version of the Superpowered SDK.
  190. The returned value is 3 unsigned chars: major,minor,revision Example: 1,0,0 means 1.0.0
  191. */
  192. const unsigned char *SuperpoweredVersion();
  193. #endif