8 static WORD
decode_alaw (UBYTE a_val
);
9 static WORD
decode_mulaw(UBYTE u_val
);
11 DEC_SETUPPROTO(SetupALaw
) {
12 struct WaveFormatEx
* fmt
;
14 if (fmt
->extraSize
!= 0)
16 if (fmt
->bitsPerSample
!= 8)
17 return ERROR_NOT_IMPLEMENTED
;
18 data
->blockFrames
= 1;
22 DECODERPROTO(DecodeALaw
) {
24 for (frame
=0;frame
<numFrames
;frame
++) {
25 for (chan
=0;chan
<fmt
->numChannels
;chan
++) {
26 *Dst
[chan
]++ = decode_alaw(*Src
++) >> 8;
32 DECODERPROTO(DecodeMuLaw
) {
34 for (frame
=0;frame
<numFrames
;frame
++) {
35 for (chan
=0;chan
<fmt
->numChannels
;chan
++) {
36 *Dst
[chan
]++ = decode_mulaw(*Src
++) >> 8;
42 #define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
43 #define QUANT_MASK (0xf) /* Quantization field mask. */
44 #define SEG_SHIFT (4) /* Left shift for segment number. */
45 #define SEG_MASK (0x70) /* Segment field mask. */
46 #define BIAS (0x84) /* Bias for linear code. */
48 static WORD
decode_alaw (UBYTE a_val
) {
54 t
= (a_val
& QUANT_MASK
) << 4;
55 seg
= ((unsigned)a_val
& SEG_MASK
) >> SEG_SHIFT
;
67 return ((a_val
& SIGN_BIT
) ? t
: -t
);
70 static WORD
decode_mulaw(UBYTE u_val
) {
73 /* Complement to obtain normal u-law value. */
77 * Extract and bias the quantization bits. Then
78 * shift up by the segment number and subtract out the bias.
80 t
= ((u_val
& QUANT_MASK
) << 3) + BIAS
;
81 t
<<= ((unsigned)u_val
& SEG_MASK
) >> SEG_SHIFT
;
83 return ((u_val
& SIGN_BIT
) ? (BIAS
- t
) : (t
- BIAS
));