aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordvdli <dvdli@google.com>2020-11-02 15:56:45 +0800
committerdvdli <dvdli@google.com>2020-11-02 15:56:45 +0800
commitfb0ab77cd593c318ba0b3a941864342553df9301 (patch)
tree29def9b548c1867a95161b5c15e309491c9fe514
parent4bbffd5c6223f8e11cf2e81b8ac9fb9cacf040fa (diff)
modify the buffer size to the period size to avoid underrun
-rw-r--r--utils/tinyplay.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/utils/tinyplay.c b/utils/tinyplay.c
index f6762a0..4f603ee 100644
--- a/utils/tinyplay.c
+++ b/utils/tinyplay.c
@@ -389,11 +389,18 @@ int sample_is_playable(const struct cmd *cmd)
int play_sample(struct ctx *ctx)
{
char *buffer;
- size_t buffer_size = pcm_frames_to_bytes(ctx->pcm, pcm_get_buffer_size(ctx->pcm));
+ size_t buffer_size = 0;
size_t num_read = 0;
size_t remaining_data_size = ctx->chunk_header.sz;
size_t read_size = 0;
+ const struct pcm_config *config = pcm_get_config(ctx->pcm);
+ if (config == NULL) {
+ fprintf(stderr, "unable to get pcm config\n");
+ return -1;
+ }
+
+ buffer_size = pcm_frames_to_bytes(ctx->pcm, config->period_size);
buffer = malloc(buffer_size);
if (!buffer) {
fprintf(stderr, "unable to allocate %zu bytes\n", buffer_size);