By solving analytically and numerically dynamical diffraction equations, we study the modulation of x-rays in ideal crystals by a co-propagating wave of impulsively excited optical phonons. Our results for a diamond crystal suggest that the output diffracted x-ray field can have a time structure much shorter than the period of the excited vibrational mode ( T v = 25 fs). We explain this dynamics in terms of high-order Raman scattering of x-rays by optical phonons. The potential of this ultrafast modulation technique for controlling x-rays from synchrotron and FEL sources is discussed.