public class CodecIBXM
extends java.lang.Object
implements paulscode.sound.ICodec
Modifier and Type | Field and Description |
---|---|
private boolean |
endOfStream
True if there is no more data to read in.
|
private static boolean |
GET
Used to return a current value from one of the synchronized
boolean-interface methods.
|
private IBXM |
ibxm
IBXM decoder.
|
private boolean |
initialized
True if the stream has finished initializing.
|
private paulscode.sound.SoundSystemLogger |
logger
Processes status messages, warnings, and error messages.
|
private Module |
module
Module instance to be played.
|
private javax.sound.sampled.AudioFormat |
myAudioFormat
Format the converted audio will be in.
|
private int |
playPosition
Audio read position (in frames).
|
private boolean |
reverseBytes
True if the using library requires data read by this codec to be
reverse-ordered before returning it from methods read() and readAll().
|
private static boolean |
SET
Used to set the value in one of the synchronized boolean-interface methods.
|
private int |
songDuration
Duration of the audio (in frames).
|
private static boolean |
XXX
Used when a parameter for one of the synchronized boolean-interface methods
is not aplicable.
|
Constructor and Description |
---|
CodecIBXM()
Constructor: Grabs a handle to the logger.
|
Modifier and Type | Method and Description |
---|---|
private static byte[] |
appendByteArrays(byte[] arrayOne,
byte[] arrayTwo,
int length)
Creates a new array with the second array appended to the end of the first
array.
|
void |
cleanup()
Closes the audio stream and remove references to all instantiated objects.
|
private static byte[] |
convertAudioBytes(byte[] audio_bytes,
boolean two_bytes_data)
Converts sound bytes to little-endian format.
|
boolean |
endOfStream()
Returns false if there is still more data available to be read in.
|
private boolean |
endOfStream(boolean action,
boolean value)
Internal method for synchronizing access to the boolean 'endOfStream'.
|
private void |
errorMessage(java.lang.String message)
Prints an error message.
|
javax.sound.sampled.AudioFormat |
getAudioFormat()
Returns the audio format of the data being returned by the read() and
readAll() methods.
|
boolean |
initialize(java.net.URL url)
Prepares an audio stream to read from.
|
boolean |
initialized()
Returns false if the stream is busy initializing.
|
private boolean |
initialized(boolean action,
boolean value)
Internal method for synchronizing access to the boolean 'initialized'.
|
private static Module |
loadModule(java.io.InputStream input)
Decodes the data in the specified InputStream into an instance of
ibxm.Module.
|
private void |
printStackTrace(java.lang.Exception e)
Prints an exception's error message followed by the stack trace.
|
paulscode.sound.SoundBuffer |
read()
Reads in one stream buffer worth of audio data.
|
paulscode.sound.SoundBuffer |
readAll()
Reads in all the audio data from the stream (up to the default
"maximum file size".
|
void |
reverseByteOrder(boolean b)
Tells this codec when it will need to reverse the byte order of
the data before returning it in the read() and readAll() methods.
|
static void |
reverseBytes(byte[] buffer)
Reverse-orders all bytes contained in the specified array.
|
static void |
reverseBytes(byte[] buffer,
int offset,
int size)
Reverse-orders the specified range of bytes contained in the specified array.
|
private void |
setModule(Module m)
Sets the Module instance to be played.
|
private static byte[] |
trimArray(byte[] array,
int maxLength)
Trims down the size of the array if it is larger than the specified
maximum length.
|
private static final boolean GET
private static final boolean SET
private static final boolean XXX
private boolean endOfStream
private boolean initialized
private javax.sound.sampled.AudioFormat myAudioFormat
private boolean reverseBytes
private IBXM ibxm
private Module module
private int songDuration
private int playPosition
private paulscode.sound.SoundSystemLogger logger
public void reverseByteOrder(boolean b)
reverseByteOrder
in interface paulscode.sound.ICodec
b
- True if the calling audio library requires byte-reversal.public boolean initialize(java.net.URL url)
initialize
in interface paulscode.sound.ICodec
url
- URL to an audio file to stream from.public boolean initialized()
initialized
in interface paulscode.sound.ICodec
public paulscode.sound.SoundBuffer read()
SoundSystemConfig
for more
information about accessing and changing default settings.read
in interface paulscode.sound.ICodec
public paulscode.sound.SoundBuffer readAll()
SoundSystemConfig
for more
information about accessing and changing default settings.readAll
in interface paulscode.sound.ICodec
public boolean endOfStream()
endOfStream
in interface paulscode.sound.ICodec
public void cleanup()
cleanup
in interface paulscode.sound.ICodec
public javax.sound.sampled.AudioFormat getAudioFormat()
getAudioFormat
in interface paulscode.sound.ICodec
private static Module loadModule(java.io.InputStream input) throws java.lang.IllegalArgumentException, java.io.IOException
input
- an InputStream containing the module file to be decoded.java.lang.IllegalArgumentException
- if the data is not recognised as a module file.java.io.IOException
private void setModule(Module m)
private boolean initialized(boolean action, boolean value)
action
- GET or SET.value
- New value if action == SET, or XXX if action == GET.private boolean endOfStream(boolean action, boolean value)
action
- GET or SET.value
- New value if action == SET, or XXX if action == GET.private static byte[] trimArray(byte[] array, int maxLength)
array
- Array containing audio data.maxLength
- Maximum size this array may be.public static void reverseBytes(byte[] buffer)
buffer
- Array containing audio data.public static void reverseBytes(byte[] buffer, int offset, int size)
buffer
- Array containing audio data.offset
- Array index to begin.size
- number of bytes to reverse-order.private static byte[] convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data)
audio_bytes
- The original wave datatwo_bytes_data
- For stereo sounds.private static byte[] appendByteArrays(byte[] arrayOne, byte[] arrayTwo, int length)
arrayOne
- The first array.arrayTwo
- The second array.length
- How many bytes to append from the second array.private void errorMessage(java.lang.String message)
message
- Message to print.private void printStackTrace(java.lang.Exception e)
e
- Exception containing the information to print.