mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Removing 1.0 Minum, will add 2.0 version soon
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* Add Listener
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>addListener</code> method of a <code>Recordable</code> class.
|
||||
* The class used here is <code>AudioPlayer</code>, but you can also add listeners to <code>AudioInput</code>,
|
||||
* <code>AudioOutput</code>, and <code>AudioSample</code> objects. The class defined in waveform.pde implements
|
||||
* the <code>AudioListener</code> interface and can therefore be added as a listener to <code>groove</code>.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer groove;
|
||||
WaveformRenderer waveform;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
groove = minim.loadFile("groove.mp3", 512);
|
||||
groove.loop();
|
||||
waveform = new WaveformRenderer();
|
||||
groove.addListener(waveform);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
// see waveform.pde for an explanation of how this works
|
||||
waveform.draw();
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
groove.close();
|
||||
// always stop Minim before exiting.
|
||||
minim.stop();
|
||||
super.stop();
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
// This class is a very simple implementation of AudioListener. By implementing this interface,
|
||||
// you can add instances of this class to any class in Minim that implements Recordable and receive
|
||||
// buffers of samples in a callback fashion. In other words, every time that a Recordable object has
|
||||
// a new buffer of samples, it will send a copy to all of its AudioListeners. You can add an instance of
|
||||
// an AudioListener to a Recordable by using the addListener method of the Recordable. If you want to
|
||||
// remove a listener that you previously added, you call the removeListener method of Recordable, passing
|
||||
// the listener you want to remove.
|
||||
//
|
||||
// Although possible, it is not advised that you add the same listener to more than one Recordable.
|
||||
// Your listener will be called any time any of the Recordables you've added it have new samples. This
|
||||
// means that the stream of samples the listener sees will likely be interleaved buffers of samples from
|
||||
// all of the Recordables it is listening to, which is probably not what you want.
|
||||
//
|
||||
// You'll notice that the three methods of this class are synchronized. This is because the samples methods
|
||||
// will be called from a different thread than the one instances of this class will be created in. That thread
|
||||
// might try to send samples to an instance of this class while the instance is in the middle of drawing the
|
||||
// waveform, which would result in a waveform made up of samples from two different buffers. Synchronizing
|
||||
// all the methods means that while the main thread of execution is inside draw, the thread that calls
|
||||
// samples will block until draw is complete. Likewise, a call to draw will block if the sample thread is inside
|
||||
// one of the samples methods. Hope that's not too confusing!
|
||||
|
||||
class WaveformRenderer implements AudioListener
|
||||
{
|
||||
private float[] left;
|
||||
private float[] right;
|
||||
|
||||
WaveformRenderer()
|
||||
{
|
||||
left = null;
|
||||
right = null;
|
||||
}
|
||||
|
||||
synchronized void samples(float[] samp)
|
||||
{
|
||||
left = samp;
|
||||
}
|
||||
|
||||
synchronized void samples(float[] sampL, float[] sampR)
|
||||
{
|
||||
left = sampL;
|
||||
right = sampR;
|
||||
}
|
||||
|
||||
synchronized void draw()
|
||||
{
|
||||
// we've got a stereo signal if right or left are not null
|
||||
if ( left != null && right != null )
|
||||
{
|
||||
noFill();
|
||||
stroke(255);
|
||||
beginShape();
|
||||
for ( int i = 0; i < left.length; i++ )
|
||||
{
|
||||
vertex(i, height/4 + left[i]*50);
|
||||
}
|
||||
endShape();
|
||||
beginShape();
|
||||
for ( int i = 0; i < right.length; i++ )
|
||||
{
|
||||
vertex(i, 3*(height/4) + right[i]*50);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
else if ( left != null )
|
||||
{
|
||||
noFill();
|
||||
stroke(255);
|
||||
beginShape();
|
||||
for ( int i = 0; i < left.length; i++ )
|
||||
{
|
||||
vertex(i, height/2 + left[i]*50);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Band Pass Filter
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the BandPass effect.
|
||||
* Move the mouse left and right to change the frequency of the pass band.
|
||||
* Move the mouse up and down to change the band width of the pass band.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.effects.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer groove;
|
||||
BandPass bpf;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
|
||||
groove = minim.loadFile("groove.mp3");
|
||||
groove.loop();
|
||||
// make a band pass filter with a center frequency of 440 Hz and a bandwidth of 20 Hz
|
||||
// the third argument is the sample rate of the audio that will be filtered
|
||||
// it is required to correctly compute values used by the filter
|
||||
bpf = new BandPass(440, 20, groove.sampleRate());
|
||||
groove.addEffect(bpf);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// draw the waveforms
|
||||
// the values returned by left.get() and right.get() will be between -1 and 1,
|
||||
// so we need to scale them up to see the waveform
|
||||
for(int i = 0; i < groove.right.size()-1; i++)
|
||||
{
|
||||
float x1 = map(i, 0, groove.bufferSize(), 0, width);
|
||||
float x2 = map(i+1, 0, groove.bufferSize(), 0, width);
|
||||
line(x1, height/4 - groove.left.get(i)*50, x2, height/4 - groove.left.get(i+1)*50);
|
||||
line(x1, 3*height/4 - groove.right.get(i)*50, x2, 3*height/4 - groove.right.get(i+1)*50);
|
||||
}
|
||||
// draw a rectangle to represent the pass band
|
||||
noStroke();
|
||||
fill(255, 0, 0, 60);
|
||||
rect(mouseX - bpf.getBandWidth()/20, 0, bpf.getBandWidth()/10, height);
|
||||
}
|
||||
|
||||
void mouseMoved()
|
||||
{
|
||||
// map the mouse position to the range [100, 10000], an arbitrary range of passBand frequencies
|
||||
float passBand = map(mouseX, 0, width, 100, 2000);
|
||||
bpf.setFreq(passBand);
|
||||
float bandWidth = map(mouseY, 0, height, 50, 500);
|
||||
bpf.setBandWidth(bandWidth);
|
||||
// prints the new values of the coefficients in the console
|
||||
bpf.printCoeff();
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you finish with them
|
||||
groove.close();
|
||||
// always stop Minim before exiting
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Forward FFT
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use an FFT to analyze an AudioBuffer
|
||||
* and draw the resulting spectrum. It also allows you to turn windowing
|
||||
* on and off, but you will see there is not much difference in the spectrum.
|
||||
* Press 'w' to turn on windowing, press 'e' to turn it off.
|
||||
*/
|
||||
|
||||
import ddf.minim.analysis.*;
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer jingle;
|
||||
FFT fft;
|
||||
String windowName;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200);
|
||||
minim = new Minim(this);
|
||||
|
||||
jingle = minim.loadFile("jingle.mp3", 2048);
|
||||
jingle.loop();
|
||||
// create an FFT object that has a time-domain buffer the same size as jingle's sample buffer
|
||||
// note that this needs to be a power of two and that it means the size of the spectrum
|
||||
// will be 512. see the online tutorial for more info.
|
||||
fft = new FFT(jingle.bufferSize(), jingle.sampleRate());
|
||||
textFont(createFont("SanSerif", 12));
|
||||
windowName = "None";
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// perform a forward FFT on the samples in jingle's left buffer
|
||||
// note that if jingle were a MONO file, this would be the same as using jingle.right or jingle.left
|
||||
fft.forward(jingle.mix);
|
||||
for(int i = 0; i < fft.specSize(); i++)
|
||||
{
|
||||
// draw the line for frequency band i, scaling it by 4 so we can see it a bit better
|
||||
line(i, height, i, height - fft.getBand(i)*4);
|
||||
}
|
||||
fill(255);
|
||||
// keep us informed about the window being used
|
||||
text("The window being used is: " + windowName, 5, 20);
|
||||
}
|
||||
|
||||
void keyReleased()
|
||||
{
|
||||
if ( key == 'w' )
|
||||
{
|
||||
// a Hamming window can be used to shape the sample buffer that is passed to the FFT
|
||||
// this can reduce the amount of noise in the spectrum
|
||||
fft.window(FFT.HAMMING);
|
||||
windowName = "Hamming";
|
||||
}
|
||||
|
||||
if ( key == 'e' )
|
||||
{
|
||||
fft.window(FFT.NONE);
|
||||
windowName = "None";
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you finish with them
|
||||
jingle.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
class BeatListener implements AudioListener
|
||||
{
|
||||
private BeatDetect beat;
|
||||
private AudioPlayer source;
|
||||
|
||||
BeatListener(BeatDetect beat, AudioPlayer source)
|
||||
{
|
||||
this.source = source;
|
||||
this.source.addListener(this);
|
||||
this.beat = beat;
|
||||
}
|
||||
|
||||
void samples(float[] samps)
|
||||
{
|
||||
beat.detect(source.mix);
|
||||
}
|
||||
|
||||
void samples(float[] sampsL, float[] sampsR)
|
||||
{
|
||||
beat.detect(source.mix);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* Frequency Energy
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the BeatDetect object in FREQ_ENERGY mode.
|
||||
* You can use <code>isKick</code>, <code>isSnare</code>, </code>isHat</code>,
|
||||
* <code>isRange</code>, and <code>isOnset(int)</code> to track whatever kind
|
||||
* of beats you are looking to track, they will report true or false based on
|
||||
* the state of the analysis. To "tick" the analysis you must call <code>detect</code>
|
||||
* with successive buffers of audio. You can do this inside of <code>draw</code>,
|
||||
* but you are likely to miss some audio buffers if you do this. The sketch implements
|
||||
* an <code>AudioListener</code> called <code>BeatListener</code> so that it can call
|
||||
* <code>detect</code> on every buffer of audio processed by the system without repeating
|
||||
* a buffer or missing one.
|
||||
*
|
||||
* This sketch plays an entire song so it may be a little slow to load.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.analysis.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer song;
|
||||
BeatDetect beat;
|
||||
BeatListener bl;
|
||||
|
||||
float kickSize, snareSize, hatSize;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200);
|
||||
smooth();
|
||||
|
||||
minim = new Minim(this);
|
||||
|
||||
song = minim.loadFile("marcus_kellis_theme.mp3", 2048);
|
||||
song.play();
|
||||
// a beat detection object that is FREQ_ENERGY mode that
|
||||
// expects buffers the length of song's buffer size
|
||||
// and samples captured at songs's sample rate
|
||||
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
|
||||
// set the sensitivity to 300 milliseconds
|
||||
// After a beat has been detected, the algorithm will wait for 300 milliseconds
|
||||
// before allowing another beat to be reported. You can use this to dampen the
|
||||
// algorithm if it is giving too many false-positives. The default value is 10,
|
||||
// which is essentially no damping. If you try to set the sensitivity to a negative value,
|
||||
// an error will be reported and it will be set to 10 instead.
|
||||
beat.setSensitivity(300);
|
||||
kickSize = snareSize = hatSize = 16;
|
||||
// make a new beat listener, so that we won't miss any buffers for the analysis
|
||||
bl = new BeatListener(beat, song);
|
||||
textFont(createFont("SanSerif", 16));
|
||||
textAlign(CENTER);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
fill(255);
|
||||
if ( beat.isKick() ) kickSize = 32;
|
||||
if ( beat.isSnare() ) snareSize = 32;
|
||||
if ( beat.isHat() ) hatSize = 32;
|
||||
textSize(kickSize);
|
||||
text("KICK", width/4, height/2);
|
||||
textSize(snareSize);
|
||||
text("SNARE", width/2, height/2);
|
||||
textSize(hatSize);
|
||||
text("HAT", 3*width/4, height/2);
|
||||
kickSize = constrain(kickSize * 0.95, 16, 32);
|
||||
snareSize = constrain(snareSize * 0.95, 16, 32);
|
||||
hatSize = constrain(hatSize * 0.95, 16, 32);
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are finished with them
|
||||
song.close();
|
||||
// always stop Minim before exiting
|
||||
minim.stop();
|
||||
// this closes the sketch
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* Get Line In
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>getLineIn</code> method of
|
||||
* <code>Minim</code>. This method returns an <code>AudioInput</code> object.
|
||||
* An <code>AudioInput</code> represents a connection to the computer's current
|
||||
* record source (usually the line-in) and is used to monitor audio coming
|
||||
* from an external source. There are five versions of <code>getLineIn</code>:
|
||||
* <pre>
|
||||
* getLineIn()
|
||||
* getLineIn(int type)
|
||||
* getLineIn(int type, int bufferSize)
|
||||
* getLineIn(int type, int bufferSize, float sampleRate)
|
||||
* getLineIn(int type, int bufferSize, float sampleRate, int bitDepth)
|
||||
* </pre>
|
||||
* The value you can use for <code>type</code> is either <code>Minim.MONO</code>
|
||||
* or <code>Minim.STEREO</code>. <code>bufferSize</code> specifies how large
|
||||
* you want the sample buffer to be, <code>sampleRate</code> specifies the
|
||||
* sample rate you want to monitor at, and <code>bitDepth</code> specifies what
|
||||
* bit depth you want to monitor at. <code>type</code> defaults to <code>Minim.STEREO</code>,
|
||||
* <code>bufferSize</code> defaults to 1024, <code>sampleRate</code> defaults to
|
||||
* 44100, and <code>bitDepth</code> defaults to 16. If an <code>AudioInput</code>
|
||||
* cannot be created with the properties you request, <code>Minim</code> will report
|
||||
* an error and return <code>null</code>.
|
||||
*
|
||||
* When you run your sketch as an applet you will need to sign it in order to get an input.
|
||||
*
|
||||
* Before you exit your sketch make sure you call the <code>close</code> method
|
||||
* of any <code>AudioInput</code>'s you have received from <code>getLineIn</code>.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioInput in;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
minim.debugOn();
|
||||
|
||||
// get a line in from Minim, default bit depth is 16
|
||||
in = minim.getLineIn(Minim.STEREO, 512);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
|
||||
// draw the waveforms
|
||||
for(int i = 0; i < in.bufferSize() - 1; i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
in.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* Get Line Out
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>getLineOut</code> method
|
||||
* of <code>Minim</code>. This method returns an <code>AudioOutput</code>
|
||||
* object. An <code>AudioOutput</code> represents a connection to the
|
||||
* computer's speakers and is used to generate audio with <code>AudioSignal</code>s.
|
||||
* There are five versions of <code>getLineOut</code>:
|
||||
* <pre>
|
||||
* getLineOut()
|
||||
* getLineOut(int type)
|
||||
* getLineOut(int type, int bufferSize)
|
||||
* getLineOut(int type, int bufferSize, float sampleRate)
|
||||
* getLineOut(int type, int bufferSize, float sampleRate, int bitDepth)
|
||||
* </pre>
|
||||
* The value you can use for <code>type</code> is either <code>Minim.MONO</code>
|
||||
* or <code>Minim.STEREO</code>. <code>bufferSize</code> specifies how large
|
||||
* you want the sample buffer to be, <code>sampleRate</code> specifies what
|
||||
* the sample rate of the audio you will be generating is, and <code>bitDepth</code>
|
||||
* specifies what the bit depth of the audio you will be generating is (8 or 16).
|
||||
* <code>type</code> defaults to <code>Minim.STEREO</code>, <code>bufferSize</code>
|
||||
* defaults to 1024, <code>sampleRate</code> defaults to 44100, and
|
||||
* <code>bitDepth</code> defaults to 16.
|
||||
*
|
||||
* Before you exit your sketch make sure you call the <code>close</code>
|
||||
* method of any <code>AudioOutput</code>'s you have received from <code>getLineOut</code>.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.signals.*;
|
||||
|
||||
Minim minim;
|
||||
AudioOutput out;
|
||||
SineWave sine;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
|
||||
// get a line out from Minim, default sample rate is 44100, default bit depth is 16
|
||||
out = minim.getLineOut(Minim.STEREO, 2048);
|
||||
|
||||
// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate 44100 to match the line out
|
||||
sine = new SineWave(440, 0.5, out.sampleRate());
|
||||
// add the oscillator to the line out
|
||||
out.addSignal(sine);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
out.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* Get Meta Data
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>getMetaData</code>
|
||||
* method of <code>AudioPlayer</code>. This method is also available
|
||||
* for <code>AudioSnippet</code> and <code>AudioSample</code>.
|
||||
* You should use this method when you want to retrieve metadata
|
||||
* about a file that you have loaded, like ID3 tags from an mp3 file.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer groove;
|
||||
AudioMetaData meta;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 256, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
groove = minim.loadFile("groove.mp3");
|
||||
meta = groove.getMetaData();
|
||||
|
||||
textFont(createFont("Serif", 12));
|
||||
textMode(SCREEN);
|
||||
}
|
||||
|
||||
int ys = 25;
|
||||
int yi = 15;
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
int y = ys;
|
||||
text("File Name: " + meta.fileName(), 5, y);
|
||||
text("Length (in milliseconds): " + meta.length(), 5, y+=yi);
|
||||
text("Title: " + meta.title(), 5, y+=yi);
|
||||
text("Author: " + meta.author(), 5, y+=yi);
|
||||
text("Album: " + meta.album(), 5, y+=yi);
|
||||
text("Date: " + meta.date(), 5, y+=yi);
|
||||
text("Comment: " + meta.comment(), 5, y+=yi);
|
||||
text("Track: " + meta.track(), 5, y+=yi);
|
||||
text("Genre: " + meta.genre(), 5, y+=yi);
|
||||
text("Copyright: " + meta.copyright(), 5, y+=yi);
|
||||
text("Disc: " + meta.disc(), 5, y+=yi);
|
||||
text("Composer: " + meta.composer(), 5, y+=yi);
|
||||
text("Orchestra: " + meta.orchestra(), 5, y+=yi);
|
||||
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();
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Get Set Pan
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>getPan</code> and
|
||||
* <code>setPan</code> methods of a <code>Controller</code> object.
|
||||
* The class used here is an <code>AudioOutput</code> but you can also
|
||||
* get and set the pan of <code>AudioSample</code>, <code>AudioSnippet</code>,
|
||||
* <code>AudioInput</code>, and <code>AudioPlayer</code> objects.
|
||||
* <code>getPan</code> and <code>setPan</code> will get and set the pan
|
||||
* of the <code>DataLine</code> that is being used for input or output,
|
||||
* but only if that line has a pan control. A <code>DataLine</code> is
|
||||
* a low-level JavaSound class that is used for sending audio to,
|
||||
* or receiving audio from, the audio system. You will notice in this
|
||||
* sketch that you will hear the pan changing (if it's available) but you
|
||||
* will not see any difference in the waveform being drawn. The reason
|
||||
* for this is that what you see in the output's sample buffers is what
|
||||
* it sends to the audio system. The system makes the pan change after
|
||||
* receiving the samples.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.signals.*;
|
||||
|
||||
Minim minim;
|
||||
AudioOutput out;
|
||||
Oscillator osc;
|
||||
WaveformRenderer waveform;
|
||||
|
||||
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);
|
||||
|
||||
waveform = new WaveformRenderer();
|
||||
// see the example Recordable >> addListener for more about this
|
||||
out.addListener(waveform);
|
||||
|
||||
textFont(createFont("SanSerif", 12));
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
// see waveform.pde for more about this
|
||||
waveform.draw();
|
||||
|
||||
if ( out.hasControl(Controller.PAN) )
|
||||
{
|
||||
// map the mouse position to the range of the pan
|
||||
float val = map(mouseX, 0, width, -1, 1);
|
||||
// if a pan control is not available, this will do nothing
|
||||
out.setPan(val);
|
||||
// if a pan control is not available this will report zero
|
||||
text("The current pan is " + out.getPan() + ".", 5, 20);
|
||||
}
|
||||
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();
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
// This class is a very simple implementation of AudioListener. By implementing this interface,
|
||||
// you can add instances of this class to any class in Minim that implements Recordable and receive
|
||||
// buffers of samples in a callback fashion. In other words, every time that a Recordable object has
|
||||
// a new buffer of samples, it will send a copy to all of its AudioListeners. You can add an instance of
|
||||
// an AudioListener to a Recordable by using the addListener method of the Recordable. If you want to
|
||||
// remove a listener that you previously added, you call the removeListener method of Recordable, passing
|
||||
// the listener you want to remove.
|
||||
//
|
||||
// Although possible, it is not advised that you add the same listener to more than one Recordable.
|
||||
// Your listener will be called any time any of the Recordables you've added it have new samples. This
|
||||
// means that the stream of samples the listener sees will likely be interleaved buffers of samples from
|
||||
// all of the Recordables it is listening to, which is probably not what you want.
|
||||
//
|
||||
// You'll notice that the three methods of this class are synchronized. This is because the samples methods
|
||||
// will be called from a different thread than the one instances of this class will be created in. That thread
|
||||
// might try to send samples to an instance of this class while the instance is in the middle of drawing the
|
||||
// waveform, which would result in a waveform made up of samples from two different buffers. Synchronizing
|
||||
// all the methods means that while the main thread of execution is inside draw, the thread that calls
|
||||
// samples will block until draw is complete. Likewise, a call to draw will block if the sample thread is inside
|
||||
// one of the samples methods. Hope that's not too confusing!
|
||||
|
||||
class WaveformRenderer implements AudioListener
|
||||
{
|
||||
private float[] left;
|
||||
private float[] right;
|
||||
|
||||
WaveformRenderer()
|
||||
{
|
||||
left = null;
|
||||
right = null;
|
||||
}
|
||||
|
||||
synchronized void samples(float[] samp)
|
||||
{
|
||||
left = samp;
|
||||
}
|
||||
|
||||
synchronized void samples(float[] sampL, float[] sampR)
|
||||
{
|
||||
left = sampL;
|
||||
right = sampR;
|
||||
}
|
||||
|
||||
synchronized void draw()
|
||||
{
|
||||
// we've got a stereo signal if right is not null
|
||||
if ( left != null && right != null )
|
||||
{
|
||||
noFill();
|
||||
stroke(255);
|
||||
beginShape();
|
||||
for ( int i = 0; i < left.length; i++ )
|
||||
{
|
||||
vertex(i, height/4 + left[i]*50);
|
||||
}
|
||||
endShape();
|
||||
beginShape();
|
||||
for ( int i = 0; i < right.length; i++ )
|
||||
{
|
||||
vertex(i, 3*(height/4) + right[i]*50);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
else if ( left != null )
|
||||
{
|
||||
noFill();
|
||||
stroke(255);
|
||||
beginShape();
|
||||
for ( int i = 0; i < left.length; i++ )
|
||||
{
|
||||
vertex(i, height/2 + left[i]*50);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Linear Averages
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the averaging abilities of the FFT.
|
||||
* 128 linearly spaced averages are requested and then those are drawn as rectangles.
|
||||
*/
|
||||
|
||||
import ddf.minim.analysis.*;
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer jingle;
|
||||
FFT fft;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
minim = new Minim(this);
|
||||
|
||||
jingle = minim.loadFile("jingle.mp3", 2048);
|
||||
// loop the file
|
||||
jingle.loop();
|
||||
// create an FFT object that has a time-domain buffer the same size as jingle's sample buffer
|
||||
// and a sample rate that is the same as jingle's
|
||||
// note that this needs to be a power of two
|
||||
// and that it means the size of the spectrum will be 1024.
|
||||
// see the online tutorial for more info.
|
||||
fft = new FFT(jingle.bufferSize(), jingle.sampleRate());
|
||||
// use 128 averages.
|
||||
// the maximum number of averages we could ask for is half the spectrum size.
|
||||
fft.linAverages(128);
|
||||
rectMode(CORNERS);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
fill(255);
|
||||
// perform a forward FFT on the samples in jingle's mix buffer
|
||||
// note that if jingle were a MONO file, this would be the same as using jingle.left or jingle.right
|
||||
fft.forward(jingle.mix);
|
||||
int w = int(fft.specSize()/128);
|
||||
for(int i = 0; i < fft.avgSize(); i++)
|
||||
{
|
||||
// draw a rectangle for each average, multiply the value by 5 so we can see it better
|
||||
rect(i*w, height, i*w + w, height - fft.getAvg(i)*5);
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you finish with them
|
||||
jingle.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Load File
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>loadFile</code> method
|
||||
* of <code>Minim</code>. The <code>loadFile</code> method allows you to
|
||||
* specify the file you want to load with a <code>String</code> and optionally
|
||||
* specify what you want the buffer size of the returned <code>AudioPlayer</code>
|
||||
* to be. If you don't specify a buffer size, the returned player will have a
|
||||
* buffer size of 1024. Minim is able to play wav files, au files, aif files,
|
||||
* snd files, and mp3 files. When you call <code>loadFile</code>, if you just
|
||||
* specify the filename it will try to load the file from the data folder of
|
||||
* your sketch. However, you can also specify an absolute path
|
||||
* (such as "C:\foo\bar\thing.wav") and the file will be loaded from that
|
||||
* location (keep in mind that won't work from an applet). You can also specify
|
||||
* a URL (such as "http://www.mysite.com/mp3/song.mp3") but keep in mind that
|
||||
* if you run the sketch as an applet you may run in to security restrictions
|
||||
* if the applet is not on the same domain as the file you want to load. You can
|
||||
* get around the restriction by signing the applet. Before you exit your sketch
|
||||
* make sure you call the <code>close</code> method of any <code>AudioPlayer</code>'s
|
||||
* you have received from <code>loadFile</code>, followed by the <code>stop</code>
|
||||
* method of <code>Minim</code>.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
AudioPlayer player;
|
||||
Minim minim;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
|
||||
// load a file, give the AudioPlayer buffers that are 1024 samples long
|
||||
// player = minim.loadFile("groove.mp3");
|
||||
|
||||
// load a file, give the AudioPlayer buffers that are 2048 samples long
|
||||
player = minim.loadFile("groove.mp3", 2048);
|
||||
// play the file
|
||||
player.play();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// draw the waveforms
|
||||
// the values returned by left.get() and right.get() will be between -1 and 1,
|
||||
// so we need to scale them up to see the waveform
|
||||
// note that if the file is MONO, left.get() and right.get() will return the same value
|
||||
for(int i = 0; i < player.left.size()-1; i++)
|
||||
{
|
||||
line(i, 50 + player.left.get(i)*50, i+1, 50 + player.left.get(i+1)*50);
|
||||
line(i, 150 + player.right.get(i)*50, i+1, 150 + player.right.get(i+1)*50);
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
player.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Load Sample
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>loadSample</code>
|
||||
* method of <code>Minim</code>. The <code>loadSample</code>
|
||||
* method allows you to specify the sample you want to load with
|
||||
* a <code>String</code> and optionally specify what you
|
||||
* want the buffer size of the returned <code>AudioSample</code>
|
||||
* to be. If you don't specify a buffer size, the returned sample
|
||||
* will have a buffer size of 1024. Minim is able to load wav files,
|
||||
* au files, aif files, snd files, and mp3 files. When you call
|
||||
* <code>loadSample</code>, if you just specify the filename it will
|
||||
* try to load the sample from the data folder of your sketch. However,
|
||||
* you can also specify an absolute path (such as "C:\foo\bar\thing.wav")
|
||||
* and the file will be loaded from that location (keep in mind that
|
||||
* won't work from an applet). You can also specify a URL (such as
|
||||
* "http://www.mysite.com/mp3/song.mp3") but keep in mind that if you
|
||||
* run the sketch as an applet you may run in to security restrictions
|
||||
* if the applet is not on the same domain as the file you want to load.
|
||||
* You can get around the restriction by signing the applet. Before you
|
||||
* exit your sketch make sure you call the <code>close</code> method
|
||||
* of any <code>AudioSamples</code>'s you have received from
|
||||
* <code>loadSample</code>.
|
||||
*
|
||||
* An <code>AudioSample</code> is a special kind of file playback that
|
||||
* allows you to repeatedly <i>trigger</i> an audio file. It does this
|
||||
* by keeping the entire file in an internal buffer and then keeping a
|
||||
* list of trigger points. <code>AudioSample</code> supports up to 20
|
||||
* overlapping triggers, which should be plenty for short sounds. It is
|
||||
* not advised that you use this class for long sounds (like entire songs,
|
||||
* for example) because the entire file is kept in memory.
|
||||
*
|
||||
* Press 'k' to trigger the sample.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioSample kick;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
// always start Minim before you do anything with it
|
||||
minim = new Minim(this);
|
||||
// load BD.mp3 from the data folder with a 1024 sample buffer
|
||||
// kick = Minim.loadSample("BD.mp3");
|
||||
// load BD.mp3 from the data folder, with a 512 sample buffer
|
||||
kick = minim.loadSample("BD.mp3", 2048);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// use the mix buffer to draw the waveforms.
|
||||
// because these are MONO files, we could have used the left or right buffers and got the same data
|
||||
for (int i = 0; i < kick.bufferSize() - 1; i++)
|
||||
{
|
||||
line(i, 100 - kick.left.get(i)*50, i+1, 100 - kick.left.get(i+1)*50);
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed()
|
||||
{
|
||||
if ( key == 'k' ) kick.trigger();
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
kick.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Load Snippet
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use the <code>loadSnippet</code>
|
||||
* method of <code>Minim</code>. The <code>loadSnippet</code> method
|
||||
* allows you to specify the file you want to load with a
|
||||
* <code>String</code>. Unlike with <code>loadFile</code> and <code>loadSample</code>,
|
||||
* you are not able to specify a buffer size because an <code>AudioSnippet</code>
|
||||
* doesn't give you access to the samples as they are played.
|
||||
*
|
||||
* Minim is able to load wav files, au files, aif files, snd files, and mp3
|
||||
* files. When you call <code>loadSnippet</code>, if you just specify the
|
||||
* filename it will try to load the file from the data folder of your sketch.
|
||||
* However, you can also specify an absolute path (such as "C:\foo\bar\thing.wav")
|
||||
* and the file will be loaded from that location (keep in mind that won't
|
||||
* work from an applet). You can also specify a URL (such as
|
||||
* "http://www.mysite.com/mp3/song.mp3") but keep in mind that if you run the
|
||||
* sketch as an applet you may run in to security restrictions if the applet
|
||||
* is not on the same domain as the file you want to load. You can get around the
|
||||
* restriction by signing the applet.
|
||||
*
|
||||
* <code>AudioSnippet</code> is a simple wrapper around a JavaSound <code>Clip</code>
|
||||
* (It isn't called AudioClip because that's an interface defined in the package
|
||||
* java.applet). It provides almost the exact same functionality, the main
|
||||
* difference being that length, position, and cue are expressed in milliseconds
|
||||
* instead of microseconds. One of the limitations of <code>AudioSnippet</code> is
|
||||
* that you do not have access to the audio samples as they are played. However,
|
||||
* you are spared all of the overhead associated with making samples available.
|
||||
* An <code>AudioSnippet</code> is a good choice if all you need to do is play
|
||||
* a short sound at some point. If your aim is to repeatedly trigger a sound, you
|
||||
* should use an <code>AudioSample</code> instead.
|
||||
*
|
||||
* Before you exit your sketch make sure you call the <code>close</code>
|
||||
* method of any <code>AudioSnippet</code>'s you have received from
|
||||
* <code>loadSnippet</code>.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioSnippet snip;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200);
|
||||
|
||||
minim = new Minim(this);
|
||||
snip = minim.loadSnippet("groove.mp3");
|
||||
// play the file
|
||||
snip.play();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
// there are no waveforms to draw
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
snip.close();
|
||||
// always stop Minim before exiting
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* Record Line In
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to an <code>AudioRecorder</code>
|
||||
* to record audio to disk. To use this sketch you need to have
|
||||
* something plugged into the line-in on your computer. 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.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
|
||||
Minim minim;
|
||||
AudioInput in;
|
||||
AudioRecorder recorder;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
textMode(SCREEN);
|
||||
|
||||
minim = new Minim(this);
|
||||
|
||||
// get a stereo line-in: sample buffer length of 2048
|
||||
// default sample rate is 44100, default bit depth is 16
|
||||
in = minim.getLineIn(Minim.STEREO, 2048);
|
||||
// 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
|
||||
// the file will be located in the sketch's root folder.
|
||||
recorder = minim.createRecorder(in, "myrecording.wav", true);
|
||||
|
||||
textFont(createFont("SanSerif", 12));
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// draw the waveforms
|
||||
// the values returned by left.get() and right.get() will be between -1 and 1,
|
||||
// so we need to scale them up to see the waveform
|
||||
for(int i = 0; i < in.bufferSize() - 1; i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if ( recorder.isRecording() )
|
||||
{
|
||||
text("Currently recording...", 5, 15);
|
||||
}
|
||||
else
|
||||
{
|
||||
text("Not recording.", 5, 15);
|
||||
}
|
||||
}
|
||||
|
||||
void keyReleased()
|
||||
{
|
||||
if ( key == 'r' )
|
||||
{
|
||||
// to indicate that you want to start or stop capturing audio data, you must call
|
||||
// beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
|
||||
// as many times as you like, the audio data will be appended to the end of the buffer
|
||||
// (in the case of buffered recording) or to the end of the file (in the case of streamed recording).
|
||||
if ( recorder.isRecording() )
|
||||
{
|
||||
recorder.endRecord();
|
||||
}
|
||||
else
|
||||
{
|
||||
recorder.beginRecord();
|
||||
}
|
||||
}
|
||||
if ( key == 's' )
|
||||
{
|
||||
// we've filled the file out buffer,
|
||||
// now write it to the file we specified in createRecorder
|
||||
// in the case of buffered recording, if the buffer is large,
|
||||
// this will appear to freeze the sketch for sometime
|
||||
// in the case of streamed recording,
|
||||
// it will not freeze as the data is already in the file and all that is being done
|
||||
// is closing the file.
|
||||
// the method returns the recorded audio as an AudioRecording,
|
||||
// see the example AudioRecorder >> RecordAndPlayback for more about that
|
||||
recorder.save();
|
||||
println("Done saving.");
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you are done with them
|
||||
in.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Sine Wave Signal
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to use a <code>SineWave</code> with
|
||||
* an <code>AudioOutput</code>. Move the mouse up and down to change
|
||||
* the frequency, left and right to change the panning.
|
||||
*
|
||||
* <code>SineWave</code> is a subclass of <code>Oscillator</code>, which
|
||||
* is an abstract class that implements the interface <code>AudioSignal</code>.
|
||||
* This means that it can be added to an <code>AudioOutput</code> and the
|
||||
* <code>AudioOutput</code> will call one of the two <code>generate()</code>
|
||||
* functions, depending on whether the AudioOutput is STEREO or MONO.
|
||||
* Since it is an abstract class, it can't be directly instantiated, it
|
||||
* merely provides the functionality of smoothly changing frequency, amplitude
|
||||
* and pan. In order to have an <code>Oscillator</code> that actually
|
||||
* produces sound, you have to extend <code>Oscillator</code> and define
|
||||
* the value function. This function takes a <b>step</b> value and returns
|
||||
* a sample value between -1 and 1. In the case of the SineWave,
|
||||
* the value function returns this: <b>sin(freq * TWO_PI * step)</b>
|
||||
* <b>freq</b> is the current frequency (in Hertz) of the <code>Oscillator</code>.
|
||||
* It is multiplied by <b>TWO_PI</b> to set the period of the sine wave
|
||||
* properly and then that sine wave is sampled at <b>step</b>.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.signals.*;
|
||||
|
||||
Minim minim;
|
||||
AudioOutput out;
|
||||
SineWave sine;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
// get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
|
||||
out = minim.getLineOut(Minim.STEREO);
|
||||
// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
|
||||
sine = new SineWave(440, 0.5, out.sampleRate());
|
||||
// set the portamento speed on the oscillator to 200 milliseconds
|
||||
sine.portamento(200);
|
||||
// add the oscillator to the line out
|
||||
out.addSignal(sine);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// draw the waveforms
|
||||
for(int i = 0; i < out.bufferSize() - 1; i++)
|
||||
{
|
||||
float x1 = map(i, 0, out.bufferSize(), 0, width);
|
||||
float x2 = map(i+1, 0, out.bufferSize(), 0, width);
|
||||
line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
|
||||
line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
|
||||
}
|
||||
}
|
||||
|
||||
void mouseMoved()
|
||||
{
|
||||
// with portamento on the frequency will change smoothly
|
||||
float freq = map(mouseY, 0, height, 1500, 60);
|
||||
sine.setFreq(freq);
|
||||
// pan always changes smoothly to avoid crackles getting into the signal
|
||||
// note that we could call setPan on out, instead of on sine
|
||||
// this would sound the same, but the waveforms in out would not reflect the panning
|
||||
float pan = map(mouseX, 0, width, -1, 1);
|
||||
sine.setPan(pan);
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
out.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// this is a really straightforward effect that just reverses the order of the samples it receives
|
||||
// it doesn't sound like how you think ;-)
|
||||
class ReverseEffect implements AudioEffect
|
||||
{
|
||||
void process(float[] samp)
|
||||
{
|
||||
float[] reversed = new float[samp.length];
|
||||
int i = samp.length - 1;
|
||||
for (int j = 0; j < reversed.length; i--, j++)
|
||||
{
|
||||
reversed[j] = samp[i];
|
||||
}
|
||||
// we have to copy the values back into samp for this to work
|
||||
arraycopy(reversed, samp);
|
||||
}
|
||||
|
||||
void process(float[] left, float[] right)
|
||||
{
|
||||
process(left);
|
||||
process(right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* User Defined Effect
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to write your own AudioEffect.
|
||||
* See NoiseEffect.pde for the implementation.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.effects.*;
|
||||
|
||||
Minim minim;
|
||||
AudioPlayer groove;
|
||||
ReverseEffect reffect;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
// try changing the buffer size to see how it changes the effect
|
||||
groove = minim.loadFile("groove.mp3", 2048);
|
||||
groove.loop();
|
||||
reffect = new ReverseEffect();
|
||||
groove.addEffect(reffect);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// we multiply the values returned by get by 50 so we can see the waveform
|
||||
for ( int i = 0; i < groove.bufferSize() - 1; i++ )
|
||||
{
|
||||
float x1 = map(i, 0, groove.bufferSize(), 0, width);
|
||||
float x2 = map(i+1, 0, groove.bufferSize(), 0, width);
|
||||
line(x1, height/4 - groove.left.get(i)*50, x2, height/4 - groove.left.get(i+1)*50);
|
||||
line(x1, 3*height/4 - groove.right.get(i)*50, x2, 3*height/4 - groove.right.get(i+1)*50);
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
// always close Minim audio classes when you finish with them
|
||||
groove.close();
|
||||
// always stop Minim before exiting
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Binary file not shown.
@@ -1,24 +0,0 @@
|
||||
// this signal uses the mouseX and mouseY position to build a signal
|
||||
class MouseSaw implements AudioSignal
|
||||
{
|
||||
void generate(float[] samp)
|
||||
{
|
||||
float range = map(mouseX, 0, width, 0, 1);
|
||||
float peaks = map(mouseY, 0, height, 1, 20);
|
||||
float inter = float(samp.length) / peaks;
|
||||
for ( int i = 0; i < samp.length; i += inter )
|
||||
{
|
||||
for ( int j = 0; j < inter && (i+j) < samp.length; j++ )
|
||||
{
|
||||
samp[i + j] = map(j, 0, inter, -range, range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this is a stricly mono signal
|
||||
void generate(float[] left, float[] right)
|
||||
{
|
||||
generate(left);
|
||||
generate(right);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* User Defined Signal
|
||||
* by Damien Di Fede.
|
||||
*
|
||||
* This sketch demonstrates how to implement your own AudioSignal
|
||||
* for Minim. See MouseSaw.pde for the implementation.
|
||||
*/
|
||||
|
||||
import ddf.minim.*;
|
||||
import ddf.minim.signals.*;
|
||||
|
||||
Minim minim;
|
||||
AudioOutput out;
|
||||
MouseSaw msaw;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(512, 200, P2D);
|
||||
|
||||
minim = new Minim(this);
|
||||
|
||||
out = minim.getLineOut(Minim.STEREO, 2048);
|
||||
msaw = new MouseSaw();
|
||||
// adds the signal to the output
|
||||
out.addSignal(msaw);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
stroke(255);
|
||||
// draw the waveforms
|
||||
for(int i = 0; i < out.bufferSize()-1; i++)
|
||||
{
|
||||
float x1 = map(i, 0, out.bufferSize(), 0, width);
|
||||
float x2 = map(i+1, 0, out.bufferSize(), 0, width);
|
||||
line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
|
||||
line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
out.close();
|
||||
minim.stop();
|
||||
|
||||
super.stop();
|
||||
}
|
||||
Reference in New Issue
Block a user