Class WavInputStream
java.lang.Object
de.pottgames.tuningfork.decoder.WavInputStream
- All Implemented Interfaces:
AudioStream, Closeable, AutoCloseable
An
AudioStream implementation to read wav files.-
Constructor Summary
ConstructorsConstructorDescriptionWavInputStream(com.badlogic.gdx.files.FileHandle file) Initializes aWavInputStreamfrom aFileHandle.WavInputStream(com.badlogic.gdx.files.FileHandle file, boolean forStreaming) Initializes aWavInputStreamfrom aFileHandle.WavInputStream(InputStream stream) Initializes aWavInputStreamfrom anInputStream.WavInputStream(InputStream stream, boolean forStreaming) Initializes aWavInputStreamfrom anInputStream. -
Method Summary
Modifier and TypeMethodDescriptionlongvoidclose()intReturns the number of bits per sample, also known as the sample depth.intReturns the block alignment in sample frames.intReturns the block size in bytes.intReturns the number of audio channels.floatReturns the duration in seconds or -1 if this information is not available.Returns the output data format of this AudioStream.intReturns the sample rate.booleanisClosed()Returns true if the AudioStream is closed.intread(byte[] bytes) Reads bytes from the stream until the given array is full or the stream ends.reset()Resets the audio stream as if it was re-opened.long
-
Constructor Details
-
WavInputStream
public WavInputStream(com.badlogic.gdx.files.FileHandle file) Initializes aWavInputStreamfrom aFileHandle.- Parameters:
file- the file handle
-
WavInputStream
public WavInputStream(com.badlogic.gdx.files.FileHandle file, boolean forStreaming) Initializes aWavInputStreamfrom aFileHandle.- Parameters:
file- the file handleforStreaming- true if this will be used for streaming
-
WavInputStream
Initializes aWavInputStreamfrom anInputStream. This stream does not support the reset function. UseWavInputStream(FileHandle)instead to get the full functionality.- Parameters:
stream- the input stream
-
WavInputStream
Initializes aWavInputStreamfrom anInputStream. This stream does not support the reset function. UseWavInputStream(FileHandle)instead to get the full functionality.- Parameters:
stream- the input streamforStreaming- true if this will be used for streaming
-
-
Method Details
-
read
public int read(byte[] bytes) Description copied from interface:AudioStreamReads bytes from the stream until the given array is full or the stream ends. Returns the number of bytes that were actually read.- Specified by:
readin interfaceAudioStream- Parameters:
bytes- the byte array to store the bytes in- Returns:
- number of bytes read or -1 if there are no bytes left
-
getDuration
public float getDuration()Description copied from interface:AudioStreamReturns the duration in seconds or -1 if this information is not available.- Specified by:
getDurationin interfaceAudioStream- Returns:
- duration in seconds or -1 if the information is not available
-
reset
Description copied from interface:AudioStreamResets the audio stream as if it was re-opened. Implementations are free to close themselves and provide a new AudioStream. The AudioStream returned by this function will be used, regardless of whether it is a new instance or the old one.- Specified by:
resetin interfaceAudioStream- Returns:
- an AudioStream
-
totalSamplesPerChannel
public long totalSamplesPerChannel() -
getChannels
public int getChannels()Description copied from interface:AudioStreamReturns the number of audio channels.- Specified by:
getChannelsin interfaceAudioStream- Returns:
- number of channels
-
getSampleRate
public int getSampleRate()Description copied from interface:AudioStreamReturns the sample rate.- Specified by:
getSampleRatein interfaceAudioStream- Returns:
- the sample rate
-
getBitsPerSample
public int getBitsPerSample()Description copied from interface:AudioStreamReturns the number of bits per sample, also known as the sample depth.- Specified by:
getBitsPerSamplein interfaceAudioStream- Returns:
- the number of bits per sample
-
getPcmDataType
Description copied from interface:AudioStreamReturns the output data format of this AudioStream.- Specified by:
getPcmDataTypein interfaceAudioStream- Returns:
- the pcm data type
-
getBlockAlign
public int getBlockAlign()Description copied from interface:AudioStreamReturns the block alignment in sample frames. This only applies for data that is organized in blocks like ADPCM, all other implementations should return -1.- Specified by:
getBlockAlignin interfaceAudioStream- Returns:
- the block size in sample frames
-
getBlockSize
public int getBlockSize()Description copied from interface:AudioStreamReturns the block size in bytes. This only applies for data that is organized in blocks like ADPCM, all other implementations should return -1.- Specified by:
getBlockSizein interfaceAudioStream- Returns:
- block size in bytes
-
bytesRemaining
public long bytesRemaining() -
isClosed
public boolean isClosed()Description copied from interface:AudioStreamReturns true if the AudioStream is closed.- Specified by:
isClosedin interfaceAudioStream- Returns:
- true if closed, false if open
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-