package main import "github.com/veandco/go-sdl2/sdl" /* #cgo CFLAGS: -I/home/nick/Downloads/include #cgo LDFLAGS: -L/home/nick/.local/lib -lprojectM-4 #include "projectM-4/projectM.h" #include */ import "C" import ( "encoding/binary" "io" "os" "time" "unsafe" ) func main() { windowWidth := 800 windowHeight := 600 err := sdl.Init(sdl.INIT_VIDEO) if err != nil { panic(err) } defer sdl.Quit() window, err := sdl.CreateWindow("milkbucket", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, int32(windowWidth), int32(windowHeight), sdl.WINDOW_OPENGL) if err != nil { panic(err) } defer window.Destroy() context, err := window.GLCreateContext() if err != nil { panic(err) } defer sdl.GLDeleteContext(context) handle := C.projectm_create() if handle == nil { panic("nil") } defer C.projectm_destroy(handle) C.projectm_set_window_size(handle, C.ulong(windowWidth), C.ulong(windowHeight)) preset := C.CString("/usr/share/projectM/presets/presets_stock/Zylot - Wisps.milk") defer C.free(unsafe.Pointer(preset)) C.projectm_load_preset_file(handle, preset, false) const bufSize uint = 2048 running := true for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { case *sdl.QuitEvent: running = false break } } var audioData [bufSize]int16 err = binary.Read(os.Stdin, binary.LittleEndian, &audioData) if err == io.ErrUnexpectedEOF { running = false break } else if err != nil { panic(err) } C.projectm_pcm_add_int16(handle, (*C.int16_t)(&audioData[0]), C.uint(bufSize), C.PROJECTM_STEREO) C.projectm_opengl_render_frame(handle) window.GLSwap() time.Sleep(1 / 60 * time.Second) } }