Combine the functions to write alaw and mulaw samples

The functionality is very similar. Reuse the basic functions and
substitute the companding function.