# HG changeset patch # User Mychaela Falconia # Date 1719172757 0 # Node ID e149ca1dd14f4a0f9c6e1cf74ae6ae76515bcf92 # Parent 5cf7818a7d08caf6b2858e3e7a6101419aed812f pcm: implement play-offset command diff -r 5cf7818a7d08 -r e149ca1dd14f pcm/globals.h --- a/pcm/globals.h Sun Jun 23 19:45:52 2024 +0000 +++ b/pcm/globals.h Sun Jun 23 19:59:17 2024 +0000 @@ -18,3 +18,4 @@ void cmd_dmw_on(int argc, char **argv); void cmd_dmw_off(int argc, char **argv); void cmd_play_file(int argc, char **argv); +void cmd_play_offset(int argc, char **argv); diff -r 5cf7818a7d08 -r e149ca1dd14f pcm/pcm_tx.c --- a/pcm/pcm_tx.c Sun Jun 23 19:45:52 2024 +0000 +++ b/pcm/pcm_tx.c Sun Jun 23 19:59:17 2024 +0000 @@ -137,3 +137,60 @@ play_buf_nframes = st.st_size / 160; play_buf_ptr = 0; } + +void cmd_play_offset(int argc, char **argv) +{ + int fd; + struct stat st; + unsigned offset, pre_offset; + + if (argc != 3) { + printf("error: play-offset command needs 2 arguments\n"); + return; + } + if (play_buffer) { + printf("error: file play already in progress\n"); + return; + } + offset = strtoul(argv[2], NULL, 0); + if (offset < 1 || offset > 159) { + printf("error: offset argument out of range\n"); + return; + } + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror(argv[1]); + return; + } + fstat(fd, &st); + if (!S_ISREG(st.st_mode)) { + close(fd); + fprintf(stderr, "error: %s is not a regular file\n", argv[1]); + return; + } + if (!st.st_size) { + close(fd); + fprintf(stderr, "error: %s is an empty file\n", argv[1]); + return; + } + if (st.st_size % 160) { + close(fd); + fprintf(stderr, + "error: size of %s is not a multiple of 160 bytes\n", + argv[1]); + return; + } + play_buffer = malloc(st.st_size + 160); + if (!play_buffer) { + close(fd); + fprintf(stderr, "unable to malloc buffer for %s\n", argv[1]); + return; + } + pre_offset = 160 - offset; + memset(play_buffer, pcm_fill_octet, pre_offset); + read(fd, play_buffer + pre_offset, st.st_size); + close(fd); + memset(play_buffer + pre_offset + st.st_size, pcm_fill_octet, offset); + play_buf_nframes = st.st_size / 160 + 1; + play_buf_ptr = 0; +} diff -r 5cf7818a7d08 -r e149ca1dd14f pcm/user_cmd.c --- a/pcm/user_cmd.c Sun Jun 23 19:45:52 2024 +0000 +++ b/pcm/user_cmd.c Sun Jun 23 19:59:17 2024 +0000 @@ -21,6 +21,7 @@ {"dmw-off", cmd_dmw_off}, {"pcm-fill", cmd_pcm_fill}, {"play", cmd_play_file}, + {"play-offset", cmd_play_offset}, {"print-rx", cmd_print_rx}, {"record", cmd_record_start}, {"record-stop", cmd_record_stop},