Digital Signal Processing Reference
In-Depth Information
int rcnew; /*right channel output */
int temp, dec;
//Left channel and right channel inputs
AIC23_data.combo ¼ input_sample();
lc ¼ (int) (AIC23_data.channel[LEFT]);
rc ¼ (int) (AIC23_data.channel[RIGHT]);
// Insert DSP algorithm below
/* Encoder :*/
tmp
lc; // for the Left Line In channel
if (tmp <0 )
{
tmp
¼
¼
-tmp; // Get magnitude bits to work with
}
tmp ¼ (tmp>>(16-nofbits));
PCMcode ¼ tmp&mask[nofbits-1]; // Get magnitude bits
if (lc> ¼ 0)
{
PCMcode ¼ PCMcode
j
sign[nofbits-1]; // Add sign bit
}
/* PCM code (stored in the lower portion) */
/* Decoder: */
dec ¼ PCMcode&mask[nofbits-1]; // Obtain magnitude bits
tmp ¼ PCMcode&sign[nofbits-1]; // Obtain the sign bit
dec ¼ (dec<<(16-nofbits)); // Scale to 15-bit magnitude
dec ¼ dec
j
rec[nofbits-1]; // Recover the midpoint of the quantization interval
lc ¼ dec;
if (tmp ¼¼ 0x00)
{
lc ¼ -dec; // Back to 2 ' s complement form (change the sign)
}
// End of the DSP algorithm
lcnew
¼
lc; /* Send to DAC */
rcnew
lc; /* Keep the original data */
AIC23_data.channel[LEFT]
¼
¼
(short) lcnew;
AIC23_data.channel[RIGHT]
(short) rcnew;
output_sample(AIC23_data.combo);
¼
}
C Program 11.2 demonstrates digital m -law encoding and decoding. It converts a 12-bit linear PCM
code to an 8-bit compressed PCM code using the principles discussed in Section 11.2 . Note that the
program only performs left-channel coding.
C Program 11.2. Digital m -law encoding and decoding.
int ulawcode;
/* Digital mu-law definition*/
// Sign-magnitude format: s segment quantization
// s ¼ 1 for the positive value, s ¼ 0 for the negative value
// Segment defines compression
// quantization with 16 levels
 
 
Search WWH ::




Custom Search