aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/fftease/src/swinger~.cpp
blob: b2ecba34055532b7b5b5835230d1c28cdbbb0716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*

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>


// 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] );
		// amplitude only
		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] );
		// phase only
		const F ph = -atan2( b2, a2 );

		_buffer1[even] = amp * cos( ph );
		if ( i != _N2 )
			_buffer1[odd] = -amp * sin( ph );
	}
}