From 478eeca99ee6f5bad3063700fbcc9d8913c770ae Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Fri, 17 Jan 2003 04:37:14 +0000 Subject: "" svn path=/trunk/; revision=342 --- externals/grill/fftease/src/swinger~.cpp | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 externals/grill/fftease/src/swinger~.cpp (limited to 'externals/grill/fftease/src/swinger~.cpp') diff --git a/externals/grill/fftease/src/swinger~.cpp b/externals/grill/fftease/src/swinger~.cpp new file mode 100644 index 00000000..39fbd9a1 --- /dev/null +++ b/externals/grill/fftease/src/swinger~.cpp @@ -0,0 +1,62 @@ +/* + +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 + + +// add quality switch + +class swinger: + public fftease +{ + FLEXT_HEADER(swinger,fftease) + +public: + swinger(); + +protected: + + virtual V Transform(I n,S *const *in); +}; + +FLEXT_LIB_DSP("fftease, swinger~",swinger) + + +swinger::swinger(): + fftease(2,F_STEREO|F_BITSHUFFLE) +{ + AddInSignal("Messages and input signal"); + AddInSignal("Signal to supply phase information"); + AddOutSignal("Transformed signal"); +} + + +V swinger::Transform(I _N2,S *const *in) +{ + for (I i = 0; i <= _N2; i++ ) { + const I even = i*2,odd = even+1; + + // convert to polar coordinates from complex values + // replace signal one's phases with those of signal two + const F a1 = ( i == _N2 ? _buffer1[1] : _buffer1[even] ); + const F b1 = ( i == 0 || i == _N2 ? 0. : _buffer1[odd] ); + const F amp = hypot( a1, b1 ); + + const F a2 = ( i == _N2 ? _buffer2[1] : _buffer2[even] ); + const F b2 = ( i == 0 || i == _N2 ? 0. : _buffer2[odd] ); + const F ph = -atan2( b2, a2 ); + + _buffer1[even] = amp * cos( ph ); + if ( i != _N2 ) + _buffer1[odd] = -amp * sin( ph ); + } +} -- cgit v1.2.1