SoundTouchDLL.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //////////////////////////////////////////////////////////////////////////////
  2. ///
  3. /// SoundTouch DLL wrapper - wraps SoundTouch routines into a Dynamic Load
  4. /// Library interface.
  5. ///
  6. /// Author : Copyright (c) Olli Parviainen
  7. /// Author e-mail : oparviai 'at' iki.fi
  8. /// SoundTouch WWW: http://www.surina.net/soundtouch
  9. ///
  10. ////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // License :
  13. //
  14. // SoundTouch audio processing library
  15. // Copyright (c) Olli Parviainen
  16. //
  17. // This library is free software; you can redistribute it and/or
  18. // modify it under the terms of the GNU Lesser General Public
  19. // License as published by the Free Software Foundation; either
  20. // version 2.1 of the License, or (at your option) any later version.
  21. //
  22. // This library is distributed in the hope that it will be useful,
  23. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. // Lesser General Public License for more details.
  26. //
  27. // You should have received a copy of the GNU Lesser General Public
  28. // License along with this library; if not, write to the Free Software
  29. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. //
  31. ////////////////////////////////////////////////////////////////////////////////
  32. #ifndef _SoundTouchDLL_h_
  33. #define _SoundTouchDLL_h_
  34. #if defined(_WIN32) || defined(WIN32)
  35. // Windows
  36. #ifndef __cplusplus
  37. #error "Expected g++"
  38. #endif
  39. #ifdef DLL_EXPORTS
  40. #define SOUNDTOUCHDLL_API extern "C" __declspec(dllexport)
  41. #else
  42. #define SOUNDTOUCHDLL_API extern "C" __declspec(dllimport)
  43. #endif
  44. #else
  45. // GNU version
  46. #if defined(DLL_EXPORTS) || defined(SoundTouchDLL_EXPORTS)
  47. // GCC declaration for exporting functions
  48. #define SOUNDTOUCHDLL_API extern "C" __attribute__((__visibility__("default")))
  49. #else
  50. // GCC doesn't require DLL imports
  51. #define SOUNDTOUCHDLL_API
  52. #endif
  53. // Linux-replacements for Windows declarations:
  54. #define __cdecl
  55. typedef unsigned int DWORD;
  56. #define FALSE 0
  57. #define TRUE 1
  58. #endif
  59. typedef void * HANDLE;
  60. /// Create a new instance of SoundTouch processor.
  61. SOUNDTOUCHDLL_API HANDLE __cdecl soundtouch_createInstance();
  62. /// Destroys a SoundTouch processor instance.
  63. SOUNDTOUCHDLL_API void __cdecl soundtouch_destroyInstance(HANDLE h);
  64. /// Get SoundTouch library version string
  65. SOUNDTOUCHDLL_API const char *__cdecl soundtouch_getVersionString();
  66. /// Get SoundTouch library version string - alternative function for
  67. /// environments that can't properly handle character string as return value
  68. SOUNDTOUCHDLL_API void __cdecl soundtouch_getVersionString2(char* versionString, int bufferSize);
  69. /// Get SoundTouch library version Id
  70. SOUNDTOUCHDLL_API unsigned int __cdecl soundtouch_getVersionId();
  71. /// Sets new rate control value. Normal rate = 1.0, smaller values
  72. /// represent slower rate, larger faster rates.
  73. SOUNDTOUCHDLL_API void __cdecl soundtouch_setRate(HANDLE h, float newRate);
  74. /// Sets new tempo control value. Normal tempo = 1.0, smaller values
  75. /// represent slower tempo, larger faster tempo.
  76. SOUNDTOUCHDLL_API void __cdecl soundtouch_setTempo(HANDLE h, float newTempo);
  77. /// Sets new rate control value as a difference in percents compared
  78. /// to the original rate (-50 .. +100 %);
  79. SOUNDTOUCHDLL_API void __cdecl soundtouch_setRateChange(HANDLE h, float newRate);
  80. /// Sets new tempo control value as a difference in percents compared
  81. /// to the original tempo (-50 .. +100 %);
  82. SOUNDTOUCHDLL_API void __cdecl soundtouch_setTempoChange(HANDLE h, float newTempo);
  83. /// Sets new pitch control value. Original pitch = 1.0, smaller values
  84. /// represent lower pitches, larger values higher pitch.
  85. SOUNDTOUCHDLL_API void __cdecl soundtouch_setPitch(HANDLE h, float newPitch);
  86. /// Sets pitch change in octaves compared to the original pitch
  87. /// (-1.00 .. +1.00);
  88. SOUNDTOUCHDLL_API void __cdecl soundtouch_setPitchOctaves(HANDLE h, float newPitch);
  89. /// Sets pitch change in semi-tones compared to the original pitch
  90. /// (-12 .. +12);
  91. SOUNDTOUCHDLL_API void __cdecl soundtouch_setPitchSemiTones(HANDLE h, float newPitch);
  92. /// Sets the number of channels, 1 = mono, 2 = stereo, n = multichannel
  93. SOUNDTOUCHDLL_API void __cdecl soundtouch_setChannels(HANDLE h, unsigned int numChannels);
  94. /// Sets sample rate.
  95. SOUNDTOUCHDLL_API void __cdecl soundtouch_setSampleRate(HANDLE h, unsigned int srate);
  96. /// Flushes the last samples from the processing pipeline to the output.
  97. /// Clears also the internal processing buffers.
  98. //
  99. /// Note: This function is meant for extracting the last samples of a sound
  100. /// stream. This function may introduce additional blank samples in the end
  101. /// of the sound stream, and thus it's not recommended to call this function
  102. /// in the middle of a sound stream.
  103. SOUNDTOUCHDLL_API void __cdecl soundtouch_flush(HANDLE h);
  104. /// Adds 'numSamples' pcs of samples from the 'samples' memory position into
  105. /// the input of the object. Notice that sample rate _has_to_ be set before
  106. /// calling this function, otherwise throws a runtime_error exception.
  107. SOUNDTOUCHDLL_API void __cdecl soundtouch_putSamples(HANDLE h,
  108. const float *samples, ///< Pointer to sample buffer.
  109. unsigned int numSamples ///< Number of sample frames in buffer. Notice
  110. ///< that in case of multi-channel sound a single
  111. ///< sample frame contains data for all channels.
  112. );
  113. /// int16 version of soundtouch_putSamples(): This accept int16 (short) sample data
  114. /// and internally converts it to float format before processing
  115. SOUNDTOUCHDLL_API void __cdecl soundtouch_putSamples_i16(HANDLE h,
  116. const short *samples, ///< Pointer to sample buffer.
  117. unsigned int numSamples ///< Number of sample frames in buffer. Notice
  118. ///< that in case of multi-channel sound a single
  119. ///< sample frame contains data for all channels.
  120. );
  121. /// Clears all the samples in the object's output and internal processing
  122. /// buffers.
  123. SOUNDTOUCHDLL_API void __cdecl soundtouch_clear(HANDLE h);
  124. /// Changes a setting controlling the processing system behaviour. See the
  125. /// 'SETTING_...' defines for available setting ID's.
  126. ///
  127. /// \return 'nonzero' if the setting was successfully changed, otherwise zero
  128. SOUNDTOUCHDLL_API int __cdecl soundtouch_setSetting(HANDLE h,
  129. int settingId, ///< Setting ID number. see SETTING_... defines.
  130. int value ///< New setting value.
  131. );
  132. /// Reads a setting controlling the processing system behaviour. See the
  133. /// 'SETTING_...' defines for available setting ID's.
  134. ///
  135. /// \return the setting value.
  136. SOUNDTOUCHDLL_API int __cdecl soundtouch_getSetting(HANDLE h,
  137. int settingId ///< Setting ID number, see SETTING_... defines.
  138. );
  139. /// Returns number of samples currently unprocessed.
  140. SOUNDTOUCHDLL_API unsigned int __cdecl soundtouch_numUnprocessedSamples(HANDLE h);
  141. /// Adjusts book-keeping so that given number of samples are removed from beginning of the
  142. /// sample buffer without copying them anywhere.
  143. ///
  144. /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
  145. /// with 'ptrBegin' function.
  146. SOUNDTOUCHDLL_API unsigned int __cdecl soundtouch_receiveSamples(HANDLE h,
  147. float *outBuffer, ///< Buffer where to copy output samples.
  148. unsigned int maxSamples ///< How many samples to receive at max.
  149. );
  150. /// int16 version of soundtouch_receiveSamples(): This converts internal float samples
  151. /// into int16 (short) return data type
  152. SOUNDTOUCHDLL_API unsigned int __cdecl soundtouch_receiveSamples_i16(HANDLE h,
  153. short *outBuffer, ///< Buffer where to copy output samples.
  154. unsigned int maxSamples ///< How many samples to receive at max.
  155. );
  156. /// Returns number of samples currently available.
  157. SOUNDTOUCHDLL_API unsigned int __cdecl soundtouch_numSamples(HANDLE h);
  158. /// Returns nonzero if there aren't any samples available for outputting.
  159. SOUNDTOUCHDLL_API int __cdecl soundtouch_isEmpty(HANDLE h);
  160. /// Create a new instance of BPM detector
  161. SOUNDTOUCHDLL_API HANDLE __cdecl bpm_createInstance(int numChannels, int sampleRate);
  162. /// Destroys a BPM detector instance.
  163. SOUNDTOUCHDLL_API void __cdecl bpm_destroyInstance(HANDLE h);
  164. /// Feed 'numSamples' sample frames from 'samples' into the BPM detector.
  165. SOUNDTOUCHDLL_API void __cdecl bpm_putSamples(HANDLE h,
  166. const float *samples, ///< Pointer to sample buffer.
  167. unsigned int numSamples ///< Number of samples in buffer. Notice
  168. ///< that in case of stereo-sound a single sample
  169. ///< contains data for both channels.
  170. );
  171. /// Feed 'numSamples' sample frames from 'samples' into the BPM detector.
  172. /// 16bit int sample format version.
  173. SOUNDTOUCHDLL_API void __cdecl bpm_putSamples_i16(HANDLE h,
  174. const short *samples, ///< Pointer to sample buffer.
  175. unsigned int numSamples ///< Number of samples in buffer. Notice
  176. ///< that in case of stereo-sound a single sample
  177. ///< contains data for both channels.
  178. );
  179. /// Analyzes the results and returns the BPM rate. Use this function to read result
  180. /// after whole song data has been input to the class by consecutive calls of
  181. /// 'inputSamples' function.
  182. ///
  183. /// \return Beats-per-minute rate, or zero if detection failed.
  184. SOUNDTOUCHDLL_API float __cdecl bpm_getBpm(HANDLE h);
  185. #endif // _SoundTouchDLL_h_