Wednesday, May 8, 2013

Research Presentation: Minim Library

I wanted to explore and discover more about the Processing library called Minim. It is a fairly easy to use audio library which helps integrate audio into your sketches. I know a lot of people are interested, including me, in creating and editing audio in Processing sketches and knowing more about Minim could be very useful.

Installation
First you should install the Minim library here: http://code.compartmental.net/minim/distro/minim-2.0.2-lib.zip

Replace your existing Minim library that comes with processing with your newly downloaded library.

Restart Processing.

Usage
Here are some cool features that Minim has:


  • AudioPlayer: Mono and Stereo playback of WAV, AIFF, AU, SND, and MP3 files.
  • AudioMetaData: An object filled with metadata about a file, such as ID3 tags.
  • AudioRecorder: Mono and Stereo audio recording either buffered or direct to disk.
  • AudioInput: Mono and Stereo input monitoring.
  • AudioOutput: Mono and Stereo sound synthesis.
  • AudioSignal: A simple interface for writing your own sound synthesis classes.
  • Comes with all the standard waveforms, a pink noise generator and a white noise generator. Additionally, you can extend the Oscillator class for easy implementation of your own periodic waveform.
  • AudioEffect: A simple interface for writing your own audio effects.
  • Comes with low pass, high pass, band pass, and notch filters. Additionally, you can extend the IIRFilter class for easy implementation of your own IIR filters.
  • Easy to attach signals and effects to AudioInputs and AudioOutputs. All the mixing and processing is taken care of for you.
  • Provides an FFT class for doing spectrum analysis.
  • Provides a BeatDetect class for doing beat detection.
Examples
1. Here is some example code that simply shows how to play a audio file with Minim:

[snip java]
import ddf.minim.*;
Minim minim;
AudioPlayer song;
void setup()
{
size(100, 100);
minim = new Minim(this);
// this loads mysong.wav from the data folder
song = minim.loadFile(“mysong.wav”);
song.play();
}
void draw()
{
background(0);
}
void stop()
{
song.close();
minim.stop();
super.stop();
}
[/snip]
2. Here is some example code of how to add a square wave to the output that goes through a low pass filter:
[snip java]
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.effects.*;
Minim minim;
AudioOutput out;
SquareWave square;
LowPassSP lowpass;
void setup()
{
size(512, 200);
minim = new Minim(this);
// get a stereo line out with a sample buffer of 512 samples
out = minim.getLineOut(Minim.STEREO, 512);
// create a SquareWave with a frequency of 440 Hz,
// an amplitude of 1 and the same sample rate as out
square = new SquareWave(440, 1, 44100);
// create a LowPassSP filter with a cutoff frequency of 200 Hz
// that expects audio with the same sample rate as out
lowpass = new LowPassSP(200, 44100);
// now we can attach the square wave and the filter to our output
out.addSignal(square);
out.addEffect(lowpass);
}
void draw()
{
// you might decide to draw the waveform here or do something else
}
// here we provide a way to mute out
// because, let's face it, it's not a very pleasant sound
void keyPressed()
{
if ( key == 'm' )
{
if ( out.isMuted() )
{
out.unmute();
}
else
{
out.mute();
}
}
}
void stop()
{
out.close();
minim.stop();
super.stop();
}
[/snip]

3. This is a link to the code and demonstration of a simple beat detect program that can see when a kick, snare, or hat is played: http://code.compartmental.net/minim/examples/BeatDetect/FrequencyEnergy/
More Info
You can do so much cool stuff with the many features that Minim has to offer. For some more info and even example codes check out the Minim website (http://code.compartmental.net/tools/minim/). If you click on Tools you can see more specific functions within Minim.
This is probably one of the coolest sketches I have seen with Minim: http://motscousus.com/stuff/2008-02_Processing.org_patterns/test_beat.pde

No comments:

Post a Comment