Minim core | ugens | analysis |
Minim Fields AIFC AIFF AU MONO SND STEREO WAV Methods createRecorder ( ) createSample ( ) debugOff ( ) debugOn ( ) getInputStream ( ) getLineIn ( ) getLineOut ( ) loadFile ( ) loadFileIntoBuffer ( ) loadFileStream ( ) loadSample ( ) setInputMixer ( ) setOutputMixer ( ) stop ( ) | 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. Constructors

    Creates an instance of Minim.

     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.

    Minim(Object fileSystemHandler)
Parameters fileSystemHandler — The Object that will be used for file operations. When using Processing, simply pass this to Minim's constructor. Related Example
    /**
      * 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();
      }
    }
Usage Web & Application