Spectrally resolved gain dynamics of a semiconductor optical amplifier for the amplification of multiwavelength pulses