💾 Archived View for heavysquare.com › noise › 2018-10-16-loading-samples.sc.txt captured on 2021-12-03 at 14:04:38.
View Raw
More Information
-=-=-=-=-=-=-
/*
Lessons learnt from this session.
(a) instead of teaching a synth to handle both mono and stere buffers,
you could write a function which loads sound into stereo, duplicating
the mono if needed
(b) it's not very convoluted to load all sounds in a folder into a
dictionary, indexed by the filenames..
(filename:buffer-with-sound-from-that-file,...)
(c) [["foo",12],["bar",42]].flat -> [ f, o, o, 12, b, a, r, 42 ]
s.boot;
(
SynthDef(\samp, { arg out = 0, amp, buf;
Out.ar( out,
amp * PlayBuf.ar(2, buf, BufRateScale.kr(buf))
)
}).add;
)
~loadStereo = {|file|Buffer.readChannel(s,file,channels:({|i|i}!SoundFile.openRead(file).numChannels).lace(2))}
~pads = Dictionary.newFrom("/Volumes/REASON/legowelt/simple/*.wav".pathMatch.collect{|f|[f.basename.splitext@0,~loadStereo.(f)]}.flatten)
b=(amp:0.8,buf:~pads["kick"],instrument:\samp)
b.play
b=Pcollect({|e|e[\buf]=~pads[e[\pad]];e.postln;e}, Pbind(\amp,0.8,\instrument,\samp,\pad,Pseq(~pads.keys.asArray)))
b.record("/tmp/2018-10-16.wav",headerFormat:"WAV")
~pads.keys.asArray // -> [ cymbal, snare, kick, chat ]