bufscale has rect input too - with modified bufstats weighing examples accordingly

nix
Pierre Alexandre Tremblay 5 years ago
parent e4607bf097
commit 574ddcd0fe

@ -1,31 +1,31 @@
FluidBufScale : UGen {
*new1 { |rate, source, destination, inputLow, inputHigh, outputLow, outputHigh, trig = 1, blocking|
*new1 { |rate, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, inputLow = 0, inputHigh = 1, outputLow = 0, outputHigh = 1, trig = 1, blocking|
source = source.asUGenInput;
destination = destination.asUGenInput;
source.isNil.if {"FluidBufScale: Invalid source buffer".throw};
destination.isNil.if {"FluidBufScale: Invalid destination buffer".throw};
^super.new1(rate, source, destination, inputLow, inputHigh, outputLow, outputHigh, trig, blocking);
^super.new1(rate, source, startFrame, numFrames, startChan, numChans, destination, inputLow, inputHigh, outputLow, outputHigh, trig, blocking);
}
*kr { |source, destination, inputLow = 0 , inputHigh = 1, outputLow = 0, outputHigh = 1, trig = 1, blocking = 1|
^this.new1('control', source, destination, inputLow, inputHigh, outputLow, outputHigh, trig, blocking);
*kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, inputLow = 0, inputHigh = 1, outputLow = 0, outputHigh = 1, trig = 1, blocking = 1|
^this.new1('control', source, startFrame, numFrames, startChan, numChans, destination, inputLow, inputHigh, outputLow, outputHigh, trig, blocking);
}
*process { |server, source, destination, inputLow = 0 , inputHigh = 1, outputLow = 0, outputHigh = 1, action|
*process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, inputLow = 0, inputHigh = 1, outputLow = 0, outputHigh = 1, action|
^FluidNRTProcess.new(
server, this, action, [destination], blocking:1
).process(
source, destination, inputLow, inputHigh, outputLow, outputHigh
source, startFrame, numFrames, startChan, numChans, destination, inputLow, inputHigh, outputLow, outputHigh
);
}
*processBlocking { |server, source, destination, inputLow = 0 , inputHigh = 1, outputLow = 0 , outputHigh = 1, action|
*processBlocking { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, inputLow = 0, inputHigh = 1, outputLow = 0, outputHigh = 1, action|
^process(
source, destination, inputLow, inputHigh, outputLow, outputHigh
source, startFrame, numFrames, startChan, numChans, destination, inputLow, inputHigh, outputLow, outputHigh
);
}
}

@ -22,6 +22,18 @@ ARGUMENT:: server
ARGUMENT:: source
The index of the buffer to use as the source material to be processed.
ARGUMENT:: startFrame
The starting point (in samples) from which to copy in the source buffer.
ARGUMENT:: numFrames
The duration (in samples) to copy from the source buffer. The default (-1) copies the full lenght of the buffer.
ARGUMENT:: startChan
The first channel from which to copy in the source buffer.
ARGUMENT:: numChans
The number of channels from which to copy in the source buffer. This parameter will wrap around the number of channels in the source buffer. The default (-1) copies all of the buffer's channel.
ARGUMENT:: destination
The index of the buffer to use as the destination for the processed material.
@ -52,7 +64,7 @@ b = Buffer.sendCollection(s,0.0.series(0.1,1.0))
// and a destination buffer
c = Buffer(s)
// play with the scaling
FluidBufScale.process(s,b,c,0,1,20,10)
FluidBufScale.process(s, b, destination: c, inputLow: 0, inputHigh: 1, outputLow: 20, outputHigh:10)
// retrieve the buffer and enjoy the results.
c.getn(0,11,{|x|x.postln;})
@ -60,7 +72,17 @@ c.getn(0,11,{|x|x.postln;})
b = Buffer.sendCollection(s,-10.0.series(-9,10.0).scramble,2)
b.plot.plotMode_(\points)
//process
FluidBufScale.process(s,b,c,-20,20,0,1)
FluidBufScale.process(s, b, destination: c, inputLow: -20, inputHigh: 20, outputLow: 0, outputHigh:1)
//enjoy - same shape, different range
c.plot.plotMode_(\points)
//also works with a subset of the input, resizing the output
b = Buffer.sendCollection(s,0.0.series(0.1,3.0).reshape(3,10).flop.flat,3)
b.plot(separately: true).plotMode_(\points)
//process
FluidBufScale.process(s, b, startFrame: 3,numFrames: 4,startChan: 1,numChans: 1, destination: c, inputLow: 0, inputHigh: 3, outputLow: 0, outputHigh:1)
//enjoy
c.plot(separately: true).plotMode_(\points)
c.query
c.getn(0,4,{|x|x.postln;})
::

@ -234,10 +234,10 @@ FluidBufStats.process(s, b, stats:d, numDerivs:1, action:{d.getn(0,d.numFrames,{
FluidBufStats.process(s, b, stats:d, numDerivs:1, weights: c, action:{d.getn(0,d.numFrames * d.numChannels,{|item|item.postln})});
// example 2b (run the stats above)
e = [(1..9), 0.series(-10,-80)].flop.scramble.flop; // this has negative weights, they are capped at 0, so nothing happens
e = [(1..9), 0.series(-10,-80)].flop.scramble.flop; // this has only negative weights, so nothing happens
// but if we scale them up
g = Buffer(s)
FluidBufScale.process(s,c,g,-100,0)
FluidBufScale.process(s,c,destination: g,inputLow: -100,inputHigh: 0)
// look at the new values - because 0->1 and -100->0 we get the same weights as example 2a
g.getn(0,9,{|x|x.postln})
// run the stats - same results as example 2a

@ -74,4 +74,6 @@ b.plot(separately: true).plotMode_(\points)
FluidBufThresh.process(s, b,startFrame: 3,numFrames: 4,startChan: 1,numChans: 1,destination: c, threshold: 1.6)
//enjoy
c.plot(separately: true).plotMode_(\points)
c.query
c.getn(0,4,{|x|x.postln;})
::

Loading…
Cancel
Save