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