commit b31459f962a4c6c1724cfb8142176bc502276de1 Author: ugrnm Date: Tue Sep 17 11:56:03 2019 +0200 script to automate sample.h creation diff --git a/utils/samplify.sh b/utils/samplify.sh new file mode 100755 index 0000000..1ab1692 --- /dev/null +++ b/utils/samplify.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Prepares a sample.h file +# sed not used, should just werk (TM) everywhere +# Usage: ./samplify.sh my_sample.wav +# Or you can install samplify.sh in your ~/bin and call it +# from anywhere you like + +# Convert original soundfile and create sample.h +# A temp file is needed otherwise xxd is unable to generate +# sample length information? +# Need to fix that later... +sox "${1}" -t u8 -c 1 -r 8000 /tmp/sample.wav +xxd -i /tmp/sample.wav > sample.h +rm /tmp/sample.wav + +# Extract sample length +SAMPLE_LEN=$(tail -1 sample.h | cut -d ' ' -f 5 | tr -d ';') + +# Inject SAMPLE_LEN in new file header +NEW_HEADER="#define SAMPLE_RATE 8000 +const int sound_length=${SAMPLE_LEN}; +const unsigned char sound_data[] PROGMEM= {" + +# Remove first line of sample.h +echo "$(tail -n +2 sample.h)" > sample.h + +# Prepend new header to sample.h +echo "$(echo "${NEW_HEADER}"; cat sample.h)" > sample.h