Wow, really not trying to give a lecture. I thought you wanted an answer to your question. I gave links that shared information specifically:
Sounding the Locomotive Horn: Under the Train Horn Rule, locomotive engineers must sound train horns for a minimum of 15 seconds, and a maximum of 20 seconds, in advance of all public grade crossings, except:
• If a train is traveling faster than 45mph, engineers will not sound the horn until it is within ¼ mile of the crossing, even if the advance warning is less than 15 seconds.
• If a train stops in close proximity to a crossing, the horn does not have to be sounded when the train begins to move again.
• There is a “good faith” exception for locations where engineers can’t precisely estimate their arrival at a crossing.
Wherever feasible, train horns must be sounded in a standardized pattern of 2 long, 1 short and 1 long. The horn must continue to sound until the lead locomotive or train car occupies the grade crossing.
For the first time, a maximum volume level for the train horn has been established at 110 decibels. The minimum sound level remains 96 decibels. Railroads have until 2010 to fully comply with the maximum volume level requirement.
The FRA has an administrative rule, which allows certain communities to apply for “quiet zones” if the rule’s requirements are met. Once the rule’s requirements are met, the locomotive would not sound its horn when passing through the crossing in most instances. See 49 Code of Federal Regulations part 222 for those requirements.
Freight trains don’t sound their horn any differently than passenger trains do, the difference you are observing has to do with where the tracks are.
The Federal Law regarding train horns is here