From 21062ae57dac9cea5a6a7dd28522ed3c166e64d7 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Thu, 30 Aug 2018 00:24:59 -0400 Subject: [PATCH] Tools used to process some raw audio data. --- tools/TSPspeech.raw.sh | 14 ++++++++ tools/chopper.c | 82 ++++++++++++++++++++++++++++++++++++++++++ tools/noise-chopper.c | 60 +++++++++++++++++++++++++++++++ tools/sounds.raw.sh | 11 ++++++ 4 files changed, 167 insertions(+) create mode 100755 tools/TSPspeech.raw.sh create mode 100644 tools/chopper.c create mode 100644 tools/noise-chopper.c create mode 100755 tools/sounds.raw.sh diff --git a/tools/TSPspeech.raw.sh b/tools/TSPspeech.raw.sh new file mode 100755 index 0000000..d5e744a --- /dev/null +++ b/tools/TSPspeech.raw.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +[ -d TSPspeech ] || ( + mkdir -p TSPspeech + cd TSPspeech + 7z x ../TSPspeech.iso +) +for i in `seq -w 01 10` +do + for j in TSPspeech/48k/*/*$i.wav + do + [ ! -e "$j" ] || ffmpeg -i "$j" -f s16le -ac 1 -ar 48000 - + done +done > TSPspeech.raw diff --git a/tools/chopper.c b/tools/chopper.c new file mode 100644 index 0000000..c794c5c --- /dev/null +++ b/tools/chopper.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018 Gregor Richards + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define CHOP_SZ 384000 + +int main(int argc, char **argv) +{ + int *fds; + int i; + ssize_t rd, total; + short buf[CHOP_SZ]; + + fds = malloc((argc-1)*sizeof(int)); + if (fds == NULL) { + perror("malloc"); + exit(1); + } + + /* Open each file */ + for (i = 1; i < argc; i++) { + int fd = open(argv[i], O_RDONLY); + if (fd < 0) { + perror(argv[i]); + exit(1); + } + fds[i-1] = fd; + } + + /* Loop over the input */ + while (1) { + char haveInput = 0; + + /* Loop over each file */ + for (i = 0; i < argc - 1; i++) { + int fd = fds[i]; + if (fd < 0) continue; + haveInput = 1; + + /* Take an appropriate chunk */ + total = 0; + while (total < sizeof(buf)) { + rd = read(fd, ((char *) buf) + total, sizeof(buf) - total); + if (rd <= 0) { + close(fd); + fds[i] = -1; + break; + } + total += rd; + } + if (total == 0 || (total%sizeof(short)) != 0) + continue; + + /* Write it out */ + write(1, buf, total); + } + + /* Stop if they were all ended */ + if (!haveInput) + break; + } + + return 0; +} diff --git a/tools/noise-chopper.c b/tools/noise-chopper.c new file mode 100644 index 0000000..0d42b49 --- /dev/null +++ b/tools/noise-chopper.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018 Gregor Richards + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#define TOTAL_SZ (10000000LL * 480) + +int main(int argc, char **argv) +{ + FILE *fh; + int i; + short *buf = NULL; + long perFileSz = TOTAL_SZ / (argc-1); + long fileSz; + size_t rd; + + buf = malloc(perFileSz * sizeof(short)); + if (!buf) { + perror("malloc"); + return 1; + } + + /* Loop over the input */ + for (i = 1; i < argc; i++) { + /* Seek to the middle */ + fh = fopen(argv[i], "rb"); + fseek(fh, 0, SEEK_END); + fileSz = ftell(fh) / sizeof(short); + if (fileSz > perFileSz) + fseek(fh, (fileSz / 2 - perFileSz / 2) * sizeof(short), SEEK_SET); + else + fseek(fh, 0, SEEK_SET); + + /* Read it in */ + rd = fread(buf, sizeof(short), perFileSz, fh); + fclose(fh); + + /* And write it out */ + write(1, buf, rd * sizeof(short)); + } + + return 0; +} diff --git a/tools/sounds.raw.sh b/tools/sounds.raw.sh new file mode 100755 index 0000000..401469f --- /dev/null +++ b/tools/sounds.raw.sh @@ -0,0 +1,11 @@ +#!/bin/sh +for i in cough laugh +do + touch $i.raw + SZ=`wc -c $i.raw | cut -d' ' -f1` + while [ "$SZ" -lt 300000000 ] + do + cat $i/*.raw >> $i.raw + SZ=`wc -c $i.raw | cut -d' ' -f1` + done +done