Minim core
ugens
analysis
Name Minim
Description The Minim class is the starting point for most everything you will do with this library. There are methods for obtaining objects for playing audio files: AudioSample and AudioPlayer. There are methods for obtaining an AudioRecorder, which is how you record audio to disk. There are methods for obtaining an AudioInput, which is how you can monitor the computer's line-in or microphone, depending on what the user has set as the record source. Finally there are methods for obtaining an AudioOutput, which is how you can play audio generated by your program, typically by connecting classes found in the ugens package.

Minim keeps references to all of the resources that are returned from these various methods so that you don't have to worry about closing them. Instead, when your application ends you can simply call the stop method of your Minim instance. Processing users do not need to do this because Minim detects when a PApplet is passed to the contructor and registers for a notification of application shutdown.

Minim requires an Object that can handle two important file system operations so that it doesn't have to worry about details of the current environment. These two methods are:

String sketchPath( String fileName )
InputStream createInput( String fileName )

These are methods that are defined in Processing, which Minim was originally designed to cleanly interface with. The sketchPath method is expected to transform a filename into an absolute path and is used when attempting to create an AudioRecorder. The createInput method is used when loading files and is expected to take a filename, which is not necessarily an absolute path, and return an InputStream that can be used to read the file. For example, in Processing, the createInput method will search in the data folder, the sketch folder, handle URLs, and absolute paths. If you are using Minim outside of Processing, you can handle whatever cases are appropriate for your project.
Examples
/**
  * This sketch demonstrates how to play a file with Minim using an AudioPlayer. <br />
  * It's also a good example of how to draw the waveform of the audio. Full documentation 
  * for AudioPlayer can be found at http://code.compartmental.net/minim/audioplayer_class_audioplayer.html
  * <p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;

Minim minim;
AudioPlayer player;

void setup()
{
  size(512, 200, P3D);
  
  // we pass this to Minim so that it can load files from the data directory
  minim = new Minim(this);
  
  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the 
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("groove.mp3");
}

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.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player.bufferSize(), 0, width );
    line( x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50 );
    line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 );
  }
  
  // draw a line to show where in the song playback is currently located
  float posx = map(player.position(), 0, player.length(), 0, width);
  stroke(0,200,0);
  line(posx, 0, posx, height);
  
  if ( player.isPlaying() )
  {
    text("Press any key to pause playback.", 10, 20 );
  }
  else
  {
    text("Press any key to start playback.", 10, 20 );
  }
}

void keyPressed()
{
  if ( player.isPlaying() )
  {
    player.pause();
  }
  // if the player is at the end of the file,
  // we have to rewind it before telling it to play again
  else if ( player.position() == player.length() )
  {
    player.rewind();
    player.play();
  }
  else
  {
    player.play();
  }
}
Constructors
Minim(fileSystemHandler);
Parameters
fileSystemHandler   The Object that will be used for file operations. When using Processing, simply pass this to Minim's constructor.
Fields
AIFC   The .aifc file format.

AIFF   The .aiff file format.

AU   The .au file format.

MONO   Specifies that you want a MONO AudioInput or AudioOutput

SND   The .snd file format.

STEREO   Specifies that you want a STEREO AudioInput or AudioOutput

WAV   The .wav file format.

Methods
createRecorder ( )   Creates an AudioRecorder.

createSample ( )   Creates an AudioSample using the provided sample data and AudioFormat.

debugOff ( )   Turns off debug messages.

debugOn ( )   Turns on debug messages.

getInputStream ( )   Get the input as an AudioStream that you can read from yourself, rather than wrapped in an AudioInput that does that work for you.

getLineIn ( )   get an AudioInput that reads from the active audio input of the soundcard

getLineOut ( )   get an AudioOutput that can be used to generate audio

loadFile ( )   Loads the requested file into an AudioPlayer.

loadFileIntoBuffer ( )   Loads the requested file into a MultiChannelBuffer.

loadFileStream ( )   Loads the file into an AudioRecordingStream.

loadSample ( )   Loads the requested file into an AudioSample.

setInputMixer ( )   When using the JavaSound implementation of Minim, this sets the JavaSound Mixer that will be used for obtaining input sources such as AudioInputs. THIS METHOD WILL BE REPLACED IN A FUTURE VERSION.

setOutputMixer ( )   When using the JavaSound implementation of Minim, this sets the JavaSound Mixer that will be used for obtain output destinations such as those required by AudioOuput, AudioPlayer, AudioSample, and so forth. THIS METHOD WILL BE REPLACED IN A FUTURE VERSION.

stop ( )   Stops Minim and releases all audio resources.

If using Minim outside of Processing, you must call this to release all of the audio resources that Minim has generated. It will call close() on all of them for you.

Usage Web & Application
Related