From efeb6058113f163046fadb487d12183bb142d969 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 26 Aug 2021 15:23:07 +0200 Subject: [PATCH] Fix for multi using a sampel with different pitches. --- addon/tools/wav2c.cfg | 0 addon/tools/wav2c.sh | 75 +++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 32 deletions(-) delete mode 100644 addon/tools/wav2c.cfg diff --git a/addon/tools/wav2c.cfg b/addon/tools/wav2c.cfg deleted file mode 100644 index e69de29..0000000 diff --git a/addon/tools/wav2c.sh b/addon/tools/wav2c.sh index d8233b4..6d5d30c 100755 --- a/addon/tools/wav2c.sh +++ b/addon/tools/wav2c.sh @@ -138,10 +138,12 @@ drum_config_t drum_config[NUM_DRUMSET_CONFIG] = { EOF +declare -A converted_files + while IFS= read -r l do declare -A sample - + if [[ "${l:0:1}" == "#" ]] then continue @@ -151,6 +153,7 @@ do sample['class']=`echo "${samplecfg[0]}" | xargs` sample['midinote']=`echo "${samplecfg[1]}" | xargs` sample['name']=`echo "${samplecfg[2]}" | xargs` + sample['data_name']="${sample['name']}" sample['shortname']=`echo "${samplecfg[3]}" | xargs` sample['pitch']=`echo "${samplecfg[4]}" | xargs` sample['pan']=`echo "${samplecfg[5]}" | xargs` @@ -166,37 +169,45 @@ do then # Generate drumset.h - 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_mod=`expr "${sample['len']}" % "${AUDIO_BLOCK_SIZE}"` - fill=`expr "${AUDIO_BLOCK_SIZE}" - "${fill_mod}"` - sample['len']=`expr "${sample['len']}" + "${fill}"` - sample['len']=`expr "${sample['len']}" / 2` - - echo "// Converted from ${sample['filename']}, length = ${sample['len']} bytes" >> "${DRUMSET_H}" - echo "PROGMEM const int8_t ${sample['name']}[] = {" >> "${DRUMSET_H}" - grep "^ " "${TMP}/${basename}.h" >> "${DRUMSET_H}" - - if (( "${fill}" > 0 )) + if [ -z "${converted_files[${sample['filename']}]}" ] 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 + 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_mod=`expr "${sample['len']}" % "${AUDIO_BLOCK_SIZE}"` + fill=`expr "${AUDIO_BLOCK_SIZE}" - "${fill_mod}"` + sample['len']=`expr "${sample['len']}" + "${fill}"` + sample['len']=`expr "${sample['len']}" / 2` + + echo "// Converted from ${sample['filename']}, length = ${sample['len']} bytes" >> "${DRUMSET_H}" + 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 "};" >> "${DRUMSET_H}" + + converted_files["${sample['filename']}"]="${sample['name']},${sample['len']}" + else + sample['data_name']=`echo ${converted_files[${sample['filename']}]} | cut -d"," -f1` + sample['len']=`echo ${converted_files[${sample['filename']}]} | cut -d"," -f2` + fi # Generate drums.h cat >> "${DRUMS_H}" << EOF @@ -204,7 +215,7 @@ do ${sample[class]}, ${sample[midinote]}, "${sample[name]}", - ${sample[name]}, + ${sample[data_name]}, "${sample[shortname]}", ${sample[len]}, ${sample[pitch]},