Added wave-in support and fixed a few bugs in the wave-out code.