[go: up one dir, main page]

0% found this document useful (0 votes)
63 views2 pages

Fast Floating-Point To Mu-Law Conversion - Dspguru

This document describes a fast algorithm for converting floating point audio data to mu-law format. The algorithm takes advantage of similarities between the mu-law companding method and a poor man's floating point format. It limits samples to a range, adds a bias, extracts exponent and mantissa bits to quantize the value, adjusts it with a "magical" constant, and splices in the sign bit. The algorithm is presented in C but was implemented and tested in assembly on a DSP in only 7 cycles, providing a very fast conversion method when speed is needed.

Uploaded by

Bui Van Thanh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views2 pages

Fast Floating-Point To Mu-Law Conversion - Dspguru

This document describes a fast algorithm for converting floating point audio data to mu-law format. The algorithm takes advantage of similarities between the mu-law companding method and a poor man's floating point format. It limits samples to a range, adds a bias, extracts exponent and mantissa bits to quantize the value, adjusts it with a "magical" constant, and splices in the sign bit. The algorithm is presented in C but was implemented and tested in assembly on a DSP in only 7 cycles, providing a very fast conversion method when speed is needed.

Uploaded by

Bui Van Thanh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/16/2018 DSP Trick: Fast Floating-Point to mu-Law Conversion - dspGuru

Home FAQs Tutorials HowTos Tricks Library Blog About  Search

by Iowegian International

DSP Trick: Fast Floating-Point to mu-Law Conversion

From: Jim Thomas DSP Design Tools


Subject: Fast floting point to mu-law conversion
Date: 6 May 1999
THIS WORK IS PLACED IN THE PUBLIC DOMAIN

Name: Fast floating point to mu-law conversion


Category: Algorithmic
Application: When you need to convert audio data to mu-law and don't have a lot of time to mess
around.
Advantages: Very Fast (I implemented this in a seven cycle loop on a Sharc processor).
Introduction: This trick is based upon the happy coincidence that mu-law compressed data is very
much like a poor man’s floating point format. Mu-law is a companding method fully descried in the ITU
specification G.711. I believe this algorithm to be fully compliant.
The Trick: The algorithm is performed in a few steps. The steps are described below. Although I have
implemented and tested this approach in assembly on a Sharc, I am not at liberty to post the code (I
do not own it). This approach will work when the data is already in floating-point format as per IEEE
754. Other floating point formats (i.e. Texas Instruments) may work as well, but will require
adaptation. The input data is expected to range from -1.0 to +1.0. I present a C algorithm, which will
not be fast, but should get the basic idea across.

#define MAX (8031.0/8192.0)


#define BIAS (33.0/8192.0)
#define MAGIC (0x16f)
float x;
long mu;
long *x_as_long;
/* limit the sample between +/- max and take absolute value */
x = input_sample;
if ((x < -MAX) || (x > MAX))
x = MAX;
else if (x < 0)
x = -x;
/* add bias */
x += BIAS;
/* Extract the segment and quantization bits from the exponent and the
mantissa. Since we have limited the range of the signal already, the
exponent will be well restricted. The pointer "x_as_long" is used to
avoid unwanted type conversion. In assembly, this is easy. */
x_as_long = (long*)&x;
mu = (*x_as_long >> 19) & 0xff;
/* Unfortunately, mu needs a slight (but magical) adjustment */
mu = MAGIC - mu;
/* All that remains is to splice in the sign bit */
if (input_samle >= 0)
mu |= 0x80;

dspGuru > DSP > Tricks > DSP Trick: Fast Floating-Point to mu-Law Follow Us
Conversion

Contact Twitter Facebook

© 1999-2017 Iowegian International Corporation

https://dspguru.com/dsp/tricks/fast-floating-point-to-mu-law-conversion/ 1/2
3/16/2018 DSP Trick: Fast Floating-Point to mu-Law Conversion - dspGuru

https://dspguru.com/dsp/tricks/fast-floating-point-to-mu-law-conversion/ 2/2

You might also like