Sharkysoft home

lava.riff.wave
Class WaveFormatChunk

java.lang.Object
  |
  +--lava.riff.wave.WaveFormatChunk
Direct Known Subclasses:
PcmWaveFormatChunk

public abstract class WaveFormatChunk
extends java.lang.Object
implements java.lang.Cloneable

Base format chunk.

Details: A WaveFormatChunk represents the mandatory portion of a wave format ('fmt') chunk in a RIFF-WAVE file. All RIFF-WAVE format chunks begin with the fields represented in this class, and then continue with their own, format-specific fields. The mandatory fields are (using "windows.h" notation):

struct
{
	WORD  wFormatTag;       // Format category
	WORD  wChannels;        // Number of channels
	DWORD dwSamplesPerSec;  // Sampling rate
	DWORD dwAvgBytesPerSec; // For buffer estimation
	WORD  wBlockAlign;      // Data block size
}


Field Summary
 int dwAvgBytesPerSec
          Average bytes per second.
 int dwSamplesPerSec
          Full sample rate.
 short wBlockAlign
          Block alignment.
 short wChannels
          Number of channels.
 short wFormatTag
          Indicates encoding format.
 
Constructor Summary
protected WaveFormatChunk()
          Default constructor.
protected WaveFormatChunk(RiffChunkReader rcr)
          Initializes from open chunk.
 
Method Summary
 java.lang.Object clone()
          Replicates instance.
abstract  int getSampleSize()
          Computes bytes per sample.
 byte[] toBytes()
          Serializes to bytes.
 java.lang.String toString()
          Serializes to string.
protected  void validateFields()
          Validates members.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

wFormatTag

public short wFormatTag
Indicates encoding format.

Details: This member is a magic value that indicates the encoding format use for the wave file. Some possible values include:

WAVE_FORMAT_PCM 0x0001 Microsoft Pulse Code Modulation (PCM)
IBM_FORMAT_MULAW 0x0101 IBM mu-law format
IBM_FORMAT_ALAW 0x0102 IBM a-law format
IBM_FORMAT_ADPCM 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation format

The value of this field also determines the presence of additional fields following the wBlockAlign field.


wChannels

public short wChannels
Number of channels.

Details: This member indicates the number of channels represented in the waveform data, i.e., 1 for mono, 2 for stereo, etc.


dwSamplesPerSec

public int dwSamplesPerSec
Full sample rate.

Details: This member indicates the number of samples per second, or the number of times per second each individual channel is sampled.


dwAvgBytesPerSec

public int dwAvgBytesPerSec
Average bytes per second.

Details: This member indicates the average number of bytes per second at which the waveform data will need to be processed. Playback and recording software can use this estimate when setting up buffers.


wBlockAlign

public short wBlockAlign
Block alignment.

Details: This member indicates the block alignment (in bytes) of the waveform data. Playback software will need to process data blocks of this size. This value can be used to ensure buffer alignment.

Constructor Detail

WaveFormatChunk

protected WaveFormatChunk()
Default constructor.

Details: This constructor initializes all members to 0.


WaveFormatChunk

protected WaveFormatChunk(RiffChunkReader rcr)
                   throws java.io.IOException
Initializes from open chunk.

Details: This constructor initializes the members of this WaveFormatChunk with values read from the given RIFF chunk. It is convenient to use this constructor when parsing wave format chunks.

Parameters:
the - RIFF chunk to process as a WaveFormatChunk
Method Detail

validateFields

protected void validateFields()
                       throws lava.io.FileFormatException
Validates members.

Details: This method verifies that the values of this format chunk's fields actually make sense. If they do not, a FileFormatException is thrown.

Throws:
if - the field are not valid

getSampleSize

public abstract int getSampleSize()
Computes bytes per sample.

Details: This method returns the number of bytes per sample. :

Details: getSampleSize returns the number of bytes required to contain a single, full sample. The value is determined by considering the number of bits per channel sample and the number of channels, as follows:

bits per channel sample mono stereo
1-8 1 byte 2 bytes
9-16 2 byte 4 bytes
17-24 3 byte 6 bytes
25-32 4 byte 8 bytes

These values are calculated without allowing bits from different channel samples to be packed into the same byte.

Returns:
number of bytes in full sample

toBytes

public byte[] toBytes()
Serializes to bytes.

Details: toBytes serializes this chunk into a string of bytes, as it would appear in a .wav file.

Returns:
this chunk in byte array form

toString

public java.lang.String toString()
Serializes to string.

Details: toString produces a string representation of this chunk. This representation is useful for debugging.

Overrides:
toString in class java.lang.Object
Returns:
string representation

clone

public final java.lang.Object clone()
Replicates instance.

Details: This method returns a perfect replica of this instance.

Overrides:
clone in class java.lang.Object
Returns:
replica

Sharkysoft home