sound file to replace saw wave in example
in
Core Library Questions
•
2 years ago
Hi,
I have a patch below which uses an ellipse to pan a simple saw wave and change its level. I want to replace this with a wav or mp3 sample. i understand how to load a snippet but i am confused how to implement this into my attached example. Any help much appreciated.
josh
- import ddf.minim.*;
- import ddf.minim.signals.*;
- Minim minim;
- AudioOutput out;
- Oscillator osc;
- boolean over = false;
- boolean selected = false;
- int posX, posY;
- int offsetX, offsetY;
- float radius = 25.0f;
- void setup()
- {
- size(512, 200);
- minim = new Minim(this);
- out = minim.getLineOut();
- // see the example AudioOutput >> SawWaveSignal for more about this class
- osc = new SawWave(100, 0.2, out.sampleRate());
- // see the example Polyphonic >> addSignal for more about this
- out.addSignal(osc);
- // see the example Recordable >> addListener for more about this
- textFont(createFont("SanSerif", 12));
- posX = width/2;
- posY = height/2;
- smooth();
- }
- void draw()
- {
- background(0);
- strokeWeight (1.0f);
- fill(255,155);
- // see waveform.pde for more about this
- if ( out.hasControl(Controller.PAN) )
- {
- // map the mouse position to the range of the pan
- float valPan = map(posX, 0, width, -1, 1);
- // if a pan control is not available, this will do nothing
- out.setPan(valPan);
- float valGain = map(posY, 0, height, 6, -48);
- out.setGain(valGain);
- // if a pan control is not available this will report zero
- ;
- if (selected)
- strokeWeight (2.0f);
- if (over)
- fill (255,255);
- ellipse (posX,posY,radius*2.0f,radius*2.0f);
- }
- else
- {
- text("The output doesn't have a pan control.", 5, 20);
- }
- }
- void stop()
- {
- // always close Minim audio classes when you are finished with them
- out.close();
- minim.stop();
- super.stop();
- }
- void mouseMoved() {
- over = false;
- if (sqrt(sq(mouseX-posX)+sq(mouseY-posY))<=radius) {
- over = true;
- }
- }
- void mousePressed() {
- if (over) {
- selected = true;
- offsetX = posX-mouseX;
- offsetY = posY-mouseY;
- }
- }
- void mouseReleased() {
- selected = false;
- }
- void mouseDragged()
- {
- if (selected) {
- posX = max(0,min(mouseX+offsetX,width));
- posY = max(0,min(mouseY+offsetY,height));
- }
- }
1