Looping Tone Instruments with Minim Sound Library and ADSR Envelope Example
in
Core Library Questions
•
3 years ago
Hello Everyone!
Any help with this question would be greatly appreciated.
My idea is to create a continuous pad sound with variable inputs that change oh, let us say, every few seconds. To accomplish this I've tweaked the ADSR Example code in the Minim Sound Library package so that I can call it as a method. I then want to call this method every 3 or 4 seconds with new frequency inputs.
The problem is that this is computing heavily on the machine and 'causing the output to bug. I think it has something to do with perpetually adding new threads or objects every time I call the method, but I'm not sure. And even if I was sure, I don't know how to change this.
Thanks so much! Here is my code:
- import ddf.minim.*;
- import ddf.minim.ugens.*;
- Minim minim;
- AudioOutput out;
- int counter = 0;
- boolean call = true;
- float freq_1 = 44;
- float freq_2 = 88;
- float freq_3 = 176;
- void setup (){
- size((int)300, (int)300, P2D);
- frameRate(60);
- }
- void draw(){
- background(240);
- if (counter == 500){
- call = true;
- println("CALL TRUE");
- }
- if (call == true){
- startTones(freq_1, freq_2, freq_3);
- call = false;
- counter = 0;
- }
- counter++;
- }
- void startTones (float f_1, float f_2, float f_3) {
- minim = new Minim( this );
- out = minim.getLineOut( Minim.MONO, 2048 );
- // pause time when adding a bunch of notes at once
- out.pauseNotes();
- // make four repetitions of the same pattern
- for( int i = 0; i < 4; i++ )
- {
- out.playNote( 0, 5, new ToneInstrument( f_1, 0.49, out ) );
- out.playNote( 0, 5, new ToneInstrument( f_2, 0.49, out ) );
- out.playNote( 2 , 10, new ToneInstrument( f_3, 0.4, out ) );
- }
- // resume time after a bunch of notes are added at once
- out.resumeNotes();
- }
- // stop is run when the user presses stop
- void stop()
- {
- // close the AudioOutput
- out.close();
- // stop the minim object
- minim.stop();
- // stop the processing object
- super.stop();
- }
1