Fix memory corruption for waveforms larger than 4096^2.

Potentially fixes Bug #1383404.