Properly handle planar audio and resample when needed
Fix various memory leaks