Here's what I do when using SndBuf:. This is just a quick and dirty copypasta of a random old project, so replace the files with any random percussive sounds you have, and something interesting should arise. :P I commented the important parts. // load the samples into a SndBuf array. SndBuf a[7]; "pan01.wav" => a[0].read; "pan02.wav" => a[1].read; "pan03.wav" => a[2].read; "pan04.wav" => a[3].read; "pan05.wav" => a[4].read; "pan06.wav" => a[5].read; "pan07.wav" => a[6].read; PRCRev rvb; .2 => rvb.mix; PitShift pt; .9 => pt.mix; 1 => pt.shift; // quickly set all to their last sample and initialize each processing path. // this keeps the samples from playing immediately when opened. for( 1 => int i; i < a.cap(); i++ ){ a[i].samples() => a[i].pos; a[i] => pt => rvb => dac; } // set pos of sample to 0 to play it. fun void plyy(int d){ 0 => a[d].pos; } fun void ply(int d, float r){ for(0 => int i; i < (r $ int); i++){ spork ~ plyy(d); (a[d].samples() / (r $ float))::samp => now; } } SinOsc lfo; .1 => lfo.freq; lfo => blackhole; Chorus ch; .1 => ch.modFreq; .5 => ch.modDepth; .2 => ch.mix; SawOsc lead1 => ADSR le => ch => rvb => dac; .3 => lead1.gain; le.set(50::ms, 200::ms, .5, 500::ms); 1 => float m; while(1){ Std.mtof(Std.rand2(30,40)) => lead1.freq; le.keyOn(); spork ~ ply(6,2*m); 400::ms => now; spork ~ ply(5,2*m); spork ~ ply(1,1*m); 350::ms => now; spork ~ ply(3,2*m); spork ~ ply(5,1*m); le.keyOff(); 400::ms => now; Std.mtof(Std.rand2(30,40)) => lead1.freq; le.keyOn(); spork ~ ply(2,2*m); spork ~ ply(4,2*m); 400::ms => now; le.keyOff(); lfo.last()/10 + pt.shift() => pt.shift; // 0.5 +=> m; <<< m >>>; } -Drew Atte André Jensen wrote:
Atte André Jensen wrote:
I tried more values of chunks and have some improvement at 16 => chunks. Will report back after more testing.
I didn't try the preloading suggestion yet, but I suspect it will work, although it's a little clumsy. However I still didn't manage to get consistently satisfactory results with chunks.
But now I'm wondering how SndBuf is performing for other people esp on osx or windows? Is it only on linux something is wrong? Actually my logic tells me chunks is not doing anything. Setting it low (like 4) should read 4 frames (whatever that is) every time it's needed, that is 4 frames have been played back. So it's very surprising to me that the hickup is when at the read() and not distributed throughout the first playback of the file...
I'll see if I can find the time to dig into the source tonight...