The aerodynamics causing the pressure difference of the air between the outside and the inside of the car.
If the airflow over the roof remains attached, i.e. laminar, then the buffeting noise will be much less. If the airflow is turbulent, noise levels will be enhanced.
This can be explained by complex 'Boundary Layer Theory'.
The buffeting can be quite bad on some cars where not enough attention has been paid to the positioning of the sunroof and to the height and orientation of the wind deflector.
So if the opening is too large, the pressure difference will be greater and the buffeting noise levels will increase.
Reduce the size of the opening by slightly closing the roof or reduce the pressure difference by dropping a window.
Can't be bothered with sunroofs myself.