512 => int WINDOW_SIZE; 10 => float DISPLAY_WIDTH; // GG.fullscreen(); GG.camera() --> GGen dolly --> GG.scene(); GG.camera().posZ( 10 ); GG.scene().backgroundColor( @(0, 0, 0) ); // Polar Flower Renderer GPoints polar_flower --> GG.scene(); polar_flower.mat().lineWidth(1.0); // polar_flower.posY(2); GLines flower_lines --> GG.scene(); flower_lines.mat().lineWidth(0.5); // flower_lines.posY(2); adc => Flip accum => blackhole; adc => PoleZero dcbloke => FFT fft => blackhole; 0.95 => dcbloke.blockZero; WINDOW_SIZE => accum.size; Windowing.hann(WINDOW_SIZE) => fft.window; WINDOW_SIZE * 2 => fft.size; Windowing.hann(WINDOW_SIZE) @=> float window[]; float samples[0]; // FFT response; complex response[0]; vec3 vertices[WINDOW_SIZE]; float positions[WINDOW_SIZE * 3]; fun void map2polar(float in[], float out[], float c, int graph_choice) { if ( in.size() * 3 != out.size() ) { <<< "size mismatch in flatten()", "" >>>; return; } // mapping to xyz coordinate; int i; DISPLAY_WIDTH => float width; for ( auto s : in ) { // MAP i * 0.5 => float theta; float r; if (graph_choice == 0) { Math.sin(c * theta) * theta / 100 => r; } // Tried to have another option but didn't work. else if (graph_choice == 1) { // Math.sin((3 * i / 4) + (1 + c) * Math.PI / 6) - Math.acos(Math.cos(3 * i)) => r; Math.cos(c * theta) + Math.sin(Math.PI * theta / 4) => r; } r * Math.cos(i) => out[i * 3]; r * Math.sin(i) => out[i * 3 + 1]; 0 => out[i * 3 + 2]; i++; } } fun void doAudio() { while (true) { accum.upchuck(); accum.output( samples ); fft.upchuck(); fft.spectrum( response ); WINDOW_SIZE::samp/2 => now; } } spork ~ doAudio(); fun float max_value(float in[]) { -1000.0 => float max; for ( auto s : in ) { Math.max(max, s) => max; } return max; } 1.0 => float cDirection; 0.0 => float c; 1 => int graph_choice; 2 => int max_choices; while (true) { max_value( samples ) => float amplitude; map2polar( samples, positions, c, graph_choice); @(amplitude * 50 + 0.2, amplitude * 50 + 0.2, amplitude * 50 + 0.2) => vec3 lighter_color; @(amplitude * 25 + 0.2, amplitude * 25 + 0.2, amplitude * 25 + 0.2) => vec3 darker_color; polar_flower.geo().positions(positions); polar_flower.mat().color(lighter_color); // if (graph_choice == 0) { flower_lines.geo().positions(positions); flower_lines.mat().color(darker_color); // } else { // flower_lines.mat().color(@(0, 0, 0)); // } if (c > 10 || c < -10) { -cDirection => cDirection; } c + cDirection * amplitude/(100) => c; GG.nextFrame() => now; }