com.groovemanager.sampled.providers
Class WaveChunk

java.lang.Object
  extended by com.groovemanager.sampled.providers.WaveChunk
Direct Known Subclasses:
RLNDChunk, SliceChunk

public class WaveChunk
extends java.lang.Object

Wave files can contain additional information besides the audio data organized in chunks. This class provides support for such a chunk. A chunk is organized in the following way:
- The first 4 bytes contain an ASCII-String identifying the chunk type, called chunk ID.
- The next 4 bytes contain an Integer describing the length of the following data in bytes.
- The format of the following data is specific to each chunk type

Author:
Manu Robledo

Field Summary
protected  java.nio.ByteBuffer chunkData
          The chunk data without the chunk ID and the length
protected  java.lang.String chunkname
          The Chunk ID (length 4)
 
Constructor Summary
WaveChunk(byte[] wholeChunk)
          Construct a new WaveChunk
WaveChunk(java.lang.String name, byte[] data)
          Construct a new WaveChunk
WaveChunk(java.lang.String name, int length)
          Construct a new empty WaveChunk
 
Method Summary
 byte[] getData()
          Get the chunk data not including the chunk ID and the chunk length
 int getLength()
          Get the chunk length
 java.lang.String getName()
          Get the Chunk ID
 int writeToOut(java.io.OutputStream out)
          Write this chunk to an OutputStream
 int writeToOut(java.io.RandomAccessFile out)
          Write this chunk to a RandomAccessFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chunkData

protected java.nio.ByteBuffer chunkData
The chunk data without the chunk ID and the length


chunkname

protected java.lang.String chunkname
The Chunk ID (length 4)

Constructor Detail

WaveChunk

public WaveChunk(byte[] wholeChunk)
Construct a new WaveChunk

Parameters:
wholeChunk - The chunk data including the chunk ID (first 4 bytes) and the chunk length (next 4 bytes)

WaveChunk

public WaveChunk(java.lang.String name,
                 byte[] data)
Construct a new WaveChunk

Parameters:
name - The chunk ID (will be filled up or shortened to length 4)
data - The chunk data without the chunk ID and the length

WaveChunk

public WaveChunk(java.lang.String name,
                 int length)
Construct a new empty WaveChunk

Parameters:
name - The chunk ID (will be filled up or shortened to length 4)
length - The length of the chunk data
Method Detail

getData

public byte[] getData()
Get the chunk data not including the chunk ID and the chunk length

Returns:
The chunk data

getLength

public int getLength()
Get the chunk length

Returns:
The chunk length in bytes, not including the chunk ID and the length itself (each 4 bytes)

getName

public java.lang.String getName()
Get the Chunk ID

Returns:
the Chunk ID

writeToOut

public int writeToOut(java.io.OutputStream out)
               throws java.io.IOException
Write this chunk to an OutputStream

Parameters:
out - The OutputStream to write to
Returns:
The number of bytes actually written (8 + chunkdata length)
Throws:
java.io.IOException - IF an I/O Error occured during the write operation

writeToOut

public int writeToOut(java.io.RandomAccessFile out)
               throws java.io.IOException
Write this chunk to a RandomAccessFile

Parameters:
out - The OutputStream to write to
Returns:
The number of bytes actually written (8 + chunkdata length)
Throws:
java.io.IOException - IF an I/O Error occured during the write operation