Skip to contentSkip to conversation

signed/unsigned pcm formats

DISCUSSION Nicolas Hüppelshäuser 2 participants 2 messages Sep 7, 2004 – Sep 8, 2004

lore
Share & tools
lore
#0 lore raw

Hi everybody!

I would like to know how pcm data is encoded.
What is the value range of a signed format type of data width x? For 8 bit I would expect -127,...,128.

How is this range encoded in unsigned type of equal bit width? Is, for 8 bit width, signed -127,...,0 mapped to unsigned 0,...,127 and signed 1,...,128 to unsigned 128,...,255? Or is it hardware dependent?

Viele Gruesse / best regards
Nicolas Hueppelshaeuser
--
nicolas hueppelshaeuser, emlix gmbh, http://www.emlix.com,
mailto:[email protected]
fon +49 551 37000-37, fax -38, keplerstrasse 24, 37085 goettingen, germany

emlix - your embedded linux partner

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#1 lore raw
Quoted 1 line · Nicolas Hüppelshäuser

What is the value range of a signed format type of data width x?

Without the sign, there are x-1 bits for the value, so the maximum value is 2^(x-1)-1. Negative values are stored as two's complement, so the minimum value is -(2^(x-1)).

Quoted 1 line

For 8 bit I would expect -127,...,128.

It's -128 ... 127.

Quoted 1 line

How is this range encoded in unsigned type of equal bit width?

Add/subtract 128 (which is the equivalent of flipping the most significant bit).

Quoted 1 line

Or is it hardware dependent?

SND_PCM_FORMAT_U8 is defined as above. If there would be any hardware using a different unsigned format (there isn't), another PCM_FORMAT_ would have to be defined.

HTH
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id808&op=click