RedDiskInSampler playing soundfiles from disk

superclass: RedAbstractSampler

this class buffers a small portion of a soundfile in RAM and then streams the rest from disk. it is built around the DiskIn ugen and makes it quick and easy to preload and manage lots of samples - much more than you could fit in your RAM. it associates each soundfile with a key (usually a number or a symbol) and can simultaneously play n overlaps of each sound.

this class has a small delay before starting the sound as it buffers or 'cues' data right before playing. on the other hand it can deal with an almost unlimited number of samples. the subclass RedDiskInSamplerGiga is recommended if you need your samples to start instantly e.g. when syncing to a beat.

do not use this class for granular synthesis or for playing heaps of sounds at once. remember that it streams data from disk. for playing very many soundfiles at once, use the RedSampler class.

see also [RedDiskInSamplerGiga] [RedSampler]

*new(server)

create a new sampler on a server. if server is nil it will use Server.default. the server must be booted.

prepareForPlay(key, path, startFrame, numFrames) (alias preload)

attach a soundfile to a key (number or symbol) and create buffers - one for each overlapping voice.

numFrames is safest to leave as nil. then the <>numFrames below is used (default for that is 32768).

play(key, attack, sustain, release, amp, out, group, loop)

preload and play the sample at key. for this class the actual preloading will happen here.

so it will not trigger instantaneously but still be pretty quick. how quick depends on the

numFrames to preload and disk drive activity.

if sustain is nil the total length of the soundfile will be used (-attack-release). so the default:

attack 0, sustain nil, release 0 will play the soundfile in its full length without an envelope.

out sets outbus and defaults to 0. if group nil it will use server.defaultGroup.

loop should be either 0 (default), 1 or 2.

0 - loop off. play once through with finite duration (using attack+sustain+release).

1 - loop on. loop infinite until it receiving a .stop (ignoring sustain).

2 - loop on. loop with finite duration (using attack+sustain+release).

stop(key, release)

stops one voice currently playing at this key. release time is in seconds.

the voice is stolen when the sound is fully released. default releasetime is 0.4 seconds.

flush(release)

stop all currently playing voices for all keys. default releasetime is 0.4 seconds.

free

clear keys, close files, free synths and buffers.

freeKey(key)

clear a key, close its file and free its synth and buffer.

loadedKeys

report which keys have been preloaded with soundfiles.

playingKeys

report which keys that currently have one or more voices playing.

<>numFrames

get and set the size of the preload buffer. default is 32768.

you can also pass this number in as an argument for .prepareForPlay. see above.

<>overlaps

get and set number of overlaps or voices allowed to play per key at once. the default is 2.

you will need to prepareForPlay again after setting this.

length(key)

report the length in seconds of the soundfile loaded at this key.

channels(key)

report the number of channels of the soundfile loaded at this key.

buffers(key)

return an array of buffer for this key. depends on how many overlaps you had when preloading.

voicesLeft(key)

return number of free voices for this key i.e. the number of non-playing voices.

isPlaying(key)

return boolean if more than one voice is playing.

amp_(val)

set amplitude for a running synth.

s.boot;

a= RedDiskInSampler(s);

//-- setting up which samples to use and prepare them

a.prepareForPlay(\snd1, "sounds/a11wlk01-44_1.aiff");

a.prepareForPlay(\snd2, "sounds/break"); //add your own soundfile

a.prepareForPlay(\snd3, "sounds/a11wlk01-44_1.aiff", 44100); //offset 44100 samples

//-- play

a.play(\snd1); //play the whole soundfile

a.voicesLeft(\snd1);

a.playingKeys;

a.isPlaying(\snd1);

a.stop(\snd1); //stop

a.play(\snd1, 3, 0, 0.05); //play with slow attack and quick release

a.play(\snd2); //play another sample

a.play(\snd3); //and another

a.play(\snd3, 0.1, 0.1, 0.1); //very short

a.play(\snd2, loop:1); //looping

a.amp_(0.3); //set amplitude

a.stop(\snd2, 4); //stop with 4 second fadetime

( //start many at once

a.play(\snd1);

a.play(\snd2);

a.play(\snd3);

)

a.flush(0); //stop all right away

a.play(\snd2);

a.play(\snd2);

a.voicesLeft(\snd2); //check if any free voices

a.stop(\snd2, 0);

a.stop(\snd2, 0);

a.voicesLeft(\snd2); //check if any free voices

a.loadedKeys; //report all keys that have soundfiles loaded

a.numFrames; //report size of preload buffer

a.overlaps; //how many voices allowed to play simultaneously

a.length(\snd1); //how long is the soundfile in seconds

a.channels(\snd1); //how many channels

a.buffers(\snd1); //access buffers for a key. one for each overlap

a.play(\snd1, 4, 4, 4, loop:2) //play in loop with finite duration

a.free; //stop and clear