• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Guidance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guidance


  • Subject: Re: Guidance
  • From: Michael Thornburgh <email@hidden>
  • Date: Mon, 14 Apr 2003 02:06:33 -0700

there are two pieces to this problem: sample rate conversion, and 5-law
coding/decoding.

for sample rate conversion, you can use AudioConverter in the AudioToolbox
framework. however, i personally find the pull-model of AudioConverter to be
a PITA for this kind of application, and wrote my own, simple, push-based
sample rate converter. you are (or anyone on the list is) welcome to use it --
the framework of which it's a part will one day (when i'm less lazy) be as
open-sourcey as MTCoreAudio. contact me off-list if you'd like a copy.

the 5-law coding/decoding problem is much easier. here are routines to
initialize conversion tables and to convert from linear to 5-law; to convert
from 5-law to linear, just use the "ulaw2linear" table in the obvious way. :)

---

static UInt8 linear2ulaw[8159];
static Float32 ulaw2linear[256];

static void init_ulaw()
{
UInt32 x;
UInt8 segment;
UInt32 tmp;

segment = 0x00;
for ( x = 33; x < 64; x++ )
linear2ulaw[x - 33] = ((( x >> 1 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x10;
for ( x = 64; x < 128; x++ )
linear2ulaw[x - 33] = ((( x >> 2 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x20;
for ( x = 128; x < 256; x++ )
linear2ulaw[x - 33] = ((( x >> 3 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x30;
for ( x = 256; x < 512; x++ )
linear2ulaw[x - 33] = ((( x >> 4 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x40;
for ( x = 512; x < 1024; x++ )
linear2ulaw[x - 33] = ((( x >> 5 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x50;
for ( x = 1024; x < 2048; x++ )
linear2ulaw[x - 33] = ((( x >> 6 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x60;
for ( x = 2048; x < 4096; x++ )
linear2ulaw[x - 33] = ((( x >> 7 ) & 0xf ) + segment ) ^ 0x7f;
segment = 0x70;
for ( x = 4096; x < 8192; x++ )
linear2ulaw[x - 33] = ((( x >> 8 ) & 0xf ) + segment ) ^ 0x7f;

for ( x = 0; x < 256; x++ )
{
segment = (( x & 0x70 ) >> 4) & 0x7;
tmp = ( 1 << ( segment + 5 )) + (( x & 0x0f ) << ( segment + 1 )) - 32;
if ( x < 128 )
ulaw2linear[x ^ 0x7f] = ((double)tmp) * ( 1.0 / 8158.0 );
else
ulaw2linear[x ^ 0x7f] = ((double)tmp) * ( -1.0 / 8158.0 );
}
}

static inline UInt8 convertLinearToulaw ( Float32 sample )
{
UInt8 rv = 0;

if ( sample < 0.0 )
{
rv = 0x80;
sample = -sample;
}
if ( sample > 1.0 )
{
sample = 1.0;
}
rv |= linear2ulaw[(unsigned)(sample * 8158.0 )];
return rv;
}


---

-mike


On Monday, April 14, 2003, at 12:35 AM, Matthew Johnson wrote:

Hello All,

I am working on a simple OSX program that takes audio from a microphone and
writes it down a socket in real time. Reads audio and plays it through the
speakers in real time. I have the playback and record working fine for 48khz
which is the hardware default for device I am using.

My problem is that the audio must be read and written in 8khz ulaw format
and I have no idea how to go about this.

Can someone come up with a suggestions on how this is done on the mac osx?

Thanks,

Matt Johnson
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

References: 
 >Guidance (From: Matthew Johnson <email@hidden>)

  • Prev by Date: Multiple output devices under CoreAudio with Quicktime
  • Next by Date: Re: Multiple output devices under CoreAudio with Quicktime
  • Previous by thread: Guidance
  • Next by thread: Multiple output devices under CoreAudio with Quicktime
  • Index(es):
    • Date
    • Thread