Converts a 16-bit linear PCM stream from and to 8-bit u-law. More...


Public Member Functions | |
| AudioCodecUlaw (AudioInterfacePCM audio) | |
| Constructs A-Law CODEC above existing PCM audio interface. | |
| int | getVoicePduSubclass () |
| Gets the VoicePDU subclass attribute of the AbstractAudio object. | |
| int | getSampleSize () |
| Returns the minimum sample size for use in creating buffers etc. | |
| void | convertToPCM (byte[] in, byte[] out) |
| Encodes data to PCM, i.e. | |
| void | convertFromPCM (byte[] in, byte[] out) |
| Decodes data from PCM, i.e. | |
Static Public Member Functions | |
| static byte | linear2ulaw (int sample) |
| Converts a linear signed 16bit sample to a uLaw byte. | |
| static short | ulaw2linear (byte ulawbyte) |
| Converts an 8-bit u-law value to 16-bit linear PCM. | |
Private Attributes | |
| int | sampleSize |
Static Private Attributes | |
| static final boolean | ZEROTRAP = true |
| static final short | BIAS = 0x84 |
| static final int | CLIP = 32635 |
| static final int | exp_lut1 [] |
| static short[] | ulaw2lin_table |
Converts a 16-bit linear PCM stream from and to 8-bit u-law.
Definition at line 11 of file AudioCodecUlaw.java.
| audio.AudioCodecUlaw.AudioCodecUlaw | ( | AudioInterfacePCM | audio ) |
Constructs A-Law CODEC above existing PCM audio interface.
Definition at line 18 of file AudioCodecUlaw.java.
References audio.AbstractCODEC.audio, audio.AudioInterfacePCM.getSampleSize(), audio.AbstractCODEC.inputPcmBuf, audio.AbstractCODEC.outputPcmBuf, and audio.AudioCodecUlaw.sampleSize.
{
this.audio = audio;
this.sampleSize = this.audio.getSampleSize ();
this.outputPcmBuf = new byte[ this.sampleSize ];
this.inputPcmBuf = new byte[ this.sampleSize ];
}
| void audio.AudioCodecUlaw.convertFromPCM | ( | byte[] | in, |
| byte[] | out | ||
| ) | [virtual] |
Decodes data from PCM, i.e.
converts samples from u-Law to PCM format.
Implements audio.AbstractCODEC.
Definition at line 56 of file AudioCodecUlaw.java.
References utils.OctetBuffer.getShort(), audio.AudioCodecUlaw.linear2ulaw(), and utils.OctetBuffer.wrap().
{
OctetBuffer bb = OctetBuffer.wrap(in);
for ( int i = 0; i < out.length; ++i )
{
out[i] = linear2ulaw( bb.getShort () );
}
}
| void audio.AudioCodecUlaw.convertToPCM | ( | byte[] | in, |
| byte[] | out | ||
| ) | [virtual] |
Encodes data to PCM, i.e.
converts samples from u-Law to CODEC format.
Implements audio.AbstractCODEC.
Definition at line 45 of file AudioCodecUlaw.java.
References utils.OctetBuffer.putShort(), audio.AudioCodecUlaw.ulaw2linear(), and utils.OctetBuffer.wrap().
{
OctetBuffer bb = OctetBuffer.wrap(out);
for (int i = 0; i < in.length; i++) {
bb.putShort( ulaw2linear( in[i] ) );
}
}
| int audio.AudioCodecUlaw.getSampleSize | ( | ) | [virtual] |
Returns the minimum sample size for use in creating buffers etc.
Implements audio.AudioInterface.
Definition at line 37 of file AudioCodecUlaw.java.
{
return 160;
}
| int audio.AudioCodecUlaw.getVoicePduSubclass | ( | ) | [virtual] |
Gets the VoicePDU subclass attribute of the AbstractAudio object.
Implements audio.AbstractCODEC.
Definition at line 29 of file AudioCodecUlaw.java.
{
return protocol.VoicePDU.ULAW;
}
| static byte audio.AudioCodecUlaw.linear2ulaw | ( | int | sample ) | [static] |
Converts a linear signed 16bit sample to a uLaw byte.
Definition at line 109 of file AudioCodecUlaw.java.
References audio.AudioCodecUlaw.BIAS, audio.AudioCodecUlaw.CLIP, audio.AudioCodecUlaw.exp_lut1, and audio.AudioCodecUlaw.ZEROTRAP.
Referenced by audio.AudioCodecUlaw.convertFromPCM().
{
int sign, exponent, mantissa, ulawbyte;
if ( sample > 32767 ) {
sample = 32767;
}
else if ( sample < -32768 ) {
sample = -32768;
/* Get the sample into sign-magnitude. */
}
sign = (sample >> 8) & 0x80; /* set aside the sign */
if ( sign != 0 ) {
sample = -sample; /* get magnitude */
}
if ( sample > CLIP ) {
sample = CLIP; /* clip the magnitude */
/* Convert from 16 bit linear to ulaw. */
}
sample = sample + BIAS;
exponent = exp_lut1[ (sample >> 7) & 0xFF];
mantissa = (sample >> (exponent + 3)) & 0x0F;
ulawbyte = ~ (sign | (exponent << 4) | mantissa);
if ( ZEROTRAP ) {
if ( ulawbyte == 0 ) {
ulawbyte = 0x02; /* optional CCITT trap */
}
}
return (byte) ulawbyte;
}
| static short audio.AudioCodecUlaw.ulaw2linear | ( | byte | ulawbyte ) | [static] |
Converts an 8-bit u-law value to 16-bit linear PCM.
Definition at line 186 of file AudioCodecUlaw.java.
References audio.AudioCodecUlaw.ulaw2lin_table.
Referenced by audio.AudioCodecUlaw.convertToPCM().
{
return ulaw2lin_table[ ulawbyte & 0xFF ];
}
final short audio.AudioCodecUlaw.BIAS = 0x84 [static, private] |
Definition at line 83 of file AudioCodecUlaw.java.
Referenced by audio.AudioCodecUlaw.linear2ulaw().
final int audio.AudioCodecUlaw.CLIP = 32635 [static, private] |
Definition at line 84 of file AudioCodecUlaw.java.
Referenced by audio.AudioCodecUlaw.linear2ulaw().
final int audio.AudioCodecUlaw.exp_lut1[] [static, private] |
{
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
}
Definition at line 86 of file AudioCodecUlaw.java.
Referenced by audio.AudioCodecUlaw.linear2ulaw().
int audio.AudioCodecUlaw.sampleSize [private] |
Definition at line 13 of file AudioCodecUlaw.java.
Referenced by audio.AudioCodecUlaw.AudioCodecUlaw().
short [] audio.AudioCodecUlaw.ulaw2lin_table [static, private] |
Definition at line 147 of file AudioCodecUlaw.java.
Referenced by audio.AudioCodecUlaw.ulaw2linear().
final boolean audio.AudioCodecUlaw.ZEROTRAP = true [static, private] |
Definition at line 82 of file AudioCodecUlaw.java.
Referenced by audio.AudioCodecUlaw.linear2ulaw().
1.7.2