Clamps Packages
cl-sfz
cl-sfz implements the basic infrastructure to deal with SFZ definitions. The SFZ format was developed in the context of software samplers. Like the sf2 format it defines a mapping of pitched samples to the keynums of a software synthesizer. If a sample is mapped to more than one keynum, the desired pitch is achieved by changing the playback speed of the sample.
The SFZ format uses a plain text file to define keynum regions and their samples in addition to the base keynum, a pitch offset and an amplitude of the recording and other playback information1.
<region> sample=samples/p200-piano-d3-l-.wav lokey=35 hikey=38 pitch_keycenter=38 pan=-100 ampeg_hold=2.80079 ampeg_decay=44.9941 ampeg_sustain=0.001 offset=0 end=193115 loop_start=158947 loop_end=193110
When loading a sfz file, Clamps parses this information from the file and creates an array of 128 lists containing lsample structs as a lookup table for the 128 keynums. A lsample struct holds the name of the sample, its loaded buffer, a oneshot flag indicating whether to play back the lsample once or using the loop points, the keynum of the buffer adjusted to the pitch-offset of the sfz entry, the amplitude in dB of the sample and its start- and endpoints for looping. Clamps keeps a list of lsample structs for each keynum, as the sfz format allows the mapping of more than one sample to the same keynum. When playing back an sfz entry, Clamps will randomly select the sample to use from this list.
(first (aref (get-sfz-preset :yamaha-grand-piano) 35)) ;; => #S(lsample ;; :name "p200-piano-d3-r-.wav" ;; :buffer #<incudine:buffer :FRAMES 193116 :CHANNELS 1 :SR 32000.0> ;; :oneshot nil ;; :keynum 38.0d0 ;; :loopstart 158947.0d0 ;; :amp 0.0d0 ;; :loopend 193110.0d0)
Note that other features of the SFZ format like defining modulations, envelopes, etc. are currently ignored by the clamps importer.
Footnotes:
events are instances of objects derived from the event class.