QUOTE(SebastianG @ Jul 3 2008, 21:20)

QUOTE(benski @ Jul 4 2008, 04:20)

The LSB requirement prevents the use of dither to improve the audio quality.
You certainly can add dithering:
CODE
// val16 == int16_t sample
int32_t bit = (val16 & 1) << 8;
int32_t dither = ...; // unsigned 9 bit random number (0..511)
int32_t q = (val16 + dither + 32768 - bit) & ~((int32_t)0x1FF);
if (q<0) q=0; else if (q>0xFE00) q=0xFE00;
uint8_t q8 = (q+bit) >> 8;
Thanks for your help. I transplant this code to matlab. Here is the code.
[x,fs,nbits] = wavread(filename);
x = fix((x+1)*32768);
x = uint16(x);
bit = bitshift(uint16(bitand(x,uint16(1))),8);
dither = ....; % rand number 0..511
dither = uint16(dither);
temp1 = x + dither + 32768 - x;
temp2 = uint16(65024);
q = bitand(temp1,temp2);
q(find(q<0)) = 0;
q(find(q>65024)) = 65024;
y = bitshift(q+x,-8);
After testing the code, i found that all of the y are below 256, that is all y<256. If the signal y is normal, the value of y may be in the range [0 512]. That is if we read 8bit audio, take procedure as follows :
[y,fs,nbits] = wavread(filename); % 8bits audio
y = (y+1)*256;
then all the y must in the range [0 512], but the tranplating code cant get this result, the new y is out of nomal.What is problem, and how can sovle it? Please help me!
Best regards!