Shaping lightwaves in time and frequency for optical fiber communication