// chuck2POVRay2.ck // copyright 2007 Les Hall // This software released under the GNU General Protective License // experiments in visualization of music using chuck to produce POV-Ray code // control variables 1024 => int num_ffts; // number of fft sample sets to take 128 => int num_samples; // number of samples in each FFT num_samples / 2 => int num_freq; // number of frequencies in each FFT output 4 => float view_size; // divisor to restrict viewing size to lower harmonics 100 => float vscale; // vertical scaling factor // the patch(es) adc => Gain g => LPF lpf => FFT fft => blackhole; // set controlling parameters 1.0 => g.gain; 10000 => lpf.freq; num_samples => fft.size; Windowing.hamming(num_samples) => fft.window; // declare variables int t; // time counter complex samples[num_freq]; complex history[num_ffts][num_freq]; // time loop num_samples::samp => now; 0 => t; while (t < num_ffts) { // take fft fft.upchuck().cvals() @=> samples; // remember fft for (0 => int i; i < num_freq; i++) { samples[i] => history[t][i]; } // advance time t++; num_samples::samp => now; } // print out the POV-Ray code <<< "// total time in seconds =", (num_samples::samp * num_ffts) / (1::second) >>>; // output header text // these are the include files <<<"#include \"colors.inc\"", " ">>>; <<<"#include \"glass.inc\"", " ">>>; <<<"#include \"textures.inc\"", " ">>>; <<<"#include \"finish.inc\"", " ">>>; // these are the settings <<<"global_settings", "{">>>; <<<" assumed_gamma", "1">>>; <<<" max_trace_level", "256">>>; <<<"}", " ">>>; // this is the camera <<<"camera { location <", 0, ", 10,", -num_freq/2, "+", 3*num_ffts/2, "* clock> look_at <", 0, ", 0,", num_freq/2, "+", 3*num_ffts/2, "* clock>", "}">>>; // this is the light source <<<"light_source { <0, 10, 0>, rgb <1, 1, 1,>", " }">>>; // this is the sky sphere <<<"sky_sphere { pigment { rgb<1, 1, 1>", "} }">>>; // loop thru all the ffts for (0 => t; t < num_ffts - 1; t++) { for (0 => int f; f < num_freq / view_size - 1; f++) { <<<"object", "{">>>; <<<" triangle", "{">>>; <<<" <", (f-num_freq/2/view_size)*view_size, ",", vscale * (history[t][f] $ polar).mag, ",", t, ">,">>>; <<<" <", (f+1-num_freq/2/view_size)*view_size, ",", vscale * (history[t][f+1] $ polar).mag, ",", t, ">,">>>; <<<" <", (f+1-num_freq/2/view_size)*view_size, ",", vscale * (history[t+1][f+1] $ polar).mag, ",", t+1, ">">>>; <<<" }", " ">>>; <<<" pigment { Blue", "}">>>; <<<"}", " ">>>; <<<"object", "{">>>; <<<" triangle", "{">>>; <<<" <", (f-num_freq/2/view_size)*view_size, ",", vscale * (history[t][f] $ polar).mag, ",", t, ">,">>>; <<<" <", (f-num_freq/2/view_size)*view_size, ",", vscale * (history[t+1][f] $ polar).mag, ",", t+1, ">,">>>; <<<" <", (f+1-num_freq/2/view_size)*view_size, ",", vscale * (history[t+1][f+1] $ polar).mag, ",", t+1, ">">>>; <<<" }", " ">>>; <<<" pigment { Blue", "}">>>; <<<"}", " ">>>; } }