Merge branch 'refactor/macro-purge' into log-scaling
commit
0b61aed2b9
@ -1,47 +1,47 @@
|
|||||||
FluidBufSTFT : FluidBufProcessor {
|
FluidBufSTFT : FluidBufProcessor {
|
||||||
|
|
||||||
*kr { |source, startFrame = 0, numFrames = -1, startChan = 0, magnitudeBuffer, phaseBuffer, resynthesisBuffer, inverse = 0,windowSize = 1024, hopSize = -1, fftSize = -1, trig = 1, blocking = 1|
|
*kr { |source, startFrame = 0, numFrames = -1, startChan = 0, magnitude, phase, resynthesis, inverse = 0,windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, trig = 1, blocking = 1|
|
||||||
|
|
||||||
// source = source.asUGenInput;
|
// source = source.asUGenInput;
|
||||||
|
|
||||||
// source.isNil.if {"FluidBufScale: Invalid source buffer".throw};
|
// source.isNil.if {"FluidBufScale: Invalid source buffer".throw};
|
||||||
source = source ? -1;
|
source = source ? -1;
|
||||||
magnitudeBuffer = magnitudeBuffer ? -1;
|
magnitude = magnitude ? -1;
|
||||||
phaseBuffer = phaseBuffer ? -1;
|
phase = phase ? -1;
|
||||||
resynthesisBuffer = resynthesisBuffer ? - 1;
|
resynthesis = resynthesis ? - 1;
|
||||||
|
|
||||||
^FluidProxyUgen.kr(\FluidBufSTFTTrigger, -1, source, startFrame, numFrames, startChan, magnitudeBuffer, phaseBuffer, resynthesisBuffer, inverse, windowSize, hopSize, fftSize,trig, blocking);
|
^FluidProxyUgen.kr(\FluidBufSTFTTrigger, -1, source, startFrame, numFrames, startChan, magnitude, phase, resynthesis, inverse, padding, windowSize, hopSize, fftSize, trig, blocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
*process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, magnitudeBuffer, phaseBuffer, resynthesisBuffer, inverse = 0, windowSize = 1024, hopSize = -1, fftSize = -1,freeWhenDone = true, action|
|
*process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, magnitude, phase, resynthesis, inverse = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, freeWhenDone = true, action|
|
||||||
|
|
||||||
// source = source.asUGenInput;
|
// source = source.asUGenInput;
|
||||||
|
|
||||||
// source.isNil.if {"FluidBufSTFT: Invalid source buffer".throw};
|
// source.isNil.if {"FluidBufSTFT: Invalid source buffer".throw};
|
||||||
source = source ? -1;
|
source = source ? -1;
|
||||||
magnitudeBuffer = magnitudeBuffer ? -1;
|
magnitude = magnitude ? -1;
|
||||||
phaseBuffer = phaseBuffer ? -1;
|
phase = phase ? -1;
|
||||||
resynthesisBuffer = resynthesisBuffer ? - 1;
|
resynthesis = resynthesis ? - 1;
|
||||||
|
|
||||||
^this.new(
|
^this.new(
|
||||||
server, nil, [magnitudeBuffer,phaseBuffer,resynthesisBuffer].select{|b| b != -1}
|
server, nil, [magnitude,phase,resynthesis].select{|b| b != -1}
|
||||||
).processList(
|
).processList(
|
||||||
[source, startFrame, numFrames, startChan, magnitudeBuffer, phaseBuffer, resynthesisBuffer, inverse, windowSize, hopSize, fftSize, 0], freeWhenDone, action
|
[source, startFrame, numFrames, startChan, magnitude, phase, resynthesis, inverse, padding, windowSize, hopSize, fftSize, 0], freeWhenDone, action
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
*processBlocking { |server, source, startFrame = 0, numFrames = -1, startChan = 0, magnitudeBuffer, phaseBuffer, resynthesisBuffer, inverse = 0, windowSize = 1024, hopSize = -1, fftSize = -1,freeWhenDone = true, action|
|
*processBlocking { |server, source, startFrame = 0, numFrames = -1, startChan = 0, magnitude, phase, resynthesis, inverse = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1,freeWhenDone = true, action|
|
||||||
|
|
||||||
// source = source.asUGenInput;
|
// source = source.asUGenInput;
|
||||||
source = source ? -1;
|
source = source ? -1;
|
||||||
magnitudeBuffer = magnitudeBuffer ? -1;
|
magnitude = magnitude ? -1;
|
||||||
phaseBuffer = phaseBuffer ? -1;
|
phase = phase ? -1;
|
||||||
resynthesisBuffer = resynthesisBuffer ? - 1;
|
resynthesis = resynthesis ? - 1;
|
||||||
|
|
||||||
^this.new(
|
^this.new(
|
||||||
server, nil, [magnitudeBuffer,phaseBuffer,resynthesisBuffer].select{|b| b != -1}
|
server, nil, [magnitude,phase,resynthesis].select{|b| b != -1}
|
||||||
).processList(
|
).processList(
|
||||||
[source, startFrame, numFrames, startChan, magnitudeBuffer, phaseBuffer, resynthesisBuffer, inverse, windowSize, hopSize, fftSize,1], freeWhenDone, action
|
[source, startFrame, numFrames, startChan, magnitude, phase, resynthesis, inverse, padding, windowSize, hopSize, fftSize, 1], freeWhenDone, action
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,70 +1,121 @@
|
|||||||
FluidKMeans : FluidRealTimeModel {
|
FluidKMeans : FluidRealTimeModel {
|
||||||
|
|
||||||
var clusters, maxiter;
|
var clusters, maxiter;
|
||||||
|
|
||||||
*new {|server, numClusters = 4, maxIter = 100|
|
*new {|server, numClusters = 4, maxIter = 100|
|
||||||
^super.new(server,[numClusters,maxIter])
|
^super.new(server,[numClusters,maxIter])
|
||||||
.numClusters_(numClusters)
|
.numClusters_(numClusters)
|
||||||
.maxIter_(maxIter);
|
.maxIter_(maxIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
numClusters_{|n| clusters = n.asInteger}
|
numClusters_{|n| clusters = n.asInteger}
|
||||||
numClusters{ ^clusters }
|
numClusters{ ^clusters }
|
||||||
|
|
||||||
maxIter_{|i| maxiter = i.asInteger}
|
maxIter_{|i| maxiter = i.asInteger}
|
||||||
maxIter{ ^maxiter }
|
maxIter{ ^maxiter }
|
||||||
|
|
||||||
prGetParams{^[this.numClusters,this.maxIter,-1,-1];}
|
prGetParams{^[this.numClusters,this.maxIter,-1,-1];}
|
||||||
|
|
||||||
fitMsg{ |dataSet| ^this.prMakeMsg(\fit,id,dataSet.id);}
|
fitMsg{ |dataSet| ^this.prMakeMsg(\fit,id,dataSet.id);}
|
||||||
|
|
||||||
fit{|dataSet, action|
|
fit{|dataSet, action|
|
||||||
actions[\fit] = [
|
actions[\fit] = [
|
||||||
numbers( FluidMessageResponse, _, this.numClusters ,_),
|
numbers( FluidMessageResponse, _, this.numClusters ,_),
|
||||||
action
|
action
|
||||||
];
|
];
|
||||||
this.prSendMsg(this.fitMsg(dataSet));
|
this.prSendMsg(this.fitMsg(dataSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
fitPredictMsg{|dataSet, labelSet|
|
fitPredictMsg{|dataSet, labelSet|
|
||||||
^this.prMakeMsg(\fitPredict, id, dataSet.id, labelSet.id)
|
^this.prMakeMsg(\fitPredict, id, dataSet.id, labelSet.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fitPredict{|dataSet, labelSet,action|
|
fitPredict{|dataSet, labelSet,action|
|
||||||
actions[\fitPredict] = [
|
actions[\fitPredict] = [
|
||||||
numbers(FluidMessageResponse, _, this.numClusters, _),
|
numbers(FluidMessageResponse, _, this.numClusters, _),
|
||||||
action
|
action
|
||||||
];
|
];
|
||||||
this.prSendMsg(this.fitPredictMsg(dataSet,labelSet));
|
this.prSendMsg(this.fitPredictMsg(dataSet,labelSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
predictMsg{|dataSet, labelSet|
|
predictMsg{|dataSet, labelSet|
|
||||||
^this.prMakeMsg(\predict, id, dataSet.id, labelSet.id)
|
^this.prMakeMsg(\predict, id, dataSet.id, labelSet.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
predict{ |dataSet, labelSet, action|
|
predict{ |dataSet, labelSet, action|
|
||||||
actions[\predict] = [
|
actions[\predict] = [
|
||||||
numbers(FluidMessageResponse, _, this.numClusters, _),
|
numbers(FluidMessageResponse, _, this.numClusters, _),
|
||||||
action
|
action
|
||||||
];
|
];
|
||||||
this.prSendMsg(this.predictMsg(dataSet,labelSet));
|
this.prSendMsg(this.predictMsg(dataSet,labelSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
predictPointMsg{|buffer|
|
predictPointMsg{|buffer|
|
||||||
^this.prMakeMsg(\predictPoint, id, this.prEncodeBuffer(buffer))
|
^this.prMakeMsg(\predictPoint, id, this.prEncodeBuffer(buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
predictPoint { |buffer, action|
|
predictPoint { |buffer, action|
|
||||||
actions[\predictPoint] = [number(FluidMessageResponse,_,_),action];
|
actions[\predictPoint] = [number(FluidMessageResponse,_,_),action];
|
||||||
this.prSendMsg(this.predictPointMsg(buffer))
|
this.prSendMsg(this.predictPointMsg(buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
kr{|trig, inputBuffer,outputBuffer|
|
fitTransformMsg{|srcDataSet, dstDataSet|
|
||||||
^FluidKMeansQuery.kr(K2A.ar(trig),
|
^this.prMakeMsg(\fitTransform, id, srcDataSet.id, dstDataSet.id)
|
||||||
this, clusters, maxiter,
|
}
|
||||||
this.prEncodeBuffer(inputBuffer),
|
|
||||||
this.prEncodeBuffer(outputBuffer));
|
fitTransform{|srcDataSet, dstDataSet,action|
|
||||||
|
actions[\fitTransform] = [nil,action];
|
||||||
|
this.prSendMsg(this.fitTransformMsg(srcDataSet,dstDataSet));
|
||||||
|
}
|
||||||
|
|
||||||
|
transformMsg{|srcDataSet, dstDataSet|
|
||||||
|
^this.prMakeMsg(\transform, id, srcDataSet.id, dstDataSet.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
transform{ |srcDataSet, dstDataSet, action|
|
||||||
|
actions[\transform] = [nil,action];
|
||||||
|
this.prSendMsg(this.transformMsg(srcDataSet,dstDataSet));
|
||||||
|
}
|
||||||
|
|
||||||
|
transformPointMsg{ |sourceBuffer, targetBuffer|
|
||||||
|
^this.prMakeMsg(\transformPoint, id,
|
||||||
|
this.prEncodeBuffer(sourceBuffer),
|
||||||
|
this.prEncodeBuffer(targetBuffer),
|
||||||
|
["/b_query", targetBuffer.asUGenInput]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transformPoint { |sourceBuffer, targetBuffer, action|
|
||||||
|
actions[\transformPoint] = [nil,{action.value(targetBuffer)}];
|
||||||
|
this.prSendMsg(this.transformPointMsg(sourceBuffer, targetBuffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
getMeansMsg{|dataSet| ^this.prMakeMsg(\getMeans, id, dataSet.asUGenInput) }
|
||||||
|
|
||||||
|
getMeans{ |dataSet, action|
|
||||||
|
actions[\getMeans] = [nil, action];
|
||||||
|
this.prSendMsg(this.getMeansMsg(dataSet));
|
||||||
|
}
|
||||||
|
|
||||||
|
setMeansMsg{|dataSet| ^this.prMakeMsg(\setMeans, id, dataSet.asUGenInput) }
|
||||||
|
|
||||||
|
setMeans{ |dataSet, action|
|
||||||
|
actions[\setMeans] = [nil, action];
|
||||||
|
this.prSendMsg(this.setMeansMsg(dataSet));
|
||||||
|
}
|
||||||
|
|
||||||
|
clearMsg{ ^this.prMakeMsg(\clear, id) }
|
||||||
|
|
||||||
|
clear{ |action|
|
||||||
|
actions[\clear] = [nil, action];
|
||||||
|
this.prSendMsg(this.clearMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
kr{|trig, inputBuffer,outputBuffer|
|
||||||
|
^FluidKMeansQuery.kr(K2A.ar(trig),
|
||||||
|
this, clusters, maxiter,
|
||||||
|
this.prEncodeBuffer(inputBuffer),
|
||||||
|
this.prEncodeBuffer(outputBuffer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FluidKMeansQuery : FluidRTQuery {}
|
FluidKMeansQuery : FluidRTQuery {}
|
||||||
|
|||||||
@ -0,0 +1,62 @@
|
|||||||
|
TITLE:: FluidBufSelect
|
||||||
|
summary:: Cherry pick values from a buffer
|
||||||
|
categories:: FluidCorpusManipulation
|
||||||
|
related:: Classes/FluidBufSelectEvery
|
||||||
|
|
||||||
|
DESCRIPTION::
|
||||||
|
Pick sets of values from a buffer, described in terms of a list of frame indices and channel numbers.
|
||||||
|
|
||||||
|
CLASSMETHODS::
|
||||||
|
|
||||||
|
private::new1
|
||||||
|
|
||||||
|
METHOD:: process, processBlocking
|
||||||
|
Run the process on the given sever, and perfrom code::action:: when done
|
||||||
|
|
||||||
|
ARGUMENT:: server
|
||||||
|
The link::Classes/Server:: on which to run
|
||||||
|
|
||||||
|
ARGUMENT:: source
|
||||||
|
The link::Classes/Buffer:: to select values from
|
||||||
|
|
||||||
|
ARGUMENT:: destination
|
||||||
|
The link::Classes/Buffer:: to write the selected data to
|
||||||
|
|
||||||
|
ARGUMENT:: indices
|
||||||
|
A 0-based list of frame indices to recover. Default is [-1], meaning all frames
|
||||||
|
|
||||||
|
ARGUMENT:: channels
|
||||||
|
A 0-based list of channel numbers to recover. Default is [-1], meaning all frames
|
||||||
|
|
||||||
|
ARGUMENT:: freeWhenDone
|
||||||
|
Free the server instance when processing complete. Default true
|
||||||
|
|
||||||
|
ARGUMENT:: action
|
||||||
|
Runs when processing is complete
|
||||||
|
|
||||||
|
EXAMPLES::
|
||||||
|
code::
|
||||||
|
//send a known collection where the value of each frame in each channel is encoded
|
||||||
|
//chan
|
||||||
|
b = Buffer.sendCollection(s,30.collect{|x| x.mod(6) + (x.div(6) * 0.1)},6)
|
||||||
|
//check the ranges (thus showing a plotter error...)
|
||||||
|
b.plot(separately: true).plotMode_(\points)
|
||||||
|
//you can also check the collection itself if in doubt
|
||||||
|
b.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
|
||||||
|
//let's make a destination buffer
|
||||||
|
c = Buffer(s);
|
||||||
|
|
||||||
|
//using default values, we copy everything:
|
||||||
|
FluidBufSelect.process(s,b,c,action: {c.query});
|
||||||
|
c.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
|
||||||
|
//more powerful copying, resizing the destination accordingly
|
||||||
|
FluidBufSelect.process(s,b,c, indices: [1,3], channels: [2,4], action: {c.query});
|
||||||
|
c.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
|
||||||
|
//observe the order can be anything, and -1 (default) passes everything in that dimension
|
||||||
|
FluidBufSelect.process(s,b,c, indices: [ -1 ] , channels: [3, 1, 4], action: {c.query});
|
||||||
|
c.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
::
|
||||||
|
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
TITLE:: FluidBufSelectEvery
|
||||||
|
summary:: Extract every N samples / channels from a buffer
|
||||||
|
categories:: FluidCorpusManipulation
|
||||||
|
related:: Classes/FluidBufSelect
|
||||||
|
|
||||||
|
DESCRIPTION::
|
||||||
|
Pick every N frames and / or channels from a buffer, described in terms of independent hop sizes for frames and channels
|
||||||
|
|
||||||
|
CLASSMETHODS::
|
||||||
|
|
||||||
|
private::new1
|
||||||
|
|
||||||
|
METHOD:: process, processBlocking
|
||||||
|
Run the process on the given sever, and perfrom code::action:: when done
|
||||||
|
|
||||||
|
ARGUMENT:: server
|
||||||
|
The link::Classes/Server:: on which to run
|
||||||
|
|
||||||
|
ARGUMENT:: source
|
||||||
|
The link::Classes/Buffer:: to select values from
|
||||||
|
|
||||||
|
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 link::Classes/Buffer:: to write the selected data to
|
||||||
|
|
||||||
|
ARGUMENT:: frameHop
|
||||||
|
Take every `framehop` frames. Default = 1 = all frames (where 2 would be every other frame, etc.)
|
||||||
|
|
||||||
|
ARGUMENT:: channelHop
|
||||||
|
Take every `channelhop` channels. Default = 1 = all channels (where 2 would be every other channel, etc.)
|
||||||
|
|
||||||
|
ARGUMENT:: freeWhenDone
|
||||||
|
Free the server instance when processing complete. Default true
|
||||||
|
|
||||||
|
ARGUMENT:: action
|
||||||
|
Runs when processing is complete
|
||||||
|
|
||||||
|
EXAMPLES::
|
||||||
|
|
||||||
|
code::
|
||||||
|
EXAMPLES::
|
||||||
|
Didactic
|
||||||
|
code::
|
||||||
|
//send a known collection where the value of each frame in each channel is encoded
|
||||||
|
//chan
|
||||||
|
b = Buffer.sendCollection(s,30.collect{|x| x.mod(6) + (x.div(6) * 0.1)},6)
|
||||||
|
//check the ranges (thus showing a plotter error...)
|
||||||
|
b.plot(separately: true).plotMode_(\points)
|
||||||
|
//you can also check the collection itself if in doubt
|
||||||
|
b.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
|
||||||
|
//let's make a destination buffer
|
||||||
|
c = Buffer(s);
|
||||||
|
|
||||||
|
//using default values, we copy everything:
|
||||||
|
FluidBufSelectEvery.process(s,b, destination: c, action: {c.query});
|
||||||
|
c.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
|
||||||
|
//more powerful copying, resizing the destination accordingly
|
||||||
|
FluidBufSelectEvery.process(s,b, destination: c, frameHop: 2, channelHop: 3, action: {c.query});
|
||||||
|
c.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
|
||||||
|
//source buffer boundaries still apply before the hopping selection
|
||||||
|
FluidBufSelectEvery.process(s,b, startFrame: 1, numFrames: 3, startChan: 2, numChans: 3, destination: c, frameHop: 1, channelHop: 2, action: {c.query});
|
||||||
|
c.getToFloatArray(action: {|x|x.round(0.1).postln;});
|
||||||
|
::::
|
||||||
Loading…
Reference in New Issue