Article View: comp.dsp
Article #475Re: SPARCStation audio conversion (ulaw <-> linear)
From: Jef Poskanzer
Date: Mon, 23 Oct 1989 16:12
Date: Mon, 23 Oct 1989 16:12
73 lines
3864 bytes
3864 bytes
In the referenced message, cfreese@super.UUCP (Craig F. Reese) wrote:
}Below are two routines I wrote for converting between ulaw and linear.
}I use them with the SparcStation and they seem to work fine.
Thanks, those will be very useful.
Since I haven't seen anyone else post it, appended is the obvious
table-lookup version of Craig's ulaw to linear converter. I did
some timings on a SPARCstation. In nanoseconds:
counting subroutine call not counting subroutine call
old new old new
1217 557 913 253
Also, the table in interesting in its own right, to get a feel for
just what ulaw does. Corrections welcome, otherwise enjoy.
---
Jef
Jef Poskanzer pokey@well.sf.ca.us {ucbvax, apple, hplabs}!well!pokey
Specifications subject to change without notice.
/*
** This routine converts from ulaw to 16 bit linear, but faster.
**
** Jef Poskanzer
** 23 October 1989
**
** Input: 8 bit ulaw sample
** Output: signed 16 bit linear sample
*/
int
ulaw2linear(ulawbyte)
unsigned char ulawbyte;
{
static int ulaw_table[] = {
-32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
-23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
-15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
-11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
-7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
-5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
-3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
-2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
-1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
-1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
-876, -844, -812, -780, -748, -716, -684, -652,
-620, -588, -556, -524, -492, -460, -428, -396,
-372, -356, -340, -324, -308, -292, -276, -260,
-244, -228, -212, -196, -180, -164, -148, -132,
-120, -112, -104, -96, -88, -80, -72, -64,
-56, -48, -40, -32, -24, -16, -8, 0,
32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
876, 844, 812, 780, 748, 716, 684, 652,
620, 588, 556, 524, 492, 460, 428, 396,
372, 356, 340, 324, 308, 292, 276, 260,
244, 228, 212, 196, 180, 164, 148, 132,
120, 112, 104, 96, 88, 80, 72, 64,
56, 48, 40, 32, 24, 16, 8, 0 };
return ulaw_table[ulawbyte];
}
Technical Details
Message-ID:
<14239@well.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!gem.mps.ohio-state.edu!apple!well!pokeyReferences:
<14899@super.ORG>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!gem.mps.ohio-state.edu!apple!well!pokey From: pokey@well.UUCP (Jef Poskanzer) Newsgroups: comp.dsp Subject: Re: SPARCStation audio conversion (ulaw <-> linear) Message-ID: <14239@well.UUCP> Date: 23 Oct 89 16:12:49 GMT References: <14899@super.ORG> Reply-To: Jef Poskanzer <pokey@well.sf.ca.us> Organization: Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal Lines: 73