Digital Sound & Music: Concepts, Applications, & Science, Chapter 5, last updated 6/25/2013

56

It may be easier to see how this works if we start with sample values on a 16-bit scale

(i.e., between 32768 and 32767) and then scale the results of the mu-law function back to 8

bits. For example, what happens if we begin with sample values of 33, 66, 32145, and 32178?

(Notice that these normalize to 0.001, 0.002, 0.981, and 0.982, respectively, on a 1 to 1 scale.)

mu(33/32768) = 0.0412;

floor(128*0.0412) = 5;

mu(66/32768) = 0.0747;

floor(128* 0.0747) = 9;

mu(32145/32768) = 0.9966;

floor(128*0.9966) = 127;

mu(32178/32768) = 0.9967;

floor(128*0.9967) = 127;

The sample values 33 and 66 on a 16-bit scale become 5 and 9, respectively, on an 8-bit scale.

The sample values 32145 and 32178 both become 127 on an 8-bit scale. Even though the

difference between 66 and 33 is the same as the difference between 32178 and 32145, 66 and 33

fall to different quantization levels when they are converted to 8 bits, but 32178 and 32145 fall to

the same quantization level. There are more quantization levels at lower amplitudes after the

mu-law function is applied.

The result is that there is less error at low amplitudes, after requantization to 16 bits, than

there would have been if a linear quantization method had been used. Equation 5.6 shows the

function for expanding back to the original bit depth.

Let x be a -law encoded sample value, . Let

( )

if x is negative and

( ) otherwise. Then the inverse -law function is defined by

(

( )

( )

(

( )| |

)

( ) (

| |

)

)

Equation 5.6

Our original 16-bit values of 33 and 66 convert to 5 and 9, respectively, in 8 bits. We can

convert them back to 16 bits using the inverse mu-law function as follows:

mu_inverse(5/128) = .00094846

ceil(32768* .00094846) = 32

mu_inverse(9/128) = 0.0019

ceil(32768*0.0019) = 63

The original value of 33 converted back to 32. The original value of 66 converted back to 63.

On the other hand, look what happens to the higher amplitude values that were originally 32145

and 32178 and converted to 127 at 8 bits.

Programming

Exercise:

Mu-Law

Encoding

in C++