work with mark: supercollider sampler

For my work together with Mark d'Inverno I coded a few tools. One of the things that came up was a need for a neutral but nice sounding way to test aspects of our musical agents systems. So we got hold of a grand-piano sample library and i wrote a 'giga sampler' like class for SuperCollider. This allowed us to use this massive sample library (2.5Gb) and let the agents play high quality samples instead of cheap MIDI or boring synthesised sounds. So for testing melodies, harmonies and such this was a good thing.

The trick with the giga sampler is that it preloads a bit from each soundfile into RAM memory and then streams the rest from disk when needed. Or at least this is how I understands it. So using this technique, one can get quick access to a lot more samples than normally would fit in the memory of a sampler. A massive library like ours with full 88keys range, sampled in many different velocities, would occupy ~5Gb of RAM (SuperCollider uses 32bit internally), nor could it be streamed from disk (the harddrive would be too slow to access and load the headers to play fast chords progressions without staggering etc).

I spent some time to make my class all round useful and it can be downloaded here or simply install by typing Quarks.install("redSampler") in SuperCollider. The class of interest in that package is called RedDiskInSampler.

And here is some testcode for it...

d= ();                                  /*for mapping midinote to filename*/;
r= RedDiskInSamplerGiga(s);             /*sampler*/
var folder= "/Users/asdf/Documents/soundfiles/bosen44100/";  //edit to match your samplebank
var velocities= #[40, 96];              /*velocities to load*/
var octavesToLoad= #[2, 3];             /*how many octaves to load*/
var scale= #['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
/*so number of samples to load is octavesToLoad.size*12*velocities.size*/
/*lowest note C2= midi 36*/{|x, i|
        var tempDict= ();
        d.put(x, tempDict);{|y, j|
      {|z, k|
                        var midinote, pathname, key;
                        midinote= y*12+12+k;
                        key= z++y;
                        pathname= folder+/+x+/+key++".aif";
                        key= (key++"_"++x).asSymbol;
                        tempDict.put(midinote, key);     /*like (45 : A2_96)*/
                        ("loading key"+key+"from file"+pathname).postln;
                        r.preload(key, pathname);
)\C2_96, 0, 3, 1)\D2_40, 0, 3, 1)
a= r.loadedKeys;
(Tdef(\test, {{|i|
      , 0, 0.45, 0.1);
(Tdef(\test, {
        b= a.asArray.scramble;{|i|
      {|x, j|
              , 0, 0.35, 0.1);
(Tdef(\test, {
        b= a.asArray.sort;{|i|
      {|x, j|
              , 0, 0.25, 0.08, amp: 0.6);