diff --git a/release-packaging/Classes/FluidBufSineFeature.sc b/release-packaging/Classes/FluidBufSineFeature.sc new file mode 100644 index 0000000..f271177 --- /dev/null +++ b/release-packaging/Classes/FluidBufSineFeature.sc @@ -0,0 +1,51 @@ +FluidBufSineFeature : FluidBufProcessor { + + *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, frequency = -1, magnitude = -1, numPeaks = 10, detectionThreshold = -96, order = 0, freqUnit = 0, magUnit = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, trig = 1, blocking = 0| + + var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; + + source = source.asUGenInput; + frequency = frequency !? {frequency.asUGenInput} ?? {-1}; + magnitude = magnitude !? {magnitude.asUGenInput} ?? {-1}; + + source.isNil.if {"FluidBufSineFeature: Invalid source buffer".throw}; + + ^FluidProxyUgen.multiNew(\FluidBufSineFeatureTrigger, -1, source, startFrame, numFrames, startChan, numChans, frequency, magnitude, padding, numPeaks, numPeaks, detectionThreshold, order, freqUnit, magUnit, windowSize, hopSize, fftSize, maxFFTSize, trig, blocking); + } + + *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, frequency = -1, magnitude = -1, numPeaks = 10, detectionThreshold = -96, order = 0, freqUnit = 0, magUnit = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, freeWhenDone = true, action| + + var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; + + source = source.asUGenInput; + frequency = frequency !? {frequency.asUGenInput} ?? {-1}; + magnitude = magnitude !? {magnitude.asUGenInput} ?? {-1}; + + source.isNil.if {"FluidBufSineFeature: Invalid source buffer".throw}; + + ^this.new( + server, nil, [frequency, magnitude].select{|x| x!= -1} + ).processList( + [source, startFrame, numFrames, startChan, numChans, frequency, magnitude, padding, numPeaks, numPeaks, detectionThreshold, order, freqUnit, magUnit, windowSize, hopSize, fftSize,maxFFTSize,0],freeWhenDone,action + ); + } + + *processBlocking { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, frequency = -1, magnitude = -1, numPeaks = 10, detectionThreshold = -96, order = 0, freqUnit = 0, magUnit = 0, windowSize = 1024, hopSize = -1, fftSize = -1, padding = 1, freeWhenDone = true, action| + + var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; + + source = source.asUGenInput; + frequency = frequency !? {frequency.asUGenInput} ?? {-1}; + magnitude = magnitude !? {magnitude.asUGenInput} ?? {-1}; + + source.isNil.if {"FluidBufSineFeature: Invalid source buffer".throw}; + + ^this.new( + server, nil, [frequency, magnitude].select{|x| x!= -1} + ).processList( + [source, startFrame, numFrames, startChan, numChans, frequency, magnitude, padding, numPeaks, numPeaks, detectionThreshold, order, freqUnit, magUnit, windowSize, hopSize, fftSize,maxFFTSize,1],freeWhenDone,action + ); + } + +} +FluidBufSineFeatureTrigger : FluidProxyUgen {} \ No newline at end of file diff --git a/release-packaging/Classes/FluidSineFeature.sc b/release-packaging/Classes/FluidSineFeature.sc new file mode 100644 index 0000000..5c92c25 --- /dev/null +++ b/release-packaging/Classes/FluidSineFeature.sc @@ -0,0 +1,37 @@ +FluidSineFeature : FluidRTMultiOutUGen { + *kr { arg in = 0, numPeaks = 10, detectionThreshold = -96, order = 0, freqUnit = 0, magUnit = 0, windowSize= 1024, hopSize= -1, fftSize= -1, maxFFTSize = -1, maxNumPeaks = nil; + + maxNumPeaks = maxNumPeaks ? numPeaks; + + ^this.multiNew('control', in.asAudioRateInput(this), numPeaks, maxNumPeaks, detectionThreshold, order, freqUnit, magUnit, windowSize, hopSize, fftSize, maxFFTSize) + } + + init { arg ... theInputs; + inputs = theInputs; + ^this.initOutputs(inputs.at(2),rate);//this instantiate the number of output from the maxNumPeaks in the multiNew order + } + + checkInputs { + if(inputs.at(8).rate != 'scalar') { + ^(": maxNumPeaks cannot be modulated."); + }; + if(inputs.at(7).rate != 'scalar') { + ^(": maxFFTSize cannot be modulated."); + }; + ^this.checkValidInputs; + } + + initOutputs{|numChans,rate| + if(numChans.isNil or: {numChans < 1}) + { + Error("No input channels").throw + }; + + channels = Array.fill(numChans * 2, { |i| + OutputProxy('control',this,i); + }); + ^channels + } + + numOutputs { ^(channels.size); } +} diff --git a/release-packaging/Examples/Guides/Neural Network Predicts FM Params from Audio Analysis.scd b/release-packaging/Examples/Guides/Neural Network Predicts FM Params from Audio Analysis.scd index 8dc3031..aa8f5b5 100644 --- a/release-packaging/Examples/Guides/Neural Network Predicts FM Params from Audio Analysis.scd +++ b/release-packaging/Examples/Guides/Neural Network Predicts FM Params from Audio Analysis.scd @@ -47,37 +47,33 @@ s.waitForBoot{ }); }); }; - var open_mlp = { - arg path; - // nn.prGetParams.postln; - nn.read(path,{ - var params = nn.prGetParams; - var n_layers = params[1]; - var layers_string = ""; - - // params.postln; + var display_mlp_params = { + var params = nn.prGetParams; + var n_layers = params[1]; + var layers_string = ""; - n_layers.do({ - arg i; - if(i > 0,{layers_string = "% ".format(layers_string)}); - layers_string = "%%".format(layers_string,params[2+i]); - }); + // params.postln; - nn.maxIter_(maxIter_nb.value); - nn.learnRate_(learnRate_nb.value); - nn.momentum_(momentum_nb.value); - nn.batchSize_(batchSize_nb.value); - - defer{ - hidden_tf.string_(layers_string); - act_pum.value_(nn.activation); - outAct_pum.value_(nn.outputActivation); - /* maxIter_nb.value_(nn.maxIter); - learnRate_nb.value_(nn.learnRate); - momentum_nb.value_(nn.momentum); - batchSize_nb.value_(nn.batchSize);*/ - }; + n_layers.do({ + arg i; + if(i > 0,{layers_string = "% ".format(layers_string)}); + layers_string = "%%".format(layers_string,params[2+i]); }); + + nn.maxIter_(maxIter_nb.value); + nn.learnRate_(learnRate_nb.value); + nn.momentum_(momentum_nb.value); + nn.batchSize_(batchSize_nb.value); + + defer{ + hidden_tf.string_(layers_string); + act_pum.value_(nn.activation); + outAct_pum.value_(nn.outputActivation); + /* maxIter_nb.value_(nn.maxIter); + learnRate_nb.value_(nn.learnRate); + momentum_nb.value_(nn.momentum); + batchSize_nb.value_(nn.batchSize);*/ + }; }; ~in_bus = Bus.audio(s); @@ -162,11 +158,11 @@ s.waitForBoot{ // MLP Parameters StaticText(win,Rect(0,0,label_width,20)).align_(\right).string_("hidden layers"); hidden_tf = TextField(win,Rect(0,0,item_width - label_width,20)) - .string_(nn.hidden.asString.replace(", "," ")[2..(nn.hidden.asString.size-3)]) + .string_(nn.hiddenLayers.asString.replace(", "," ")[2..(nn.hiddenLayers.asString.size-3)]) .action_{ arg tf; var hidden_ = "[%]".format(tf.string.replace(" ",",")).interpret; - nn.hidden_(hidden_); + nn.hiddenLayers_(hidden_); // nn.prGetParams.postln; }; @@ -256,20 +252,39 @@ s.waitForBoot{ win.view.decorator.nextLine; Button(win,Rect(0,0,100,20)) - .states_([["Save MLP"]]) + .states_([["Save"]]) .action_{ Dialog.savePanel({ arg path; - nn.write(path); + nn.dump{ + arg mlp_dict; + scaler_params.dump{ + arg scaler_params_dict; + scaler_mfcc.dump{ + arg scaler_mfcc_dict; + var dict = Dictionary.new; + dict['mlp'] = mlp_dict; + dict['scaler_params'] = scaler_params_dict; + dict['scaler_mfcc'] = scaler_mfcc_dict; + + dict.writeArchive(path); + }; + }; + }; + }); }; Button(win,Rect(0,0,100,20)) - .states_([["Open MLP"]]) + .states_([["Open"]]) .action_{ Dialog.openPanel({ arg path; - open_mlp.(path); + var dict = Object.readArchive(path); + + nn.load(dict['mlp'].postln,{display_mlp_params.value}); + scaler_params.load(dict['scaler_params'].postln); + scaler_mfcc.load(dict['scaler_mfcc'].postln); }); }; @@ -299,15 +314,6 @@ s.waitForBoot{ statsWinSl.valueAction_(0.0); - /* 100.do{ - var cfreq = exprand(20,20000); - var mfreq = exprand(20,20000); - var index = rrand(0.0,20); - parambuf.setn(0,[cfreq,mfreq,index]); - 0.2.wait; - add_point.value; - 0.05.wait; - };*/ 40.do{ var cfreq = exprand(100.0,1000.0); var mfreq = exprand(100.0,min(cfreq,500.0)); diff --git a/release-packaging/HelpSource/Guides/FluidCorpusManipulation.schelp b/release-packaging/HelpSource/Guides/FluidCorpusManipulation.schelp index 7426ea7..cca29dc 100644 --- a/release-packaging/HelpSource/Guides/FluidCorpusManipulation.schelp +++ b/release-packaging/HelpSource/Guides/FluidCorpusManipulation.schelp @@ -49,6 +49,7 @@ table:: ##link::Classes/FluidAmpFeature:: || link::Classes/FluidBufAmpFeature:: || Detrending Amplitude Envelope Descriptor ##link::Classes/FluidNoveltyFeature:: || link::Classes/FluidBufNoveltyFeature:: || Novelty descriptor based on a choice of analysis descriptors ##link::Classes/FluidOnsetFeature:: || link::Classes/FluidBufOnsetFeature:: || Descriptor comparing spectral frames using a choice of comparisons +##link::Classes/FluidSineFeature:: || link::Classes/FluidBufSineFeature:: || Sinusoidal peak extraction :: section:: Decompose Audio