Open svenskmand opened 1 year ago
Hi @svenskmand, the function signature of SineWave
should stay the same which is:
func SineWave(userdata unsafe.Pointer, stream *C.Uint8, length C.int)
However, you might need to divide the data length by four as C's float is usually four bytes:
n := int(length / 4)
The sample calculation might also need to be modified to:
sample := C.float(math.Sin(phase))
as I'm guessing float audio sample range is only between -1.0 and 1.0.
Go version: 1.20.4 Go-SDL2 version: v0.4.35 SDL2 version: 2.0.20+dfsg-2build1 OS: Ubuntu 22.04 Architecture: 64 Bit
I am trying to follow the example on how to play audio, and the example works fine, but I would really want to use another format than 8 bit sound. How do I use 32 bit floating point?:
I tried simply changing all references to the type
C.Uint8
withC.float
as this should be the 32 bit floating point number in C, and then i changed theFormat
field in theAudioSpec
tosdl.AUDIO_F32SYS
, but unfortunately it does not work, then I just get this segfault when running the program:I have not work with Cgo before so I might be missing something completely trivial. Any help here would be awesome :)