alsa
alsa copied to clipboard
Write ioctl is not guaranteed to write requested number of frames
https://github.com/yobert/alsa/blob/d079056f5370c525161fa2ec4b72d0dfd5ef48b8/device.go#L256
Hi, sometimes write method write less number of frames, here is how i fixed this:
func (device *Device) write1(buf []byte, frames int) (int, error) {
x := pcm.XferI{
Buf: uintptr(unsafe.Pointer(&buf[0])),
Frames: alsatype.Uframes(frames),
}
err := ioctl(device.fh.Fd(), ioctl_encode_ptr(cmdWrite, &x, cmdPCMWriteIFrames), &x)
written := alsatype.Uframes(frames)
if err == syscall.EAGAIN {
return written, nil
}
return written, err
}
func (device *Device) Write(buf []byte, framesize int) error {
for len(buf) > 0 {
w, err := dev.write1(buf, len(buf)/framesize)
if err != nil {
return err
}
buf = buf[w*framesize:]
}
}
i not going to send PR, please update from this issue,
Regards
PS May be Read can also read less that requested frames ?
Great report! That makes sense. I was hoping it would block until it was able to write as many frames as requested. I'll make a PR for this sometime.