Release: AutoSampler version 2.0

Link to good samples/soundfonts at http://wiki.linuxaudio.org/wiki/free_audio_data

Moderators: MattKingUSA, khz

Post Reply
jeanette_c
Established Member
Posts: 728
Joined: Tue May 12, 2020 5:53 pm
Has thanked: 347 times
Been thanked: 268 times

Release: AutoSampler version 2.0

Post by jeanette_c »

Hey hey,
I've just released my AutoSampler version 2.0:
http://juliencoder.de/sound/autosampler-2.0.zip
It's written in Csound, but you don't need to know it! If you're not frightened to look at text to choose your audio and MIDI setup, you're good to go.
What is an autosampler: it's a tool to play MIDI notes to an external synthesizer and record the audio. So you can turn a patch on your external synth into a convenient software sample library.
Features:
* Mono or stereo sampling
* Configuarable note interval (how many notes in which range to sample)
* support for multiple velocity layers
* support for round robin (record the same note at the same velocity several times, because analogue synthesizers might not play the exact same sound everytime you press the same key)
* automatically create an SFZ file ready to play in LinuxSampler (and most likely others).
This is a rather simple tool, so best suited to naturally decaying sounds (like pianos, plucked sounds, ...). It will record after key release, until audio has decayed below a certain threshold, but it will not (yet?) make a key release sample from that.
Hopefully, someone finds a use for it. :)
Best wishes, Jeanette
--
distro: ArchLinux, DAW: Nama, MIDI sequencer: Midish
All my latest music on https://www.youtube.com/channel/UCMS4rf ... 7jhC1Jnv7g
Albums, patches and Csound on http://juliencoder.de
User avatar
TAERSH
Established Member
Posts: 455
Joined: Mon Feb 03, 2020 6:48 pm
Has thanked: 27 times
Been thanked: 21 times

Re: Release: AutoSampler version 2.0

Post by TAERSH »

Sounds interesting.
Downloaded, will give it a try.
User avatar
TAERSH
Established Member
Posts: 455
Joined: Mon Feb 03, 2020 6:48 pm
Has thanked: 27 times
Been thanked: 21 times

Re: Release: AutoSampler version 2.0

Post by TAERSH »

Hmm,
root# csoundqt
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
0dBFS level = 32768,0
--Csound version 6.10 (double samples) 2018-01-27
[commit: none]
libsndfile-1.0.28
end of score. overall amps: 0,0
overall samples out of range: 0
0 errors in performance
Elapsed time at end of performance: real: 0,000s, CPU: 0,000s
WidgetLayout::loadXmlWidgets Older Widget Format version
DocumentPage::getMacOptions() Option Options: not found!
DocumentPage::applyMacOptions() no Geometry!
<MacOptions> loaded.
CsoundQt::play()...
0dBFS level = 32768,0
--Csound version 6.10 (double samples) 2018-01-27
[commit: none]
libsndfile-1.0.28
csound
-+rtaudio=jack
-iadc
-odac
-+jack_client=autosampler.csd
-+rtmidi=alsaseq
-Mhw:28,0
-Q0
--env:CSNOSTOP=yes
/mnt/sda1/Dateien/Downloads/autosampler/autosampler.csd
Csound compile failed! -1
jeanette_c
Established Member
Posts: 728
Joined: Tue May 12, 2020 5:53 pm
Has thanked: 347 times
Been thanked: 268 times

Re: Release: AutoSampler version 2.0

Post by jeanette_c »

Don't use csoundQt, the program runs without interaction anyway. Just type this into any terminal, even xterm or gterm or possibly using alt+f for the run dialogue:
csound autosampler.csd
Remember to edit autosampler.csd first to set your system defaults at the top and decide what to sample at the bottom.
I hope it works for you!
--
distro: ArchLinux, DAW: Nama, MIDI sequencer: Midish
All my latest music on https://www.youtube.com/channel/UCMS4rf ... 7jhC1Jnv7g
Albums, patches and Csound on http://juliencoder.de
User avatar
TAERSH
Established Member
Posts: 455
Joined: Mon Feb 03, 2020 6:48 pm
Has thanked: 27 times
Been thanked: 21 times

Re: Release: AutoSampler version 2.0

Post by TAERSH »


Running autosampler.csd Terminal output:
root# csound autosampler.csd
0dBFS level = 32768.0
--Csound version 6.10 (double samples) 2018-01-27
[commit: none]
libsndfile-1.0.28
UnifiedCSD: autosampler.csd
STARTING FILE
Creating options
Creating orchestra
closing tag
Creating score
rtmidi: ALSA Raw MIDI module enabled
rtaudio: JACK module enabled

error: syntax error, unexpected T_IDENTB (token "schedulek") from file autosampler.csd (1)
line 124:
>>> schedulek <<<
Parsing failed due to invalid input!
Stopping on parser failure
cannot compile orchestra
end of score. overall amps: 0.0
overall samples out of range: 0
1 errors in performance
root#

My edit of autosampler.csd
; AutoSampler version 2.0
; Written by Jeanette C., find the latest version on:
; http://juliencoder.de
; This software is licensed under the GPL (GNU General Public License)
; version 3 (see COPYING for details).
; Auto sampler for sampling from a MIDI instrument (synthesizer)
; To run this successfully you need to set your appropriate audio and MIDI
; devices. See in the CsOptions section directly below.
; Once you've set up everything simply run it with:
; csound autosampler.csd
<CsoundSynthesizer>
<CsOptions>
; Choose your realtime audio module. Remove the semicolon from the beginning
; of the correct line (ONLY from the beginning!!!)
;-+rtaudio=PortAudio ; All platforms
;-+rtaudio=alsa ; Linux: ALSA (Advanced Linux Sound Architecture)
-+rtaudio=jack ; Linux JACK Audio Connection Kit
;-+rtaudio=mme ; Windows MultiMedia Extension (the Windows standard?)
;-+rtaudio=CoreAudio ; Mac OS standard

; Choose your realtime MIDI module. Rem ove the semicolon from the beginning
; of the correct line
;-+rtmidi=PortMIDI ; All platforms
-+rtmidi=alsa ; Linux (Advanced Linux Sound Architecture)
;-+rtmidi=cmidi ; Mac OS (CoreMidi?)
;-+rtmidi=mme ; Windows MultiMedia Extension
;-+rtmidi=winmm ; Windows

; Choose your MIDI output port
; ALSA will use the hw:card,subdevice format, you can list your ports
; with amidi -l
; if possible this will also show proper names, especially with USB MIDI
; devices.
; All other MIDI modules only use one number, check your desktop multimedia
; control centre, audio-MIDI setup or whereever you can see your devices
; (maybe inside your DAW, if you use one).
-Q hw:2,0,0 ; ALSA format)
;-Q 1 ; format for all others
; Leave these options and go down to sr and nchnls
-d --messagelevel=2 -Ma -o dac -i adc
</CsOptions>
; ==============================================
<CsInstruments>
; sr sets the samplerate, usually either 44100 or 48000Hz.
sr = 44100
ksmps = 1
; nchnls tells Csound how many audio channels your soundcard has.
; 2 should work for every soundcard, but you may have more (18 is excessive!)
nchnls = 2
; Go down to the very bottom to setup the sampler (how many notes, velocity
; layers, etc.)
0dbfs = 1
massign -1, 1
massign -1, 2
massign -1, 3

; Shut down Csound when the work is done
instr Exit
exitnow
endin

; Record a single note at given velocity and length for the specified round
; robin index
; p4 = iMidiNote, p5 = iVelocity, p6 = iRoundRobin, p7 = iLength
; p8 = iCurLayer
instr Record
; Initialise the parameters
iNote init p4
iVelocity init p5
iRoundRobin init p6
iLength init p7
iCurLayer init p8
Sname chnget "AutoSampler.Name"
iStereo = chnget("AutoSampler.Stereo")
iMidiChannel = chnget("AutoSampler.Channel")

; Controls for realtime
kStartTrig init 1
kStopTrig init 0
kStopTrig vdelayk kStartTrig, iLength, (iLength + .1)
kRelease init 0
kRelStart init 0
kNow times
kDone init 0

; Terminate instrument when done
if (kDone == 1) then
turnoff
endif

; Create filename
Sfilename = sprintf("Samples/%s-%d-%d-%d.wav", Sname, iNote, iVelocity, iRoundRobin)

; Set up audio signals and record
aLeft init 0
aRight init 0

if (iStereo == 0) then
aLeft = chnget:a("AutoSampler.Left")
kRms1 = rms(aLeft)
kRms2 init 0
fout(Sfilename, -1, aLeft)
else
aLeft = chnget:a("AutoSampler.Left")
aRight = chnget:a("AutoSampler.Right")
kRms1 = rms(aLeft)
kRms2 = rms(aRight)
fout(Sfilename, -1, aLeft, aRight)
endif

; trigger MIDI, stop MIDI and wait for audio tail to decay
if (kRelease == 0) then
if (kStartTrig == 1) then ; Start note
midiout(144, iMidiChannel, iNote, iVelocity)
endif
if (kStopTrig == 1) then ; Stop note
midiout(128, iMidiChannel, iNote, iVelocity)
kRelease = 1
kRelStart times
endif
else ; Allow audio to decay
if ((kRms1 <.001) && (kRms2 <.001)) then
kDone = 1
chnset(kDone, "AutoSampler.Ready")
schedulek("MakeSFZ", 0, .1, iNote, iVelocity, iRoundRobin, (kNow - kRelStart), iCurLayer)
endif
endif

kStartTrig = 0
endin

; Print the SFZ header
instr MakeHeader
Sname chnget "AutoSampler.Name"
Sfilename = strcat(Sname, ".sfz")

fprints(Sfilename, "// SFZ file generated by Jeanette C's AutoSampler, powered by Csound\n")
fprints(Sfilename, "//==============================================================================\n")
turnoff
endin

; Write an SFZ entry to the file
; p4 = iNote, p5 = iVelocity, p6 = iRobin, p7 = iRelease, p8 = iCurLayer
instr MakeSFZ
; Initialise the parameters
iNote init p4
iVelocity init p5
iRobin init p6
iReleaseTime init p7
iCurLayer init p8
Sname chnget "AutoSampler.Name"

; Get additional data from channels
iRobinStep = chnget:i("AutoSampler.RobinStep")
iDownRange = chnget:i("AutoSampler.Down")
iUpRange = chnget:i("AutoSampler.Up")
iVelLayers = chnget:i("AutoSampler.Layers")

; Calculate values for the SFZ file
if (iNote != chnget:i("AutoSampler.First")) then
iLokey = iNote - iDownRange
else
iLokey = iNote
endif

if (iNote != chnget:i("AutoSampler.Last")) then
iHikey = iNote + iUpRange
else
iHikey = iNote
endif

if ((iCurLayer + 1) == iVelLayers) then
iLovel = 1
else
iLovel = int(127 * (1 - ((iCurLayer + 1) / iVelLayers)))
endif

iLorand = (iRobin -1) * iRobinStep
iHirand = iRobin * iRobinStep

; Create SFZ filename
Sfilename = strcat(Sname, ".sfz")

; Write data to SFZ file
if ((iVelocity == 127) && (iRobin == 1)) then
fprints(Sfilename, "\n<group> amp_veltrack=98\n")
endif
fprints(Sfilename,"<region>\n")
fprints(Sfilename,"sample=Samples\\\\%s-%d-%d-%d.wav\n", Sname, iNote, iVelocity, iRobin)
fprints(Sfilename,"ampeg_release=%f\n", iReleaseTime)
fprints(Sfilename,"lokey=%d\nhikey=%d\npitch_keycenter=%d\n", iLokey, iHikey, iNote)
fprints(Sfilename,"lovel=%d\nhivel=%d\n", iLovel, iVelocity)
if (iRobinStep != 1) then ; we have round robins
fprints(Sfilename,"lorand=%f\nhirand=%f\n", iLorand, iHirand)
endif
fprints(Sfilename, "\n")
turnoff
endin

; The master instrument to auto sample
; p4 = SinstrumentName, p5 = iNoteLength, p6 = iFirstNote, p7 = iLastNote,
; p8 = iNoteStep, p9 = iVelocityLayers, p10 = iRoundRobins
; p11 = iLeftChannel, p12 = iRightChannel(-1 for mono), p13 = iMidiChannel
instr AutoSampler
Sname = strget(p4)
iNoteLength init p5
iFirstNote init p6
iLastNote init p7
iNoteStep init p8
iVelocityLayers init p9
iRoundRobins init p10
iLeftChannel init p11
iRightChannel init p12
iMidiChannel init p13
kVal0 init 0 ; just a 0 for chnset at k-rate

; Set global channels
chn_S("AutoSampler.Name", 3)
chnset(Sname, "AutoSampler.Name")
chn_k("AutoSampler.Channel", 3)
chnset(iMidiChannel, "AutoSampler.Channel")
chn_k("AutoSampler.Ready", 3)
chnset(1, "AutoSampler.Ready") ; needs to be ready for first sampling
chn_k("AutoSampler.Stereo", 3)
chn_k("AutoSampler.First", 3)
chnset(iFirstNote, "AutoSampler.First")
chn_k("AutoSampler.Last", 3)
chnset(iLastNote, "AutoSampler.Last")
chn_k("AutoSampler.Layers", 3)
chnset(iVelocityLayers, "AutoSampler.Layers")
chn_k("AutoSampler.RobinStep", 3)
chnset((1 / iRoundRobins), "AutoSampler.RobinStep")
iDownRange = int(iNoteStep / 2)
chn_k("AutoSampler.Down", 3)
chnset(iDownRange, "AutoSampler.Down")
chn_k("AutoSampler.Up", 3)
chnset((iNoteStep - iDownRange -1), "AutoSampler.Up")

if (iRightChannel == -1) then
chnset(0, "AutoSampler.Stereo")
else
chnset(1, "AutoSampler.Stereo")
endif

; Create Samples folder
iMkdir = system_i(1,"mkdir Samples")

; Write SFZ file header
schedule("MakeHeader", 0, .1)

; Input audio and copy to channels
aLeft init 0
aRight init 0

if (k(iRightChannel) == -1) then
aLeft inch iLeftChannel
chnset(aLeft, "AutoSampler.Left")
else
aLeft, aRight inch iLeftChannel, iRightChannel
chnset(aLeft, "AutoSampler.Left")
chnset(aRight, "AutoSampler.Right")
endif

; Set up variables for looping
kCurNote init iFirstNote
kCurRobin init 1 ; This is encoded into the filename and counted from 1
kCurVelocity init 127
kCurLayer init 0

; Record notes
if (chnget:k("AutoSampler.Ready") == 1) then
chnset(kVal0, "AutoSampler.Ready")
if (kCurNote <= iLastNote) then
printks "\nRecording note %d, round robin %d velocity %d", 1/kr, kCurNote, kCurRobin, kCurVelocity
schedulek("Record", 0, -1, kCurNote, kCurVelocity, kCurRobin, iNoteLength, kCurLayer)
if (kCurRobin < iRoundRobins) then
kCurRobin += 1
else ; check for velocity next
kCurRobin = 1
if (kCurLayer < (iVelocityLayers - 1)) then ; Next Velocity
kCurLayer += 1
kCurVelocity = int(127 * (1 - (kCurLayer / iVelocityLayers)))
else ; Next note
kCurLayer = 0
kCurVelocity = 127
kCurNote += iNoteStep
endif
endif
else ; kCurNote > iLastNote: stop
schedulek("Exit", 0, .1)
;turnoff
endif
endif

; Output the audio live
if (iRightChannel == -1) then
outs(aLeft, aLeft)
else
outs(aLeft, aRight)
endif
endin

</CsInstruments>
; ==============================================
<CsScore>
; Remember: right audio channel = -1 for mono
; p4=Sname p5=iNoteLength, p6=iFirstNote p7=iLastNote p8=iNoteInterval
; p9=iVelocityLayers p10=iRoundRobins
; p11=iLeftAudioChannel p12=iRightAudioChannel p13=iMidiChannel

; Example: sample instrument Saw, hold each note for .2 seconds, sample from note 36 to note 96, sample every 3rd
; key, four velocity layers, two round robins on each velocity, record
; audio from channels 7 and 8 and MIDI channel 1
; Modify the line below, but don't forget to remove the semicolon at the
; beginning.
i"AutoSampler" 0 z "Gtr" .2 36 96 3 4 2 7 8 1
e
</CsScore>
</CsoundSynthesizer>
jeanette_c
Established Member
Posts: 728
Joined: Tue May 12, 2020 5:53 pm
Has thanked: 347 times
Been thanked: 268 times

Re: Release: AutoSampler version 2.0

Post by jeanette_c »

Ah, I'm sorry, your Csound version is apparnetly too old. The schedulek opcode was introduced in January 2020, Csound 6.14 should work.
I'm currently running 6.15 from the ArchLinux repository. Very bad luck. Sorry, after all you've tried that it's a question of the software version. I should include this in the release notes!
--
distro: ArchLinux, DAW: Nama, MIDI sequencer: Midish
All my latest music on https://www.youtube.com/channel/UCMS4rf ... 7jhC1Jnv7g
Albums, patches and Csound on http://juliencoder.de
User avatar
d.healey
Established Member
Posts: 610
Joined: Fri Sep 22, 2017 8:33 pm
Has thanked: 274 times
Been thanked: 100 times

Re: Release: AutoSampler version 2.0

Post by d.healey »

This seems very useful. I'll have to spend some time with it to figure out how to use it but I have a question...

Many years ago I bought some (very expensive) sample libraries that are "trapped" in a proprietary format. It would be great if I could re-record the samples to use in another player. Is it possible using your program to do this?
David Healey
YouTube - Free HISE scripting and sample library dev tutorials
Libre Wave - Freedom respecting instruments and effects.
jeanette_c
Established Member
Posts: 728
Joined: Tue May 12, 2020 5:53 pm
Has thanked: 347 times
Been thanked: 268 times

Re: Release: AutoSampler version 2.0

Post by jeanette_c »

d.healey wrote: Wed Mar 31, 2021 3:49 pm ...
Many years ago I bought some (very expensive) sample libraries that are "trapped" in a proprietary format. It would be great if I could re-record the samples to use in another player. Is it possible using your program to do this?
Principally speaking: yes. If your samples are of naturally decaying sounds or without looping, you can use AutoSampler to re-record them. If you can send MIDI to the other machine.
Theoretically it is also possible to record something from a JACK port, but it would need some adaptation to use anything else besides the soundcard.
Best wishes, Jeanette
--
distro: ArchLinux, DAW: Nama, MIDI sequencer: Midish
All my latest music on https://www.youtube.com/channel/UCMS4rf ... 7jhC1Jnv7g
Albums, patches and Csound on http://juliencoder.de
User avatar
TAERSH
Established Member
Posts: 455
Joined: Mon Feb 03, 2020 6:48 pm
Has thanked: 27 times
Been thanked: 21 times

Re: Release: AutoSampler version 2.0

Post by TAERSH »

Ah, I'm sorry, your Csound version is apparnetly too old.
My OS is from 2018. It seems I can't run any newer version of Csound.
cistaceae
Established Member
Posts: 3
Joined: Tue Dec 31, 2019 8:51 am

Re: Release: AutoSampler version 2.0

Post by cistaceae »

Could you please upload AutoSampler to github? :)

jeanette_c
Established Member
Posts: 728
Joined: Tue May 12, 2020 5:53 pm
Has thanked: 347 times
Been thanked: 268 times

Re: Release: AutoSampler version 2.0

Post by jeanette_c »

Hi @cistaceae , I'll look into that. It will take time though. I have to read up on the complete github stuff and find my key. :) Sorry, I'm a little overworked right now.
Best wishes and thanks for your interest, Jeanette

--
distro: ArchLinux, DAW: Nama, MIDI sequencer: Midish
All my latest music on https://www.youtube.com/channel/UCMS4rf ... 7jhC1Jnv7g
Albums, patches and Csound on http://juliencoder.de
Post Reply