import pitaru.sonia_v2_9.*; //import com.sun.javax.swing.*; RGS theRGS; Frame theFrame; void setup() { theRGS = new RGS(); size(theRGS.timeAxisSize,theRGS.freqAxisSize); // start sonia, and LiveOutput.. Sonia.start(this,theRGS.SAMPLE_RATE); LiveOutput.start(theRGS.framesPerBuffer, 2*theRGS.framesPerBuffer); // Bigger buffers will increase latency, yet reduce 'pop' sounds. LiveOutput.setSleep(5); // Set the LiveOutput Thread sleep time (lower numbers will give more power to the sonia engine, but slows down other CPU tasks) LiveOutput.startStream(); theFrame = new ControlFrame("RGS",theRGS); theFrame.show(); theRGS.clearAll(); } void draw(){ } public void stop(){ Sonia.stop(); super.stop(); } /* event monitoring */ // serve up the audio buffer void liveOutputEvent() { for (int i =0;itheRGS.audioSampleSize) theRGS.audioSamplePointer=0; LiveOutput.data[i]=theRGS.audioSample[theRGS.audioSamplePointer]; }; // transferred... } void mousePressed() { theRGS. mouseWasPressed=true; theRGS.mouseDragged(); // println("Pressed!"); } void mouseReleased() { theRGS.mouseWasPressed=false; theRGS.dotOnce=false; // println("released!"); } void mouseMoved() { theRGS.mouseWasPressed=false; theRGS.dotOnce=false; // println("moved!"); } void mouseDragged() { theRGS.mouseDragged(); } // up 38 left 37 right 39 down 40 void keyPressed() { int keyCode = keyEvent.getKeyCode(); // println("KEY EVENT CODE:"+keyCode ); if((key == 'T')||(key =='t')) { theRGS.clearAll(); // println("cleared"); } if((key == 'R')||(key =='r')) { theRGS.regen(); // println("regenned"); } // key pad .. if( (keyCode >= 97) &&(keyCode<=106)) { theRGS.rgsPen = keyCode-97; // println("selected pen "+ rgsPen); } if(key == 'o') { // write the thing? }; //up if(keyCode == 38) { } // down if(keyCode == 40) { } //left if(keyCode == 37) { theRGS.setRampAmount( theRGS.rampAmount--); } // right if(keyCode == 39) { theRGS.setRampAmount( theRGS.rampAmount++); } } /* RGS object */ class RGS extends Object { int SAMPLE_RATE = 22050; //int framesPerBuffer = 512; // LiveOutput buffer size. try 256 as well for better latency performance. int framesPerBuffer = 2048; // LiveOutput buffer size. try 256 as well for better latency performance. int freqAxisSize=1024; // better be well below nyquist float topFreq=5000.0; float botFreq=topFreq/128.0; float phase[]=new float[freqAxisSize]; float phaseInc[]=new float[freqAxisSize]; // time space: fiddle with these numbers so it's integral int samplesPerX = 128; int timeAxisSize=800; int audioSampleSize=samplesPerX * timeAxisSize; float timeAxisSeconds= (float)audioSampleSize/(float)SAMPLE_RATE; float secondsPerX = timeAxisSeconds/timeAxisSize; float audioSample[] = new float[audioSampleSize]; int audioSamplePointer= 0; int colorSpread=16; color ampColors[]= new color[16]; /* the rgs colors: 00 00 00 rgb w, 06 06 06 rgb w, 00 00 09 rgb w, 02 00 00 rgb w, 04 00 00 rgb w, 06 00 00 rgb w, 07 00 00 rgb w, 08 00 00 rgb w, 09 00 00 rgb w, 10 02 00 rgb w, 11 04 00 rgb w, 12 06 00 rgb w, 13 08 00 rgb w, 14 10 00 rgb w, 15 13 00 rgb w, 09 15 05 rgb w, \ phonemic color */ float ampColorLow,ampColorHigh; float ampArray[]=new float[freqAxisSize*timeAxisSize]; int rgsPen; float mixAmp=1.0/32.0; int blob_x=3; int blob_y=3; float currentAmp=0.8; int rampAmount=20; boolean mouseWasPressed; boolean dotOnce; // interface crapola Frame theFrame; RGS() { int c,i; // amplitude "axis" = color c=0; ampColorLow=0.0; ampColorHigh=1.0; if(false) { for(i=0;ifreqAxisSize-5)) // println("pI["+i+"] = "+phaseInc[i]); } mousePressed=false; clearAll(); } void mouseDragged() { // determine which "pen" to use // println("dragged! ud: "+(mousePressed?"up":"down")+" X:"+mouseX+" y:"+mouseY); if(mousePressed) int i,j; float ampt,sum; switch(rgsPen) { case 0: // Ramp! { ampt=currentAmp; for(i=0;i0) addSonicPixel(mouseX-i,mouseY,ampt); ampt-=(currentAmp/rampAmount); } break; } case 1: // dotty more often { addSonicPixel(mouseX,mouseY,currentAmp); break; } case 2: // dotty once { if(! dotOnce) { for(i=0;i=timeAxisSize) return; if(y>=freqAxisSize) return; // clamp amp if(amp>=1.0) amp=1.0-(1.0/SAMPLE_RATE); if(amp<0.0) amp=0.0; // println("DDD amp:"+amp+" colorPtr:"+colorPtr); float timeStart = x*secondsPerX; int samplePtr = x*samplesPerX; float myPhase = phase[y]+timeStart*SAMPLE_RATE*phaseInc[y]; // if I were using Qsins, this would be more interesting float pInc= phaseInc[y]; int coord = clampCoord(x,y); // println("sPix: x:"+x+" y:"+y+" sptr:"+samplePtr+" myPhase:"+myPhase+" phaseInc: "+pInc+" phaseInc*samplesize:"+pInc*samplesPerX); set(x,y,ampColorOf(amp)); // a0=ampArray[clampCoord(x-1,y)]*mixAmp; //println("DDD add s pix a0:"+a0+" a1:"+a1); for(int s=0;s=0) { audioSample[samplePtr-1-s]+=mixedAmp*sin(phase0); } if(samplePtr+1+s=timeAxisSize) x=timeAxisSize-1; if(y>=freqAxisSize) y=freqAxisSize-1; return y*timeAxisSize+x; } void sonicWipe(int x, int y) { if(x<0) return; if(y<0) return; if(x>=timeAxisSize) return; if(y>=freqAxisSize) return; float timeStart = x*secondsPerX; int samplePtr = x*samplesPerX; // if I were using Qsins, this would be more interesting int coord = y*timeAxisSize+x; // println("sPix: x:"+x+" y:"+y+" sptr:"+samplePtr+" myPhase:"+myPhase+" phaseInc: "+pInc+" phaseInc*samplesize:"+pInc*samplesPerX); set(x,y,ampColorOf(0.0)); for(int s=0;sampColorHigh) return ampColors[15]; ix = (int)(3.0+12.0*(amp-ampColorLow)/(ampColorHigh-ampColorLow)); return ampColors[ix]; } public int setRGSPen(int p) { return rgsPen=p; } int setRampAmount(int r) { if(r<1) r=1; if(r>100) r=100; return rampAmount=r; } float setAmpAmount(float r) { return currentAmp=r; } float setMixAmp(float Mix) { //println("mix:"+Mix); return mixAmp =(1.0f/ (float) Mix); }; void clearAll() { int i; for(i=0;i