|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.beadsproject.beads.data.Sample
public class Sample
A Sample encapsulates audio data, either loaded from an audio file (such as
an MP3) or written by a Recorder.
The typical use of a Sample is through
SampleManager
. For example, to load an
mp3, you would do the following.
Sample wicked = SampleManager.sample("wickedTrack.mp3");
Samples are usually played with a
SamplePlayer
. Sample data can also be
accessed through the methods: getFrame
,
getFrameLinear
, and
getFrames
. Sample data can be written
with: putFrame
or
putFrames
.
SampleManager
,
RecordToSample
Constructor Summary | |
---|---|
Sample(AudioFile af)
Create a sample from an Audio File, using the default buffering scheme. |
|
Sample(double length)
Instantiates a new writable sample with specified length and default audio format: 44.1KHz, 16 bit, stereo. |
|
Sample(java.io.InputStream is)
Create a sample from an input stream. |
|
Sample(SampleAudioFormat audioFormat,
double length)
Instantiates a new writeable Sample with the specified audio format and length; The sample isn't initialised, so may contain junk. |
|
Sample(java.lang.String filename)
Create a sample from a file. |
Method Summary | |
---|---|
void |
clear()
Clears the (writeable) sample. |
AudioFile |
getAudioFile()
|
java.lang.Class<? extends AudioFile> |
getAudioFileHandlerClass()
Gets the current AudioFileHandlerClass. |
SampleAudioFormat |
getAudioFormat()
|
int |
getBytesPerSample()
|
java.lang.String |
getFileName()
Gets the full file path. |
void |
getFrame(int frame,
float[] frameData)
Return a single frame. |
void |
getFrameCubic(double posInMS,
float[] result)
Retrieves a frame of audio using cubic interpolation. |
void |
getFrameLinear(double posInMS,
float[] result)
Retrieves a frame of audio using linear interpolation. |
void |
getFrameNoInterp(double posInMS,
float[] result)
Retrieves a frame of audio using no interpolation. |
void |
getFrames(int frame,
float[][] frameData)
Get a series of frames. |
double |
getLength()
|
int |
getNumChannels()
|
long |
getNumFrames()
|
float |
getSampleRate()
|
java.lang.String |
getSimpleName()
Gets the simple name. |
double |
msToSamples(double msTime)
Converts from milliseconds to samples based on the sample rate specified by audioFormat . |
void |
printAudioFormatInfo()
Prints audio format info to System.out. |
void |
putFrame(int frame,
float[] frameData)
Write a single frame into this sample. |
void |
putFrames(int frame,
float[][] frameData)
Write multiple frames into the sample. |
void |
putFrames(int frame,
float[][] frameData,
int offset,
int numFrames)
Write multiple frames into the sample. |
void |
resize(long frames)
Advanced Change the number of frames in the (writeable) sample. |
void |
resizeWithZeros(long frames)
Just like resize(long) but initialises the new frames with
zeros. |
double |
samplesToMs(double sampleTime)
Converts from samples to milliseconds based on the sample rate specified by audioFormat . |
void |
setAudioFileHandlerClass(java.lang.Class<? extends AudioFile> audioFileHandlerClass)
Set the audioFileHandlerClass. |
void |
setSimpleName(java.lang.String simpleName)
Sets the simple name. |
java.lang.String |
toString()
|
void |
write(java.lang.String fn)
This records the sample to a WAV format audio file. |
void |
write(java.lang.String fn,
AudioFile.Type type)
This records the sample to a file with the specified AudioFile.Type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Sample(double length)
length
- the length in ms.public Sample(SampleAudioFormat audioFormat, double length)
clear()
to clear it.
audioFormat
- the audio format.length
- The length of the sample in ms.public Sample(java.lang.String filename) throws java.io.IOException
UnsupportedAudioFileException
java.io.IOException
AudioFileUnsupportedException
public Sample(java.io.InputStream is) throws java.io.IOException
UnsupportedAudioFileException
java.io.IOException
AudioFileUnsupportedException
public Sample(AudioFile af) throws java.io.IOException
UnsupportedAudioFileException
java.io.IOException
AudioFileUnsupportedException
Method Detail |
---|
public java.lang.Class<? extends AudioFile> getAudioFileHandlerClass()
AudioFile
that Sample will use for file IO operations. If unset
or set to null Sample will attempt to find a default implementation:
JavaSoundAudioFile.
public void setAudioFileHandlerClass(java.lang.Class<? extends AudioFile> audioFileHandlerClass)
AudioFile
that Sample will use for file IO operations. If unset
or set to null Sample will attempt to find a default implementation:
JavaSoundAudioFile.
audioFileHandlerClass
- public void getFrame(int frame, float[] frameData)
frame
- Must be in range, else framedata is unchanged.frameData
- public void getFrameNoInterp(double posInMS, float[] result)
posInMS
- The frame to read -- will take the last frame before this one.result
- The framedata to fill.public void getFrameLinear(double posInMS, float[] result)
posInMS
- The frame to read -- can be fractional (e.g., 4.4).result
- The framedata to fill.public void getFrameCubic(double posInMS, float[] result)
posInMS
- The frame to read -- can be fractional (e.g., 4.4).result
- The framedata to fill.public void getFrames(int frame, float[][] frameData)
min(nFrames - frame, frameData[0].length)
frames in
frameData are valid.
If the data is not readily available this doesn't do anything.
frame
- The frame number (NOTE: This parameter is in frames, not in
ms!)frameData
- public void clear()
public void putFrame(int frame, float[] frameData)
frame
- The frame to write into. Must be >=0 and frameData
- The frame data to write.public void putFrames(int frame, float[][] frameData)
frame
- The frame to write into.frameData
- The frames to write.public void putFrames(int frame, float[][] frameData, int offset, int numFrames)
frame
- The frame to write into.frameData
- The frames to write.offset
- The offset into frameDatanumFrames
- The number of frames from frameData to writepublic void write(java.lang.String fn) throws java.lang.Exception
fn
- The filename (should have the .aif extension).
java.io.IOException
- Signals that an I/O exception has occurred.
java.lang.Exception
public void write(java.lang.String fn, AudioFile.Type type) throws java.lang.Exception
fn
- The filename.type
- The type (AIFF, WAVE, etc.)
java.io.IOException
- Signals that an I/O exception has occurred.
java.lang.Exception
public void resize(long frames)
resizeWithZeros(long)
.
frames
- The total number of frames the sample should have.
java.lang.Exception
- Thrown if the sample isn't writeable.public void resizeWithZeros(long frames)
resize(long)
but initialises the new frames with
zeros.
frames
- The total number of frames the sample should have.public void printAudioFormatInfo()
public double msToSamples(double msTime)
audioFormat
.
msTime
- the time in milliseconds.
public double samplesToMs(double sampleTime)
audioFormat
.
sampleTime
- the time in samples.
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getFileName()
public java.lang.String getSimpleName()
public void setSimpleName(java.lang.String simpleName)
simpleName
- the name.public AudioFile getAudioFile()
public SampleAudioFormat getAudioFormat()
public int getNumChannels()
public long getNumFrames()
public int getBytesPerSample()
public double getLength()
public float getSampleRate()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |