read stdin

This commit is contained in:
filifa 2024-08-22 21:23:53 -05:00
parent a9a6211521
commit c709e012bf
1 changed files with 14 additions and 0 deletions

14
main.go
View File

@ -10,6 +10,8 @@ import "github.com/veandco/go-sdl2/sdl"
import "C" import "C"
import ( import (
"bufio"
"os"
"time" "time"
) )
@ -40,6 +42,8 @@ func main() {
C.projectm_set_window_size(handle, 800, 600) C.projectm_set_window_size(handle, 800, 600)
reader := bufio.NewReader(os.Stdin)
running := true running := true
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
@ -51,6 +55,16 @@ func main() {
} }
} }
audioData := make([]byte, 4096)
n, err := reader.Read(audioData)
if err != nil {
panic(err)
}
ptr := C.CBytes(audioData)
C.projectm_pcm_add_float(handle, (*C.float)(ptr), C.uint(n / C.sizeof_float), C.PROJECTM_STEREO)
C.projectm_opengl_render_frame(handle) C.projectm_opengl_render_frame(handle)
window.GLSwap() window.GLSwap()
time.Sleep(1 / 60 * time.Second) time.Sleep(1 / 60 * time.Second)