DSPRelated.com
Forums

8bit to 16bit conversion

Started by Kunal February 26, 2006
Hi,

I have a code which captures 8bit speech samples from audio port and
dumps it into a file. The codec that I am using uses 16 bit values. I
am looking to convert the 8 bit values to 16 bit. I used the following

short temp16 =  (short)val[i] << 8 ;

where val is an  array of 8 bit samples.

The above statement makes the resultant speech waveform extremely
noisy. Can anybody suggest a method for 8bit to 16bit conversion ?

Regards

KL

It's not any noisier, just much louder because of the left shift by 8. Try
just sign extending the samples to 16 bits:

e.g.

if val[i] &0x80
    temp16 = 0xff00 | val[i];
else
    temp16 = val[i];


"Kunal" <kunal.lagwankar@gmail.com> wrote in message
news:1140958351.945044.266630@i39g2000cwa.googlegroups.com...
> Hi, > > I have a code which captures 8bit speech samples from audio port and > dumps it into a file. The codec that I am using uses 16 bit values. I > am looking to convert the 8 bit values to 16 bit. I used the following > > short temp16 = (short)val[i] << 8 ; > > where val is an array of 8 bit samples. > > The above statement makes the resultant speech waveform extremely > noisy. Can anybody suggest a method for 8bit to 16bit conversion ? > > Regards > > KL >
Anonymous wrote:
> It's not any noisier, just much louder because of the left shift by 8. Try > just sign extending the samples to 16 bits: > > e.g. > > if val[i] &0x80 > temp16 = 0xff00 | val[i]; > else > temp16 = val[i]; >
8-bit codecs usually (AFAIK, always) output unsigned values (range 0 to 255), whereas 16bit samples are always signed (2s complement): range -32768 to 32767. So before the left shift, one has to subtract 128 from the 8-bit value: short samp16 = (samp8 - 128) << 8; Rendering it one may be more aware of the 8-bit truncation noise, but there will not be any ~added~ noise. Richard Dobson
On Sun, 26 Feb 2006 15:14:50 GMT, Richard Dobson
<richarddobson@blueyonder.co.uk> wrote:

>Anonymous wrote: >> It's not any noisier, just much louder because of the left shift by 8. Try >> just sign extending the samples to 16 bits: >> >> e.g. >> >> if val[i] &0x80 >> temp16 = 0xff00 | val[i]; >> else >> temp16 = val[i]; >> > >8-bit codecs usually (AFAIK, always) output unsigned values (range 0 to 255), >whereas 16bit samples are always signed (2s complement): range -32768 to 32767. >So before the left shift, one has to subtract 128 from the 8-bit value: > > short samp16 = (samp8 - 128) << 8; > >Rendering it one may be more aware of the 8-bit truncation noise, but there will >not be any ~added~ noise.
Some 8-bit codecs will output A-law or Mu-law values. The OP should clarify what "8bit speech samples from audio port" actually means. Regards, Allan
Hi

The samples being read from the audio port are raw values. I am dumping
the 8-bit values into a file. The file when opened using Cooledit plays
properly.
I dont think the values read from the audio port are compressed.

I will try out the things given here.

Regards
KL

Kunal wrote:
> Hi > > The samples being read from the audio port are raw values. I am dumping > the 8-bit values into a file. The file when opened using Cooledit plays > properly. > I dont think the values read from the audio port are compressed. > > I will try out the things given here. > > Regards > KL
Hi KL if you are using matlab's sound function to playback the audio then you should normalize the shifted signal in the range of -1.0 <= x <= 1.0. It will be played with out any distortion. Regards, gold
Richard Dobson wrote:
> > 8-bit codecs usually (AFAIK, always) output unsigned values (range 0 to 255),
Sorry Richard, but thats not right. When 8 bit PCM samples are stored in WAV files, they are stored as unsigned 8 bit values as you suggest. However, AIFF, AU and other file formats store signed 8 bit values (-128 to 127). Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ Virgins? What virgins? Its 72 raisins! http://www.guardian.co.uk/religion/Story/0,2763,631357,00.html
Erik de Castro Lopo wrote:
> Richard Dobson wrote: > >>8-bit codecs usually (AFAIK, always) output unsigned values (range 0 to 255), > > > Sorry Richard, but thats not right. When 8 bit PCM samples are stored > in WAV files, they are stored as unsigned 8 bit values as you suggest. > However, AIFF, AU and other file formats store signed 8 bit values > (-128 to 127). > > Erik
Yes, indeed, file formats can be unipolar or bipolar. I was thinking more of the hardware, since the OP refers to a "codec", which I still tend to think of as hardware more than software. Most of the 8bit audio-rate ADC chips I remember looking at were unipolar; some offered the option of both unipolar and bipolar conversion. But I got the firm impression that for a bog-standard successive-approx ADC, the "normal" configuration was unipolar (e.g. for simple single-rail powering). Maybe modern chips are different? I last looked seriously at 8bit ADC designs at least a decade ago! Richard Dobson
Richard Dobson wrote:
> Erik de Castro Lopo wrote: > >> Richard Dobson wrote: >> >>> 8-bit codecs usually (AFAIK, always) output unsigned values (range 0 >>> to 255), >> >> >> >> Sorry Richard, but thats not right. When 8 bit PCM samples are stored >> in WAV files, they are stored as unsigned 8 bit values as you suggest. >> However, AIFF, AU and other file formats store signed 8 bit values >> (-128 to 127). >> >> Erik > > > Yes, indeed, file formats can be unipolar or bipolar. I was thinking > more of the hardware, since the OP refers to a "codec", which I still > tend to think of as hardware more than software. Most of the 8bit > audio-rate ADC chips I remember looking at were unipolar; some offered > the option of both unipolar and bipolar conversion. But I got the firm > impression that for a bog-standard successive-approx ADC, the "normal" > configuration was unipolar (e.g. for simple single-rail powering). Maybe > modern chips are different? I last looked seriously at 8bit ADC designs > at least a decade ago!
The only difference between a unipolar and an offset-binary ADC is a half-scale offset to the analog input. The only difference between an offset-binary and a twos-complement ADC is inversion of the MSB. Offset is in any event needed to deal with bipolar audio. The polarity of the MSB is a trivial matter. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Hi all,

I have successfully converted 8-bit samples to 16-bit values for my
16-bit codec. However I am facing another problem now. The 16-bit
values that I read from the port are very large. Even at times when no
speech exists (and only noise exists), the sample values are very
large.

I found some standard speech test sequences on the net which had very
small values as compared to the 16-bit samples file I have generated.

To add to my problems, I found that I get very less compression for the
16-bit samples file generated by me and the compression for the
standard test sequence is very large. I tried scaling the values down
but it didnt help.

I am using G.729AB as the codec.

Regards
KL