diff options
author | XANTRONIX Development | 2022-03-19 16:23:49 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-19 16:23:49 -0400 |
commit | 00d5cfc107dfadf6a3476e5e8679e1067e800cee (patch) | |
tree | 572b3466decc564e18bacc3c718c0d86958fd5f1 | |
parent | 94473725d958e91a97bba36b3133790b8f15d715 (diff) | |
download | xas-00d5cfc107dfadf6a3476e5e8679e1067e800cee.tar.gz xas-00d5cfc107dfadf6a3476e5e8679e1067e800cee.tar.bz2 xas-00d5cfc107dfadf6a3476e5e8679e1067e800cee.zip |
Fix buffer size calculation in src/riff.cmain
-rw-r--r-- | src/riff.c | 42 |
1 files changed, 26 insertions, 16 deletions
@@ -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; } |