game.sound
Class CSoundFrameData

java.lang.Object
  extended by game.sound.CSoundFrameData

public class CSoundFrameData
extends java.lang.Object

Encapsulates frame data storage in a byte array. Supports mono/stereo, 8/16 bits, 22050/44100 Hz, little/big endian signed sound signals. Note: CSoundFrameData is not synchronized.

Author:
seb

Field Summary
private static int BYTES_PER_FRAME
           
private static int BYTES_PER_SAMPLE
           
private static int HIGH_BYTE
           
private static boolean IS_BIG_ENDIAN
           
private static boolean IS_SIGNED
           
private static int LOW_BYTE
           
private  byte[] m_aFrameData
           
private  int m_index
           
private static int MAX_AMPLITUDE
           
private static int NB_CHANNELS
           
 
Constructor Summary
CSoundFrameData(int nbFrames)
          Constructor, inits data array and checks sound player is signed.
 
Method Summary
private  void checkSampleValue(int iSample)
          Do a bit of bound checking if assertions are enabled.
 byte[] getByteArray()
          Get the stored data.
 void putFrame(int iSample)
          Inputs a mono sound frame.
 void putFrame(int iSample, float fPanning)
          Inputs a panned stereo (if applicable) sound frame.
 void putFrame(int iLeftSample, int iRightSample)
          Inputs a stereo (if applicable) sound frame.
private  void storeMonoFrame(int iSample)
          Stores a mono frame in the byte array.
private  void storeStereoFrame(int iLeftSample, int iRightSample)
          Stores a stereo frame in the byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_SIGNED

private static final boolean IS_SIGNED
See Also:
Constant Field Values

IS_BIG_ENDIAN

private static final boolean IS_BIG_ENDIAN
See Also:
Constant Field Values

BYTES_PER_FRAME

private static final int BYTES_PER_FRAME
See Also:
Constant Field Values

MAX_AMPLITUDE

private static final int MAX_AMPLITUDE

BYTES_PER_SAMPLE

private static final int BYTES_PER_SAMPLE
See Also:
Constant Field Values

NB_CHANNELS

private static final int NB_CHANNELS
See Also:
Constant Field Values

LOW_BYTE

private static final int LOW_BYTE
See Also:
Constant Field Values

HIGH_BYTE

private static final int HIGH_BYTE
See Also:
Constant Field Values

m_aFrameData

private byte[] m_aFrameData

m_index

private int m_index
Constructor Detail

CSoundFrameData

public CSoundFrameData(int nbFrames)
Constructor, inits data array and checks sound player is signed.

Parameters:
nbFrames - : exact number of frames that WILL be converted in bytes and stored.
Method Detail

putFrame

public final void putFrame(int iLeftSample,
                           int iRightSample)
Inputs a stereo (if applicable) sound frame. If the player is mono, iLeftSample and iRightSample are blended. Property : if left and right samples are within allowed bounds, blended sample value will be allowed too.

Parameters:
iLeftSample - : the left sample value to be stored.
iRightSample - : the right sample value to be stored.

putFrame

public final void putFrame(int iSample,
                           float fPanning)
Inputs a panned stereo (if applicable) sound frame. If the player is mono, panning value is discarded (iSample is stored directly). Property : if iSample is within allowed bounds, panned samples values will be allowed too.

Parameters:
iSample - : the sample value to be panned and stored.
fPanning - : value of 0 means left speaker only, 1 means right speaker only.

putFrame

public final void putFrame(int iSample)
Inputs a mono sound frame. If the player is stereo, the sample is centered.

Parameters:
iSample - : the mono sample value to be stored.

getByteArray

public final byte[] getByteArray()
Get the stored data.

Returns:
the stored frames as a byte array.

checkSampleValue

private final void checkSampleValue(int iSample)
Do a bit of bound checking if assertions are enabled.

Parameters:
iSample - : the sample value to bound check.

storeMonoFrame

private final void storeMonoFrame(int iSample)
Stores a mono frame in the byte array.

Parameters:
iSample - : the sample value to convert in byte(s) and store.

storeStereoFrame

private final void storeStereoFrame(int iLeftSample,
                                    int iRightSample)
Stores a stereo frame in the byte array.

Parameters:
iLeftSample - : the left sample value to convert in byte(s) and store.
iRightSample - : the right sample value to convert in byte(s) and store.