added FluidBufToKr.kr and FluidKrToBuf.kr (#24)

* added FluidBufToKr.kr and FluidKrToBuf.kr

* tested a few more use cases, no problems detected

* Update release-packaging/Classes/FluidBufToKr.sc

Co-authored-by: weefuzzy <gungwho@gmail.com>

* semicolon

added a the end of line 4

* check if the buffer is huge (like an audio file)

if one tries to pass a huge buffer to either, this is throw an error and report the number of frames in that buffer. I tested it with an audio file-size buffer and it froze the server (not crash though, the bar stayed green...?).

* added huge buffer check to BufToKr as well

* added one more validity check and re tested

* FluidBufToKr now can return single value or array

if the buffer is only one frame long, it will return a single value instead of an array of length one (which is what it did before)

Co-authored-by: weefuzzy <gungwho@gmail.com>
nix
Ted Moore 4 years ago committed by GitHub
parent a2f66aedc5
commit c72f7a9575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,28 @@
FluidKrToBuf {
*kr {
arg krStream, buffer;
if(buffer.numFrames == 0) {"FluidKrToBuf: UGen will have 0 outputs!".warn};
if(buffer.numFrames > 1000) {"FluidKrToBuf: Buffer is % frames. This is probably not the buffer you intended.".format(buffer.numFrames).error};
^buffer.numFrames.do{
arg i;
BufWr.kr(krStream[i], buffer, i);
}
}
}
FluidBufToKr {
*kr {
arg buffer;
if(buffer.numFrames == 0) {"FluidKrToBuf: Buffer has 0 frames!".warn};
if(buffer.numFrames > 1000) {"FluidKrToBuf: Buffer is % frames. This is probably not the buffer you intended.".format(buffer.numFrames).error};
if(buffer.numFrames > 1,{
^buffer.numFrames.collect{
arg i;
BufRd.kr(1,buffer,i,0,0);
}
},{
^BufRd.kr(1,buffer,0,0,0);
});
}
}

@ -0,0 +1,153 @@
(
// FluidKrToBuf test
s.waitForBoot{
Routine{
var buf = Buffer.alloc(s,5);
s.sync;
{
var sig = SinOsc.kr(rrand(1.0.dup(buf.numFrames),4.0));
FluidKrToBuf.kr(sig,buf);
}.play;
3.wait;
defer{buf.plot};
}.play;
}
)
(
// FluidBufToKr
s.waitForBoot{
Routine{
var buf = Buffer.loadCollection(s,[0,1,2,3,4,7]);
s.sync;
{
var sig = FluidBufToKr.kr(buf);
sig.poll;
}.play;
}.play;
}
)
(
// test both
s.waitForBoot{
Routine{
{
var buf = LocalBuf(5);
var insig = SinOsc.kr(rrand(1.0.dup(buf.numFrames),4.0));
var outsig;
FluidKrToBuf.kr(insig,buf);
outsig = FluidBufToKr.kr(buf);
outsig.poll;
}.play;
}.play;
}
)
(
// FluidKrToBuf --- kr is longer than buf...
// it just doesnt write all the values of kr into the buffer
s.waitForBoot{
Routine{
var buf = Buffer.alloc(s,5);
s.sync;
{
var sig = SinOsc.kr(rrand(1.0.dup(6),4.0));
FluidKrToBuf.kr(sig,buf);
}.play;
3.wait;
defer{buf.plot};
}.play;
}
)
(
// FluidKrToBuf --- kr is shorter than buf...
// the last index of the buffer is just not being written into, it's still zero
s.waitForBoot{
Routine{
var buf = Buffer.alloc(s,5);
s.sync;
{
var sig = SinOsc.kr([1,2,3,4]);
FluidKrToBuf.kr(sig,buf);
}.play;
3.wait;
defer{buf.plot};
}.play;
}
)
(
// FluidBufToKr
// 100 is fine
/// 1000 is fine
s.waitForBoot{
Routine{
var buf = Buffer.loadCollection(s,Array.fill(1000,{arg i; i}));
s.sync;
{
var sig = FluidBufToKr.kr(buf);
sig.poll;
}.play;
}.play;
}
)
(
// FluidBufToKr
// 100 is fine
/// 1000 is fine
s.waitForBoot{
Routine{
var buf = Buffer.read(s,"/Users/macprocomputer/Desktop/_flucoma/code/flucoma-core-src/AudioFiles/Harker-DS-TenOboeMultiphonics-M.wav");
s.sync;
{
var sig = FluidBufToKr.kr(buf);
sig.poll;
}.play;
}.play;
}
)
(
// FluidKrToBuf test with super long buffer
// 100 is fine
// 1000 is fine
s.waitForBoot{
Routine{
// var buf = Buffer.alloc(s,1000);
var buf = Buffer.read(s,"/Users/macprocomputer/Desktop/_flucoma/code/flucoma-core-src/AudioFiles/Harker-DS-TenOboeMultiphonics-M.wav");
s.sync;
{
var sig = SinOsc.kr(rrand(1.0.dup(buf.numFrames),4.0));
FluidKrToBuf.kr(sig,buf);
}.play;
3.wait;
defer{buf.plot};
}.play;
}
)
Loading…
Cancel
Save