aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/fftease/src/vacancy~.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/fftease/src/vacancy~.cpp')
-rw-r--r--externals/grill/fftease/src/vacancy~.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/externals/grill/fftease/src/vacancy~.cpp b/externals/grill/fftease/src/vacancy~.cpp
new file mode 100644
index 00000000..a6d0a852
--- /dev/null
+++ b/externals/grill/fftease/src/vacancy~.cpp
@@ -0,0 +1,125 @@
+/*
+
+FFTease - A set of Live Spectral Processors
+Originally written by Eric Lyon and Christopher Penrose for the Max/MSP platform
+
+Copyright (c)Thomas Grill (xovo@gmx.net)
+For information on usage and redistribution, and for a DISCLAIMER OF ALL
+WARRANTIES, see the file, "license.txt," in this distribution.
+
+*/
+
+#include "main.h"
+#include <stdlib.h>
+
+class vacancy:
+ public fftease
+{
+ FLEXT_HEADER_S(vacancy,fftease,setup)
+
+public:
+ vacancy(I argc,const t_atom *argv);
+
+protected:
+ virtual V Transform(I n,S *const *in);
+
+ V ms_thresh(F thr) { _threshold = (F)pow(10.,(_threshdB = thr)*.05); }
+
+ F _threshold,_threshdB;
+ BL _invert,_useRms,_swapPhase;
+
+private:
+ static V setup(t_classid c);
+
+ FLEXT_ATTRGET_F(_threshdB)
+ FLEXT_CALLSET_F(ms_thresh)
+ FLEXT_ATTRVAR_B(_invert)
+ FLEXT_ATTRVAR_B(_useRms)
+ FLEXT_ATTRVAR_B(_swapPhase)
+};
+
+FLEXT_LIB_DSP_V("fftease, vacancy~",vacancy)
+
+
+V vacancy::setup(t_classid c)
+{
+ FLEXT_CADDATTR_VAR(c,"threshold",_threshdB,ms_thresh);
+ FLEXT_CADDATTR_VAR1(c,"invert",_invert);
+ FLEXT_CADDATTR_VAR1(c,"rms",_useRms);
+ FLEXT_CADDATTR_VAR1(c,"swapphase",_swapPhase);
+}
+
+
+vacancy::vacancy(I argc,const t_atom *argv):
+ fftease(2,F_BITSHUFFLE|F_CONVERT),
+ _threshdB(-30),_invert(false),_useRms(true),_swapPhase(false)
+{
+ /* parse and set object's options given */
+ if(argc >= 1) {
+ if(CanbeFloat(argv[0]))
+ _threshdB = GetAFloat(argv[0]);
+ else
+ post("%s - Threshold must be a float value - set to %f",thisName(),_threshdB);
+ }
+
+ if(argc >= 2) {
+ if(CanbeBool(argv[1]))
+ _invert = GetABool(argv[1]);
+ else
+ post("%s - Invert must be a boolean value - set to %0i",thisName(),_invert?1:0);
+ }
+
+ if(argc >= 3) {
+ if(CanbeBool(argv[2]))
+ _useRms = GetABool(argv[2]);
+ else
+ post("%s - Rms flag must be a boolean value - set to %0i",thisName(),_useRms?1:0);
+ }
+
+ if(argc >= 4) {
+ if(CanbeBool(argv[3]))
+ _swapPhase = GetABool(argv[3]);
+ else
+ post("%s - Swapphase flag must be a boolean value - set to %0i",thisName(),_swapPhase?1:0);
+ }
+
+ ms_thresh(_threshdB);
+
+ AddInSignal("Messages and input signal");
+ AddInSignal("Reference signal");
+ AddOutSignal("Transformed signal");
+}
+
+
+V vacancy::Transform(I _N2,S *const *in)
+{
+ const F useme = _useRms?_rms * _threshold:_threshold;
+
+ // composite here please
+ if (_invert)
+ if (_swapPhase)
+ for (I i=0; i < _N2; i+=2 )
+ if ( _channel1[i] > useme && _channel2[i] < _channel1[i] ) {
+ _channel1[i] = _channel2[i];
+ _channel1[i+1] = _channel2[i+1];
+ }
+ else
+ for (I i=0; i < _N2; i+=2 )
+ if ( _channel1[i] > useme && _channel2[i] < _channel1[i] ) {
+ _channel1[i] = _channel2[i];
+ if ( _channel1[i+1] == 0. ) _channel1[i+1] = _channel2[i+1];
+ }
+ else
+ if (_swapPhase)
+ for (I i=0; i < _N2; i+=2 )
+ if ( _channel1[i] < useme && _channel2[i] > _channel1[i] ) {
+ _channel1[i] = _channel2[i];
+ _channel1[i+1] = _channel2[i+1];
+ }
+ else
+ for (I i=0; i < _N2; i+=2 )
+ if ( _channel1[i] < useme && _channel2[i] > _channel1[i] ) {
+ _channel1[i] = _channel2[i];
+ if ( _channel1[i+1] == 0. ) _channel1[i+1] = _channel2[i+1];
+ }
+}