audio/internal/readerdriver: Bug fix: Need to align the buffer size

This commit is contained in:
Hajime Hoshi 2021-04-20 02:39:33 +09:00
parent e650e71d8c
commit 24dc20e80e

View File

@ -124,7 +124,11 @@ func (c *contextImpl) Close() error {
// oneBufferSize returns the size of one buffer in the player implementation. // oneBufferSize returns the size of one buffer in the player implementation.
func (c *contextImpl) oneBufferSize() int { func (c *contextImpl) oneBufferSize() int {
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4 bytesPerSample := c.channelNum * c.bitDepthInBytes
s := c.sampleRate * bytesPerSample / 4
// Align s in multiples of bytes per sample, or a buffer could have extra bytes.
return s / bytesPerSample * bytesPerSample
} }
// maxBufferSize returns the maximum size of the buffer for the audio source. // maxBufferSize returns the maximum size of the buffer for the audio source.