Fix portaudio encoding

These patches fix problems with the PortAudio audio code.  See the commits for descriptions.