@echo off
mkdir .\temp
copy .\tools\meta\*.* .\temp
cls
echo #######################################
echo # E-mu Drumulator ROM Encoder v0.60 #
echo #######################################
echo.
echo Conforming samplerate and lengths...
echo.
rem -- all length must be 7 samples shorter than given in metadata!!
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\clave.wav .\temp\clave_rt.wav rate 22050 channels 1 fade p 2s 1960s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\cowbell.wav .\temp\cowbell_rt.wav rate 22050 channels 1 fade p 2s 2733s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\claps.wav .\temp\claps_rt.wav rate 22050 channels 1 fade p 2s 3725s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\openhat.wav .\temp\openhat_rt.wav rate 22050 channels 1 fade p 2s 8665s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\cl_hat.wav .\temp\cl_hat_rt.wav rate 22050 channels 1 fade p 2s 2505s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\cymbal.wav .\temp\cymbal_rt.wav rate 22050 channels 1 fade p 2s 16364s 500s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\kick.wav .\temp\kick_rt.wav rate 22050 channels 1 fade p 2s 1536s 5s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\snare.wav .\temp\snare_rt.wav rate 22050 channels 1 fade p 2s 3212s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\rimshot.wav .\temp\rimshot_rt.wav rate 22050 channels 1 fade p 2s 2329s 5s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\hi_tom.wav .\temp\hi_tom_rt.wav rate 22050 channels 1 fade p 2s 6011s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\mid_tom.wav .\temp\mid_tom_rt.wav rate 22050 channels 1 fade p 2s 7182s 50s
.\tools\sox\sox.exe -V1 -D --norm=-0.3 .\drum_hits\low_tom.wav .\temp\low_tom_rt.wav rate 22050 channels 1 fade p 2s 9140s 50s
echo Dithering and converting WAVs into mu-law data...
echo.
.\tools\soxdither\sox.exe -V1 .\temp\clave_rt.wav --encoding mu-law .\temp\clave.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\cowbell_rt.wav --encoding mu-law .\temp\cowbell.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\claps_rt.wav --encoding mu-law .\temp\claps.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\openhat_rt.wav --encoding mu-law .\temp\openhat.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\cl_hat_rt.wav --encoding mu-law .\temp\cl_hat.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\cymbal_rt.wav --encoding mu-law .\temp\cymbal.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\kick_rt.wav --encoding mu-law .\temp\kick.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\snare_rt.wav --encoding mu-law .\temp\snare.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\rimshot_rt.wav --encoding mu-law .\temp\rimshot.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\hi_tom_rt.wav --encoding mu-law .\temp\hi_tom.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\mid_tom_rt.wav --encoding mu-law .\temp\mid_tom.raw dither -r
.\tools\soxdither\sox.exe -V1 .\temp\low_tom_rt.wav --encoding mu-law .\temp\low_tom.raw dither -r

echo Padding against disaster...
cd temp
COPY /B lead_4.raw + clave.raw + trail_3.raw clave.pad >NUL
COPY /B lead_4.raw + cowbell.raw + trail_3.raw cowbell.pad >NUL
COPY /B lead_4.raw + claps.raw + trail_3.raw claps.pad >NUL
COPY /B lead_4.raw + openhat.raw + trail_3.raw openhat.pad >NUL
COPY /B lead_4.raw + cl_hat.raw + trail_3.raw cl_hat.pad >NUL
COPY /B lead_4.raw + cymbal.raw + trail_3.raw cymbal.pad >NUL
COPY /B lead_4.raw + kick.raw + trail_3.raw kick.pad >NUL
COPY /B lead_4.raw + snare.raw + trail_3.raw snare.pad >NUL
COPY /B lead_4.raw + rimshot.raw + trail_3.raw rimshot.pad >NUL
COPY /B lead_4.raw + hi_tom.raw + trail_3.raw hi_tom.pad >NUL
COPY /B lead_4.raw + mid_tom.raw + trail_3.raw mid_tom.pad >NUL
COPY /B lead_4.raw + low_tom.raw + trail_3.raw low_tom.pad >NUL
echo.
echo Creating sub-sections...
copy /B mid_tom.pad + low_tom.pad rom_b.sub >NUL
copy /B openhat.pad + cl_hat.pad + snare.pad + clave.pad rom_c.sub >NUL
copy /B hi_tom.pad + kick.pad + rimshot.pad + claps.pad + cowbell.pad rom_d.sub >NUL
cd..
echo.
echo Inverting mu-Law values for proper signing...
.\tools\srec_cat .\temp\cymbal.pad -raw -xor 0xFF -o .\temp\rom_a.inv -raw
.\tools\srec_cat .\temp\rom_b.sub -raw -xor 0xFF -o .\temp\rom_b.inv -raw
.\tools\srec_cat .\temp\rom_c.sub -raw -xor 0xFF -o .\temp\rom_c.inv -raw
.\tools\srec_cat .\temp\rom_d.sub -raw -xor 0xFF -o .\temp\rom_d.inv -raw
echo.
echo Merging into final ROMs...
cd temp
copy /B sr_header.bin + rom_a.inv + end_A.bin NEW_A.BIN >NUL
copy /B sr_header.bin + rom_b.inv + end_B.bin NEW_B.BIN >NUL
copy /B sr_header.bin + rom_c.inv + end_C.bin NEW_C.BIN >NUL
copy /B sr_header.bin + rom_d.inv + end_D.bin NEW_D.BIN >NUL
move NEW_?.BIN .. >NUL
cd ..
copy .\OS_ROMs\OSv30.BIN NEW_OS.BIN >NUL
echo.
echo E-mu Drumulator custom sound ROM creation complete!
echo.
echo The four resulting files should each be 16,384 bytes exactly or the process 
echo has failed somewhere in the chain. It is advisable to verify this before 
echo burning or distributing any created ROMs.
echo.
echo If the stock program ROM is already installed then it is not necessary to 
echo change it, as the standard format encoder maintains the same sample structure.
echo.
pause
rmdir /s /q .\temp