Package ca.phon.audio
Class AudioIO
java.lang.Object
ca.phon.audio.AudioIO
Methods for reading and writing uncompressed audio sample data.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic AudioFileInfo
checkHeaders
(File file) Check headers of given file and return an filled AudioFileInfo object.static double[]
decodeFrame
(byte[] buffer, int offset, AudioFileEncoding encoding, int numberOfChannels) static void
decodeFrame
(byte[] buffer, int offset, AudioFileEncoding encoding, int numberOfChannels, double[] samples, int sampleOffset) Decode a single frame of channel interleaved audio data frombuffer
atoffset
usingencoding
.static byte[]
encodeFrame
(double[] samples, AudioFileEncoding encoding) static boolean
encodeFrame
(double[] samples, AudioFileEncoding encoding, byte[] buffer, int offset) Encode frame using encoding into buffer at offsetstatic AudioFile
openAudioFile
(File file) static int
writeSamples
(Sampled samples, int firstSample, int numSamples, AudioFileEncoding encoding, byte[] buffer, int offset) Write numSamples from Sampled starting at firstSample into the buffer starting at offsetstatic int
writeSamples
(Sampled samples, int firstSample, int numSamples, AudioFileEncoding encoding, OutputStream os) static void
writeSamplesToFile
(Sampled samples, int firstSample, int numSamples, AudioFileEncoding encoding, File file) static void
writeSamplesToFile
(Sampled samples, int firstSample, int numSamples, AudioFileType fileType, AudioFileEncoding encoding, File file)
-
Constructor Details
-
AudioIO
public AudioIO()
-
-
Method Details
-
openAudioFile
public static AudioFile openAudioFile(File file) throws IOException, UnsupportedFormatException, InvalidHeaderException -
checkHeaders
public static AudioFileInfo checkHeaders(File file) throws IOException, InvalidHeaderException, UnsupportedFormatException Check headers of given file and return an filled AudioFileInfo object.- Parameters:
file
-- Returns:
- audio file information
- Throws:
IOException
InvalidHeaderException
UnsupportedFormatException
-
writeSamplesToFile
public static void writeSamplesToFile(Sampled samples, int firstSample, int numSamples, AudioFileEncoding encoding, File file) throws IOException, AudioIOException - Throws:
IOException
AudioIOException
-
writeSamplesToFile
public static void writeSamplesToFile(Sampled samples, int firstSample, int numSamples, AudioFileType fileType, AudioFileEncoding encoding, File file) throws IOException, AudioIOException - Throws:
IOException
AudioIOException
-
writeSamples
public static int writeSamples(Sampled samples, int firstSample, int numSamples, AudioFileEncoding encoding, OutputStream os) throws IOException, AudioIOException - Throws:
IOException
AudioIOException
-
writeSamples
public static int writeSamples(Sampled samples, int firstSample, int numSamples, AudioFileEncoding encoding, byte[] buffer, int offset) throws AudioIOException Write numSamples from Sampled starting at firstSample into the buffer starting at offset- Parameters:
samples
-numSamples
-encoding
-buffer
-offset
-- Returns:
- number of samples written
- Throws:
AudioIOException
-
decodeFrame
public static double[] decodeFrame(byte[] buffer, int offset, AudioFileEncoding encoding, int numberOfChannels) throws BufferUnderflowException, UnsupportedFormatException -
decodeFrame
public static void decodeFrame(byte[] buffer, int offset, AudioFileEncoding encoding, int numberOfChannels, double[] samples, int sampleOffset) throws BufferUnderflowException, UnsupportedFormatException Decode a single frame of channel interleaved audio data frombuffer
atoffset
usingencoding
. Samples will be written intosamples
starting atsampleOffset
.- Parameters:
buffer
-offset
-encoding
-numberOfChannels
-samples
-sampleOffset
-- Throws:
BufferUnderflowException
- ifbuffer
orsamples
is not large enoughUnsupportedFormatException
- if unable to decode samples which usingencoding
-
encodeFrame
public static byte[] encodeFrame(double[] samples, AudioFileEncoding encoding) throws UnsupportedFormatException, BufferUnderflowException -
encodeFrame
public static boolean encodeFrame(double[] samples, AudioFileEncoding encoding, byte[] buffer, int offset) throws UnsupportedFormatException, BufferUnderflowException Encode frame using encoding into buffer at offset- Parameters:
samples
- array of samples, one per channelencoding
-buffer
-offset
-- Returns:
true
if the sample was clipped,false
otherwise- Throws:
UnsupportedFormatException
- if encoding is not supportedBufferUnderflowException
- if the buffer does not have enough space
-