use projectm_pcm_get_max_samples to set buffer size
This commit is contained in:
parent
afb198052e
commit
d59a2859b6
|
@ -117,7 +117,7 @@ func update(m *milkDropWindow) (bool, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
audioData := make([]int16, 2048)
|
audioData := make([]int16, maxSamples(2, 2))
|
||||||
|
|
||||||
err := binary.Read(os.Stdin, binary.LittleEndian, audioData)
|
err := binary.Read(os.Stdin, binary.LittleEndian, audioData)
|
||||||
if err == io.ErrUnexpectedEOF {
|
if err == io.ErrUnexpectedEOF {
|
||||||
|
|
|
@ -31,6 +31,18 @@ import (
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* maxSamples returns the maximum number of audio samples stored by projectm
|
||||||
|
* when passing it audio data, given the number of bytes in one sample and the
|
||||||
|
* number of channels.
|
||||||
|
*/
|
||||||
|
func maxSamples(bytesPerSample uint, numChannels uint) uint {
|
||||||
|
// NOTE: not 100% sure about this, but I think
|
||||||
|
// projectm_pcm_get_max_samples assumes 4 bytes per sample, so we
|
||||||
|
// multiply by 4/bytesPerSample to convert
|
||||||
|
return 4 / bytesPerSample * numChannels * uint(C.projectm_pcm_get_max_samples())
|
||||||
|
}
|
||||||
|
|
||||||
// milkDropWindow represents the window projectm will render visualizations in.
|
// milkDropWindow represents the window projectm will render visualizations in.
|
||||||
type milkDropWindow struct {
|
type milkDropWindow struct {
|
||||||
window *sdl.Window
|
window *sdl.Window
|
||||||
|
|
Loading…
Reference in New Issue