Skip to content

Instantly share code, notes, and snippets.

@jrsa
Created April 20, 2016 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrsa/4d7e8b187c4b692d1d0e05c87e9737bd to your computer and use it in GitHub Desktop.
Save jrsa/4d7e8b187c4b692d1d0e05c87e9737bd to your computer and use it in GitHub Desktop.
// chuck patch that takes in x, y from processing and
// uses them as complex frequency bins to be fed into
// an inverse fourier transform
IFFT ifft => dac;
0.25 => ifft.gain;
512 => int size;
size / 2 => int arraySize;
complex s[ arraySize ];
OscOut out;
( "127.0.0.1", 6969 ) => out.dest;
// tell processing how big the spectrum should be
"/init/spectrumWidth" => out.start;
arraySize - 1 => out.add;
out.send();
OscIn in;
6970 => in.port;
in.listenAll();
fun void oscListener() {
while( true ) {
in => now;
OscMsg msg;
while( in.recv( msg ) != 0 ) {
if( msg.address == "/bin" ) {
// pcessing sends a bin index and a
// complex value
msg.getInt( 0 ) => int idx;
msg.getFloat( 1 ) => float re;
msg.getFloat( 2 ) => float im;
// insert complex value into array
#(re, im) => s[ idx ];
<<< idx, #(re, im) >>>;
}
}
}
}
fun void resynth() {
while( true ) {
// 's' contains the spectrum values
// sent from processing
s => ifft.transform;
(size * 2) :: samp => now;
}
}
spork ~ oscListener();
spork ~ resynth();
while( true ) 1::second => now;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment