From 00d5cfc107dfadf6a3476e5e8679e1067e800cee Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sat, 19 Mar 2022 16:23:49 -0400 Subject: Fix buffer size calculation in src/riff.c --- src/riff.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/riff.c b/src/riff.c index d50ed60..a1bb908 100644 --- a/src/riff.c +++ b/src/riff.c @@ -13,7 +13,7 @@ struct _xas_riff { int fd; size_t size, - blksize; + buffer_size; xas_audio_format format; }; @@ -92,9 +92,9 @@ static xas_riff *new_file(const char *path, goto error_fstat; } - riff->file = path; - riff->size = 0; - riff->blksize = st.st_blksize; + riff->file = path; + riff->size = 0; + riff->buffer_size = st.st_blksize / format.channels / format.sample_size; riff->format.channels = format.channels; riff->format.sample_size = format.sample_size; @@ -210,10 +210,9 @@ static xas_riff *open_fd(int fd) { goto error_malloc_riff; } - riff->file = NULL; - riff->fd = fd; - riff->size = 0; - riff->blksize = st.st_blksize; + riff->file = NULL; + riff->fd = fd; + riff->size = 0; riff->format.channels = 0; riff->format.sample_size = 0; @@ -233,6 +232,10 @@ static xas_riff *open_fd(int fd) { goto error_wave_header_parse; } + riff->buffer_size = st.st_blksize + / riff->format.channels + / riff->format.sample_size; + return riff; error_wave_header_parse: @@ -266,9 +269,12 @@ static xas_riff *open_file(const char *path, int flags) { goto error_fstat; } - riff->file = path; - riff->size = 0; - riff->blksize = st.st_blksize; + riff->file = path; + riff->size = 0; + + riff->buffer_size = st.st_blksize + / riff->format.channels + / riff->format.sample_size; riff->format.channels = 0; riff->format.sample_size = 0; @@ -292,6 +298,10 @@ static xas_riff *open_file(const char *path, int flags) { goto error_wave_header_parse; } + riff->buffer_size = st.st_blksize + / riff->format.channels + / riff->format.sample_size; + return riff; error_wave_header_parse: @@ -372,7 +382,7 @@ xas_audio_stream *xas_riff_new_file(const char *path, if ((stream = xas_audio_stream_new_sink((xas_audio_drain)audio_drain, (xas_audio_cleanup)close_file, format, - riff->blksize, + riff->buffer_size, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -380,7 +390,7 @@ xas_audio_stream *xas_riff_new_file(const char *path, if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill, (xas_audio_cleanup)close_file, format, - riff->blksize, + riff->buffer_size, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -407,7 +417,7 @@ xas_audio_stream *xas_riff_open_file(const char *path, int flags) { if ((stream = xas_audio_stream_new_sink((xas_audio_drain)audio_drain, (xas_audio_cleanup)close_file, riff->format, - riff->blksize, + riff->buffer_size, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -415,7 +425,7 @@ xas_audio_stream *xas_riff_open_file(const char *path, int flags) { if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill, (xas_audio_cleanup)close_file, riff->format, - riff->blksize, + riff->buffer_size, riff)) == NULL) { goto error_audio_stream_new_sink; } @@ -441,7 +451,7 @@ xas_audio_stream *xas_riff_open_fd(int fd) { if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill, (xas_audio_cleanup)close_file, riff->format, - riff->blksize, + riff->buffer_size, riff)) == NULL) { goto error_audio_stream_new_sink; } -- cgit v1.2.3