/ Examples / Instruments / SampleInst


Projects .. AudioIO .. Control
NoteStreams .. Instruments
Filters .. Effects .. LiCK Effects
Plot .. Utility .. Pure ChucK


Wherein we present the SampleInst and its companion SampleMgr.

Right-click to copy examples to your workspace

SampleInst

SampleInst is a polyphonic sample-playing instrument that automatically adjusts the pitch of the audio sample files according to the incoming notes. It relies on the services of SampleMgr to asssociate a semantic instrument name, like piano, with a collection of sample files covering a range of pitches. SampleInst is similar to FluidSynth but uses individual sample files rather than monolithic sound fonts. Currently SampleInst can handle .wav, .mp3, .flac and some .aif files.

Parameters

Voice the name of the voice referenced in an upstream SampleMgr.

Gain a linear multiplier for the instrument volume.

Attack, Decay, Sustain, Release control the amplitude envelope of your sample over the evolution of a note event.

In this diagram signal amplitudes are larger in the down direction. Also, note that A, D and R are durations and S is an amplitude.

SampleMgrs - connect one or more SampleMgr Nodes to this input port. It is the SampleMgr that converts the combination of your semantic voice, here accordion, to a pile of sample files that reside on your local filesystem.

The Example

This simple example has two instances of SampleInst, Accordion and bass. The shared SampleMgr defines the interpretation of the SampleInst Voice values: accordion and bass.

Here are the contents of the SoundMgr node.

Note that both samples currently employ the abcjs bank to provide samples. This bank is available via _fiddleBanks, a lightweight collection of files that point to internet-hosted sample bank libraries. _fiddleBanks is auto-installed into your Workspace directory and SampleMgr has parameters that refer to these components.

After right-click-copying this example to your workspace you can observe SampleMgr do its job when you first run the example. At that point notice that some abcjs sample files are downloaded before the performance begins. Sample files are placed below the _cache area of your Workspace. You can override the the SampleMgr's Cachedir should you wish to store samples on an external drive, etc.

Similarly you can create your own Banklist file. This default file, banklist.json includes a reference to the midi-js-soundfonts package and a sub-component of that package is the abcjs sound bank. All the sample files for each bank are enumerated by the TOC-files (Table of Contents) referred to in banklist.json. You can inspect these files using the usual combination of Workspace and Code editors. Both kinds of files are in .json format and thus easily perused, searched, modified or created.

Known Issues

There is no special handling of notes with long sustains. When a sample reaches its end, it "just stops" independent of the Release timing.

There is no special velocity-specific voice selection.

Currently sample files are loaded in their entirety. Since a voice may comprise multiple sample files, there can be a lag or choppiness on the first use especially for the .flac format due to the extra work required to load it.

home .. topics .. interface .. reference .. examples .. tipjar