makesfz.sh - Quick and easy creation of simple .sfz files

Things that make the work with LinuxSampler & Co easier, better, faster, louder and more sexy. Including friends like JACK, ALSA, etc.

makesfz.sh - Quick and easy creation of simple .sfz files

Postby danboid » Sun Jan 01, 2012 2:56 pm

makesfz.sh README, docs, history and code

I needed a way to quickly and easily create simple drum kit .sfz files for use with Linuxsampler. I had found a perl script called makesfz.pl that I failed to get to work and I couldn't find a suitable script or app within these forums or linked to on linuxsampler.org so I wrote the following little bash script that scans for wav files in the current dir then writes out a corresponding .sfz file for every wav found, mapping that sample to MIDI note 0.

Otherwise you can run it like 'makesfz.sh 1' in which case it simply creates one big .sfz named after the containing folder which assigns each sample to a MIDI note ('key'), ascending through the filenames alphabetically and pairing these with a progressively higher MIDI note (Linuxsampler 'key') so it is recommended that you name your files like:

000-kick.wav
001-snare.wav

etc. etc. so you know which sample will be assigned to which key although this isn't a requirement.

I hope others will find this script useful. The LS devs are free to improve and include this script with LS should they wish to do so.

Dan

UPDATES

3rd Jan 2012

Following feedback on LAU I have just updated the script to include the 'loop_mode=one_shot' option and tidied it up a bit too.

23rd Jan 2012

Added command line switch of '1' to create one big sfz, otherwise default to creating one per wav

1st Feb 2012

Added quotes to variables to fix problem when running 'makesfz 1' from a directory with spaces in it

Code: Select all
#!/bin/bash
#
# makesfz.sh
#
# Running 'makesfz.sh' with no or any other parameter than 1 will create a .sfz
# file for every wav file in the present dir. mapping the wav to MIDI note 0.
#
# Alternatively, 'makesfz.sh 1' reads all wav files in the current dir and creates
# a single .sfz named after the present folder mapping each sample to a MIDI note.
#
#
# by Dan MacDonald 2012

key=0

if [ "$1" = "1" ]; then

rm -f "${PWD##*/}".sfz
echo -e "# This file was auto-generated by makesfz.sh\n\n<group>\nloop_mode=one_shot\n" > "${PWD##*/}".sfz

for wavs in *.wav

do
echo -e "<region>\nsample=$wavs\nkey=$key\nlovel=0 hivel=127\n" >> "${PWD##*/}".sfz
key=$(($key+1))
done

else

for wavs in *.wav

do
echo -e "# This file was auto-generated by makesfz.sh\n\n<group>\nloop_mode=one_shot\n" > $wavs.sfz
echo -e "<region>\nsample=$wavs\nkey=0\nlovel=0 hivel=127\n" >> $wavs.sfz
done

fi
Last edited by danboid on Wed Feb 01, 2012 7:23 pm, edited 3 times in total.
danboid
Newbie
 
Posts: 3
Joined: Sun Jan 01, 2012 2:37 pm

Re: makesfz.sh - Quick and easy creation of simple .sfz files

Postby rooz » Thu Jan 19, 2012 10:18 pm

How do you change it for flac (and ogg and mp3)?

How about the MIDI mapping? Now the samples seems to be our of range of my midi keybd...


http://www.midi-hits.com/GM_Drums.html
rooz
Newbie
 
Posts: 15
Joined: Sun Aug 24, 2008 6:42 pm

Re: makesfz.sh - Quick and easy creation of simple .sfz files

Postby danboid » Mon Jan 23, 2012 5:23 am

Updated script

I have edited my OP to include an updated script which now defaults to creating one sfz file for each wav in the present folder. If you wish to create one big sfz file with each wav in the current dir mapped chromatically then you can run it 'makesfz.sh 1' style instead.

rooz:

I don't actually know what sample file formats LS sfz files can use other than wav as it happens. I don't plan on using any other format nor supporting any other format or options (like MIDI mapping) although if I was really stuck for drive space and LS supported it I would consider looking into wavpack lossless compression. As I'm sure you know, OGG and MP3 are lossy codecs and should be avoided in music production where possible.

However, FLAC does make sense to use if you're not recording in 24/32bit float or something (Ardour for one defaults to recording as float wavs iirc) as you should be aware that unlike wavpack (and wav) FLAC can't deal with these types of wavs. So, if LS does support flac all you would need to do is change both

for wavs in *.wav

to

for wavs in *.flac

or whatever other extension LS/sfz supports that you wanted to process.

If having the first wav assigned to MIDI key 0 (which is often C-2) doesn't suit you you just need to change

key=0

or the key value in the line:

echo -e "<region>\nsample=$wavs\nkey=0\nlovel=0 hivel=127\n" >> $wavs.sfz

To whatever key you wish to be the lowest note.

HTH

Dan
danboid
Newbie
 
Posts: 3
Joined: Sun Jan 01, 2012 2:37 pm

Re: makesfz.sh - Quick and easy creation of simple .sfz files

Postby Alex » Fri Feb 24, 2012 1:50 pm

As far as i remember, sfz formats are WAV and Ogg.

Alex.
Alex
Moderator
 
Posts: 316
Joined: Wed Jan 23, 2008 9:08 pm

Re: makesfz.sh - Quick and easy creation of simple .sfz files

Postby funkmuscle » Tue Feb 28, 2012 12:57 am

hey guys, I have the DirectBass FREE samples and I'm trying to make a sfz file using makesfz.sh.

I ran:
Code: Select all
makesfz.sh  1/media/HITACHI/audio/DirectBassFREE/DirectBass2.0FREE/DirectBassFREESamples/


I get this:
Code: Select all
# This file was auto-generated by makesfz.sh

<group>
loop_mode=one_shot

<region>
sample=BD_L1A_02.wav
key=0
lovel=0 hivel=127

<region>
sample=BD_L1A_04.wav
key=1
lovel=0 hivel=127

<region>
sample=BD_L1A_06.wav
key=2
lovel=0 hivel=127

<region>
sample=BD_L1A_09.wav
key=3
lovel=0 hivel=127

<region>
sample=BD_L1A_11.wav
key=4
lovel=0 hivel=127

<region>
sample=BD_L1A_14.wav
key=5
lovel=0 hivel=127

<region>
sample=BD_L1A_16.wav
key=6
lovel=0 hivel=127

<region>
sample=BD_L1A_18.wav
key=7
lovel=0 hivel=127

<region>
sample=BD_L1A_21.wav
key=8
lovel=0 hivel=127

<region>
sample=BD_L1A_23.wav
key=9
lovel=0 hivel=127

<region>
sample=BD_L1A_26.wav
key=10
lovel=0 hivel=127

<region>
sample=BD_L1A_28.wav
key=11
lovel=0 hivel=127

<region>
sample=BD_L1A_30.wav
key=12
lovel=0 hivel=127

<region>
sample=BD_L1A_33.wav
key=13
lovel=0 hivel=127

<region>
sample=BD_L1A_35.wav
key=14
lovel=0 hivel=127

<region>
sample=BD_L1A_38.wav
key=15
lovel=0 hivel=127

<region>
sample=BD_L1A_40.wav
key=16
lovel=0 hivel=127

<region>
sample=BD_L1A_42.wav
key=17
lovel=0 hivel=127

<region>
sample=BD_L1A_45.wav
key=18
lovel=0 hivel=127

<region>
sample=BD_L1B_02.wav
key=19
lovel=0 hivel=127

<region>
sample=BD_L1B_04.wav
key=20
lovel=0 hivel=127

<region>
sample=BD_L1B_06.wav
key=21
lovel=0 hivel=127

<region>
sample=BD_L1B_09.wav
key=22
lovel=0 hivel=127

<region>
sample=BD_L1B_11.wav
key=23
lovel=0 hivel=127

<region>
sample=BD_L1B_14.wav
key=24
lovel=0 hivel=127

<region>
sample=BD_L1B_16.wav
key=25
lovel=0 hivel=127

<region>
sample=BD_L1B_18.wav
key=26
lovel=0 hivel=127

<region>
sample=BD_L1B_21.wav
key=27
lovel=0 hivel=127

<region>
sample=BD_L1B_23.wav
key=28
lovel=0 hivel=127

<region>
sample=BD_L1B_26.wav
key=29
lovel=0 hivel=127

<region>
sample=BD_L1B_28.wav
key=30
lovel=0 hivel=127

<region>
sample=BD_L1B_30.wav
key=31
lovel=0 hivel=127

<region>
sample=BD_L1B_33.wav
key=32
lovel=0 hivel=127

<region>
sample=BD_L1B_35.wav
key=33
lovel=0 hivel=127

<region>
sample=BD_L1B_38.wav
key=34
lovel=0 hivel=127

<region>
sample=BD_L1B_40.wav
key=35
lovel=0 hivel=127

<region>
sample=BD_L1B_42.wav
key=36
lovel=0 hivel=127

<region>
sample=BD_L1B_45.wav
key=37
lovel=0 hivel=127

<region>
sample=BD_L1C_02.wav
key=38
lovel=0 hivel=127

<region>
sample=BD_L1C_04.wav
key=39
lovel=0 hivel=127

<region>
sample=BD_L1C_06.wav
key=40
lovel=0 hivel=127

<region>
sample=BD_L1C_09.wav
key=41
lovel=0 hivel=127

<region>
sample=BD_L1C_11.wav
key=42
lovel=0 hivel=127

<region>
sample=BD_L1C_14.wav
key=43
lovel=0 hivel=127

<region>
sample=BD_L1C_16.wav
key=44
lovel=0 hivel=127

<region>
sample=BD_L1C_18.wav
key=45
lovel=0 hivel=127

<region>
sample=BD_L1C_21.wav
key=46
lovel=0 hivel=127

<region>
sample=BD_L1C_23.wav
key=47
lovel=0 hivel=127

<region>
sample=BD_L1C_26.wav
key=48
lovel=0 hivel=127

<region>
sample=BD_L1C_28.wav
key=49
lovel=0 hivel=127

<region>
sample=BD_L1C_30.wav
key=50
lovel=0 hivel=127

<region>
sample=BD_L1C_33.wav
key=51
lovel=0 hivel=127

<region>
sample=BD_L1C_35.wav
key=52
lovel=0 hivel=127

<region>
sample=BD_L1C_38.wav
key=53
lovel=0 hivel=127

<region>
sample=BD_L1C_40.wav
key=54
lovel=0 hivel=127

<region>
sample=BD_L1C_42.wav
key=55
lovel=0 hivel=127

<region>
sample=BD_L1C_45.wav
key=56
lovel=0 hivel=127

<region>
sample=BD_L1D_02.wav
key=57
lovel=0 hivel=127

<region>
sample=BD_L1D_04.wav
key=58
lovel=0 hivel=127

<region>
sample=BD_L1D_06.wav
key=59
lovel=0 hivel=127

<region>
sample=BD_L1D_09.wav
key=60
lovel=0 hivel=127

<region>
sample=BD_L1D_11.wav
key=61
lovel=0 hivel=127

<region>
sample=BD_L1D_14.wav
key=62
lovel=0 hivel=127

<region>
sample=BD_L1D_16.wav
key=63
lovel=0 hivel=127

<region>
sample=BD_L1D_18.wav
key=64
lovel=0 hivel=127

<region>
sample=BD_L1D_21.wav
key=65
lovel=0 hivel=127

<region>
sample=BD_L1D_23.wav
key=66
lovel=0 hivel=127

<region>
sample=BD_L1D_26.wav
key=67
lovel=0 hivel=127

<region>
sample=BD_L1D_28.wav
key=68
lovel=0 hivel=127

<region>
sample=BD_L1D_30.wav
key=69
lovel=0 hivel=127

<region>
sample=BD_L1D_33.wav
key=70
lovel=0 hivel=127

<region>
sample=BD_L1D_35.wav
key=71
lovel=0 hivel=127

<region>
sample=BD_L1D_38.wav
key=72
lovel=0 hivel=127

<region>
sample=BD_L1D_40.wav
key=73
lovel=0 hivel=127

<region>
sample=BD_L1D_42.wav
key=74
lovel=0 hivel=127

<region>
sample=BD_L1D_45.wav
key=75
lovel=0 hivel=127

<region>
sample=BD_L5A_02.wav
key=76
lovel=0 hivel=127

<region>
sample=BD_L5A_04.wav
key=77
lovel=0 hivel=127

<region>
sample=BD_L5A_06.wav
key=78
lovel=0 hivel=127

<region>
sample=BD_L5A_09.wav
key=79
lovel=0 hivel=127

<region>
sample=BD_L5A_11.wav
key=80
lovel=0 hivel=127

<region>
sample=BD_L5A_14.wav
key=81
lovel=0 hivel=127

<region>
sample=BD_L5A_16.wav
key=82
lovel=0 hivel=127

<region>
sample=BD_L5A_18.wav
key=83
lovel=0 hivel=127

<region>
sample=BD_L5A_21.wav
key=84
lovel=0 hivel=127

<region>
sample=BD_L5A_23.wav
key=85
lovel=0 hivel=127

<region>
sample=BD_L5A_26.wav
key=86
lovel=0 hivel=127

<region>
sample=BD_L5A_28.wav
key=87
lovel=0 hivel=127

<region>
sample=BD_L5A_30.wav
key=88
lovel=0 hivel=127

<region>
sample=BD_L5A_33.wav
key=89
lovel=0 hivel=127

<region>
sample=BD_L5A_35.wav
key=90
lovel=0 hivel=127

<region>
sample=BD_L5A_38.wav
key=91
lovel=0 hivel=127

<region>
sample=BD_L5A_40.wav
key=92
lovel=0 hivel=127

<region>
sample=BD_L5A_42.wav
key=93
lovel=0 hivel=127

<region>
sample=BD_L5A_45.wav
key=94
lovel=0 hivel=127

<region>
sample=BD_L5B_02.wav
key=95
lovel=0 hivel=127

<region>
sample=BD_L5B_04.wav
key=96
lovel=0 hivel=127

<region>
sample=BD_L5B_06.wav
key=97
lovel=0 hivel=127

<region>
sample=BD_L5B_09.wav
key=98
lovel=0 hivel=127

<region>
sample=BD_L5B_11.wav
key=99
lovel=0 hivel=127

<region>
sample=BD_L5B_14.wav
key=100
lovel=0 hivel=127

<region>
sample=BD_L5B_16.wav
key=101
lovel=0 hivel=127

<region>
sample=BD_L5B_18.wav
key=102
lovel=0 hivel=127

<region>
sample=BD_L5B_21.wav
key=103
lovel=0 hivel=127

<region>
sample=BD_L5B_23.wav
key=104
lovel=0 hivel=127

<region>
sample=BD_L5B_26.wav
key=105
lovel=0 hivel=127

<region>
sample=BD_L5B_28.wav
key=106
lovel=0 hivel=127

<region>
sample=BD_L5B_30.wav
key=107
lovel=0 hivel=127

<region>
sample=BD_L5B_33.wav
key=108
lovel=0 hivel=127

<region>
sample=BD_L5B_35.wav
key=109
lovel=0 hivel=127

<region>
sample=BD_L5B_38.wav
key=110
lovel=0 hivel=127

<region>
sample=BD_L5B_40.wav
key=111
lovel=0 hivel=127

<region>
sample=BD_L5B_42.wav
key=112
lovel=0 hivel=127

<region>
sample=BD_L5B_45.wav
key=113
lovel=0 hivel=127

<region>
sample=BD_L5C_02.wav
key=114
lovel=0 hivel=127

<region>
sample=BD_L5C_04.wav
key=115
lovel=0 hivel=127

<region>
sample=BD_L5C_06.wav
key=116
lovel=0 hivel=127

<region>
sample=BD_L5C_09.wav
key=117
lovel=0 hivel=127

<region>
sample=BD_L5C_11.wav
key=118
lovel=0 hivel=127

<region>
sample=BD_L5C_14.wav
key=119
lovel=0 hivel=127

<region>
sample=BD_L5C_16.wav
key=120
lovel=0 hivel=127

<region>
sample=BD_L5C_18.wav
key=121
lovel=0 hivel=127

<region>
sample=BD_L5C_21.wav
key=122
lovel=0 hivel=127

<region>
sample=BD_L5C_23.wav
key=123
lovel=0 hivel=127

<region>
sample=BD_L5C_26.wav
key=124
lovel=0 hivel=127

<region>
sample=BD_L5C_28.wav
key=125
lovel=0 hivel=127

<region>
sample=BD_L5C_30.wav
key=126
lovel=0 hivel=127

<region>
sample=BD_L5C_33.wav
key=127
lovel=0 hivel=127

<region>
sample=BD_L5C_35.wav
key=128
lovel=0 hivel=127

<region>
sample=BD_L5C_38.wav
key=129
lovel=0 hivel=127

<region>
sample=BD_L5C_40.wav
key=130
lovel=0 hivel=127

<region>
sample=BD_L5C_42.wav
key=131
lovel=0 hivel=127

<region>
sample=BD_L5C_45.wav
key=132
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_01.wav
key=133
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_02.wav
key=134
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_04.wav
key=135
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_07.wav
key=136
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_09.wav
key=137
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_12.wav
key=138
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_14.wav
key=139
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_16.wav
key=140
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_19.wav
key=141
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_21.wav
key=142
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_24.wav
key=143
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_26.wav
key=144
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_28.wav
key=145
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_31.wav
key=146
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_33.wav
key=147
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_36.wav
key=148
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_38.wav
key=149
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_40.wav
key=150
lovel=0 hivel=127

<region>
sample=DB_HamON_B+N_42.wav
key=151
lovel=0 hivel=127

<region>
sample=Main 11.wav
key=152
lovel=0 hivel=127

<region>
sample=Main 14.wav
key=153
lovel=0 hivel=127

<region>
sample=Main 16.wav
key=154
lovel=0 hivel=127

<region>
sample=Main 18.wav
key=155
lovel=0 hivel=127

<region>
sample=Main 21.wav
key=156
lovel=0 hivel=127

<region>
sample=Main 23.wav
key=157
lovel=0 hivel=127

<region>
sample=Main 26.wav
key=158
lovel=0 hivel=127

<region>
sample=Main 28.wav
key=159
lovel=0 hivel=127

<region>
sample=Main 2.wav
key=160
lovel=0 hivel=127

<region>
sample=Main 30.wav
key=161
lovel=0 hivel=127

<region>
sample=Main 33.wav
key=162
lovel=0 hivel=127

<region>
sample=Main 35.wav
key=163
lovel=0 hivel=127

<region>
sample=Main 38.wav
key=164
lovel=0 hivel=127

<region>
sample=Main 40.wav
key=165
lovel=0 hivel=127

<region>
sample=Main 42.wav
key=166
lovel=0 hivel=127

<region>
sample=Main 45.wav
key=167
lovel=0 hivel=127

<region>
sample=Main 4.wav
key=168
lovel=0 hivel=127

<region>
sample=Main 6.wav
key=169
lovel=0 hivel=127

<region>
sample=Main 9.wav
key=170
lovel=0 hivel=127

<region>
sample=Rel_01.wav
key=171
lovel=0 hivel=127

<region>
sample=Rel_02.wav
key=172
lovel=0 hivel=127

<region>
sample=Rel_03.wav
key=173
lovel=0 hivel=127

<region>
sample=Rel_04.wav
key=174
lovel=0 hivel=127

<region>
sample=Rel_05.wav
key=175
lovel=0 hivel=127

<region>
sample=Rel_06.wav
key=176
lovel=0 hivel=127

<region>
sample=Rel_07.wav
key=177
lovel=0 hivel=127

<region>
sample=Rel_08.wav
key=178
lovel=0 hivel=127

<region>
sample=Rel_09.wav
key=179
lovel=0 hivel=127

<region>
sample=Rel_10.wav
key=180
lovel=0 hivel=127

<region>
sample=Rel_12.wav
key=181
lovel=0 hivel=127

<region>
sample=Rel_13.wav
key=182
lovel=0 hivel=127

<region>
sample=Rel_14.wav
key=183
lovel=0 hivel=127

<region>
sample=Rel_15.wav
key=184
lovel=0 hivel=127

<region>
sample=Rel_16.wav
key=185
lovel=0 hivel=127

<region>
sample=Rel_17.wav
key=186
lovel=0 hivel=127

<region>
sample=Rel_18.wav
key=187
lovel=0 hivel=127

<region>
sample=Rel_19.wav
key=188
lovel=0 hivel=127

<region>
sample=Rel_20.wav
key=189
lovel=0 hivel=127

<region>
sample=Rel_21.wav
key=190
lovel=0 hivel=127

<region>
sample=Rel_22.wav
key=191
lovel=0 hivel=127

<region>
sample=Rel_23.wav
key=192
lovel=0 hivel=127

<region>
sample=Rel_24.wav
key=193
lovel=0 hivel=127

<region>
sample=Rel_25.wav
key=194
lovel=0 hivel=127

<region>
sample=Rel_26.wav
key=195
lovel=0 hivel=127

<region>
sample=Rel_27.wav
key=196
lovel=0 hivel=127

<region>
sample=Rel_28.wav
key=197
lovel=0 hivel=127

<region>
sample=Rel_29.wav
key=198
lovel=0 hivel=127

<region>
sample=Rel_30.wav
key=199
lovel=0 hivel=127

<region>
sample=Rel_31.wav
key=200
lovel=0 hivel=127

<region>
sample=Rel_32.wav
key=201
lovel=0 hivel=127

<region>
sample=Rel_33.wav
key=202
lovel=0 hivel=127

<region>
sample=Rel_34.wav
key=203
lovel=0 hivel=127

<region>
sample=Rel_35.wav
key=204
lovel=0 hivel=127

<region>
sample=Rel_36.wav
key=205
lovel=0 hivel=127

<region>
sample=Rel_37.wav
key=206
lovel=0 hivel=127

<region>
sample=Rel_38.wav
key=207
lovel=0 hivel=127

<region>
sample=Rel_39.wav
key=208
lovel=0 hivel=127

<region>
sample=Rel_40.wav
key=209
lovel=0 hivel=127

<region>
sample=Rel_41.wav
key=210
lovel=0 hivel=127

<region>
sample=Rel_42.wav
key=211
lovel=0 hivel=127

<region>
sample=Rel_43.wav
key=212
lovel=0 hivel=127



LS will not load that output file..
funkmuscle
Newbie
 
Posts: 1
Joined: Tue Feb 28, 2012 12:50 am

Re: makesfz.sh - Quick and easy creation of simple .sfz files

Postby danboid » Fri Mar 09, 2012 12:24 pm

Hi funkmuscle!

Your command is incorrect as makesfz does not take any paths as arguments, you either run

Code: Select all
makesfz.sh


or

Code: Select all
makesfz.sh 1


In the same folder as all your wavs and the sfz (or sfzs) that the script creates must be located and used from the same directory as the wavs too.
danboid
Newbie
 
Posts: 3
Joined: Sun Jan 01, 2012 2:37 pm


Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest