sfml_audio.nim 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. import
  2. sfml
  3. const
  4. Lib = "libcsfml-audio.so.2.0"
  5. type
  6. PMusic* = ptr TMusic
  7. TMusic* {.pure, final.} = object
  8. PSound* = ptr TSound
  9. TSound* {.pure, final.} = object
  10. PSoundBuffer* = ptr TSoundBuffer
  11. TSoundBuffer* {.pure, final.} = object
  12. PSoundBufferRecorder* = ptr TSoundBufferRecorder
  13. TSoundBufferRecorder* {.pure, final.} = object
  14. PSoundRecorder* = ptr TSoundRecorder
  15. TSoundRecorder* {.pure, final.} = object
  16. PSoundStream* = ptr TSoundStream
  17. TSoundStream* {.pure, final.} = object
  18. TSoundStatus* {.size: sizeof(cint).} = enum
  19. Stopped, Paused, Playing
  20. proc newMusic*(filename: cstring): PMusic {.
  21. cdecl, importc: "sfMusic_createFromFile", dynlib: Lib.}
  22. proc newMusic*(data: pointer, size: cint): PMusic {.
  23. cdecl, importc: "sfMusic_createFromMemory", dynlib: Lib.}
  24. proc newMusic*(stream: PInputStream): PMusic {.
  25. cdecl, importc: "sfMusic_createFromStream", dynlib: Lib.}
  26. proc destroy*(music: PMusic) {.
  27. cdecl, importc: "sfMusic_destroy", dynlib: Lib.}
  28. proc setLoop*(music: PMusic, loop: bool) {.
  29. cdecl, importc: "sfMusic_setLoop", dynlib: Lib.}
  30. proc getLoop*(music: PMusic): bool {.
  31. cdecl, importc: "sfMusic_getLoop", dynlib: Lib.}
  32. proc getDuration*(music: PMusic): TTime {.
  33. cdecl, importc: "sfMusic_getDuration", dynlib: Lib.}
  34. proc play*(music: PMusic) {.
  35. cdecl, importc: "sfMusic_play", dynlib: Lib.}
  36. proc pause*(music: PMusic) {.
  37. cdecl, importc: "sfMusic_pause", dynlib: Lib.}
  38. proc stop*(music: PMusic) {.
  39. cdecl, importc: "sfMusic_stop", dynlib: Lib.}
  40. proc getChannelCount*(music: PMusic): cint {.
  41. cdecl, importc: "sfMusic_getChannelCount", dynlib: Lib.}
  42. proc getSampleRate*(music: PMusic): cint {.
  43. cdecl, importc: "sfMusic_getSampleRate", dynlib: Lib.}
  44. proc getStatus*(music: PMusic): TSoundStatus {.
  45. cdecl, importc: "sfMusic_getStatus", dynlib: Lib.}
  46. proc getPlayingOffset*(music: PMusic): TTime {.
  47. cdecl, importc: "sfMusic_getPlayingOffset", dynlib: Lib.}
  48. proc setPitch*(music: PMusic, pitch: cfloat) {.
  49. cdecl, importc: "sfMusic_setPitch", dynlib: Lib.}
  50. proc setVolume*(music: PMusic, volume: float) {.
  51. cdecl, importc: "sfMusic_setVolume", dynlib: Lib.}
  52. proc setPosition*(music: PMusic, position: TVector3f) {.
  53. cdecl, importc: "sfMusic_setPosition", dynlib: Lib.}
  54. proc setRelativeToListener*(music: PMusic, relative: bool) {.
  55. cdecl, importc: "sfMusic_setRelativeToListener", dynlib: Lib.}
  56. proc setMinDistance*(music: PMusic, distance: cfloat) {.
  57. cdecl, importc: "sfMusic_setMinDistance", dynlib: Lib.}
  58. proc setAttenuation*(music: PMusic, attenuation: cfloat) {.
  59. cdecl, importc: "sfMusic_setAttenuation", dynlib: Lib.}
  60. proc setPlayingOffset*(music: PMusic, time: TTime) {.
  61. cdecl, importc: "sfMusic_setPlayingOffset", dynlib: Lib.}
  62. proc getPitch*(music: PMusic): cfloat {.
  63. cdecl, importc: "sfMusic_getPitch", dynlib: Lib.}
  64. proc getVolume*(music: PMusic): cfloat {.
  65. cdecl, importc: "sfMusic_getVolume", dynlib: Lib.}
  66. proc getPosition*(music: PMusic): TVector3f {.
  67. cdecl, importc: "sfMusic_getPosition", dynlib: Lib.}
  68. proc isRelativeToListener*(music: PMusic): bool {.
  69. cdecl, importc: "sfMusic_isRelativeToListener", dynlib: Lib.}
  70. proc getMinDistance*(music: PMusic): cfloat {.
  71. cdecl, importc: "sfMusic_isRelativeToListener", dynlib: Lib.}
  72. proc getAttenuation*(music: PMusic): cfloat {.
  73. cdecl, importc: "sfMusic_isRelativeToListener", dynlib: Lib.}
  74. #/ \brief Create a new sound
  75. proc newSound*(): PSound{.
  76. cdecl, importc: "sfSound_create", dynlib: Lib.}
  77. #//////////////////////////////////////////////////////////
  78. #/ \brief Create a new sound by copying an existing one
  79. #/
  80. #/ \param sound Sound to copy
  81. #/
  82. #/ \return A new sfSound object which is a copy of \a sound
  83. #/
  84. #//////////////////////////////////////////////////////////
  85. proc copy*(sound: PSound): PSound{.
  86. cdecl, importc: "sfSound_copy", dynlib: Lib.}
  87. #//////////////////////////////////////////////////////////
  88. #/ \brief Destroy a sound
  89. proc destroy*(sound: PSound){.
  90. cdecl, importc: "sfSound_destroy", dynlib: Lib.}
  91. #//////////////////////////////////////////////////////////
  92. #/ \brief Start or resume playing a sound
  93. #/
  94. #/ This function starts the sound if it was stopped, resumes
  95. #/ it if it was paused, and restarts it from beginning if it
  96. #/ was it already playing.
  97. #/ This function uses its own thread so that it doesn't block
  98. #/ the rest of the program while the sound is played.
  99. proc play*(sound: PSound){.
  100. cdecl, importc: "sfSound_play", dynlib: Lib.}
  101. #//////////////////////////////////////////////////////////
  102. #/ This function pauses the sound if it was playing,
  103. #/ otherwise (sound already paused or stopped) it has no effect.
  104. proc pause*(sound: PSound){.
  105. cdecl, importc: "sfSound_pause", dynlib: Lib.}
  106. #//////////////////////////////////////////////////////////
  107. #/ This function stops the sound if it was playing or paused,
  108. #/ and does nothing if it was already stopped.
  109. #/ It also resets the playing position (unlike sfSound_pause).
  110. proc stop*(sound: PSound){.
  111. cdecl, importc: "sfSound_stop", dynlib: Lib.}
  112. #//////////////////////////////////////////////////////////
  113. #/ It is important to note that the sound buffer is not copied,
  114. #/ thus the sfSoundBuffer object must remain alive as long
  115. #/ as it is attached to the sound.
  116. proc setBuffer*(sound: PSound; buffer: PSoundBuffer){.
  117. cdecl, importc: "sfSound_setBuffer", dynlib: Lib.}
  118. #//////////////////////////////////////////////////////////
  119. #/ \brief Get the audio buffer attached to a sound
  120. proc getBuffer*(sound: PSound): PSoundBuffer{.
  121. cdecl, importc: "sfSound_getBuffer", dynlib: Lib.}
  122. #//////////////////////////////////////////////////////////
  123. #/ \brief Set whether or not a sound should loop after reaching the end
  124. #/
  125. #/ If set, the sound will restart from beginning after
  126. #/ reaching the end and so on, until it is stopped or
  127. #/ sfSound_setLoop(sound, sfFalse) is called.
  128. #/ The default looping state for sounds is false.
  129. proc setLoop*(sound: PSound; loop: bool){.
  130. cdecl, importc: "sfSound_setLoop", dynlib: Lib.}
  131. #//////////////////////////////////////////////////////////
  132. #/ \brief Tell whether or not a soud is in loop mode
  133. proc getLoop*(sound: PSound): bool {.
  134. cdecl, importc: "sfSound_getLoop", dynlib: Lib.}
  135. #//////////////////////////////////////////////////////////
  136. #/ \brief Get the current status of a sound (stopped, paused, playing)
  137. proc getStatus*(sound: PSound): TSoundStatus{.
  138. cdecl, importc: "sfSound_getStatus", dynlib: Lib.}
  139. #//////////////////////////////////////////////////////////
  140. #/ \brief Set the pitch of a sound
  141. #/
  142. #/ The pitch represents the perceived fundamental frequency
  143. #/ of a sound; thus you can make a sound more acute or grave
  144. #/ by changing its pitch. A side effect of changing the pitch
  145. #/ is to modify the playing speed of the sound as well.
  146. #/ The default value for the pitch is 1.
  147. proc setPitch*(sound: PSound; pitch: cfloat){.
  148. cdecl, importc: "sfSound_setPitch", dynlib: Lib.}
  149. #//////////////////////////////////////////////////////////
  150. #/ \brief Set the volume of a sound
  151. #/
  152. #/ The volume is a value between 0 (mute) and 100 (full volume).
  153. #/ The default value for the volume is 100.
  154. proc setVolume*(sound: PSound; volume: cfloat){.
  155. cdecl, importc: "sfSound_setVolume", dynlib: Lib.}
  156. #//////////////////////////////////////////////////////////
  157. #/ \brief Set the 3D position of a sound in the audio scene
  158. #/
  159. #/ Only sounds with one channel (mono sounds) can be
  160. #/ spatialized.
  161. #/ The default position of a sound is (0, 0, 0).
  162. proc setPosition*(sound: PSound; position: TVector3f){.
  163. cdecl, importc: "sfSound_setPosition", dynlib: Lib.}
  164. #//////////////////////////////////////////////////////////
  165. #/ \brief Make the sound's position relative to the listener or absolute
  166. #/
  167. #/ Making a sound relative to the listener will ensure that it will always
  168. #/ be played the same way regardless the position of the listener.
  169. #/ This can be useful for non-spatialized sounds, sounds that are
  170. #/ produced by the listener, or sounds attached to it.
  171. #/ The default value is false (position is absolute).
  172. proc setRelativeToListener*(sound: PSound; relative: bool){.
  173. cdecl, importc: "sfSound_setRelativeToListener", dynlib: Lib.}
  174. #//////////////////////////////////////////////////////////
  175. #/ \brief Set the minimum distance of a sound
  176. #/
  177. #/ The "minimum distance" of a sound is the maximum
  178. #/ distance at which it is heard at its maximum volume. Further
  179. #/ than the minimum distance, it will start to fade out according
  180. #/ to its attenuation factor. A value of 0 ("inside the head
  181. #/ of the listener") is an invalid value and is forbidden.
  182. #/ The default value of the minimum distance is 1.
  183. proc setMinDistance*(sound: PSound; distance: cfloat){.
  184. cdecl, importc: "sfSound_setMinDistance", dynlib: Lib.}
  185. #//////////////////////////////////////////////////////////
  186. #/ \brief Set the attenuation factor of a sound
  187. #/
  188. #/ The attenuation is a multiplicative factor which makes
  189. #/ the sound more or less loud according to its distance
  190. #/ from the listener. An attenuation of 0 will produce a
  191. #/ non-attenuated sound, i.e. its volume will always be the same
  192. #/ whether it is heard from near or from far. On the other hand,
  193. #/ an attenuation value such as 100 will make the sound fade out
  194. #/ very quickly as it gets further from the listener.
  195. #/ The default value of the attenuation is 1.
  196. proc setAttenuation*(sound: PSound; attenuation: cfloat){.
  197. cdecl, importc: "sfSound_setAttenuation", dynlib: Lib.}
  198. #//////////////////////////////////////////////////////////
  199. #/ \brief Change the current playing position of a sound
  200. #/
  201. #/ The playing position can be changed when the sound is
  202. #/ either paused or playing.
  203. proc setPlayingOffset*(sound: PSound; timeOffset: sfml.TTime){.
  204. cdecl, importc: "sfSound_setPlayingOffset", dynlib: Lib.}
  205. #//////////////////////////////////////////////////////////
  206. #/ \brief Get the pitch of a sound
  207. proc getPitch*(sound: PSound): cfloat{.
  208. cdecl, importc: "sfSound_getPitch", dynlib: Lib.}
  209. #//////////////////////////////////////////////////////////
  210. #/ \brief Get the volume of a sound
  211. proc getVolume*(sound: PSound): cfloat{.
  212. cdecl, importc: "sfSound_getVolume", dynlib: Lib.}
  213. #//////////////////////////////////////////////////////////
  214. #/ \brief Get the 3D position of a sound in the audio scene
  215. proc getPosition*(sound: PSound): TVector3f{.
  216. cdecl, importc: "sfSound_getPosition", dynlib: Lib.}
  217. #//////////////////////////////////////////////////////////
  218. #/ \brief Tell whether a sound's position is relative to the
  219. #/ listener or is absolute
  220. proc isRelativeToListener*(sound: PSound): bool{.
  221. cdecl, importc: "sfSound_isRelativeToListener", dynlib: Lib.}
  222. #//////////////////////////////////////////////////////////
  223. #/ \brief Get the minimum distance of a sound
  224. proc getMinDistance*(sound: PSound): cfloat{.
  225. cdecl, importc: "sfSound_getMinDistance", dynlib: Lib.}
  226. #//////////////////////////////////////////////////////////
  227. #/ \brief Get the attenuation factor of a sound
  228. proc getAttenuation*(sound: PSound): cfloat{.
  229. cdecl, importc: "sfSound_getAttenuation", dynlib: Lib.}
  230. #//////////////////////////////////////////////////////////
  231. #/ \brief Get the current playing position of a sound
  232. proc getPlayingOffset*(sound: PSound): TTime{.
  233. cdecl, importc: "sfSound_getPlayingOffset", dynlib: Lib.}
  234. #//////////////////////////////////////////////////////////
  235. # Headers
  236. #//////////////////////////////////////////////////////////
  237. #//////////////////////////////////////////////////////////
  238. #/ \brief Create a new sound buffer and load it from a file
  239. #/
  240. #/ Here is a complete list of all the supported audio formats:
  241. #/ ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
  242. #/ w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
  243. #/
  244. #/ \param filename Path of the sound file to load
  245. #/
  246. #/ \return A new sfSoundBuffer object (NULL if failed)
  247. #/
  248. #//////////////////////////////////////////////////////////
  249. proc newSoundBuffer*(filename: cstring): PSoundBuffer{.
  250. cdecl, importc: "sfSoundBuffer_createFromFile", dynlib: Lib.}
  251. #//////////////////////////////////////////////////////////
  252. #/ \brief Create a new sound buffer and load it from a file in memory
  253. #/
  254. #/ Here is a complete list of all the supported audio formats:
  255. #/ ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
  256. #/ w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
  257. #/
  258. #/ \param data Pointer to the file data in memory
  259. #/ \param sizeInBytes Size of the data to load, in bytes
  260. #/
  261. #/ \return A new sfSoundBuffer object (NULL if failed)
  262. #/
  263. #//////////////////////////////////////////////////////////
  264. proc newSoundBuffer*(data: pointer; sizeInBytes: cint): PSoundBuffer{.
  265. cdecl, importc: "sfSoundBuffer_createFromMemory", dynlib: Lib.}
  266. #//////////////////////////////////////////////////////////
  267. #/ \brief Create a new sound buffer and load it from a custom stream
  268. #/
  269. #/ Here is a complete list of all the supported audio formats:
  270. #/ ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
  271. #/ w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
  272. #/
  273. #/ \param stream Source stream to read from
  274. #/
  275. #/ \return A new sfSoundBuffer object (NULL if failed)
  276. #/
  277. #//////////////////////////////////////////////////////////
  278. proc newSoundBuffer*(stream: PInputStream): PSoundBuffer{.
  279. cdecl, importc: "sfSoundBuffer_createFromStream", dynlib: Lib.}
  280. #//////////////////////////////////////////////////////////
  281. #/ \brief Create a new sound buffer and load it from an array of samples in memory
  282. #/
  283. #/ The assumed format of the audio samples is 16 bits signed integer
  284. #/ (sfint16).
  285. #/
  286. #/ \param samples Pointer to the array of samples in memory
  287. #/ \param sampleCount Number of samples in the array
  288. #/ \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
  289. #/ \param sampleRate Sample rate (number of samples to play per second)
  290. #/
  291. #/ \return A new sfSoundBuffer object (NULL if failed)
  292. #/
  293. #//////////////////////////////////////////////////////////
  294. proc createFromSamples*(samples: ptr int16; sampleCount: cuint;
  295. channelCount: cuint; sampleRate: cuint): PSoundBuffer{.
  296. cdecl, importc: "sfSoundBuffer_createFromSamples", dynlib: Lib.}
  297. #//////////////////////////////////////////////////////////
  298. #/ \brief Create a new sound buffer by copying an existing one
  299. #/
  300. #/ \param soundBuffer Sound buffer to copy
  301. #/
  302. #/ \return A new sfSoundBuffer object which is a copy of \a soundBuffer
  303. #/
  304. #//////////////////////////////////////////////////////////
  305. proc copy*(soundBuffer: PSoundBuffer): PSoundBuffer{.
  306. cdecl, importc: "sfSoundBuffer_copy", dynlib: Lib.}
  307. #//////////////////////////////////////////////////////////
  308. #/ \brief Destroy a sound buffer
  309. #/
  310. #/ \param soundBuffer Sound buffer to destroy
  311. #/
  312. #//////////////////////////////////////////////////////////
  313. proc destroy*(soundBuffer: PSoundBuffer){.
  314. cdecl, importc: "sfSoundBuffer_destroy", dynlib: Lib.}
  315. #//////////////////////////////////////////////////////////
  316. #/ \brief Save a sound buffer to an audio file
  317. #/
  318. #/ Here is a complete list of all the supported audio formats:
  319. #/ ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
  320. #/ w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
  321. #/
  322. #/ \param soundBuffer Sound buffer object
  323. #/ \param filename Path of the sound file to write
  324. #/
  325. #/ \return sfTrue if saving succeeded, sfFalse if it failed
  326. #/
  327. #//////////////////////////////////////////////////////////
  328. proc saveToFile*(soundBuffer: PSoundBuffer; filename: cstring): bool {.
  329. cdecl, importc: "sfSoundBuffer_saveToFile", dynlib: Lib.}
  330. #//////////////////////////////////////////////////////////
  331. #/ \brief Get the array of audio samples stored in a sound buffer
  332. #/
  333. #/ The format of the returned samples is 16 bits signed integer
  334. #/ (sfint16). The total number of samples in this array
  335. #/ is given by the sfSoundBuffer_getSampleCount function.
  336. #/
  337. #/ \param soundBuffer Sound buffer object
  338. #/
  339. #/ \return Read-only pointer to the array of sound samples
  340. #/
  341. #//////////////////////////////////////////////////////////
  342. proc sfSoundBuffer_getSamples*(soundBuffer: PSoundBuffer): ptr int16{.
  343. cdecl, importc: "sfSoundBuffer_getSamples", dynlib: Lib.}
  344. #//////////////////////////////////////////////////////////
  345. #/ \brief Get the number of samples stored in a sound buffer
  346. #/
  347. #/ The array of samples can be accessed with the
  348. #/ sfSoundBuffer_getSamples function.
  349. proc getSampleCount*(soundBuffer: PSoundBuffer): cint{.
  350. cdecl, importc: "sfSoundBuffer_getSampleCount", dynlib: Lib.}
  351. #//////////////////////////////////////////////////////////
  352. #/ \brief Get the sample rate of a sound buffer
  353. #/
  354. #/ The sample rate is the number of samples played per second.
  355. #/ The higher, the better the quality (for example, 44100
  356. #/ samples/s is CD quality).
  357. proc getSampleRate*(soundBuffer: PSoundBuffer): cuint{.
  358. cdecl, importc: "sfSoundBuffer_getSampleRate", dynlib: Lib.}
  359. #//////////////////////////////////////////////////////////
  360. #/ \brief Get the number of channels used by a sound buffer
  361. #/
  362. #/ If the sound is mono then the number of channels will
  363. #/ be 1, 2 for stereo, etc.
  364. proc getChannelCount*(soundBuffer: PSoundBuffer): cuint{.
  365. cdecl, importc: "sfSoundBuffer_getChannelCount", dynlib: Lib.}
  366. #//////////////////////////////////////////////////////////
  367. #/ \brief Get the total duration of a sound buffer
  368. #/
  369. #/ \param soundBuffer Sound buffer object
  370. #/
  371. #/ \return Sound duration
  372. #/
  373. #//////////////////////////////////////////////////////////
  374. proc getDuration*(soundBuffer: PSoundBuffer): TTime{.
  375. cdecl, importc: "sfSoundBuffer_getDuration", dynlib: Lib.}
  376. #//////////////////////////////////////////////////////////
  377. #/ \brief Change the global volume of all the sounds and musics
  378. #/
  379. #/ The volume is a number between 0 and 100; it is combined with
  380. #/ the individual volume of each sound / music.
  381. #/ The default value for the volume is 100 (maximum).
  382. #/
  383. #/ \param volume New global volume, in the range [0, 100]
  384. #/
  385. #//////////////////////////////////////////////////////////
  386. proc listenerSetGlobalVolume*(volume: cfloat){.
  387. cdecl, importc: "sfListener_setGlobalVolume", dynlib: Lib.}
  388. #//////////////////////////////////////////////////////////
  389. #/ \brief Get the current value of the global volume
  390. #/
  391. #/ \return Current global volume, in the range [0, 100]
  392. #/
  393. #//////////////////////////////////////////////////////////
  394. proc listenerGetGlobalVolume*(): cfloat{.
  395. cdecl, importc: "sfListener_getGlobalVolume", dynlib: Lib.}
  396. #//////////////////////////////////////////////////////////
  397. #/ \brief Set the position of the listener in the scene
  398. #/
  399. #/ The default listener's position is (0, 0, 0).
  400. #/
  401. #/ \param position New position of the listener
  402. #/
  403. #//////////////////////////////////////////////////////////
  404. proc listenerSetPosition*(position: TVector3f){.
  405. cdecl, importc: "sfListener_setPosition", dynlib: Lib.}
  406. #//////////////////////////////////////////////////////////
  407. #/ \brief Get the current position of the listener in the scene
  408. #/
  409. #/ \return The listener's position
  410. #/
  411. #//////////////////////////////////////////////////////////
  412. proc listenerGetPosition*(): TVector3f{.
  413. cdecl, importc: "sfListener_getPosition", dynlib: Lib.}
  414. #//////////////////////////////////////////////////////////
  415. #/ \brief Set the orientation of the listener in the scene
  416. #/
  417. #/ The orientation defines the 3D axes of the listener
  418. #/ (left, up, front) in the scene. The orientation vector
  419. #/ doesn't have to be normalized.
  420. #/ The default listener's orientation is (0, 0, -1).
  421. #/
  422. #/ \param position New direction of the listener
  423. #/
  424. #//////////////////////////////////////////////////////////
  425. proc listenerSetDirection*(orientation: TVector3f){.
  426. cdecl, importc: "sfListener_setDirection", dynlib: Lib.}
  427. #//////////////////////////////////////////////////////////
  428. #/ \brief Get the current orientation of the listener in the scene
  429. #/
  430. #/ \return The listener's direction
  431. #/
  432. #//////////////////////////////////////////////////////////
  433. proc listenerGetDirection*(): TVector3f{.
  434. cdecl, importc: "sfListener_getDirection", dynlib: Lib.}
  435. type
  436. TSoundRecorderStartCallback* = proc (a2: pointer): bool {.cdecl.}
  437. #/< Type of the callback used when starting a capture
  438. TSoundRecorderProcessCallback* = proc(a2: ptr int16; a3: cuint;
  439. a4: pointer): bool {.cdecl.}
  440. #/< Type of the callback used to process audio data
  441. TSoundRecorderStopCallback* = proc (a2: pointer){.cdecl.}
  442. #/< Type of the callback used when stopping a capture
  443. #//////////////////////////////////////////////////////////
  444. #/ \brief Construct a new sound recorder from callback functions
  445. #/
  446. #/ \param onStart Callback function which will be called when a new capture starts (can be NULL)
  447. #/ \param onProcess Callback function which will be called each time there's audio data to process
  448. #/ \param onStop Callback function which will be called when the current capture stops (can be NULL)
  449. #/ \param userData Data to pass to the callback function (can be NULL)
  450. #/
  451. #/ \return A new sfSoundRecorder object (NULL if failed)
  452. #/
  453. #//////////////////////////////////////////////////////////
  454. proc newSoundRecorder*(onStart: TSoundRecorderStartCallback;
  455. onProcess: TSoundRecorderProcessCallback;
  456. onStop: TSoundRecorderStopCallback;
  457. userData: pointer = nil): PSoundRecorder{.
  458. cdecl, importc: "sfSoundRecorder_create", dynlib: Lib.}
  459. #//////////////////////////////////////////////////////////
  460. #/ \brief Destroy a sound recorder
  461. #/
  462. #/ \param soundRecorder Sound recorder to destroy
  463. #/
  464. #//////////////////////////////////////////////////////////
  465. proc destroy*(soundRecorder: PSoundRecorder){.
  466. cdecl, importc: "sfSoundRecorder_destroy", dynlib: Lib.}
  467. #//////////////////////////////////////////////////////////
  468. #/ \brief Start the capture of a sound recorder
  469. #/
  470. #/ The \a sampleRate parameter defines the number of audio samples
  471. #/ captured per second. The higher, the better the quality
  472. #/ (for example, 44100 samples/sec is CD quality).
  473. #/ This function uses its own thread so that it doesn't block
  474. #/ the rest of the program while the capture runs.
  475. #/ Please note that only one capture can happen at the same time.
  476. #/
  477. #/ \param soundRecorder Sound recorder object
  478. #/ \param sampleRate Desired capture rate, in number of samples per second
  479. #/
  480. #//////////////////////////////////////////////////////////
  481. proc start*(soundRecorder: PSoundRecorder; sampleRate: cuint){.
  482. cdecl, importc: "sfSoundRecorder_start", dynlib: Lib.}
  483. #//////////////////////////////////////////////////////////
  484. #/ \brief Stop the capture of a sound recorder
  485. #/
  486. #/ \param soundRecorder Sound recorder object
  487. #/
  488. #//////////////////////////////////////////////////////////
  489. proc stop*(soundRecorder: PSoundRecorder){.
  490. cdecl, importc: "sfSoundRecorder_stop", dynlib: Lib.}
  491. #//////////////////////////////////////////////////////////
  492. #/ \brief Get the sample rate of a sound recorder
  493. #/
  494. #/ The sample rate defines the number of audio samples
  495. #/ captured per second. The higher, the better the quality
  496. #/ (for example, 44100 samples/sec is CD quality).
  497. #/
  498. #/ \param soundRecorder Sound recorder object
  499. #/
  500. #/ \return Sample rate, in samples per second
  501. #/
  502. #//////////////////////////////////////////////////////////
  503. proc getSampleRate*(soundRecorder: PSoundRecorder): cuint{.
  504. cdecl, importc: "sfSoundRecorder_getSampleRate", dynlib: Lib.}
  505. #//////////////////////////////////////////////////////////
  506. #/ \brief Check if the system supports audio capture
  507. #/
  508. #/ This function should always be called before using
  509. #/ the audio capture features. If it returns false, then
  510. #/ any attempt to use sfSoundRecorder will fail.
  511. #/
  512. #/ \return sfTrue if audio capture is supported, sfFalse otherwise
  513. #/
  514. #//////////////////////////////////////////////////////////
  515. proc soundRecorderIsAvailable*(): bool {.
  516. cdecl, importc: "sfSoundRecorder_isAvailable", dynlib: Lib.}
  517. #//////////////////////////////////////////////////////////
  518. #/ \brief Create a new sound buffer recorder
  519. #/
  520. #/ \return A new sfSoundBufferRecorder object (NULL if failed)
  521. #/
  522. #//////////////////////////////////////////////////////////
  523. proc newSoundBufferRecorder*(): PSoundBufferRecorder{.
  524. cdecl, importc: "sfSoundBufferRecorder_create", dynlib: Lib.}
  525. #//////////////////////////////////////////////////////////
  526. #/ \brief Destroy a sound buffer recorder
  527. #/
  528. #/ \param soundBufferRecorder Sound buffer recorder to destroy
  529. #/
  530. #//////////////////////////////////////////////////////////
  531. proc destroy*(soundBufferRecorder: PSoundBufferRecorder){.
  532. cdecl, importc: "sfSoundBufferRecorder_destroy", dynlib: Lib.}
  533. #//////////////////////////////////////////////////////////
  534. #/ \brief Start the capture of a sound recorder recorder
  535. #/
  536. #/ The \a sampleRate parameter defines the number of audio samples
  537. #/ captured per second. The higher, the better the quality
  538. #/ (for example, 44100 samples/sec is CD quality).
  539. #/ This function uses its own thread so that it doesn't block
  540. #/ the rest of the program while the capture runs.
  541. #/ Please note that only one capture can happen at the same time.
  542. #/
  543. #/ \param soundBufferRecorder Sound buffer recorder object
  544. #/ \param sampleRate Desired capture rate, in number of samples per second
  545. #/
  546. #//////////////////////////////////////////////////////////
  547. proc start*(soundBufferRecorder: PSoundBufferRecorder; sampleRate: cuint){.
  548. cdecl, importc: "sfSoundBufferRecorder_start", dynlib: Lib.}
  549. #//////////////////////////////////////////////////////////
  550. #/ \brief Stop the capture of a sound recorder
  551. #/
  552. #/ \param soundBufferRecorder Sound buffer recorder object
  553. #/
  554. #//////////////////////////////////////////////////////////
  555. proc stop*(soundBufferRecorder: PSoundBufferRecorder){.
  556. cdecl, importc: "sfSoundBufferRecorder_stop", dynlib: Lib.}
  557. #//////////////////////////////////////////////////////////
  558. #/ \brief Get the sample rate of a sound buffer recorder
  559. #/
  560. #/ The sample rate defines the number of audio samples
  561. #/ captured per second. The higher, the better the quality
  562. #/ (for example, 44100 samples/sec is CD quality).
  563. #/
  564. #/ \param soundBufferRecorder Sound buffer recorder object
  565. #/
  566. #/ \return Sample rate, in samples per second
  567. #/
  568. #//////////////////////////////////////////////////////////
  569. proc getSampleRate*(soundBufferRecorder: PSoundBufferRecorder): cuint{.
  570. cdecl, importc: "sfSoundBufferRecorder_getSampleRate", dynlib: Lib.}
  571. #//////////////////////////////////////////////////////////
  572. #/ \brief Get the sound buffer containing the captured audio data
  573. #/
  574. #/ The sound buffer is valid only after the capture has ended.
  575. #/ This function provides a read-only access to the internal
  576. #/ sound buffer, but it can be copied if you need to
  577. #/ make any modification to it.
  578. #/
  579. #/ \param soundBufferRecorder Sound buffer recorder object
  580. #/
  581. #/ \return Read-only access to the sound buffer
  582. #/
  583. #//////////////////////////////////////////////////////////
  584. proc getBuffer*(soundBufferRecorder: PSoundBufferRecorder): PSoundBuffer{.
  585. cdecl, importc: "sfSoundBufferRecorder_getBuffer", dynlib: Lib.}
  586. #//////////////////////////////////////////////////////////
  587. #/ \brief defines the data to fill by the OnGetData callback
  588. #/
  589. #//////////////////////////////////////////////////////////
  590. type
  591. PSoundStreamChunk* = ptr TSoundStreamChunk
  592. TSoundStreamChunk*{.pure, final.} = object
  593. samples*: ptr int16 #/< Pointer to the audio samples
  594. sampleCount*: cuint #/< Number of samples pointed by Samples
  595. TSoundStreamGetDataCallback* = proc (a2: PSoundStreamChunk;
  596. a3: pointer): bool{.cdecl.}
  597. #/< Type of the callback used to get a sound stream data
  598. TSoundStreamSeekCallback* = proc (a2: TTime; a3: pointer){.cdecl.}
  599. #/< Type of the callback used to seek in a sound stream
  600. #//////////////////////////////////////////////////////////
  601. #/ \brief Create a new sound stream
  602. #/
  603. #/ \param onGetData Function called when the stream needs more data (can't be NULL)
  604. #/ \param onSeek Function called when the stream seeks (can't be NULL)
  605. #/ \param channelCount Number of channels to use (1 = mono, 2 = stereo)
  606. #/ \param sampleRate Sample rate of the sound (44100 = CD quality)
  607. #/ \param userData Data to pass to the callback functions
  608. #/
  609. #/ \return A new sfSoundStream object
  610. #/
  611. #//////////////////////////////////////////////////////////
  612. proc create*(onGetData: TSoundStreamGetDataCallback; onSeek: TSoundStreamSeekCallback;
  613. channelCount: cuint; sampleRate: cuint; userData: pointer): PSoundStream{.
  614. cdecl, importc: "sfSoundStream_create", dynlib: Lib.}
  615. #//////////////////////////////////////////////////////////
  616. #/ \brief Destroy a sound stream
  617. #/
  618. #/ \param soundStream Sound stream to destroy
  619. #/
  620. #//////////////////////////////////////////////////////////
  621. proc destroy*(soundStream: PSoundStream){.
  622. cdecl, importc: "sfSoundStream_destroy", dynlib: Lib.}
  623. #//////////////////////////////////////////////////////////
  624. #/ \brief Start or resume playing a sound stream
  625. #/
  626. #/ This function starts the stream if it was stopped, resumes
  627. #/ it if it was paused, and restarts it from beginning if it
  628. #/ was it already playing.
  629. #/ This function uses its own thread so that it doesn't block
  630. #/ the rest of the program while the music is played.
  631. #/
  632. #/ \param soundStream Sound stream object
  633. #/
  634. #//////////////////////////////////////////////////////////
  635. proc play*(soundStream: PSoundStream){.
  636. cdecl, importc: "sfSoundStream_play", dynlib: Lib.}
  637. #//////////////////////////////////////////////////////////
  638. #/ \brief Pause a sound stream
  639. #/
  640. #/ This function pauses the stream if it was playing,
  641. #/ otherwise (stream already paused or stopped) it has no effect.
  642. #/
  643. #/ \param soundStream Sound stream object
  644. #/
  645. #//////////////////////////////////////////////////////////
  646. proc pause*(soundStream: PSoundStream){.
  647. cdecl, importc: "sfSoundStream_pause", dynlib: Lib.}
  648. #//////////////////////////////////////////////////////////
  649. #/ \brief Stop playing a sound stream
  650. #/
  651. #/ This function stops the stream if it was playing or paused,
  652. #/ and does nothing if it was already stopped.
  653. #/ It also resets the playing position (unlike sfSoundStream_pause).
  654. #/
  655. #/ \param soundStream Sound stream object
  656. #/
  657. #//////////////////////////////////////////////////////////
  658. proc stop*(soundStream: PSoundStream){.
  659. cdecl, importc: "sfSoundStream_stop", dynlib: Lib.}
  660. #//////////////////////////////////////////////////////////
  661. #/ \brief Get the current status of a sound stream (stopped, paused, playing)
  662. #/
  663. #/ \param soundStream Sound stream object
  664. #/
  665. #/ \return Current status
  666. #/
  667. #//////////////////////////////////////////////////////////
  668. proc getStatus*(soundStream: PSoundStream): TSoundStatus{.
  669. cdecl, importc: "sfSoundStream_getStatus", dynlib: Lib.}
  670. #//////////////////////////////////////////////////////////
  671. #/ \brief Return the number of channels of a sound stream
  672. #/
  673. #/ 1 channel means a mono sound, 2 means stereo, etc.
  674. #/
  675. #/ \param soundStream Sound stream object
  676. #/
  677. #/ \return Number of channels
  678. #/
  679. #//////////////////////////////////////////////////////////
  680. proc getChannelCount*(soundStream: PSoundStream): cuint{.
  681. cdecl, importc: "sfSoundStream_getChannelCount", dynlib: Lib.}
  682. #//////////////////////////////////////////////////////////
  683. #/ \brief Get the sample rate of a sound stream
  684. #/
  685. #/ The sample rate is the number of audio samples played per
  686. #/ second. The higher, the better the quality.
  687. #/
  688. #/ \param soundStream Sound stream object
  689. #/
  690. #/ \return Sample rate, in number of samples per second
  691. #/
  692. #//////////////////////////////////////////////////////////
  693. proc getSampleRate*(soundStream: PSoundStream): cuint{.
  694. cdecl, importc: "sfSoundStream_getSampleRate", dynlib: Lib.}
  695. #//////////////////////////////////////////////////////////
  696. #/ \brief Set the pitch of a sound stream
  697. #/
  698. #/ The pitch represents the perceived fundamental frequency
  699. #/ of a sound; thus you can make a stream more acute or grave
  700. #/ by changing its pitch. A side effect of changing the pitch
  701. #/ is to modify the playing speed of the stream as well.
  702. #/ The default value for the pitch is 1.
  703. #/
  704. #/ \param soundStream Sound stream object
  705. #/ \param pitch New pitch to apply to the stream
  706. #/
  707. #//////////////////////////////////////////////////////////
  708. proc setPitch*(soundStream: PSoundStream; pitch: cfloat){.
  709. cdecl, importc: "sfSoundStream_setPitch", dynlib: Lib.}
  710. #//////////////////////////////////////////////////////////
  711. #/ \brief Set the volume of a sound stream
  712. #/
  713. #/ The volume is a value between 0 (mute) and 100 (full volume).
  714. #/ The default value for the volume is 100.
  715. #/
  716. #/ \param soundStream Sound stream object
  717. #/ \param volume Volume of the stream
  718. #/
  719. #//////////////////////////////////////////////////////////
  720. proc setVolume*(soundStream: PSoundStream; volume: cfloat){.
  721. cdecl, importc: "sfSoundStream_setVolume", dynlib: Lib.}
  722. #//////////////////////////////////////////////////////////
  723. #/ \brief Set the 3D position of a sound stream in the audio scene
  724. #/
  725. #/ Only streams with one channel (mono streams) can be
  726. #/ spatialized.
  727. #/ The default position of a stream is (0, 0, 0).
  728. #/
  729. #/ \param soundStream Sound stream object
  730. #/ \param position Position of the stream in the scene
  731. #/
  732. #//////////////////////////////////////////////////////////
  733. proc setPosition*(soundStream: PSoundStream; position: TVector3f){.
  734. cdecl, importc: "sfSoundStream_setPosition", dynlib: Lib.}
  735. #//////////////////////////////////////////////////////////
  736. #/ \brief Make a sound stream's position relative to the listener or absolute
  737. #/
  738. #/ Making a stream relative to the listener will ensure that it will always
  739. #/ be played the same way regardless the position of the listener.
  740. #/ This can be useful for non-spatialized streams, streams that are
  741. #/ produced by the listener, or streams attached to it.
  742. #/ The default value is false (position is absolute).
  743. #/
  744. #/ \param soundStream Sound stream object
  745. #/ \param relative sfTrue to set the position relative, sfFalse to set it absolute
  746. #/
  747. #//////////////////////////////////////////////////////////
  748. proc setRelativeToListener*(soundStream: PSoundStream; relative: bool){.
  749. cdecl, importc: "sfSoundStream_setRelativeToListener", dynlib: Lib.}
  750. #//////////////////////////////////////////////////////////
  751. #/ \brief Set the minimum distance of a sound stream
  752. #/
  753. #/ The "minimum distance" of a stream is the maximum
  754. #/ distance at which it is heard at its maximum volume. Further
  755. #/ than the minimum distance, it will start to fade out according
  756. #/ to its attenuation factor. A value of 0 ("inside the head
  757. #/ of the listener") is an invalid value and is forbidden.
  758. #/ The default value of the minimum distance is 1.
  759. #/
  760. #/ \param soundStream Sound stream object
  761. #/ \param distance New minimum distance of the stream
  762. #/
  763. #//////////////////////////////////////////////////////////
  764. proc setMinDistance*(soundStream: PSoundStream; distance: cfloat){.
  765. cdecl, importc: "sfSoundStream_setMinDistance", dynlib: Lib.}
  766. #//////////////////////////////////////////////////////////
  767. #/ \brief Set the attenuation factor of a sound stream
  768. #/
  769. #/ The attenuation is a multiplicative factor which makes
  770. #/ the stream more or less loud according to its distance
  771. #/ from the listener. An attenuation of 0 will produce a
  772. #/ non-attenuated stream, i.e. its volume will always be the same
  773. #/ whether it is heard from near or from far. On the other hand,
  774. #/ an attenuation value such as 100 will make the stream fade out
  775. #/ very quickly as it gets further from the listener.
  776. #/ The default value of the attenuation is 1.
  777. #/
  778. #/ \param soundStream Sound stream object
  779. #/ \param attenuation New attenuation factor of the stream
  780. #/
  781. #//////////////////////////////////////////////////////////
  782. proc setAttenuation*(soundStream: PSoundStream; attenuation: cfloat){.
  783. cdecl, importc: "sfSoundStream_setAttenuation", dynlib: Lib.}
  784. #//////////////////////////////////////////////////////////
  785. #/ \brief Change the current playing position of a sound stream
  786. #/
  787. #/ The playing position can be changed when the stream is
  788. #/ either paused or playing.
  789. #/
  790. #/ \param soundStream Sound stream object
  791. #/ \param timeOffset New playing position
  792. #/
  793. #//////////////////////////////////////////////////////////
  794. proc setPlayingOffset*(soundStream: PSoundStream; timeOffset: TTime){.
  795. cdecl, importc: "sfSoundStream_setPlayingOffset", dynlib: Lib.}
  796. #//////////////////////////////////////////////////////////
  797. #/ \brief Set whether or not a sound stream should loop after reaching the end
  798. #/
  799. #/ If set, the stream will restart from beginning after
  800. #/ reaching the end and so on, until it is stopped or
  801. #/ sfSoundStream_setLoop(stream, sfFalse) is called.
  802. #/ The default looping state for sound streams is false.
  803. #/
  804. #/ \param soundStream Sound stream object
  805. #/ \param loop sfTrue to play in loop, sfFalse to play once
  806. #/
  807. #//////////////////////////////////////////////////////////
  808. proc setLoop*(soundStream: PSoundStream; loop: bool){.
  809. cdecl, importc: "sfSoundStream_setLoop", dynlib: Lib.}
  810. #//////////////////////////////////////////////////////////
  811. #/ \brief Get the pitch of a sound stream
  812. #/
  813. #/ \param soundStream Sound stream object
  814. #/
  815. #/ \return Pitch of the stream
  816. #/
  817. #//////////////////////////////////////////////////////////
  818. proc getPitch*(soundStream: PSoundStream): cfloat{.
  819. cdecl, importc: "sfSoundStream_getPitch", dynlib: Lib.}
  820. #//////////////////////////////////////////////////////////
  821. #/ \brief Get the volume of a sound stream
  822. #/
  823. #/ \param soundStream Sound stream object
  824. #/
  825. #/ \return Volume of the stream, in the range [0, 100]
  826. #/
  827. #//////////////////////////////////////////////////////////
  828. proc getVolume*(soundStream: PSoundStream): cfloat{.
  829. cdecl, importc: "sfSoundStream_getVolume", dynlib: Lib.}
  830. #//////////////////////////////////////////////////////////
  831. #/ \brief Get the 3D position of a sound stream in the audio scene
  832. #/
  833. #/ \param soundStream Sound stream object
  834. #/
  835. #/ \return Position of the stream in the world
  836. #/
  837. #//////////////////////////////////////////////////////////
  838. proc getPosition*(soundStream: PSoundStream): TVector3f{.
  839. cdecl, importc: "sfSoundStream_getPosition", dynlib: Lib.}
  840. #//////////////////////////////////////////////////////////
  841. #/ \brief Tell whether a sound stream's position is relative to the
  842. #/ listener or is absolute
  843. #/
  844. #/ \param soundStream Sound stream object
  845. #/
  846. #/ \return sfTrue if the position is relative, sfFalse if it's absolute
  847. #/
  848. #//////////////////////////////////////////////////////////
  849. proc isRelativeToListener*(soundStream: PSoundStream): bool{.
  850. cdecl, importc: "sfSoundStream_isRelativeToListener", dynlib: Lib.}
  851. #//////////////////////////////////////////////////////////
  852. #/ \brief Get the minimum distance of a sound stream
  853. #/
  854. #/ \param soundStream Sound stream object
  855. #/
  856. #/ \return Minimum distance of the stream
  857. #/
  858. #//////////////////////////////////////////////////////////
  859. proc getMinDistance*(soundStream: PSoundStream): cfloat{.
  860. cdecl, importc: "sfSoundStream_getMinDistance", dynlib: Lib.}
  861. #//////////////////////////////////////////////////////////
  862. #/ \brief Get the attenuation factor of a sound stream
  863. #/
  864. #/ \param soundStream Sound stream object
  865. #/
  866. #/ \return Attenuation factor of the stream
  867. #/
  868. #//////////////////////////////////////////////////////////
  869. proc getAttenuation*(soundStream: PSoundStream): cfloat{.
  870. cdecl, importc: "sfSoundStream_getAttenuation", dynlib: Lib.}
  871. #//////////////////////////////////////////////////////////
  872. #/ \brief Tell whether or not a sound stream is in loop mode
  873. #/
  874. #/ \param soundStream Sound stream object
  875. #/
  876. #/ \return sfTrue if the music is looping, sfFalse otherwise
  877. #/
  878. #//////////////////////////////////////////////////////////
  879. proc getLoop*(soundStream: PSoundStream): bool{.
  880. cdecl, importc: "sfSoundStream_getLoop", dynlib: Lib.}
  881. #//////////////////////////////////////////////////////////
  882. #/ \brief Get the current playing position of a sound stream
  883. #/
  884. #/ \param soundStream Sound stream object
  885. #/
  886. #/ \return Current playing position
  887. #/
  888. #//////////////////////////////////////////////////////////
  889. proc getPlayingOffset*(soundStream: PSoundStream): TTime{.
  890. cdecl, importc: "sfSoundStream_getPlayingOffset", dynlib: Lib.}