From 07c8dc2123270f88622ec2d543b844367d500362 Mon Sep 17 00:00:00 2001 From: dvdli Date: Wed, 28 Oct 2020 22:15:21 +0800 Subject: initialize silence_size to zero --- utils/tinyplay.c | 1 + 1 file changed, 1 insertion(+) (limited to 'utils') diff --git a/utils/tinyplay.c b/utils/tinyplay.c index 20dd7e8..8b01a1d 100644 --- a/utils/tinyplay.c +++ b/utils/tinyplay.c @@ -59,6 +59,7 @@ void cmd_init(struct cmd *cmd) cmd->config.rate = 48000; cmd->config.format = PCM_FORMAT_S16_LE; cmd->config.silence_threshold = 1024 * 2; + cmd->config.silence_size = 0; cmd->config.stop_threshold = 1024 * 2; cmd->config.start_threshold = 1024; cmd->bits = 16; -- cgit v1.2.3 From c0c5e7534011a9a3d64b74e0f20a3417fbbbc290 Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 29 Oct 2020 15:32:35 +0800 Subject: AOSP CL "tinyalsa: fix typos in tinyplay and asoundlib.h" commit f451f433520fc154de6e371747f21d2f746da83b author Glenn Kasten tinyalsa: fix typos in tinyplay and asoundlib.h Test: run tinyplay and look for typos in the output Change-Id: Ieedcc1b7610700aa3d5ff913d5c01105db2c1601 --- utils/tinyplay.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/tinyplay.c b/utils/tinyplay.c index 8b01a1d..c006acc 100644 --- a/utils/tinyplay.c +++ b/utils/tinyplay.c @@ -376,8 +376,10 @@ int sample_is_playable(const struct cmd *cmd) can_play = check_param(params, PCM_PARAM_RATE, cmd->config.rate, "sample rate", "hz"); can_play &= check_param(params, PCM_PARAM_CHANNELS, cmd->config.channels, "sample", " channels"); can_play &= check_param(params, PCM_PARAM_SAMPLE_BITS, cmd->bits, "bits", " bits"); - can_play &= check_param(params, PCM_PARAM_PERIOD_SIZE, cmd->config.period_size, "period size", ""); - can_play &= check_param(params, PCM_PARAM_PERIODS, cmd->config.period_count, "period count", ""); + can_play &= check_param(params, PCM_PARAM_PERIOD_SIZE, cmd->config.period_size, "period size", + " frames"); + can_play &= check_param(params, PCM_PARAM_PERIODS, cmd->config.period_count, "period count", + " frames"); pcm_params_free(params); -- cgit v1.2.3 From ee63fc9a456215d88de45881565b7dae71eafb48 Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 29 Oct 2020 18:31:55 +0800 Subject: check whether the audio data are still enough to play reference: https://android.googlesource.com/platform/external/tinyalsa/+/8b7274b2ec686c87673bf39328381acbdea1a333 commit 8b7274b2ec686c87673bf39328381acbdea1a333 author Haynes Mathew George tinyplay: play PCM up to size specified in the header tinyplay plays to the end of file without checking whether playback goes beyond end of data section which its size is specified in the RIFF wave header. This could lead to playing out unwanted data which is placed at the end of file. authored-by: Patrick Lai Change-Id: I17bd3f6ebca4813f8987585472208c1f52696cae --- utils/tinyplay.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'utils') diff --git a/utils/tinyplay.c b/utils/tinyplay.c index c006acc..f6762a0 100644 --- a/utils/tinyplay.c +++ b/utils/tinyplay.c @@ -389,13 +389,14 @@ int sample_is_playable(const struct cmd *cmd) int play_sample(struct ctx *ctx) { char *buffer; - int size; - int num_read; + size_t buffer_size = pcm_frames_to_bytes(ctx->pcm, pcm_get_buffer_size(ctx->pcm)); + size_t num_read = 0; + size_t remaining_data_size = ctx->chunk_header.sz; + size_t read_size = 0; - size = pcm_frames_to_bytes(ctx->pcm, pcm_get_buffer_size(ctx->pcm)); - buffer = malloc(size); + buffer = malloc(buffer_size); if (!buffer) { - fprintf(stderr, "unable to allocate %d bytes\n", size); + fprintf(stderr, "unable to allocate %zu bytes\n", buffer_size); return -1; } @@ -403,15 +404,17 @@ int play_sample(struct ctx *ctx) signal(SIGINT, stream_close); do { - num_read = fread(buffer, 1, size, ctx->file); + read_size = remaining_data_size > buffer_size ? buffer_size : remaining_data_size; + num_read = fread(buffer, 1, read_size, ctx->file); if (num_read > 0) { if (pcm_writei(ctx->pcm, buffer, pcm_bytes_to_frames(ctx->pcm, num_read)) < 0) { fprintf(stderr, "error playing sample\n"); break; } + remaining_data_size -= num_read; } - } while (!close && num_read > 0); + } while (!close && num_read > 0 && remaining_data_size > 0); pcm_wait(ctx->pcm, -1); -- cgit v1.2.3 From 877ccaf02b773ad7b995bacbfba8e1bdfe11b00d Mon Sep 17 00:00:00 2001 From: dvdli Date: Thu, 29 Oct 2020 18:38:53 +0800 Subject: AOSP CL "tinymix: fix setting enum str started with digits" https://android.googlesource.com/platform/external/tinyalsa/+/f2d93a540297e75815eeb6644bf675cdae3be909 commit f2d93a540297e75815eeb6644bf675cdae3be909 author HW Lee tinymix: fix setting enum str started with digits For those value strings which are started with digits, they must be set as enum instead of index value. Test: with mixer control values started with digits like '48KHz' Change-Id: I1c70f5613a48d020d3248b71c1e4384f83e33d25 Signed-off-by: HW Lee --- utils/tinymix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/tinymix.c b/utils/tinymix.c index fdb774c..41ca269 100644 --- a/utils/tinymix.c +++ b/utils/tinymix.c @@ -146,6 +146,16 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } +static int isnumber(const char *str) { + char *end; + + if (str == NULL || strlen(str) == 0) + return 0; + + strtol(str, &end, 0); + return strlen(end) == 0; +} + static void tinymix_list_controls(struct mixer *mixer, int print_all) { struct mixer_ctl *ctl; @@ -201,7 +211,7 @@ static void tinymix_detail_control(struct mixer *mixer, const char *control) int ret; char *buf = NULL; - if (isdigit(control[0])) + if (isnumber(control)) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); @@ -469,7 +479,7 @@ static int tinymix_set_value(struct mixer *mixer, const char *control, struct mixer_ctl *ctl; enum mixer_ctl_type type; - if (isdigit(control[0])) + if (isnumber(control)) ctl = mixer_get_ctl(mixer, atoi(control)); else ctl = mixer_get_ctl_by_name(mixer, control); -- cgit v1.2.3