public class Utils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static short |
bytesToShort(javax.sound.sampled.AudioFormat format,
byte[] byteArray)
Convert the bytes starting at the given offset to a signed short based upon the AudioFormat.
|
static AudioData |
readAudioFile(java.lang.String filename)
Attempts to read an audio file using the Java Sound APIs.
|
static AudioData |
readRawFile(java.lang.String filename)
Reads the given stream in as 8kHz 16-bit signed PCM little endian audio data and returns an audio clip.
|
static void |
toBytes(short sVal,
byte[] bytes,
boolean bigEndian)
Converts a short into a byte array.
|
static short |
toShort(byte[] bytes,
boolean bigEndian)
Converts a byte array to a signed short value.
|
static short[] |
toSignedPCM(javax.sound.sampled.AudioInputStream ais)
Turns the AudioInputStream into a 16bit, SIGNED_PCM, little endian audio stream that preserves the original sample
rate of the AudioInputStream.
|
static int |
toUnsignedShort(byte[] bytes,
boolean bigEndian)
Converts a byte array into an unsigned short.
|
static void |
writeRawFile(AudioData audio,
java.lang.String filename)
Writes the given 8kHz 16-bit signed PCM audio clip to the given file as raw little endian data.
|
public static short toShort(byte[] bytes,
boolean bigEndian)
bytes - array to convertbigEndian - is big endianpublic static int toUnsignedShort(byte[] bytes,
boolean bigEndian)
bytes - array to convertbigEndian - is big endianpublic static void toBytes(short sVal,
byte[] bytes,
boolean bigEndian)
sVal - source valuebytes - array to convertbigEndian - is big endianpublic static short bytesToShort(javax.sound.sampled.AudioFormat format,
byte[] byteArray)
format - the audio formatbyteArray - the byte arraypublic static short[] toSignedPCM(javax.sound.sampled.AudioInputStream ais)
throws java.io.IOException
ais - stream to convertjava.io.IOException - if error occurredpublic static AudioData readAudioFile(java.lang.String filename) throws java.io.IOException
filename - the file containing audio datajava.io.IOException - if error occuredpublic static AudioData readRawFile(java.lang.String filename) throws java.io.IOException
filename - the file containing audio datajava.io.IOException - if exception occurredpublic static void writeRawFile(AudioData audio, java.lang.String filename) throws java.io.IOException
audio - datafilename - filename to write tojava.io.IOException - if IO went wrong