The locomotive engineers blow the whistles when going across crossings to warn pedestrians and vehicles. It is a federal violation for an engineer not to blow the whistle and they can lose their jobs over it. There is actually the equivalent of an airplane's black box recording the train's movements, speed, and whether or not the engineer blew the whistle the appropriate way.
The length of time the engineer holds each blow is subjective. Some just do a quick toot and others love to hold a long note. There is a certain series of blows mandated for crossings. Something like long-short-long, I think.