// Sample Control for Processing V.90 // Description: Loads and manipulates the Pitch and Panning of a sample object // Instructions: Move the mouse Up/Down to control the sample-pitch, and sideways for the panning. // By: Amit Pitaru on July 16th 2005 import pitaru.sonia_v2_9.*; // automatically created when importing sonia using the processing menu. Sample mySample; void setup(){ size(512,200); Sonia.start(this); // Start Sonia engine. // create a new sample object. mySample = new Sample("sine.aiff"); } void draw(){ background(0,30,0); strokeWeight(1); // If sample is playing (or looping), do this... if(mySample.isPlaying()){ background(0,40,0); } setRate(); // use mouseY to control sample-rate playback setPan(); // use mouseX to control sample Panning //setVolume(); // use mouseX to control sample volume drawScroller(); } void mousePressed(){ // loop the sample mySample.repeat(); } void mouseReleased(){ // Stop the sample, and unload it form memory in 1 frames (each frame is about 1 ms). mySample.stop(1); } void setPan(){ // set the pan of the sample object. // Range: float from -1 to 1 .... -1 -> left, 0 -> balanced ,1 -> right // notes: only works with MONO samples. Pan for Stereo support in next version. float pan = -1f + mouseX/(width/2f); mySample.setPan(pan); } // NOT IN USE FOR THIS EXAMPLE void setVolume(){ // set the volume of the sample. // Range: float from 0 to 1 float vol = mouseY/(height*1f); mySample.setVolume(vol); } void setRate(){ // set the speed (sampling rate) of the sample. // Values: // 0 -> very low pitch (slow playback). // 88200 -> very high pitch (fast playback). float rate = (height - mouseY)*88200/(height); mySample.setRate(rate); } // Draw a scroller that shows the current sample-frame being played. // Notice how the sample plays faster when the Sample-Rate is higher.(controlled by mouseY) void drawScroller(){ strokeWeight(1); stroke(0,255,0); // figure out which percent of the sample has been played. float percent = mySample.getCurrentFrame() *100f / mySample.getNumFrames(); // calculate the marker position float marker = percent*width/100f; // draw... line(marker,0,marker,20); line(0,10, width,10); } // Safely close the sound engine upon Browser shutdown. public void stop(){ Sonia.stop(); super.stop(); }