get rid of bufSize

This commit is contained in:
filifa 2024-09-05 22:21:12 -05:00
parent 23cb23de15
commit 3882ffe4f7
1 changed files with 7 additions and 7 deletions

View File

@ -24,6 +24,7 @@ package cmd
import "C"
import (
"bufio"
"container/ring"
"encoding/binary"
"errors"
@ -34,16 +35,13 @@ import (
"github.com/veandco/go-sdl2/sdl"
)
// bufSize is the size of the buffer to store data from stdin. NOTE: this might
// need tuning.
const bufSize uint = 2048
// milkDropWindow represents the window projectm will render visualizations in.
type milkDropWindow struct {
window *sdl.Window
context sdl.GLContext
handle C.projectm_handle
preset *ring.Ring
buffer *bufio.Reader
}
/*
@ -85,6 +83,8 @@ func newMilkDropWindow(width, height int32, presets []string) (*milkDropWindow,
m.setupPresets(presets)
m.buffer = bufio.NewReader(os.Stdin)
m.window, err = sdl.CreateWindow("milkbucket", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, width, height, sdl.WINDOW_OPENGL|sdl.WINDOW_RESIZABLE)
if err != nil {
return &m, err
@ -131,16 +131,16 @@ func (m *milkDropWindow) loadPreset(smooth bool) {
* It returns a bool for if the program should keep running and an error.
*/
func (m *milkDropWindow) render() (bool, error) {
var audioData [bufSize]int16
audioData := make([]int16, m.buffer.Size()/2)
err := binary.Read(os.Stdin, binary.LittleEndian, &audioData)
err := binary.Read(m.buffer, binary.LittleEndian, audioData)
if err == io.ErrUnexpectedEOF {
return false, nil
} else if err != nil {
return true, err
}
C.projectm_pcm_add_int16(m.handle, (*C.int16_t)(&audioData[0]), C.uint(bufSize), C.PROJECTM_STEREO)
C.projectm_pcm_add_int16(m.handle, (*C.int16_t)(&audioData[0]), C.uint(len(audioData)), C.PROJECTM_STEREO)
C.projectm_opengl_render_frame(m.handle)
m.window.GLSwap()