title: Python u-Law (MULAW) wave decompression to raw wave signal
body: <p>I googled this issue for last 2 weeks and wasn't able to find an algorithm or solution. I have some short .wav file but it has MULAW compression and python doesn't seem to have function inside <code>wave.py</code> that can successfully decompresses it. So I've taken upon myself to build a decoder in python.  </p>
  
  <p>I've found some info about MULAW in basic elements:  </p>
  
  <ol>
  <li><a href="https://en.wikipedia.org/wiki/%CE%9C-law_algorithm#Algorithm_types" rel="nofollow noreferrer">Wikipedia</a>  </li>
  <li><a href="http://www.ti.com/lit/an/spra349/spra349.pdf" rel="nofollow noreferrer">A-law u-Law comparison</a>  </li>
  <li><a href="http://www.jot.fm/issues/issue_2008_11/column2.pdf" rel="nofollow noreferrer">Some c-esc codec library</a>  </li>
  </ol>
  
  <p>So I need some guidance, since I don't know how to approach getting from signed short integer to a full wave signal. This is my initial thought from what I've gathered so far:  </p>
  
  <hr>
  
  <p>So from wiki I've got a equation for u-law compression and decompression :  </p>
  
  <p>compression :  <a href="https://i.stack.imgur.com/pWJ6C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pWJ6C.png" alt="compression "></a>  </p>
  
  <p>decompression :  <a href="https://i.stack.imgur.com/P3o5p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3o5p.png" alt="enter image description here"></a>  </p>
  
  <p>So judging by compression equation, it looks like the output is limited to a <code>float</code> range of -1 to +1 , and with signed short integer from –32,768 to 32,767 so it looks like I would need to convert it from <strong><code>short int</code></strong> to <strong><code>float</code></strong> in specific range.   </p>
  
  <p>Now, to be honest, I've heard of quantisation before, but I am not sure if I should first try and dequantize and then decompress or in the other way, or even if in this case it is the same thing... the tutorials/documentation can be a bit of tricky with terminology. </p>
  
  <p>The wave file I am working with is supposed to contain 'A' sound like for speech synthesis, I could probably verify success by comparing 2 waveforms in some audio software and custom wave analyzer but I would really like to diminish trial and error section of this process. </p>
  
  <p>So what I've had in mind:  </p>
  
  <pre><code>u = 0xff
  data_chunk = b'\xe7\xe7' # -6169
  data_to_r1 = unpack('h',data_chunk)[0]/0xffff # I suspect this is wrong,
  #                                             # but I don't know what else
  
  u_law = ( -1 if data_chunk&lt;0 else 1 )*( pow( 1+u, abs(data_to_r1)) -1 )/u   
  </code></pre>
  
  <p>So is there some sort of algorithm or crucial steps I would need to take in form of <strong>first</strong>: <em>decompression</em>, <strong>second</strong>: <em>quantisation</em> : <strong>third</strong> ?<br>
  Since everything I find on google is how to read a <code>.wav</code> PCM-modulated file type, not how to manage it if wild compression arises. </p>