/
audio_gen.go
578 lines (485 loc) · 15.1 KB
/
audio_gen.go
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
package raylib
/*
//Generated 2020-01-21T13:50:21+11:00
#include "raylib.h"
#include <stdlib.h>
#include "go.h"
*/
import "C"
import "unsafe"
//InitAudioDevice : Initialize audio device and context
func InitAudioDevice() {
C.InitAudioDevice()
}
//CloseAudioDevice : Close the audio device and context
func CloseAudioDevice() {
C.CloseAudioDevice()
}
//IsAudioDeviceReady : Check if audio device has been initialized successfully
func IsAudioDeviceReady() bool {
res := C.IsAudioDeviceReady()
return bool(res)
}
//SetMasterVolume : Set master volume (listener)
func SetMasterVolume(volume float32) {
C.SetMasterVolume(C.float(volume))
}
//LoadWave : Load wave data from file
func LoadWave(fileName string) *Wave {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
res := C.LoadWave(cfileName)
retval := newWaveFromPointer(unsafe.Pointer(&res))
RegisterUnloadable(retval)
return retval
}
//LoadSound : Load sound from file
func LoadSound(fileName string) *Sound {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
res := C.LoadSound(cfileName)
retval := newSoundFromPointer(unsafe.Pointer(&res))
RegisterUnloadable(retval)
return retval
}
//LoadSoundFromWave : Load sound from wave data
func LoadSoundFromWave(wave *Wave) *Sound {
cwave := *wave.cptr()
res := C.LoadSoundFromWave(cwave)
retval := newSoundFromPointer(unsafe.Pointer(&res))
RegisterUnloadable(retval)
return retval
}
//Update : Update sound buffer with new data
func (sound *Sound) Update(data unsafe.Pointer, samplesCount int) {
csound := *sound.cptr()
C.UpdateSound(csound, data, C.int(int32(samplesCount)))
}
//UpdateSound : Update sound buffer with new data
//Recommended to use sound.Update(data, samplesCount) instead
func UpdateSound(sound *Sound, data unsafe.Pointer, samplesCount int) {
sound.Update(data, samplesCount)
}
//Unload : Unload wave data
func (wave *Wave) Unload() {
cwave := *wave.cptr()
C.UnloadWave(cwave)
UnregisterUnloadable(wave)
}
//UnloadWave : Unload wave data
//Recommended to use wave.Unload() instead
func UnloadWave(wave *Wave) {
wave.Unload()
}
//Unload : Unload sound
func (sound *Sound) Unload() {
csound := *sound.cptr()
C.UnloadSound(csound)
UnregisterUnloadable(sound)
}
//UnloadSound : Unload sound
//Recommended to use sound.Unload() instead
func UnloadSound(sound *Sound) {
sound.Unload()
}
//Export : Export wave data to file
func (wave *Wave) Export(fileName string) {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
cwave := *wave.cptr()
C.ExportWave(cwave, cfileName)
}
//ExportWave : Export wave data to file
//Recommended to use wave.Export(fileName) instead
func ExportWave(wave *Wave, fileName string) {
wave.Export(fileName)
}
//ExportAsCode : Export wave sample data to code (.h)
func (wave *Wave) ExportAsCode(fileName string) {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
cwave := *wave.cptr()
C.ExportWaveAsCode(cwave, cfileName)
}
//ExportWaveAsCode : Export wave sample data to code (.h)
//Recommended to use wave.ExportAsCode(fileName) instead
func ExportWaveAsCode(wave *Wave, fileName string) {
wave.ExportAsCode(fileName)
}
//Play : Play a sound
func (sound *Sound) Play() {
csound := *sound.cptr()
C.PlaySound(csound)
}
//PlaySound : Play a sound
//Recommended to use sound.Play() instead
func PlaySound(sound *Sound) {
sound.Play()
}
//Stop : Stop playing a sound
func (sound *Sound) Stop() {
csound := *sound.cptr()
C.StopSound(csound)
}
//StopSound : Stop playing a sound
//Recommended to use sound.Stop() instead
func StopSound(sound *Sound) {
sound.Stop()
}
//Pause : Pause a sound
func (sound *Sound) Pause() {
csound := *sound.cptr()
C.PauseSound(csound)
}
//PauseSound : Pause a sound
//Recommended to use sound.Pause() instead
func PauseSound(sound *Sound) {
sound.Pause()
}
//Resume : Resume a paused sound
func (sound *Sound) Resume() {
csound := *sound.cptr()
C.ResumeSound(csound)
}
//ResumeSound : Resume a paused sound
//Recommended to use sound.Resume() instead
func ResumeSound(sound *Sound) {
sound.Resume()
}
//PlayMulti : Play a sound (using multichannel buffer pool)
func (sound *Sound) PlayMulti() {
csound := *sound.cptr()
C.PlaySoundMulti(csound)
}
//PlaySoundMulti : Play a sound (using multichannel buffer pool)
//Recommended to use sound.PlayMulti() instead
func PlaySoundMulti(sound *Sound) {
sound.PlayMulti()
}
//StopSoundMulti : Stop any sound playing (using multichannel buffer pool)
func StopSoundMulti() {
C.StopSoundMulti()
}
//GetSoundsPlaying : Get number of sounds playing in the multichannel
func GetSoundsPlaying() int {
res := C.GetSoundsPlaying()
return int(int32(res))
}
//IsPlaying : Check if a sound is currently playing
func (sound *Sound) IsPlaying() bool {
csound := *sound.cptr()
res := C.IsSoundPlaying(csound)
return bool(res)
}
//IsSoundPlaying : Check if a sound is currently playing
//Recommended to use sound.IsPlaying() instead
func IsSoundPlaying(sound *Sound) bool {
return sound.IsPlaying()
}
//SetVolume : Set volume for a sound (1.0 is max level)
func (sound *Sound) SetVolume(volume float32) {
csound := *sound.cptr()
C.SetSoundVolume(csound, C.float(volume))
}
//SetSoundVolume : Set volume for a sound (1.0 is max level)
//Recommended to use sound.SetVolume(volume) instead
func SetSoundVolume(sound *Sound, volume float32) {
sound.SetVolume(volume)
}
//SetPitch : Set pitch for a sound (1.0 is base level)
func (sound *Sound) SetPitch(pitch float32) {
csound := *sound.cptr()
C.SetSoundPitch(csound, C.float(pitch))
}
//SetSoundPitch : Set pitch for a sound (1.0 is base level)
//Recommended to use sound.SetPitch(pitch) instead
func SetSoundPitch(sound *Sound, pitch float32) {
sound.SetPitch(pitch)
}
//Format : Convert wave data to desired format
func (wave *Wave) Format(sampleRate int, sampleSize int, channels int) {
cwave := wave.cptr()
C.WaveFormat(cwave, C.int(int32(sampleRate)), C.int(int32(sampleSize)), C.int(int32(channels)))
}
//WaveFormat : Convert wave data to desired format
//Recommended to use wave.Format(sampleRate, sampleSize, channels) instead
func WaveFormat(wave *Wave, sampleRate int, sampleSize int, channels int) {
wave.Format(sampleRate, sampleSize, channels)
}
//Copy : Copy a wave to a new wave
func (wave *Wave) Copy() *Wave {
cwave := *wave.cptr()
res := C.WaveCopy(cwave)
retval := newWaveFromPointer(unsafe.Pointer(&res))
RegisterUnloadable(retval)
return retval
}
//WaveCopy : Copy a wave to a new wave
//Recommended to use wave.Copy() instead
func WaveCopy(wave *Wave) *Wave {
return wave.Copy()
}
//Crop : Crop a wave to defined samples range
func (wave *Wave) Crop(initSample int, finalSample int) {
cwave := wave.cptr()
C.WaveCrop(cwave, C.int(int32(initSample)), C.int(int32(finalSample)))
}
//WaveCrop : Crop a wave to defined samples range
//Recommended to use wave.Crop(initSample, finalSample) instead
func WaveCrop(wave *Wave, initSample int, finalSample int) {
wave.Crop(initSample, finalSample)
}
//GetWaveData : Get samples data from wave as a floats array
func GetWaveData(wave Wave) []float32 {
samples := wave.SampleCount * wave.Channels
cwave := *wave.cptr()
res := C.GetWaveData(cwave)
tmpslice := (*[1 << 24]*C.float)(unsafe.Pointer(res))[:samples:samples]
defer C.free(unsafe.Pointer(res))
gostrings := make([]float32, samples)
for i, s := range tmpslice {
gostrings[i] = float32(*s)
}
return gostrings
}
//LoadMusicStream : Load music stream from file
func LoadMusicStream(fileName string) *Music {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
res := C.LoadMusicStream(cfileName)
retval := newMusicFromPointer(unsafe.Pointer(&res))
RegisterUnloadable(retval)
return retval
}
//UnloadStream : Unload music stream
func (music *Music) Unload() {
UnloadMusicStream(music)
}
//UnloadMusicStream : Unload music stream
func UnloadMusicStream(music *Music) {
cmusic := *music.cptr()
C.UnloadMusicStream(cmusic)
UnregisterUnloadable(music)
}
//PlayStream : Start music playing
func (music *Music) PlayStream() {
cmusic := *music.cptr()
C.PlayMusicStream(cmusic)
}
//PlayMusicStream : Start music playing
//Recommended to use music.PlayStream() instead
func PlayMusicStream(music *Music) {
music.PlayStream()
}
//UpdateStream : Updates buffers for music streaming
func (music *Music) UpdateStream() {
cmusic := *music.cptr()
C.UpdateMusicStream(cmusic)
}
//UpdateMusicStream : Updates buffers for music streaming
//Recommended to use music.UpdateStream() instead
func UpdateMusicStream(music *Music) {
music.UpdateStream()
}
//StopStream : Stop music playing
func (music *Music) StopStream() {
cmusic := *music.cptr()
C.StopMusicStream(cmusic)
}
//StopMusicStream : Stop music playing
//Recommended to use music.StopStream() instead
func StopMusicStream(music *Music) {
music.StopStream()
}
//PauseStream : Pause music playing
func (music *Music) PauseStream() {
cmusic := *music.cptr()
C.PauseMusicStream(cmusic)
}
//PauseMusicStream : Pause music playing
//Recommended to use music.PauseStream() instead
func PauseMusicStream(music *Music) {
music.PauseStream()
}
//ResumeStream : Resume playing paused music
func (music *Music) ResumeStream() {
cmusic := *music.cptr()
C.ResumeMusicStream(cmusic)
}
//ResumeMusicStream : Resume playing paused music
//Recommended to use music.ResumeStream() instead
func ResumeMusicStream(music *Music) {
music.ResumeStream()
}
//IsPlaying : Check if music is playing
func (music *Music) IsPlaying() bool {
cmusic := *music.cptr()
res := C.IsMusicPlaying(cmusic)
return bool(res)
}
//IsMusicPlaying : Check if music is playing
//Recommended to use music.IsPlaying() instead
func IsMusicPlaying(music *Music) bool {
return music.IsPlaying()
}
//SetVolume : Set volume for music (1.0 is max level)
func (music *Music) SetVolume(volume float32) {
cmusic := *music.cptr()
C.SetMusicVolume(cmusic, C.float(volume))
}
//SetMusicVolume : Set volume for music (1.0 is max level)
//Recommended to use music.SetVolume(volume) instead
func SetMusicVolume(music *Music, volume float32) {
music.SetVolume(volume)
}
//SetPitch : Set pitch for a music (1.0 is base level)
func (music *Music) SetPitch(pitch float32) {
cmusic := *music.cptr()
C.SetMusicPitch(cmusic, C.float(pitch))
}
//SetMusicPitch : Set pitch for a music (1.0 is base level)
//Recommended to use music.SetPitch(pitch) instead
func SetMusicPitch(music *Music, pitch float32) {
music.SetPitch(pitch)
}
//SetLoopCount : Set music loop count (loop repeats)
func (music *Music) SetLoopCount(count int) {
cmusic := *music.cptr()
C.SetMusicLoopCount(cmusic, C.int(int32(count)))
}
//SetMusicLoopCount : Set music loop count (loop repeats)
//Recommended to use music.SetLoopCount(count) instead
func SetMusicLoopCount(music *Music, count int) {
music.SetLoopCount(count)
}
//GetTimeLength : Get music time length (in seconds)
func (music *Music) GetTimeLength() float32 {
cmusic := *music.cptr()
res := C.GetMusicTimeLength(cmusic)
return float32(res)
}
//GetMusicTimeLength : Get music time length (in seconds)
//Recommended to use music.GetTimeLength() instead
func GetMusicTimeLength(music *Music) float32 {
return music.GetTimeLength()
}
//GetTimePlayed : Get current music time played (in seconds)
func (music *Music) GetTimePlayed() float32 {
cmusic := *music.cptr()
res := C.GetMusicTimePlayed(cmusic)
return float32(res)
}
//GetMusicTimePlayed : Get current music time played (in seconds)
//Recommended to use music.GetTimePlayed() instead
func GetMusicTimePlayed(music *Music) float32 {
return music.GetTimePlayed()
}
//InitAudioStream : Init audio stream (to stream raw audio pcm data)
func InitAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) *AudioStream {
res := C.InitAudioStream(C.uint(sampleRate), C.uint(sampleSize), C.uint(channels))
retval := newAudioStreamFromPointer(unsafe.Pointer(&res))
RegisterUnloadable(retval)
return retval
}
//Update : Update audio stream buffers with data
func (stream *AudioStream) Update(data []float32, samplesCount int) {
cstream := *stream.cptr()
C.UpdateAudioStream(cstream, unsafe.Pointer(&data[0]), C.int(int32(samplesCount)))
}
//UpdateSound : Update audio stream buffers with data
//Recommended to use stream.Update(data, samplesCount) instead
func UpdateAudioStream(stream *AudioStream, data []float32, samplesCount int) {
stream.Update(data, samplesCount)
}
//Unload : Close audio stream and free memory
func (stream *AudioStream) Unload() {
cstream := *stream.cptr()
C.CloseAudioStream(cstream)
}
//CloseAudioStream : Close audio stream and free memory
//Recommended to use stream.Unload() instead
func CloseAudioStream(stream *AudioStream) {
stream.Unload()
}
//IsProcessed : Check if any audio stream buffers requires refill
func (stream *AudioStream) IsProcessed() bool {
cstream := *stream.cptr()
res := C.IsAudioStreamProcessed(cstream)
return bool(res)
}
//IsAudioStreamProcessed : Check if any audio stream buffers requires refill
//Recommended to use stream.IsProcessed() instead
func IsAudioStreamProcessed(stream *AudioStream) bool {
return stream.IsProcessed()
}
//Play : Play audio stream
func (stream *AudioStream) Play() {
cstream := *stream.cptr()
C.PlayAudioStream(cstream)
}
//PlayAudioStream : Play audio stream
//Recommended to use stream.Play() instead
func PlayAudioStream(stream *AudioStream) {
stream.Play()
}
//Pause : Pause audio stream
func (stream *AudioStream) Pause() {
cstream := *stream.cptr()
C.PauseAudioStream(cstream)
}
//PauseAudioStream : Pause audio stream
//Recommended to use stream.Pause() instead
func PauseAudioStream(stream *AudioStream) {
stream.Pause()
}
//Resume : Resume audio stream
func (stream *AudioStream) Resume() {
cstream := *stream.cptr()
C.ResumeAudioStream(cstream)
}
//ResumeAudioStream : Resume audio stream
//Recommended to use stream.Resume() instead
func ResumeAudioStream(stream *AudioStream) {
stream.Resume()
}
//IsPlaying : Check if audio stream is playing
func (stream *AudioStream) IsPlaying() bool {
cstream := *stream.cptr()
res := C.IsAudioStreamPlaying(cstream)
return bool(res)
}
//IsAudioStreamPlaying : Check if audio stream is playing
//Recommended to use stream.IsPlaying() instead
func IsAudioStreamPlaying(stream *AudioStream) bool {
return stream.IsPlaying()
}
//Stop : Stop audio stream
func (stream *AudioStream) Stop() {
cstream := *stream.cptr()
C.StopAudioStream(cstream)
}
//StopAudioStream : Stop audio stream
//Recommended to use stream.Stop() instead
func StopAudioStream(stream *AudioStream) {
stream.Stop()
}
//SetVolume : Set volume for audio stream (1.0 is max level)
func (stream *AudioStream) SetVolume(volume float32) {
cstream := *stream.cptr()
C.SetAudioStreamVolume(cstream, C.float(volume))
}
//SetAudioStreamVolume : Set volume for audio stream (1.0 is max level)
//Recommended to use stream.SetVolume(volume) instead
func SetAudioStreamVolume(stream *AudioStream, volume float32) {
stream.SetVolume(volume)
}
//SetPitch : Set pitch for audio stream (1.0 is base level)
func (stream *AudioStream) SetPitch(pitch float32) {
cstream := *stream.cptr()
C.SetAudioStreamPitch(cstream, C.float(pitch))
}
//SetAudioStreamPitch : Set pitch for audio stream (1.0 is base level)
//Recommended to use stream.SetPitch(pitch) instead
func SetAudioStreamPitch(stream *AudioStream, pitch float32) {
stream.SetPitch(pitch)
}