|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object acm.util.SoundClip
public class SoundClip
This class represents a sound, which can be created from a URL, sound file, resource stream, or digital samples.
Field Summary | |
---|---|
static int |
LEFT
Identifies the left channel in a stereo sound. |
static int |
MAX_SAMPLE
Specifies the maximum value of a sample in a sound. |
static int |
MONO
Number of channels in a mono sound. |
static int |
RIGHT
Identifies the right channel in a stereo sound. |
static double |
STANDARD_FRAME_RATE
Specifies the standard frame rate in a sampled sound. |
static int |
STEREO
Number of channels in a stereo sound. |
Constructor Summary | |
---|---|
SoundClip()
Creates an empty single-channel sound to which samples can be added. |
|
SoundClip(File file)
Creates a new sound by reading the data from the specified file. |
|
SoundClip(InputStream in)
Creates a new sound by reading the data from the specified input stream. |
|
SoundClip(int channels)
Creates an empty sound with the specified number of channels, which must be 1 for mono and 2 for stereo. |
|
SoundClip(int[] samples)
Creates a new mono sound from the sample array. |
|
SoundClip(int[] left,
int[] right)
Creates a new stereo sound from the two sample arrays. |
|
SoundClip(String name)
Creates a new sound by reading the data from the specified file. |
|
SoundClip(URL url)
Creates a new sound by reading the data from the specified URL. |
Method Summary | |
---|---|
void |
addSampleData(int sample)
Adds a single sound sample to the end of the sound. |
void |
addSampleData(int[] samples)
Adds the specified samples to the end of the sound. |
void |
addSampleData(int[] left,
int[] right)
Adds the specified samples to the end of the appropriate channels of the stereo sound. |
void |
addSampleData(int left,
int right)
Adds the specified samples to the end of the appropriate channels of the stereo sound. |
protected AudioInputStream |
getAudioInputStream()
Returns an AudioInputStream for the sound. |
int |
getChannelCount()
Returns the number of channels. |
protected byte[] |
getData()
Returns the byte array containing the sound data. |
double |
getDuration()
Returns the duration of a sound (in seconds). |
protected AudioFormat |
getFormat()
Returns the format in which the sound is stored. |
int |
getFrameCount()
Returns the number of frames in a sound. |
int |
getFrameIndex()
Returns the current frame index in the sound. |
double |
getFrameRate()
Returns the frame rate of the sound. |
String |
getName()
Returns the name of the sound, which is typically the file name from which it was read. |
int[] |
getSampleData()
Returns an array of integers corresponding to the samples in the primary channel of the sound. |
int[] |
getSampleData(int channel)
Returns an array of integers corresponding to the samples in the specified channel, which is typically represented by LEFT or RIGHT . |
double |
getVolume()
Returns the overall volume setting for the sound, which is a number between 0 (silent) and 1 (maximum volume). |
static int |
intensityToSample(double intensity)
Converts an intensity value between -1.0 and +1.0 into the corresponding integer sample in the range -32767 and +32767. |
boolean |
isStereo()
Returns true if the sound is recorded in stereo. |
void |
loop()
Plays the sound in a continuous audio loop. |
void |
play()
Plays the sound through the computer's audio system. |
void |
rewind()
Rewinds the sound to the beginning. |
static double |
sampleToIntensity(int sample)
Converts an integer sample in the range -32767 and +32767 into a double between -1.0 and +1.0. |
void |
save(File file)
Writes the sound to the specified File object. |
void |
save(String filename)
Writes a data file containing the specified sound. |
void |
setFrameIndex(int frameIndex)
Sets the current frame index. |
void |
setName(String name)
Sets a name to identify the sound. |
void |
setVolume(double volume)
Sets the overall volume setting for the sound, which is a number between 0 (silent) and 1 (maximum volume). |
void |
stop()
Stops the playback of the sound. |
String |
toString()
Converts a sound to a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int LEFT
public static final int MAX_SAMPLE
-MAX_SAMPLE
and MAX_SAMPLE
.
public static final int MONO
public static final int RIGHT
public static final double STANDARD_FRAME_RATE
public static final int STEREO
Constructor Detail |
---|
public SoundClip()
public SoundClip(File file)
file
- A File
object from which the sound is readpublic SoundClip(InputStream in)
in
- An InputStream
from which the sound is readpublic SoundClip(int channels)
channels
- The desired number of channels (1 for mono, 2 for stereo)public SoundClip(int[] samples)
samples
- An array of integers containing the sampled soundpublic SoundClip(int[] left, int[] right)
left
- An array of integers containing the samples for the left channelright
- An array of integers containing the samples for the right channelpublic SoundClip(String name)
name
- The file from which the sound is readpublic SoundClip(URL url)
url
- A network URL containing the soundMethod Detail |
---|
public void addSampleData(int sample)
sample
- An integers representing a new sound samplespublic void addSampleData(int[] samples)
samples
- An array of integers containing the new sound samplespublic void addSampleData(int[] left, int[] right)
left
- An array of integers containing the samples for the left channelright
- An array of integers containing the samples for the right channelpublic void addSampleData(int left, int right)
left
- An integer containing a single sample for the left channelright
- An integer containing a single sample for the right channelprotected AudioInputStream getAudioInputStream()
AudioInputStream
for the sound.
public int getChannelCount()
protected byte[] getData()
public double getDuration()
protected AudioFormat getFormat()
public int getFrameCount()
public int getFrameIndex()
public double getFrameRate()
public String getName()
public int[] getSampleData()
public int[] getSampleData(int channel)
LEFT
or RIGHT
.
channel
- The channel for which samples are requested
public double getVolume()
public static int intensityToSample(double intensity)
intensity
- An intensity value between -1.0 and +1.0
public boolean isStereo()
true
if the sound is recorded in stereo.
true
if the sound is recorded in stereopublic void loop()
loop
in interface AudioClip
public void play()
play
in interface AudioClip
public void rewind()
public static double sampleToIntensity(int sample)
double
between -1.0 and +1.0.
sample
- An integer sample from a digital sound
public void save(File file)
File
object.
file
- The File
object to which the sound is writtenpublic void save(String filename)
.au | Sun audio file with ALAW encoding |
.wav | Waveform audio format |
.aif or .aiff | Audio Interchange File Format |
filename
- The name of the filepublic void setFrameIndex(int frameIndex)
frameIndex
- The current frame index in the soundpublic void setName(String name)
name
- The name to use for the soundpublic void setVolume(double volume)
volume
- The new overall volume setting for the soundpublic void stop()
stop
saves the
current frame index so that calling start
will resume from
the point at which it stopped.
stop
in interface AudioClip
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |