AUDIO_ULAW2LINEAR(3)

NAME
audio_ulaw2linear, audio_u2c, audio_u2s, audio_u2l, audio_c2u, audio_s2u, audio_l2u - μ-law data conversions

DISCLAIMER

The manual pages, header files, and object library associated with /usr/demo/SOUND/libaudio.a are furnished on an AS IS basis as a preliminary interface to several useful audio data-processing capabilities. A future release of the operating system may redefine the syntax or semantics of some of the functions described herein.

SYNOPSIS
#include <multimedia/ulaw2linear.h>

char audio_u2c(ulaw)
unsigned char ulaw;

short audio_u2s(ulaw)
unsigned char ulaw;

long audio_u2l(ulaw)
unsigned char ulaw;

unsigned char audio_c2u(pcm)
char pcm;

unsigned char audio_s2u(pcm)
short pcm;

unsigned char audio_l2u(pcm)
long pcm;

DESCRIPTION
These macros are designed to make conversion to and from the format used by the SPARCstation audio chip as easy and fast as possible.

The audio chip processes data encoded using μ-law companding, a technique that allows Pulse Code Modulated (PCM) data to be compressed to 8 bits. The resulting data word contains 7 bits of magnitude and a high-order sign bit. By convention, the data is also subjected to a one's-complement; the zero value (i.e., half-scale) is therefore represented by the μ-law value 0xFF.

The μ-law transfer function results in a nearly linear relationship to PCM at low amplitudes and a logarithmic relationship at high amplitudes. Thus, it is not reasonable to perform arithmetic operations (such as would be performed on PCM data) directly on the encoded data. For instance, to sum two μ-law values, the following two lines of code will give very different answers (the second is correct):
	wrong = (ulaw1 + ulaw2);
	right = audio_s2u(audio_u2s(ulaw1) + audio_u2s(ulaw2));

audio_u2c(), audio_u2s(), and audio_u2l() convert μ-law data to PCM signed integers of 8, 16, or 32 bit precision, respectively. Since μ-law data represents approximately 13 bits of precision to begin with, the conversion to 8-bit integers loses precision, while the conversion to 32-bit integers is provided merely as a convenience.

audio_c2u(), audio_s2u(), and audio_l2u() convert 8, 16, and 32 bit PCM signed integers to their μ-law encoded form.

SEE ALSO
audio_convert(3).