Sharkysoft home

lava.riff.wave
Class PcmWaveStreamReader

java.lang.Object
  |
  +--lava.riff.wave.WaveStreamReader
        |
        +--lava.riff.wave.PcmWaveStreamReader

public class PcmWaveStreamReader
extends WaveStreamReader

Reads standard Microsoft PCM .wav file.

Details: This class parses a standard, uncompressed .wav file whose sample data is encoded in the Microsoft Pulse Code Modulation (PCM) format. This is the format most commonly used for .wav files.

Author:
Sharky

Fields inherited from class lava.riff.wave.WaveStreamReader
fmt, riff
 
Constructor Summary
PcmWaveStreamReader(IRiffInput rais)
          Sets input source.
 
Method Summary
 long countSamples()
          Returns number of samples.
 void freeSamples(long when, int duration)
          Releases samples from buffer.
 int getBitsPerChannelSample()
          Returns number of bits per channel sample.
 int getChannelSampleSize()
          Returns size of individual channel sample.
 java.lang.Object readSamples(long when, java.lang.Object dest, int dest_from, int duration)
          Reads and decodes samples.
 
Methods inherited from class lava.riff.wave.WaveStreamReader
close, countChannels, findChunk, getAdtlChunkReader, getChunkReader, getCuePoints, getFormatChunk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PcmWaveStreamReader

public PcmWaveStreamReader(IRiffInput rais)
                    throws java.io.IOException
Sets input source.

Details: This constructor sets the .wav file input source (rais) and parses the format chunk.

Parameters:
rais - the input source
Throws:
lava.io.FileFormatException - if the PCM .wav stream is invalid
java.io.IOException - if an I/O error occurs
Method Detail

getBitsPerChannelSample

public int getBitsPerChannelSample()
Description copied from class: WaveStreamReader
Returns number of bits per channel sample.

Details: This method returns the number of bits per sample per channel.

Overrides:
getBitsPerChannelSample in class WaveStreamReader
Tags copied from class: WaveStreamReader
Returns:
number of bits per sample channel sample.

countSamples

public long countSamples()
                  throws java.io.IOException
Description copied from class: WaveStreamReader
Returns number of samples.

Details: This method returns the number of samples contained in this wave stream. This value devided by the sample rate is the duration of the sound.

Overrides:
countSamples in class WaveStreamReader
Tags copied from class: WaveStreamReader
Returns:
number of samples

readSamples

public java.lang.Object readSamples(long when,
                                    java.lang.Object dest,
                                    int dest_from,
                                    int duration)
                             throws java.io.IOException
Description copied from class: WaveStreamReader
Reads and decodes samples.

Details: This method reads sample data from the source file and returns the samples in a sample array. Exactly amount samples are read, beginning with the whenth sample in the sample stream (where 0 is the index of the first sample). The samples are copied into the given array (dest). If that array is not the correct type for the sample resolution of this wave stream, the samples are automatically converted to the resolution required by the array. (See the package header for more details.)

If dest is null, an array of the most natural type for this stream is automatically created, and its length is set just large enough to accomodate the request. The new sample array is then treated exactly as if it had been provided as the original dest parameter.

The first sample written into dest is written into dest [dest_from]. Exactly duration * wChannels values are decoded and written into the array, where wChannels is the number of channels as set in the format chunk.

Overrides:
readSamples in class WaveStreamReader
Tags copied from class: WaveStreamReader
Parameters:
when - sample position
dest - destination array
dest_from - starting index in destination array
duration - number of samples to read
Returns:
the samples
Throws:
java.io.IOException - if an I/O error occurs

freeSamples

public void freeSamples(long when,
                        int duration)
                 throws java.io.IOException
Description copied from class: WaveStreamReader
Releases samples from buffer.

Details: This method informs this wave stream reader that the client will no longer requires access to the given range of samples. Calling this method allows this implementation to send buffering hints to the underlying .wav file input source, which may be buffering the data stream.

Overrides:
freeSamples in class WaveStreamReader
Tags copied from class: WaveStreamReader
Parameters:
when - beginning sample index
duration - number of samples to release
Throws:
if - an I/O error occurs
See Also:
IRiffInput.free(long, long)

getChannelSampleSize

public int getChannelSampleSize()
                         throws java.io.IOException
Description copied from class: WaveStreamReader
Returns size of individual channel sample.

Details: getChannelSampleSize returns the size of the data type used by readSamples to store a single channel sample. The value returned by this method indicates the type of array most naturally preferred by this instance in calls to readSamples.

channel sample size value returned array type
1-8 bits 1 byte
9-16 bits 2 short
17-32 bits 4 int
Overrides:
getChannelSampleSize in class WaveStreamReader
Tags copied from class: WaveStreamReader
Returns:
size of array type

Sharkysoft home