Fix for multi using a sampel with different pitches.

pull/98/head
Holger Wirtz 3 years ago
parent 907ba61c4b
commit efeb605811
  1. 0
      addon/tools/wav2c.cfg
  2. 71
      addon/tools/wav2c.sh

@ -138,6 +138,8 @@ drum_config_t drum_config[NUM_DRUMSET_CONFIG] =
{ {
EOF EOF
declare -A converted_files
while IFS= read -r l while IFS= read -r l
do do
declare -A sample declare -A sample
@ -151,6 +153,7 @@ do
sample['class']=`echo "${samplecfg[0]}" | xargs` sample['class']=`echo "${samplecfg[0]}" | xargs`
sample['midinote']=`echo "${samplecfg[1]}" | xargs` sample['midinote']=`echo "${samplecfg[1]}" | xargs`
sample['name']=`echo "${samplecfg[2]}" | xargs` sample['name']=`echo "${samplecfg[2]}" | xargs`
sample['data_name']="${sample['name']}"
sample['shortname']=`echo "${samplecfg[3]}" | xargs` sample['shortname']=`echo "${samplecfg[3]}" | xargs`
sample['pitch']=`echo "${samplecfg[4]}" | xargs` sample['pitch']=`echo "${samplecfg[4]}" | xargs`
sample['pan']=`echo "${samplecfg[5]}" | xargs` sample['pan']=`echo "${samplecfg[5]}" | xargs`
@ -166,37 +169,45 @@ do
then then
# Generate drumset.h # Generate drumset.h
basename=`echo "${sample['filename']}" | cut -d'.' -f1` if [ -z "${converted_files[${sample['filename']}]}" ]
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 then
echo -n "," >> "${DRUMSET_H}" basename=`echo "${sample['filename']}" | cut -d'.' -f1`
fill_counter=0 sox "${WAV_DIR}/${sample['filename']}" -c 1 -b 16 -L "${TMP}/${basename}.raw"
for i in $(seq 1 "${fill}") xxd -i "${TMP}/${basename}.raw" > "${TMP}/${basename}.h"
do sample['len']=`grep "^unsigned int" "${TMP}/${basename}.h" | cut -d"=" -f2 | sed 's/\s*\([0-9]\+\);/\1/'`
echo -n "0x00" >> "${DRUMSET_H}" fill_mod=`expr "${sample['len']}" % "${AUDIO_BLOCK_SIZE}"`
let fill_counter+=1 fill=`expr "${AUDIO_BLOCK_SIZE}" - "${fill_mod}"`
if (( "${fill_counter}" >= 8 )) sample['len']=`expr "${sample['len']}" + "${fill}"`
then sample['len']=`expr "${sample['len']}" / 2`
echo "" >> "${DRUMSET_H}"
fill_counter=0 echo "// Converted from ${sample['filename']}, length = ${sample['len']} bytes" >> "${DRUMSET_H}"
else echo "PROGMEM const int8_t ${sample['name']}[] = {" >> "${DRUMSET_H}"
echo -n ", " >> "${DRUMSET_H}" grep "^ " "${TMP}/${basename}.h" >> "${DRUMSET_H}"
fi
done 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 fi
echo "};" >> /tmp/b
# Generate drums.h # Generate drums.h
cat >> "${DRUMS_H}" << EOF cat >> "${DRUMS_H}" << EOF
@ -204,7 +215,7 @@ do
${sample[class]}, ${sample[class]},
${sample[midinote]}, ${sample[midinote]},
"${sample[name]}", "${sample[name]}",
${sample[name]}, ${sample[data_name]},
"${sample[shortname]}", "${sample[shortname]}",
${sample[len]}, ${sample[len]},
${sample[pitch]}, ${sample[pitch]},

Loading…
Cancel
Save