public class Minim
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static javax.sound.sampled.AudioFileFormat.Type |
AIFC
The .aifc file format.
|
static javax.sound.sampled.AudioFileFormat.Type |
AIFF
The .aiff file format.
|
static javax.sound.sampled.AudioFileFormat.Type |
AU
The .au file format.
|
static int |
LOOP_CONTINUOUSLY |
static int |
MONO
Specifies that you want a MONO AudioInput or AudioOutput
|
static javax.sound.sampled.AudioFileFormat.Type |
SND
The .snd file format.
|
static int |
STEREO
Specifies that you want a STEREO AudioInput or AudioOutput
|
static javax.sound.sampled.AudioFileFormat.Type |
WAV
The .wav file format.
|
Constructor and Description |
---|
Minim(ddf.minim.spi.MinimServiceProvider implementation) |
Minim(java.lang.Object fileSystemHandler)
Creates an instance of Minim.
|
Modifier and Type | Method and Description |
---|---|
AudioRecorder |
createRecorder(Recordable source,
java.lang.String fileName)
Creates an AudioRecorder that will use the provided Recordable object as its
record source and that will save to the file name specified.
|
AudioRecorder |
createRecorder(Recordable source,
java.lang.String fileName,
boolean buffered)
Creates an AudioRecorder that will use the provided Recordable object as its
record source and that will save to the file name specified.
|
AudioSample |
createSample(float[] sampleData,
javax.sound.sampled.AudioFormat format)
Creates an AudioSample using the provided sample data and AudioFormat.
|
AudioSample |
createSample(float[] sampleData,
javax.sound.sampled.AudioFormat format,
int bufferSize)
Creates an AudioSample using the provided sample data and
AudioFormat, with the desired output buffer size.
|
AudioSample |
createSample(float[] leftSampleData,
float[] rightSampleData,
javax.sound.sampled.AudioFormat format)
Creates an AudioSample using the provided left and right channel
sample data with an output buffer size of 1024.
|
AudioSample |
createSample(float[] leftSampleData,
float[] rightSampleData,
javax.sound.sampled.AudioFormat format,
int bufferSize)
Creates an AudioSample using the provided left and right channel
sample data.
|
static void |
debug(java.lang.String message) |
void |
debugOff()
Turns off debug messages.
|
void |
debugOn()
Turns on debug messages.
|
void |
dispose() |
static void |
error(java.lang.String message) |
ddf.minim.spi.AudioStream |
getInputStream(int type,
int bufferSize,
float sampleRate,
int bitDepth)
Get the input as an AudioStream that you can read from yourself, rather
than wrapped in an AudioInput that does that work for you.
|
AudioInput |
getLineIn()
An AudioInput is used when you want to monitor the active audio input
of the computer.
|
AudioInput |
getLineIn(int type)
Gets either a MONO or STEREO
AudioInput . |
AudioInput |
getLineIn(int type,
int bufferSize)
Gets an
AudioInput . |
AudioInput |
getLineIn(int type,
int bufferSize,
float sampleRate)
Gets an
AudioInput . |
AudioInput |
getLineIn(int type,
int bufferSize,
float sampleRate,
int bitDepth)
Gets an
AudioInput . |
AudioOutput |
getLineOut()
An AudioOutput is used to generate sound in real-time and output it to
the soundcard.
|
AudioOutput |
getLineOut(int type)
Gets an
AudioOutput . |
AudioOutput |
getLineOut(int type,
int bufferSize)
Gets an
AudioOutput . |
AudioOutput |
getLineOut(int type,
int bufferSize,
float sampleRate)
Gets an
AudioOutput . |
AudioOutput |
getLineOut(int type,
int bufferSize,
float sampleRate,
int bitDepth)
Gets an
AudioOutput . |
AudioPlayer |
loadFile(java.lang.String filename)
Loads the requested file into an AudioPlayer.
|
AudioPlayer |
loadFile(java.lang.String filename,
int bufferSize)
Loads the requested file into an
AudioPlayer with the request
buffer size. |
float |
loadFileIntoBuffer(java.lang.String filename,
MultiChannelBuffer outBuffer)
Loads the requested file into a MultiChannelBuffer.
|
ddf.minim.spi.AudioRecordingStream |
loadFileStream(java.lang.String filename)
Load the file into an AudioRecordingStream with a buffer size of 1024
samples.
|
ddf.minim.spi.AudioRecordingStream |
loadFileStream(java.lang.String filename,
int bufferSize,
boolean inMemory)
Loads the file into an AudioRecordingStream, which allows you to stream
audio data from the file yourself.
|
AudioSample |
loadSample(java.lang.String filename)
Loads the requested file into an AudioSample.
|
AudioSample |
loadSample(java.lang.String filename,
int bufferSize)
Loads the requested file into an AudioSample.
|
AudioSnippet |
loadSnippet(java.lang.String filename)
Deprecated.
|
void |
setInputMixer(javax.sound.sampled.Mixer mixer)
Deprecated.
|
void |
setOutputMixer(javax.sound.sampled.Mixer mixer)
Deprecated.
|
void |
stop()
Stops Minim and releases all audio resources.
|
public static final int MONO
public static final int STEREO
public static final int LOOP_CONTINUOUSLY
public static javax.sound.sampled.AudioFileFormat.Type WAV
public static javax.sound.sampled.AudioFileFormat.Type AIFF
public static javax.sound.sampled.AudioFileFormat.Type AIFC
public static javax.sound.sampled.AudioFileFormat.Type AU
public static javax.sound.sampled.AudioFileFormat.Type SND
public Minim(java.lang.Object fileSystemHandler)
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.
fileSystemHandler
- The Object that will be used for file operations.
When using Processing, simply pass this to Minim's constructor.public Minim(ddf.minim.spi.MinimServiceProvider implementation)
implementation
- the MinimServiceProvider that will be used for returning audio
resourcespublic static void error(java.lang.String message)
message
- the error message to reportpublic static void debug(java.lang.String message)
message
- the message to displaydebugOn()
public void debugOn()
public void debugOff()
public void dispose()
public void stop()
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.
@Deprecated public void setInputMixer(javax.sound.sampled.Mixer mixer)
mixer
- The Mixer we should try to acquire inputs from.@Deprecated public void setOutputMixer(javax.sound.sampled.Mixer mixer)
mixer
- The Mixer we should try to acquire outputs from.public AudioSample createSample(float[] sampleData, javax.sound.sampled.AudioFormat format)
sampleData
- float[]: the single channel of sample dataformat
- the AudioFormat describing the sample datapublic AudioSample createSample(float[] sampleData, javax.sound.sampled.AudioFormat format, int bufferSize)
sampleData
- float[]: the single channel of sample dataformat
- the AudioFormat describing the sample databufferSize
- int: the output buffer size to use,
which controls the size of the left, right, and mix AudioBuffer
fields of the returned AudioSample.public AudioSample createSample(float[] leftSampleData, float[] rightSampleData, javax.sound.sampled.AudioFormat format)
leftSampleData
- float[]: the left channel of the sample datarightSampleData
- float[]: the right channel of the sample dataformat
- the AudioFormat describing the sample datapublic AudioSample createSample(float[] leftSampleData, float[] rightSampleData, javax.sound.sampled.AudioFormat format, int bufferSize)
leftSampleData
- float[]: the left channel of the sample datarightSampleData
- float[]: the right channel of the sample dataformat
- the AudioFormat describing the sample databufferSize
- int: the output buffer size to use,
which controls the size of the left, right, and mix AudioBuffer
fields of the returned AudioSample.public AudioSample loadSample(java.lang.String filename)
filename
- the file or URL that you want to loadloadSample(String, int)
,
AudioSample
public AudioSample loadSample(java.lang.String filename, int bufferSize)
filename
- the file or URL that you want to loadbufferSize
- int: The sample buffer size you want.
This controls the size of the left, right, and mix
AudioBuffer fields of the returned AudioSample.@Deprecated public AudioSnippet loadSnippet(java.lang.String filename)
filename
- the file or URL you want to loadAudioSnippet
of the requested file or URLpublic AudioPlayer loadFile(java.lang.String filename)
filename
- the file or URL you want to loadAudioPlayer
that plays the fileloadFile(String, int)
public AudioPlayer loadFile(java.lang.String filename, int bufferSize)
AudioPlayer
with the request
buffer size.filename
- the file or URL you want to loadbufferSize
- int: the sample buffer size you want, which determines the
size of the left, right, and mix AudioBuffer fields of the
returned AudioPlayer.AudioPlayer
with a sample buffer of the requested
size, or null if we were unable to load the filepublic ddf.minim.spi.AudioRecordingStream loadFileStream(java.lang.String filename, int bufferSize, boolean inMemory)
filename
- the file to loadbufferSize
- int: the bufferSize to use, which controls how much
of the streamed file is stored in memory at a time.inMemory
- boolean: whether or not the file should be cached in memory as it is readpublic ddf.minim.spi.AudioRecordingStream loadFileStream(java.lang.String filename)
filename
- the file to loadpublic float loadFileIntoBuffer(java.lang.String filename, MultiChannelBuffer outBuffer)
filename
- the file to loadoutBuffer
- the MultiChannelBuffer to fill with the file's audio samplespublic AudioRecorder createRecorder(Recordable source, java.lang.String fileName)
source
- the Recordable
object you want to use as a record sourcefileName
- the name of the file to record toAudioRecorder
for the record sourcepublic AudioRecorder createRecorder(Recordable source, java.lang.String fileName, boolean buffered)
source
- the Recordable
object you want to use as a record sourcefileName
- the name of the file to record tobuffered
- boolean: whether or not to use buffered recordingAudioRecorder
for the record sourcepublic AudioInput getLineIn()
getLineIn(int, int, float, int)
public AudioInput getLineIn(int type)
AudioInput
.type
- Minim.MONO or Minim.STEREOAudioInput
with the requested type, a 1024 sample
buffer, a sample rate of 44100 and a bit depth of 16getLineIn(int, int, float, int)
public AudioInput getLineIn(int type, int bufferSize)
AudioInput
.type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioInput
's sample buffer
to be (ie the size of left, right, and mix buffers)AudioInput
with the requested attributes, a
sample rate of 44100 and a bit depth of 16getLineIn(int, int, float, int)
public AudioInput getLineIn(int type, int bufferSize, float sampleRate)
AudioInput
.type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioInput
's sample buffer
to be (ie the size of left, right, and mix buffers)sampleRate
- float: the desired sample rate in Hertz (typically 44100)AudioInput
with the requested attributes and a
bit depth of 16getLineIn(int, int, float, int)
public AudioInput getLineIn(int type, int bufferSize, float sampleRate, int bitDepth)
AudioInput
.type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioInput
's sample buffer
to be (ie the size of left, right, and mix buffers)sampleRate
- float: the desired sample rate in Hertz (typically 44100)bitDepth
- int: the desired bit depth (typically 16)AudioInput
with the requested attributespublic ddf.minim.spi.AudioStream getInputStream(int type, int bufferSize, float sampleRate, int bitDepth)
type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioStream's interal
buffer to be.sampleRate
- float: the desired sample rate in Hertz (typically 44100)bitDepth
- int: the desired bit depth (typically 16)public AudioOutput getLineOut()
Using setOutputMixer you can also create AudioOutputs that send sound to specific output channels of a soundcard.
getLineOut(int, int, float, int)
public AudioOutput getLineOut(int type)
AudioOutput
.type
- Minim.MONO or Minim.STEREOAudioOutput
with the requested type, a 1024
sample buffer, a sample rate of 44100 and a bit depth of 16getLineOut(int, int, float, int)
public AudioOutput getLineOut(int type, int bufferSize)
AudioOutput
.type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioOutput's sample buffer
to be (ie the size of the left, right, and mix buffers)AudioOutput
with the requested attributes, a
sample rate of 44100 and a bit depth of 16getLineOut(int, int, float, int)
public AudioOutput getLineOut(int type, int bufferSize, float sampleRate)
AudioOutput
.type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioOutput's sample buffer
to be (ie the size of the left, right, and mix buffers)sampleRate
- float: the desired sample rate in Hertz (typically 44100)AudioOutput
with the requested attributes and a
bit depth of 16getLineOut(int, int, float, int)
public AudioOutput getLineOut(int type, int bufferSize, float sampleRate, int bitDepth)
AudioOutput
.type
- Minim.MONO or Minim.STEREObufferSize
- int: how long you want the AudioOutput's sample buffer
to be (ie the size of the left, right, and mix buffers)sampleRate
- float: the desired sample rate in Hertz (typically 44100)bitDepth
- int: the desired bit depth (typically 16)AudioOutput
with the requested attributes