parent
21d79308f4
commit
a18fe8f830
@ -0,0 +1,23 @@ |
||||
#!/bin/bash |
||||
|
||||
WAV2SKETCH="${HOME}/Arduino-Teensy/MicroDexed/third-party/wav2sketch" |
||||
|
||||
if [ ! -e "${WAV2SKETCH}" ] |
||||
then |
||||
gcc "${HOME}/Arduino-Teensy/MicroDexed/third-party/wav2sketch.c" -o "${WAV2SKETCH}" |
||||
chmod 700 "${WAV2SKETCH}" |
||||
fi |
||||
|
||||
"${WAV2SKETCH}" -16 |
||||
|
||||
rm *.h |
||||
rm -f drumset.h |
||||
touch drumset.h |
||||
|
||||
for i in `ls -1 *.cpp` |
||||
do |
||||
echo "# ${i}" >> drumset.h |
||||
cat "${i}" | grep '^[A-Za-z0-9]' >> drumset.h |
||||
echo "" >> drumset.h |
||||
rm "${i}" |
||||
done |
@ -0,0 +1,3 @@ |
||||
# class, midinote, name, shortname, pitch, pan, vol_max, vol_min, reverb_send, filename |
||||
DRUM_BASS,MIDI_A2,Xrhitom,B,0.0,0.0,0.8,0.0,0.0,bd01.wav |
||||
DRUM_BASS,MIDI_AIS2,Vl1lbeep,B,0.0,0.0,0.8,0.0,0.0,bd02.wav |
@ -0,0 +1,139 @@ |
||||
#!/bin/bash |
||||
# |
||||
# Converter for WAV to C Header |
||||
# Used for MicroDexed sampler |
||||
# |
||||
# (c) 2021 Holger Wirtz |
||||
# |
||||
|
||||
SOX=`which sox` |
||||
XXD=`which xxd` |
||||
TMP="/tmp/wav2c" |
||||
AUDIO_BLOCK_SIZE=128 |
||||
DRUMSET_H="drumset.h" |
||||
|
||||
function cleanexit() |
||||
{ |
||||
#rm -rf "${TMP}" |
||||
echo -n "" |
||||
} |
||||
|
||||
trap cleanexit EXIT |
||||
|
||||
if [ -z "${SOX}" ] |
||||
then |
||||
echo "Cannot find 'sox' in your PATH." >&2 |
||||
exit 100 |
||||
fi |
||||
|
||||
if [ -z "${XXD}" ] |
||||
then |
||||
echo "Cannot find 'xxd' in your PATH." >&2 |
||||
exit 101 |
||||
fi |
||||
|
||||
POSITIONAL=() |
||||
while [[ $# -gt 0 ]]; do |
||||
key="$1" |
||||
|
||||
case $key in |
||||
-c|--config) |
||||
CONFIG="$2" |
||||
shift # past argument |
||||
shift # past value |
||||
;; |
||||
-w|--wavs) |
||||
WAV_DIR="$2" |
||||
shift # past argument |
||||
shift # past value |
||||
;; |
||||
# -t|--test) |
||||
# TEST="true" |
||||
# shift # past argument |
||||
# ;; |
||||
*) # unknown option |
||||
POSITIONAL+=("$1") # save it in an array for later |
||||
shift # past argument |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
if [ ! -f "${CONFIG}" ] |
||||
then |
||||
echo "Cannot find configuration file." >&2 |
||||
exit 200 |
||||
fi |
||||
|
||||
if [ ! -d "${WAV_DIR}" ] |
||||
then |
||||
echo "Cannot find folder for WAV files." >&2 |
||||
exit 201 |
||||
fi |
||||
|
||||
if (( `ls "${WAV_DIR}" | wc -l` == 0 )) |
||||
then |
||||
echo "Cannot find any file in ${WAV_DIR}." >&2 |
||||
exit 202 |
||||
fi |
||||
|
||||
mkdir -p "${TMP}" |
||||
rm -f "${DRUMSET_H}" |
||||
|
||||
while IFS= read -r l |
||||
do |
||||
declare -A sample |
||||
|
||||
if [[ "${l:0:1}" == "#" ]] |
||||
then |
||||
continue |
||||
fi |
||||
IFS=',' read -ra samplecfg <<< "${l}" |
||||
|
||||
sample['class']="${samplecfg[0]}" |
||||
sample['midi_note']="${samplecfg[1]}" |
||||
sample['name']="${samplecfg[2]}" |
||||
sample['shortname']="${samplecfg[3]}" |
||||
sample['pitch']="${samplecfg[4]}" |
||||
sample['pan']="${samplecfg[5]}" |
||||
sample['vol_max']="${samplecfg[6]}" |
||||
sample['vol_min']="${samplecfg[7]}" |
||||
sample['reverb_send']="${samplecfg[8]}" |
||||
sample['filename']="${samplecfg[9]}" |
||||
|
||||
if [ -f "${WAV_DIR}/${sample['filename']}" ] |
||||
then |
||||
file "${WAV_DIR}/${sample['filename']}" | grep -i -q "WAVE audio" |
||||
if [ "${?}" == 0 ] |
||||
then |
||||
basename=`echo "${sample['filename']}" | cut -d'.' -f1` |
||||
sox "${WAV_DIR}/${sample['filename']}" -c 1 -b 16 -L "${TMP}/${basename}.raw" |
||||
xxd -i "${TMP}/${basename}.raw" > "${TMP}/${basename}.h" |
||||
sample['len']=`grep "^unsigned int" "${TMP}/${basename}.h" | cut -d"=" -f2 | sed 's/\s*\([0-9]\+\);/\1/'` |
||||
fill=`expr "${sample['len']}" % "${AUDIO_BLOCK_SIZE}"` |
||||
|
||||
echo "PROGMEM const int8_t ${sample['name']}[] = {" >> "${DRUMSET_H}" |
||||
grep "^ " "${TMP}/${basename}.h" >> "${DRUMSET_H}" |
||||
|
||||
if (( "${fill}" > 0 )) |
||||
then |
||||
echo -n "," >> "${DRUMSET_H}" |
||||
fill_counter=0 |
||||
for i in $(seq 1 "${fill}") |
||||
do |
||||
echo -n "0x00" >> "${DRUMSET_H}" |
||||
let fill_counter+=1 |
||||
if (( "${fill_counter}" >= 8 )) |
||||
then |
||||
echo "" >> "${DRUMSET_H}" |
||||
fill_counter=0 |
||||
else |
||||
echo -n ", " >> "${DRUMSET_H}" |
||||
fi |
||||
done |
||||
fi |
||||
echo "};" >> /tmp/b |
||||
fi |
||||
else |
||||
echo "File \'${WAV_DIR}/${sample['filename']}\' does not exits." >&2 |
||||
fi |
||||
done < "${CONFIG}" |
Loading…
Reference in new issue