diff --git a/java/libraries/minim/examples/AnalyzeSound/AnalyzeSound.pde b/java/libraries/minim/examples/AnalyzeSound/AnalyzeSound.pde index d2122efb7..46bdec13a 100644 --- a/java/libraries/minim/examples/AnalyzeSound/AnalyzeSound.pde +++ b/java/libraries/minim/examples/AnalyzeSound/AnalyzeSound.pde @@ -7,6 +7,9 @@ * the frequency content of a signal. You've seen * visualizations like this before in music players * and car stereos. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.analysis.*; diff --git a/java/libraries/minim/examples/CreateAnInstrument/CreateAnInstrument.pde b/java/libraries/minim/examples/CreateAnInstrument/CreateAnInstrument.pde new file mode 100644 index 000000000..e43c3f339 --- /dev/null +++ b/java/libraries/minim/examples/CreateAnInstrument/CreateAnInstrument.pde @@ -0,0 +1,85 @@ +/** + * This sketch demonstrates how to create synthesized sound with Minim using an AudioOutput and + * an Instrument we define. By using the playNote method you can schedule notes to played + * at some point in the future, essentially allowing to you create musical scores with code. + * Because they are constructed with code, they can be either deterministic or different every time. + * This sketch creates a deterministic score, meaning it is the same every time you run the sketch. + *

+ * For more complex examples of using playNote check out algorithmicCompExample and compositionExample + * in the Synthesis folder. + *

+ * For more information about Minim and additional features, visit http://code.compartmental.net/minim/ + */ + +import ddf.minim.*; +import ddf.minim.ugens.*; + +Minim minim; +AudioOutput out; + +// to make an Instrument we must define a class +// that implements the Instrument interface. +class SineInstrument implements Instrument +{ + Oscil wave; + Line ampEnv; + + SineInstrument( float frequency ) + { + // make a sine wave oscillator + // the amplitude is zero because + // we are going to patch a Line to it anyway + wave = new Oscil( frequency, 0, Waves.SINE ); + ampEnv = new Line(); + ampEnv.patch( wave.amplitude ); + } + + // this is called by the sequencer when this instrument + // should start making sound. the duration is expressed in seconds. + void noteOn( float duration ) + { + // start the amplitude envelope + ampEnv.activate( duration, 0.5f, 0 ); + // attach the oscil to the output so it makes sound + wave.patch( out ); + } + + // this is called by the sequencer when the instrument should + // stop making sound + void noteOff() + { + wave.unpatch( out ); + } +} + +void setup() +{ + size(512, 200, P3D); + + minim = new Minim(this); + + // use the getLineOut method of the Minim object to get an AudioOutput object + out = minim.getLineOut(); + + // when providing an Instrument, we always specify start time and duration + out.playNote( 0.0, 0.9, new SineInstrument( 97.99 ) ); + out.playNote( 1.0, 0.9, new SineInstrument( 123.47 ) ); + + // we can use the Frequency class to create frequencies from pitch names + out.playNote( 2.0, 2.9, new SineInstrument( Frequency.ofPitch( "C3" ).asHz() ) ); + out.playNote( 3.0, 1.9, new SineInstrument( Frequency.ofPitch( "E3" ).asHz() ) ); + out.playNote( 4.0, 0.9, new SineInstrument( Frequency.ofPitch( "G3" ).asHz() ) ); +} + +void draw() +{ + background(0); + stroke(255); + + // draw the waveforms + for(int i = 0; i < out.bufferSize() - 1; i++) + { + line( i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50 ); + line( i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50 ); + } +} diff --git a/java/libraries/minim/examples/GetMetaData/GetMetaData.pde b/java/libraries/minim/examples/GetMetaData/GetMetaData.pde index fe47ea429..717152ba2 100644 --- a/java/libraries/minim/examples/GetMetaData/GetMetaData.pde +++ b/java/libraries/minim/examples/GetMetaData/GetMetaData.pde @@ -10,6 +10,9 @@ * If you load WAV file or other non-tagged file, most of the metadata * will be empty, but you will still have information like the filename * and the length. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; @@ -52,14 +55,3 @@ void draw() text("Publisher: " + meta.publisher(), 5, y+=yi); text("Encoded: " + meta.encoded(), 5, y+=yi); } - - -void stop() -{ - // always close Minim audio classes when you are done with them - groove.close(); - // always stop Minim before exiting - minim.stop(); - - super.stop(); -} diff --git a/java/libraries/minim/examples/GetMetaData/data/groove.mp3 b/java/libraries/minim/examples/GetMetaData/data/groove.mp3 index abfd3c811..22fd64fd4 100644 Binary files a/java/libraries/minim/examples/GetMetaData/data/groove.mp3 and b/java/libraries/minim/examples/GetMetaData/data/groove.mp3 differ diff --git a/java/libraries/minim/examples/MonitorInput/MonitorInput.pde b/java/libraries/minim/examples/MonitorInput/MonitorInput.pde index 3ec94cc6f..86679683b 100644 --- a/java/libraries/minim/examples/MonitorInput/MonitorInput.pde +++ b/java/libraries/minim/examples/MonitorInput/MonitorInput.pde @@ -1,12 +1,17 @@ /** * This sketch demonstrates how to monitor the currently active audio input - * of the computer using an AudioInput. What you will actually + * of the computer using an AudioInput. What you will actually * be monitoring depends on the current settings of the machine the sketch is running on. * Typically, you will be monitoring the built-in microphone, but if running on a desktop - * its feasible that the user may have the actual audio output of the computer + * it's feasible that the user may have the actual audio output of the computer * as the active audio input, or something else entirely. *

- * When you run your sketch as an applet you will need to sign it in order to get an input. + * Press 'm' to toggle monitoring on and off. + *

+ * When you run your sketch as an applet you will need to sign it in order to get an input. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; @@ -22,9 +27,6 @@ void setup() // use the getLineIn method of the Minim object to get an AudioInput in = minim.getLineIn(); - - // uncomment this line to *hear* what is being monitored, in addition to seeing it - in.enableMonitoring(); } void draw() @@ -38,4 +40,22 @@ void draw() line( i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50 ); line( i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50 ); } + + String monitoringState = in.isMonitoring() ? "enabled" : "disabled"; + text( "Input monitoring is currently " + monitoringState + ".", 5, 15 ); +} + +void keyPressed() +{ + if ( key == 'm' || key == 'M' ) + { + if ( in.isMonitoring() ) + { + in.disableMonitoring(); + } + else + { + in.enableMonitoring(); + } + } } diff --git a/java/libraries/minim/examples/PatchingAnInput/PatchingAnInput.pde b/java/libraries/minim/examples/PatchingAnInput/PatchingAnInput.pde index 54b8719aa..e756a6d17 100644 --- a/java/libraries/minim/examples/PatchingAnInput/PatchingAnInput.pde +++ b/java/libraries/minim/examples/PatchingAnInput/PatchingAnInput.pde @@ -4,6 +4,9 @@ * a UGen. In this case, we patch an Oscil generating a sine wave into * the amplitude input of an Oscil generating a square wave. The result * is known as amplitude modulation. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; diff --git a/java/libraries/minim/examples/PlayAFile/PlayAFile.pde b/java/libraries/minim/examples/PlayAFile/PlayAFile.pde index a906820ea..c95eb3956 100644 --- a/java/libraries/minim/examples/PlayAFile/PlayAFile.pde +++ b/java/libraries/minim/examples/PlayAFile/PlayAFile.pde @@ -1,6 +1,9 @@ /** * This sketch demonstrates how to play a file with Minim using an AudioPlayer.
* It's also a good example of how to draw the waveform of the audio. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; @@ -20,7 +23,9 @@ void setup() // sketch folder. you can also pass an absolute path, or a URL. player = minim.loadFile("marcus_kellis_theme.mp3"); - // play the file + // play the file from start to finish. + // if you want to play the file again, + // you need to call rewind() first. player.play(); } diff --git a/java/libraries/minim/examples/RecordAudioInput/RecordAudioInput.pde b/java/libraries/minim/examples/RecordAudioInput/RecordAudioInput.pde index 296d23814..b5983fde7 100644 --- a/java/libraries/minim/examples/RecordAudioInput/RecordAudioInput.pde +++ b/java/libraries/minim/examples/RecordAudioInput/RecordAudioInput.pde @@ -1,8 +1,13 @@ /** * This sketch demonstrates how to an AudioRecorder to record audio to disk. - * To use this sketch you need to have something plugged into the line-in on your computer, or else be working on a - * laptop with an active built-in microphone. Press 'r' to toggle recording on and off and the press 's' to save to disk. + * To use this sketch you need to have something plugged into the line-in on your computer, + * or else be working on a laptop with an active built-in microphone. + *

+ * Press 'r' to toggle recording on and off and the press 's' to save to disk. * The recorded file will be placed in the sketch folder of the sketch. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; @@ -18,11 +23,9 @@ void setup() minim = new Minim(this); in = minim.getLineIn(); - // create a recorder that will record from the input to the filename specified, using buffered recording - // buffered recording means that all captured audio will be written into a sample buffer - // then when save() is called, the contents of the buffer will actually be written to a file + // create a recorder that will record from the input to the filename specified // the file will be located in the sketch's root folder. - recorder = minim.createRecorder(in, "myrecording.wav", true); + recorder = minim.createRecorder(in, "myrecording.wav"); textFont(createFont("Arial", 12)); } diff --git a/java/libraries/minim/examples/RecordAudioOutput/RecordAudioOutput.pde b/java/libraries/minim/examples/RecordAudioOutput/RecordAudioOutput.pde index ae7cefdbf..c34d03f1e 100644 --- a/java/libraries/minim/examples/RecordAudioOutput/RecordAudioOutput.pde +++ b/java/libraries/minim/examples/RecordAudioOutput/RecordAudioOutput.pde @@ -2,6 +2,9 @@ * This sketch demonstrates how to use an AudioRecorder to record audio to disk. * Press 'r' to toggle recording on and off and the press 's' to save to disk. * The recorded file will be placed in the sketch folder of the sketch. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; @@ -19,11 +22,9 @@ void setup() out = minim.getLineOut(); - // create a recorder that will record from the input to the filename specified, using buffered recording - // buffered recording means that all captured audio will be written into a sample buffer - // then when save() is called, the contents of the buffer will actually be written to a file + // create a recorder that will record from the output to the filename specified // the file will be located in the sketch's root folder. - recorder = minim.createRecorder(out, "myrecording.wav", true); + recorder = minim.createRecorder(out, "myrecording.wav"); // patch some sound into the output so we have something to record Oscil wave = new Oscil( 440.f, 1.0f ); diff --git a/java/libraries/minim/examples/Scrubbing/Scrubbing.pde b/java/libraries/minim/examples/Scrubbing/Scrubbing.pde index dc3c5fedd..23f24bdb1 100644 --- a/java/libraries/minim/examples/Scrubbing/Scrubbing.pde +++ b/java/libraries/minim/examples/Scrubbing/Scrubbing.pde @@ -5,6 +5,9 @@ * But the end result is convincing enough. *

* The positioning code is inside of the Play, Rewind, and Forward classes, which are in button.pde. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; diff --git a/java/libraries/minim/examples/SequenceSound/SequenceSound.pde b/java/libraries/minim/examples/SequenceSound/SequenceSound.pde index 9d4878e94..c23c8fa36 100644 --- a/java/libraries/minim/examples/SequenceSound/SequenceSound.pde +++ b/java/libraries/minim/examples/SequenceSound/SequenceSound.pde @@ -6,8 +6,11 @@ * sketch creates a deterministic score, meaning it is the same every time you run the sketch. It also demonstrates * a couple different versions of the playNote method. *

- * For more complex examples of using playNote check out algorithmicCompExample and compositionExample - * in the Synthesis folder. + * For more complex examples of using playNote check out + * algorithmicCompExample and compositionExample in the Synthesis folder. + *

+ * For more information about Minim and additional features, + * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; @@ -25,6 +28,20 @@ void setup() // use the getLineOut method of the Minim object to get an AudioOutput object out = minim.getLineOut(); + // set the tempo of the sequencer + // this makes the first argument of playNote + // specify the start time in quarter notes + // and the duration becomes relative to the length of a quarter note + // by default the tempo is 60 BPM (beats per minute). + // at 60 BPM both start time and duration can be interpreted as seconds. + // to retrieve the current tempo, use getTempo(). + out.setTempo( 80 ); + + // pause the sequencer so our note play back will be rock solid + // if you don't do this, then tiny bits of error can occur since + // the sequencer is running in parallel with you note queueing. + out.pauseNotes(); + // given start time, duration, and frequency out.playNote( 0.0, 0.9, 97.99 ); out.playNote( 1.0, 0.9, 123.47 ); @@ -41,15 +58,17 @@ void setup() out.playNote( 7.0, "G4" ); // the note offset is simply added into the start time of - // every subsequenct call to playNote. It's expressed in beats, - // but since the default tempo of an AudioOuput is 60 beats per minute, - // this particular call translates to 8.1 seconds, as you might expect. + // every subsequenct call to playNote. It's expressed in beats. + // to get the current note offset, use getNoteOffset(). out.setNoteOffset( 8.1 ); // because only given a note name or frequency // starttime defaults to 0.0 and duration defaults to 1.0 out.playNote( "G5" ); out.playNote( 987.77 ); + + // now we can start the sequencer again to hear our sequence + out.resumeNotes(); } void draw() diff --git a/java/libraries/minim/examples/SoundSpectrum/SoundSpectrum.pde b/java/libraries/minim/examples/SoundSpectrum/SoundSpectrum.pde index c9095d953..73de17a0c 100644 --- a/java/libraries/minim/examples/SoundSpectrum/SoundSpectrum.pde +++ b/java/libraries/minim/examples/SoundSpectrum/SoundSpectrum.pde @@ -6,8 +6,8 @@ * these can be calculated: Linearly, by grouping equal numbers of adjacent frequency bands, or * Logarithmically, by grouping frequency bands by octave, which is more akin to how humans hear sound. *
- * This sketch illustrates the difference between viewing the full spectrum, linearly spaced averaged bands, - * and logarithmically spaced averaged bands. + * This sketch illustrates the difference between viewing the full spectrum, + * linearly spaced averaged bands, and logarithmically spaced averaged bands. *

* From top to bottom: *