// MAUI-Based Spectrum display // (and CPU/GFX Chip heater) // by Perry R. Cook, 2012 adc => Gain inGain => FFT fft => blackhole; // draw samples through FFT 128 => fft.size; fft.size() / 2 => int halfSize; Windowing.hamming(fft.size()) => fft.window; UAnaBlob blob; MAUI_View myWinder; myWinder.size(640,300); myWinder.name("Silly MAUI Log Spectrum Display, Perry R. Cook, 2012"); MAUI_Button points[halfSize]; MAUI_Slider volume; volume.position(400,0); volume.name("Input Gain"); volume.range(0.0,10.0); volume.value(1.0);myWinder.addElement(volume); MAUI_Button exit; exit.name("Exit"); exit.toggleType(); exit.size(80,80); exit.position(570,200); myWinder.addElement(exit); MAUI_Button abcissa[2]; abcissa[0].size(100,60); abcissa[1].size(100,60); abcissa[0].position(0,250); abcissa[1].position(530,250); abcissa[0].name("0Hz.");abcissa[1].name("SRATE/2"); myWinder.addElement(abcissa[0]); myWinder.addElement(abcissa[1]); int i; for (0 => i; i < halfSize; i++) { points[i].size(46,45); points[i].toggleType; 1 => points[i].state; myWinder.addElement(points[i]); } myWinder.display(); 1 => int notDone; float targs[halfSize]; while (notDone) { 8*halfSize :: samp => now; fft.upchuck() @=> blob; // Compute and blob.fvals() @=> float mag[]; // store spectrum volume.value() => inGain.gain; for (0 => i; i < halfSize; i++) { if (mag[i] > 0.000001) Math.log10(mag[i]) => mag[i]; else -6.0 => mag[i]; targs[i]*0.9 + mag[i]*0.1 => targs[i]; } for (0 => i; i < halfSize; i++) { points[i].position(20+i*8,-targs[i]*40); points[i].size(45,(7+targs[i])*40); } if (exit.state()) 0 => notDone; } myWinder.destroy();