This time I wanted to add support for sound through SDL_Audio, so I came up with a decent square-wave generator and started using this Go-SDL fork for audio output.
Problem: SDL audio works with samples or callbacks, and my samples are generated on the fly, being simple PC-buzzer-like sounds.
Strangely enough, that Go-SDL package I found uses a very complex architecture of mutexes and hard-coded hacks to simulate possibility of sending audio synchronously from Go, and only continuous streaming is supported, no custom samples playing, although the API fingerprint seems like it could support it.
Without continuous playback, my game was condemned to display
ALSA lib pcm.c:7339:(snd_pcm_recover) underrun occurredfrom time to time during gameplay. And that sucks.
|The cage of Love where Go|
is currently held prisoner without
proper support of C integration
runtime: cgo callback on thread not created by Go.I digged a bit and found out the reason behind it, basically Go language is not (yet) that well-integrated with C language.
runtime: signal received on thread not created by Go.
However, thanks to Roger Peppe's callback package it is possible to use C callbacks in Go, like Gordon K. did for PortAudio. It is a hack, but a nice one.
At this point I was going to use PortAudio because it already uses that callback package, but PortAudio has an extra "feature": incredible garbage in the console terminal, and that was not going to be bearable for my little ncurses game.
So I armed my fingers and started coding a fix, here's the result:
PC-speaker buzz sound simulator, for all you nostalgic BEEP guys :)
Talk about how much you can learn with a such a simple game :)
At the end of this coding adventure I have to agree with Otstol that it is a huge limitation (to usage&adoption) that Go! language does not sport better callbacks support. I am quite sure all these fireworks will soon be obsolete because the Go Authors will fix this ;)
* = the game in question is Langwar, my battering ram used to discover the Go! language and also bring back what I recognize with some nostalgia as a classic game useful for learning programming
Update 16 June 2013: thanks to G. Klaus for letting me know about Go having fixed the issue, I have now updated my fork of Go-SDL