| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,9 @@ | |||
| 7 | 7 | * the frequency content of a signal. You've seen | |
| 8 | 8 | * visualizations like this before in music players | |
| 9 | 9 | * and car stereos. | |
| 10 | + * <p> | ||
| 11 | + * For more information about Minim and additional features, | ||
| 12 | + * visit http://code.compartmental.net/minim/ | ||
| 10 | 13 | */ | |
| 11 | 14 | ||
| 12 | 15 | import ddf.minim.analysis.*; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,85 @@ | |||
| 1 | + /** | ||
| 2 | + * This sketch demonstrates how to create synthesized sound with Minim using an AudioOutput and | ||
| 3 | + * an Instrument we define. By using the playNote method you can schedule notes to played | ||
| 4 | + * at some point in the future, essentially allowing to you create musical scores with code. | ||
| 5 | + * Because they are constructed with code, they can be either deterministic or different every time. | ||
| 6 | + * This sketch creates a deterministic score, meaning it is the same every time you run the sketch. | ||
| 7 | + * <p> | ||
| 8 | + * For more complex examples of using playNote check out algorithmicCompExample and compositionExample | ||
| 9 | + * in the Synthesis folder. | ||
| 10 | + * <p> | ||
| 11 | + * For more information about Minim and additional features, visit http://code.compartmental.net/minim/ | ||
| 12 | + */ | ||
| 13 | + | ||
| 14 | + import ddf.minim.*; | ||
| 15 | + import ddf.minim.ugens.*; | ||
| 16 | + | ||
| 17 | + Minim minim; | ||
| 18 | + AudioOutput out; | ||
| 19 | + | ||
| 20 | + // to make an Instrument we must define a class | ||
| 21 | + // that implements the Instrument interface. | ||
| 22 | + class SineInstrument implements Instrument | ||
| 23 | + { | ||
| 24 | + Oscil wave; | ||
| 25 | + Line ampEnv; | ||
| 26 | + | ||
| 27 | + SineInstrument( float frequency ) | ||
| 28 | + { | ||
| 29 | + // make a sine wave oscillator | ||
| 30 | + // the amplitude is zero because | ||
| 31 | + // we are going to patch a Line to it anyway | ||
| 32 | + wave = new Oscil( frequency, 0, Waves.SINE ); | ||
| 33 | + ampEnv = new Line(); | ||
| 34 | + ampEnv.patch( wave.amplitude ); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + // this is called by the sequencer when this instrument | ||
| 38 | + // should start making sound. the duration is expressed in seconds. | ||
| 39 | + void noteOn( float duration ) | ||
| 40 | + { | ||
| 41 | + // start the amplitude envelope | ||
| 42 | + ampEnv.activate( duration, 0.5f, 0 ); | ||
| 43 | + // attach the oscil to the output so it makes sound | ||
| 44 | + wave.patch( out ); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + // this is called by the sequencer when the instrument should | ||
| 48 | + // stop making sound | ||
| 49 | + void noteOff() | ||
| 50 | + { | ||
| 51 | + wave.unpatch( out ); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + void setup() | ||
| 56 | + { | ||
| 57 | + size(512, 200, P3D); | ||
| 58 | + | ||
| 59 | + minim = new Minim(this); | ||
| 60 | + | ||
| 61 | + // use the getLineOut method of the Minim object to get an AudioOutput object | ||
| 62 | + out = minim.getLineOut(); | ||
| 63 | + | ||
| 64 | + // when providing an Instrument, we always specify start time and duration | ||
| 65 | + out.playNote( 0.0, 0.9, new SineInstrument( 97.99 ) ); | ||
| 66 | + out.playNote( 1.0, 0.9, new SineInstrument( 123.47 ) ); | ||
| 67 | + | ||
| 68 | + // we can use the Frequency class to create frequencies from pitch names | ||
| 69 | + out.playNote( 2.0, 2.9, new SineInstrument( Frequency.ofPitch( "C3" ).asHz() ) ); | ||
| 70 | + out.playNote( 3.0, 1.9, new SineInstrument( Frequency.ofPitch( "E3" ).asHz() ) ); | ||
| 71 | + out.playNote( 4.0, 0.9, new SineInstrument( Frequency.ofPitch( "G3" ).asHz() ) ); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + void draw() | ||
| 75 | + { | ||
| 76 | + background(0); | ||
| 77 | + stroke(255); | ||
| 78 | + | ||
| 79 | + // draw the waveforms | ||
| 80 | + for(int i = 0; i < out.bufferSize() - 1; i++) | ||
| 81 | + { | ||
| 82 | + line( i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50 ); | ||
| 83 | + line( i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50 ); | ||
| 84 | + } | ||
| 85 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,9 @@ | |||
| 10 | 10 | * If you load WAV file or other non-tagged file, most of the metadata | |
| 11 | 11 | * will be empty, but you will still have information like the filename | |
| 12 | 12 | * and the length. | |
| 13 | + * <p> | ||
| 14 | + * For more information about Minim and additional features, | ||
| 15 | + * visit http://code.compartmental.net/minim/ | ||
| 13 | 16 | */ | |
| 14 | 17 | ||
| 15 | 18 | import ddf.minim.*; | |
@@ -52,14 +55,3 @@ void draw() | |||
| 52 | 55 | text("Publisher: " + meta.publisher(), 5, y+=yi); | |
| 53 | 56 | text("Encoded: " + meta.encoded(), 5, y+=yi); | |
| 54 | 57 | } | |
| 55 | - | ||
| 56 | - | ||
| 57 | - void stop() | ||
| 58 | - { | ||
| 59 | - // always close Minim audio classes when you are done with them | ||
| 60 | - groove.close(); | ||
| 61 | - // always stop Minim before exiting | ||
| 62 | - minim.stop(); | ||
| 63 | - | ||
| 64 | - super.stop(); | ||
| 65 | - } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,17 @@ | |||
| 1 | 1 | /** | |
| 2 | 2 | * This sketch demonstrates how to monitor the currently active audio input | |
| 3 | - * of the computer using an <code>AudioInput</code>. What you will actually | ||
| 3 | + * of the computer using an AudioInput. What you will actually | ||
| 4 | 4 | * be monitoring depends on the current settings of the machine the sketch is running on. | |
| 5 | 5 | * Typically, you will be monitoring the built-in microphone, but if running on a desktop | |
| 6 | - * its feasible that the user may have the actual audio output of the computer | ||
| 6 | + * it's feasible that the user may have the actual audio output of the computer | ||
| 7 | 7 | * as the active audio input, or something else entirely. | |
| 8 | 8 | * <p> | |
| 9 | - * When you run your sketch as an applet you will need to sign it in order to get an input. | ||
| 9 | + * Press 'm' to toggle monitoring on and off. | ||
| 10 | + * <p> | ||
| 11 | + * When you run your sketch as an applet you will need to sign it in order to get an input. | ||
| 12 | + * <p> | ||
| 13 | + * For more information about Minim and additional features, | ||
| 14 | + * visit http://code.compartmental.net/minim/ | ||
| 10 | 15 | */ | |
| 11 | 16 | ||
| 12 | 17 | import ddf.minim.*; | |
@@ -22,9 +27,6 @@ void setup() | |||
| 22 | 27 | ||
| 23 | 28 | // use the getLineIn method of the Minim object to get an AudioInput | |
| 24 | 29 | in = minim.getLineIn(); | |
| 25 | - | ||
| 26 | - // uncomment this line to *hear* what is being monitored, in addition to seeing it | ||
| 27 | - in.enableMonitoring(); | ||
| 28 | 30 | } | |
| 29 | 31 | ||
| 30 | 32 | void draw() | |
@@ -38,4 +40,22 @@ void draw() | |||
| 38 | 40 | line( i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50 ); | |
| 39 | 41 | line( i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50 ); | |
| 40 | 42 | } | |
| 43 | + | ||
| 44 | + String monitoringState = in.isMonitoring() ? "enabled" : "disabled"; | ||
| 45 | + text( "Input monitoring is currently " + monitoringState + ".", 5, 15 ); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + void keyPressed() | ||
| 49 | + { | ||
| 50 | + if ( key == 'm' || key == 'M' ) | ||
| 51 | + { | ||
| 52 | + if ( in.isMonitoring() ) | ||
| 53 | + { | ||
| 54 | + in.disableMonitoring(); | ||
| 55 | + } | ||
| 56 | + else | ||
| 57 | + { | ||
| 58 | + in.enableMonitoring(); | ||
| 59 | + } | ||
| 60 | + } | ||
| 41 | 61 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,9 @@ | |||
| 4 | 4 | * a UGen. In this case, we patch an Oscil generating a sine wave into | |
| 5 | 5 | * the amplitude input of an Oscil generating a square wave. The result | |
| 6 | 6 | * is known as amplitude modulation. | |
| 7 | + * <p> | ||
| 8 | + * For more information about Minim and additional features, | ||
| 9 | + * visit http://code.compartmental.net/minim/ | ||
| 7 | 10 | */ | |
| 8 | 11 | ||
| 9 | 12 | import ddf.minim.*; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,9 @@ | |||
| 1 | 1 | /** | |
| 2 | 2 | * This sketch demonstrates how to play a file with Minim using an AudioPlayer. <br /> | |
| 3 | 3 | * It's also a good example of how to draw the waveform of the audio. | |
| 4 | + * <p> | ||
| 5 | + * For more information about Minim and additional features, | ||
| 6 | + * visit http://code.compartmental.net/minim/ | ||
| 4 | 7 | */ | |
| 5 | 8 | ||
| 6 | 9 | import ddf.minim.*; | |
@@ -20,7 +23,9 @@ void setup() | |||
| 20 | 23 | // sketch folder. you can also pass an absolute path, or a URL. | |
| 21 | 24 | player = minim.loadFile("marcus_kellis_theme.mp3"); | |
| 22 | 25 | ||
| 23 | - // play the file | ||
| 26 | + // play the file from start to finish. | ||
| 27 | + // if you want to play the file again, | ||
| 28 | + // you need to call rewind() first. | ||
| 24 | 29 | player.play(); | |
| 25 | 30 | } | |
| 26 | 31 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,13 @@ | |||
| 1 | 1 | /** | |
| 2 | 2 | * This sketch demonstrates how to an <code>AudioRecorder</code> to record audio to disk. | |
| 3 | - * To use this sketch you need to have something plugged into the line-in on your computer, or else be working on a | ||
| 4 | - * laptop with an active built-in microphone. Press 'r' to toggle recording on and off and the press 's' to save to disk. | ||
| 3 | + * To use this sketch you need to have something plugged into the line-in on your computer, | ||
| 4 | + * or else be working on a laptop with an active built-in microphone. | ||
| 5 | + * <p> | ||
| 6 | + * Press 'r' to toggle recording on and off and the press 's' to save to disk. | ||
| 5 | 7 | * The recorded file will be placed in the sketch folder of the sketch. | |
| 8 | + * <p> | ||
| 9 | + * For more information about Minim and additional features, | ||
| 10 | + * visit http://code.compartmental.net/minim/ | ||
| 6 | 11 | */ | |
| 7 | 12 | ||
| 8 | 13 | import ddf.minim.*; | |
@@ -18,11 +23,9 @@ void setup() | |||
| 18 | 23 | minim = new Minim(this); | |
| 19 | 24 | ||
| 20 | 25 | in = minim.getLineIn(); | |
| 21 | - // create a recorder that will record from the input to the filename specified, using buffered recording | ||
| 22 | - // buffered recording means that all captured audio will be written into a sample buffer | ||
| 23 | - // then when save() is called, the contents of the buffer will actually be written to a file | ||
| 26 | + // create a recorder that will record from the input to the filename specified | ||
| 24 | 27 | // the file will be located in the sketch's root folder. | |
| 25 | - recorder = minim.createRecorder(in, "myrecording.wav", true); | ||
| 28 | + recorder = minim.createRecorder(in, "myrecording.wav"); | ||
| 26 | 29 | ||
| 27 | 30 | textFont(createFont("Arial", 12)); | |
| 28 | 31 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,9 @@ | |||
| 2 | 2 | * This sketch demonstrates how to use an <code>AudioRecorder</code> to record audio to disk. | |
| 3 | 3 | * Press 'r' to toggle recording on and off and the press 's' to save to disk. | |
| 4 | 4 | * The recorded file will be placed in the sketch folder of the sketch. | |
| 5 | + * <p> | ||
| 6 | + * For more information about Minim and additional features, | ||
| 7 | + * visit http://code.compartmental.net/minim/ | ||
| 5 | 8 | */ | |
| 6 | 9 | ||
| 7 | 10 | import ddf.minim.*; | |
@@ -19,11 +22,9 @@ void setup() | |||
| 19 | 22 | ||
| 20 | 23 | out = minim.getLineOut(); | |
| 21 | 24 | ||
| 22 | - // create a recorder that will record from the input to the filename specified, using buffered recording | ||
| 23 | - // buffered recording means that all captured audio will be written into a sample buffer | ||
| 24 | - // then when save() is called, the contents of the buffer will actually be written to a file | ||
| 25 | + // create a recorder that will record from the output to the filename specified | ||
| 25 | 26 | // the file will be located in the sketch's root folder. | |
| 26 | - recorder = minim.createRecorder(out, "myrecording.wav", true); | ||
| 27 | + recorder = minim.createRecorder(out, "myrecording.wav"); | ||
| 27 | 28 | ||
| 28 | 29 | // patch some sound into the output so we have something to record | |
| 29 | 30 | Oscil wave = new Oscil( 440.f, 1.0f ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,9 @@ | |||
| 5 | 5 | * But the end result is convincing enough. | |
| 6 | 6 | * <p> | |
| 7 | 7 | * The positioning code is inside of the Play, Rewind, and Forward classes, which are in button.pde. | |
| 8 | + * <p> | ||
| 9 | + * For more information about Minim and additional features, | ||
| 10 | + * visit http://code.compartmental.net/minim/ | ||
| 8 | 11 | */ | |
| 9 | 12 | ||
| 10 | 13 | import ddf.minim.*; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments