read data as int16

This commit is contained in:
filifa 2024-08-22 22:27:04 -05:00
parent b9257adf5f
commit e5172787a1
1 changed files with 6 additions and 6 deletions

12
main.go
View File

@ -11,6 +11,7 @@ import "C"
import ( import (
"bufio" "bufio"
"encoding/binary"
"os" "os"
"time" "time"
) )
@ -42,7 +43,7 @@ func main() {
C.projectm_set_window_size(handle, 800, 600) C.projectm_set_window_size(handle, 800, 600)
preset := C.CString("/usr/share/projectM/presets/presets_projectM/Unchained - ReAwoke.milk") preset := C.CString("/usr/share/projectM/presets/presets_stock/Zylot - Wisps.milk")
C.projectm_load_preset_file(handle, preset, false) C.projectm_load_preset_file(handle, preset, false)
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
@ -58,15 +59,14 @@ func main() {
} }
} }
audioData := make([]byte, 4096) audioData := make([]int16, 4096)
n, err := reader.Read(audioData)
err = binary.Read(reader, binary.LittleEndian, audioData)
if err != nil { if err != nil {
panic(err) panic(err)
} }
ptr := C.CBytes(audioData) C.projectm_pcm_add_int16(handle, (*C.int16_t)(&audioData[0]), C.uint(len(audioData)), C.PROJECTM_STEREO)
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()