From 6c9bc8fc9d882ddccd197c8eddf51f9e664b7723 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 22 Jun 2016 02:02:31 +0200 Subject: BowelyzerAnalyzer.sc: Further deviding functionality by moving adding and starting (alongside stopping, toggling) of Synths to their own sub functions. Adding input channel as separate argument to the analysis synths. Adding separate SendReply Ugen for LevelIndicator in GUI. --- BowelyzerAnalyzer.sc | 192 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 114 insertions(+), 78 deletions(-) diff --git a/BowelyzerAnalyzer.sc b/BowelyzerAnalyzer.sc index f50f89d..f6ad54e 100644 --- a/BowelyzerAnalyzer.sc +++ b/BowelyzerAnalyzer.sc @@ -33,107 +33,143 @@ BowelyzerAnalyzer{ arg config; config.at(\inputs).keysValuesDo({|name, inputChannel| ("Adding SynthDef \""++name++"\" on input "++inputChannel).postln; - SynthDef(name, { - arg sendReplyFreq, - amplitudeAttackTime, - amplitudeReleaseTime, - hfHainsworth, - hfFoote, - hfThreshold, - hfWaitTime, - pitchInitFreq, - pitchMinFreq, - pitchMaxFreq, - pitchExecFreq, - pitchMaxBinsPerOctave, - pitchMedian, - pitchAmpThreshold, - pitchPeakThreshold, - pitchDownSample - ; - var amplitude, input, detect, pitch, hasPitch; - //TODO: Add volume for SoundIn - input = SoundIn.ar(bus: inputChannel); - amplitude = Amplitude.kr( - in: input, - attackTime: amplitudeAttackTime, - releaseTime: amplitudeReleaseTime - ); - detect = A2K.kr( - PV_HainsworthFoote.ar( - FFT(LocalBuf(2048), input), - proph: hfHainsworth, - propf: hfFoote, - threshold: hfThreshold, - waittime: hfWaitTime - ) - ); - # pitch, hasPitch = Pitch.kr( - in: input, - initFreq: pitchInitFreq, - minFreq: pitchMinFreq, - maxFreq: pitchMaxFreq, - execFreq: pitchExecFreq, - maxBinsPerOctave: pitchMaxBinsPerOctave, - median: pitchMedian, - ampThreshold: pitchAmpThreshold, - peakThreshold: pitchPeakThreshold, - downSample: pitchDownSample - ); - SendReply.kr( - Impulse.kr(sendReplyFreq), - "/"++name, - [amplitude, pitch, hasPitch, detect] - ); - }).add; + this.addSynthWithName(name); }); } + addSynthWithName{ + arg name; + SynthDef(name, { + arg inputChannel, + sendReplyFreq, + amplitudeAttackTime, + amplitudeReleaseTime, + hfHainsworth, + hfFoote, + hfThreshold, + hfWaitTime, + pitchInitFreq, + pitchMinFreq, + pitchMaxFreq, + pitchExecFreq, + pitchMaxBinsPerOctave, + pitchMedian, + pitchAmpThreshold, + pitchPeakThreshold, + pitchDownSample + ; + var amplitude, input, detect, pitch, hasPitch; + //TODO: Add volume for SoundIn + input = SoundIn.ar(bus: inputChannel); + amplitude = Amplitude.kr( + in: input, + attackTime: amplitudeAttackTime, + releaseTime: amplitudeReleaseTime + ); + detect = A2K.kr( + PV_HainsworthFoote.ar( + FFT(LocalBuf(2048), input), + proph: hfHainsworth, + propf: hfFoote, + threshold: hfThreshold, + waittime: hfWaitTime + ) + ); + # pitch, hasPitch = Pitch.kr( + in: input, + initFreq: pitchInitFreq, + minFreq: pitchMinFreq, + maxFreq: pitchMaxFreq, + execFreq: pitchExecFreq, + maxBinsPerOctave: pitchMaxBinsPerOctave, + median: pitchMedian, + ampThreshold: pitchAmpThreshold, + peakThreshold: pitchPeakThreshold, + downSample: pitchDownSample + ); + // SendReply for OSCHub + SendReply.kr( + Impulse.kr(sendReplyFreq), + "/"++name, + [amplitude, pitch, hasPitch, detect] + ); + // SendReply for LevelIndicator + SendReply.kr( + Impulse.kr(10), + "/levels/"++name, + [ + Amplitude.kr(input), + K2A.ar( + Peak.ar( + input, + Delay1.kr(Impulse.kr(10)) + ).lag(0, 3) + ) + ] + ); + }).add; + } + startSynthsFromConfig{ arg config; config.at(\controls).keysValuesDo({|name, controls| postln("Starting synth \""++name++"\"."); - synths.add(name -> Synth( - name, - [ - sendReplyFreq: controls.at(\sendReplyFreq), - amplitudeAttackTime: controls.at(\amplitudeAttackTime), - amplitudeReleaseTime: controls.at(\amplitudeReleaseTime), - hfHainsworth: controls.at(\hfhainsworth), - hfFoote: controls.at(\hfFoote), - hfThreshold: controls.at(\hfThreshold), - hfWaitTime: controls.at(\hfWaitTime), - pitchInitFreq: controls.at(\pitchInitFreq), - pitchMinFreq: controls.at(\pitchMinFreq), - pitchMaxFreq: controls.at(\pitchMaxFreq), - pitchExecFreq: controls.at(\pitchExecFreq), - pitchMaxBinsPerOctave: controls.at(\pitchMaxBinsPerOctave), - pitchMedian: controls.at(\pitchMedian), - pitchAmpThreshold: controls.at(\pitchAmpThreshold), - pitchPeakThreshold: controls.at(\pitchPeakThreshold), - pitchDownSample: controls.at(\pitchDownSample) - ], - analyzerGroup - ); - ); + this.startSynthWithNameAndControls(name, controls, config.at(\inputs).at(name)); }); } + startSynthWithNameAndControls{ + arg name, controls, input; + synths.add(name -> Synth( + name, + [ + inputChannel: input, + sendReplyFreq: controls.at(\sendReplyFreq), + amplitudeAttackTime: controls.at(\amplitudeAttackTime), + amplitudeReleaseTime: controls.at(\amplitudeReleaseTime), + hfHainsworth: controls.at(\hfhainsworth), + hfFoote: controls.at(\hfFoote), + hfThreshold: controls.at(\hfThreshold), + hfWaitTime: controls.at(\hfWaitTime), + pitchInitFreq: controls.at(\pitchInitFreq), + pitchMinFreq: controls.at(\pitchMinFreq), + pitchMaxFreq: controls.at(\pitchMaxFreq), + pitchExecFreq: controls.at(\pitchExecFreq), + pitchMaxBinsPerOctave: controls.at(\pitchMaxBinsPerOctave), + pitchMedian: controls.at(\pitchMedian), + pitchAmpThreshold: controls.at(\pitchAmpThreshold), + pitchPeakThreshold: controls.at(\pitchPeakThreshold), + pitchDownSample: controls.at(\pitchDownSample) + ], + analyzerGroup + ); + ); + } + + // set a synth control by provoding its name, its control name and control value setSynthControl{ - arg name, control; - synths.at(name).set(control[0], control[1]); + arg name, controlName, controlValue; + synths.at(name).set(controlName, controlValue); } + // start a synth by name startAnalysisSynth{ arg name; synths.at(name).run(true); } + // stop a synth by name stopAnalysisSynth{ arg name; synths.at(name).run(false); } + // free a synth by name + freeAnalysisSynth{ + arg name; + synths.at(name).free; + } + startAllAnalysisSynths{ analyzerGroup.run(true); } -- cgit v1.2.3-54-g00ecf