Theory of spin-wave generation in nonuniform magnetic fields