The general idea behind a train horn - and really any air horn - is that the air flow through the horn is oscillating, causing sound waves. The way the air oscillates in a train horn in particular is via a metal diaphragm. When air is applied to the horn, the diaphragm starts vibrating back and forth. Since the position of the diaphragm at any given instant will allow more or less air through the horn, the constant oscillation of the diaphragm causes "waves" of air which produce audible sounds.
By looking at the color-coded picture below, it should be easier to understand these basic principles. (Original picture courtesy Glen Cleary, used with permission.) We will follow air through the horn to show how air will make the horn sound. First, air enters the inlet, or orifice, (yellow), usually by means of an air line to a manifold that combines each individual bell into the chime horn. Air entering this inlet will end up in the green chamber, which is initially sealed by the diaphragm (purple). The outer seal of the diaphragm is permanent (at least while the horn is assembled), while the inner seal is not. As pressure builds in this green chamber, the diaphragm is forced outwards, allowing air to escape across the nozzle (red). Escaping air is vented into the throat of the horn (blue), which opens up to the bell, or resonating chamber, to the atmosphere. When the pressure in the throat starts to meet or exceed the pressure in the green chamber, the diaphragm will return to its "resting position" (or close to it), sealing off (or nearly sealing) the green chamber against the nozzle again. This cycle repeats itself many times a second, so that the diaphragm is in constant motion, continually causing different amounts of air to enter the bell. Since the diaphragm moves in a repeatable pattern, the waves in the bell are generally consistent. Also, these waves have a low enough frequency to be in the audible sound range.
The part of the diaphragm that seals against the nozzle is sometimes called the clapper. The clapper and diaphragm disk(s) are not always the same disk, unlike the K horn in the diagram above. In a Nathan M horn, and the Wabco E-2 horn, the clapper is actually a smaller disk bolted (or riveted in the case of really old examples) to the larger diaphragm disks. In addition, the diaphragm isn't necessarily just one disk. Nathan M horns use 2-3 disks per bell, depending on which bell it is. Using multiple disks tends to stiffen the combined diaphragm, giving it a higher strength, yet letting it remain more flexible than a single thick diaphragm.
Inside the green chamber, you may also have what's known as a diffuser. This piece's sole purpose is to "diffuse" the air coming in from the orifice so that it more evenly distributes into the green chamber. The idea is to not wear out one side of the diaphragm as quickly. Nathan K and M horns and Leslie SuperTyfon horns all have a type of diffuser. In the photo above, the diffuser is the disk held in place with three hex-key bolts; the nozzle opens up underneath the diffuser.
A couple other terms commonly heard when talking about the operation of a horn are the head, power chamber, and diaphragm assembly/housing. These terms are basically the same component of the horn - the part of the horn consisting of the green chamber, nozzle, and diaphragm, along with the housing that encloses it all. The only reason there are so many terms is because each manufacturer has a different name for this assembly on their horns. For instance, Leslie uses "power chambers" on their SuperTyfon models, while Nathan M horns use "heads". I haven't heard anything specified for Nathan K or P horns, or Wabco horns, and so "diaphragm assembly/housing" is often used, though reuse of "head" and "power chamber" is also common. Also of note is that on K and P horns, as well as some Wabcos, the bell is physically attached to the diaphragm housing (except for the older K1L bells and some marine K horns with bronze heads), and so talking about the bell typically includes this component as well.
Now, let's cover the sounds produced by a horn, and why it may sound the way it does. The first variable that can effect the sound of a horn is the size of the orifice. Leslie SuperTyfon horns are available in variable-orifice (larger orifices on larger bells) as well fixed-orifice models. The larger the air inlet, the more air is admitted into the diaphragm chamber, and the louder the horn will be. I believe this is due to the diaphragm moving further each oscillation, causing the resulting sound waves to have a higher amplitude. Second, how the diaphragm oscillates causes a major difference in the tone of the horn. If the diaphragm oscillates without coming to rest against the nozzle each cycle, the waves produced will be more sinusoidal than if the clapper came into contact with the nozzle each cycle. The former will cause a more mellow sound with less harmonics (like the M series), where a the latter will cause a more brassy sound (like the P series). I've also noticed that bell thickness, and overall quantity of metal used in a horn's construction, will effect the tone. The heavier or thicker the castings, the richer the tone will be. I believe this is due to the fact that there is more metal to help resonate the sound, which helps explain the tonal differences in Leslie and Prime horns, which are otherwise nearly identical. Last, the type of diaphragm and nozzle will also help determine the sound of a horn. For example, P horns use a rubber nozzle and stainless diaphragm disk. Changing the stock stainless steel diaphragm to a phosphor bronze diaphragm, as done in some tests in the 70s, yielded a more mellow tone, bringing the sound closer to the M series, which use a phosphor bronze clapper, nozzle, and diaphragm disks. It should be noted that while these materials do have some impact, the other factors have a much higher impact on the sound of the horn.
Finally, we'll cover the most obvious determinant of the sound produced by a horn - the bell. Since I do not know all the physics behind the "why" on much of this, I will be speaking more from experience than science. It is my understanding that the bell length and shape alter the sound waves emitted by the power chamber, causing changes in what we hear. The volume of space in the bell before opening up to the atmosphere or flaring out past a certain point are also important. Beyond that the physics are above my understanding.
Bells for horns come in many different sizes and shapes. The length of the bell will help determine the pitch of the horn. All other factors being equal, the longer the bell, the lower the pitch. However, the inside throat diameter and bell diameter also seem to play a role. The greater the throat diameter, the lower the pitch. This seems to be part of the reason why a P5, with it's long, narrow-throated bells, plays the same chord as an M5, with its short, wide-throated bells. Also, it seems that the shape of the throat, and how fast it opens, help determine part of the tone, and volume of a horn. While I do not know why, it seems that an exponentially opening flare tends to produce a louder sound, perhaps as it helps project the sound waves better.