public class SimpleAudio
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static boolean |
BIGENDIAN
BIGENDIAN byte order format for audio samples.
|
private static int |
BITS_PER_SAMPLE
BITS_PER_SAMPLE number of bits used to represent an audio sample.
|
private static int |
BUFFER_SIZE
BUFFER_SIZE size of the buffer used by SimpleAudio objects.
|
private static int |
CHANNELS
CHANNELS number of audio channels.
|
private static int |
DEFAULT_SAMPLE_RATE
BUFFER_SIZE size of the buffer used by SimpleAudio objects.
|
private javax.sound.sampled.AudioFormat |
format
format audio format information.
|
private static boolean |
SIGNED_BYTES
SIGNED_BYTES are the audio samples signed.
|
Constructor and Description |
---|
SimpleAudio()
Default constructor which uses the default sample rate.
|
SimpleAudio(float sampleRate)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
play(java.util.List<java.lang.Float> samples)
Send audio samples to the the speakers.
|
void |
saveWAV(java.io.File file,
java.util.List<java.lang.Float> samples)
Save audio samples to a file using the .wav format.
|
private javax.sound.sampled.AudioInputStream |
toAudioInputStream(java.util.List<java.lang.Float> samples)
Convert the audio samples into an audio input stream.
|
private byte[] |
toBytes(java.util.List<java.lang.Float> samples)
Convert the audio samples into a byte array that can be used
to populate an AudioInputStream.
|
private static final int BITS_PER_SAMPLE
private static final int CHANNELS
private static final boolean SIGNED_BYTES
private static final boolean BIGENDIAN
private static final int BUFFER_SIZE
private static final int DEFAULT_SAMPLE_RATE
private javax.sound.sampled.AudioFormat format
public SimpleAudio(float sampleRate)
sampleRate
- number of audio samples per secondpublic SimpleAudio()
public void play(java.util.List<java.lang.Float> samples) throws javax.sound.sampled.LineUnavailableException, java.io.IOException
samples
- Audio samples to be sent to the speakers.javax.sound.sampled.LineUnavailableException
java.io.IOException
public void saveWAV(java.io.File file, java.util.List<java.lang.Float> samples) throws java.io.IOException
file
- File to receive the audio samples.samples
- Audio samples to be written to the file.java.io.IOException
private javax.sound.sampled.AudioInputStream toAudioInputStream(java.util.List<java.lang.Float> samples)
samples
- Audio samples to be used.private byte[] toBytes(java.util.List<java.lang.Float> samples)
samples
- Audio samples to be used.